Skip to content

Commit

Permalink
test: try using loadscope instead of loadgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
darwintree committed Dec 17, 2024
1 parent 274151f commit c53edea
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
export USE_TESTNET=1 &&
export ENS_ACCOUNT_NAME=${{secrets.ENS_ACCOUNT_NAME}} &&
export ENS_ACCOUNT_SECRET=${{secrets.ENS_ACCOUNT_SECRET}} &&
pytest --cov tests -n 3 --dist loadgroup
pytest --cov tests -n 4 --dist loadscope
- name: Upload coverage reports to Codecov
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/local-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
pip install ".[tester]"
- name: Run test
run: |
pytest tests -vv -n 3 --dist loadgroup
pytest tests -vv -n 4 --dist loadscope
2 changes: 1 addition & 1 deletion .github/workflows/testnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
export ENS_ACCOUNT_NAME=${{secrets.ENS_ACCOUNT_NAME}} &&
export ENS_ACCOUNT_SECRET=${{secrets.ENS_ACCOUNT_SECRET}} &&
export TEST_FINALIZATION=1 &&
pytest tests -vv -n 3 --dist loadgroup
pytest tests -vv -n 4 --dist loadscope
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ doc: rm-doc gen-doc-config
# make html

test:
pytest tests && export USE_TESTNET=1 && pytest tests
pytest tests -vv -n 4 --dist loadscope
# && export USE_TESTNET=1 && pytest tests
# cd ./docs && make doctest
10 changes: 5 additions & 5 deletions tests/cns/test_cns.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_cns_with_rpc(w3: Web3, use_testnet: bool, ens_name: str):
with pytest.raises(NameServiceNotSet):
balance = w3.cfx.get_balance("hello45678oiuytrrtyuiytredcv.web3")

@pytest.mark.xdist_group(name="account")

def test_cns_usage_as_contract_param(w3: Web3, to_test_cns_write_api: bool, account: LocalAccount, ens_name: str):
if to_test_cns_write_api:
w3.cfx.default_account = account
Expand All @@ -51,7 +51,7 @@ def test_cns_usage_as_contract_param(w3: Web3, to_test_cns_write_api: bool, acco
assert erc20.functions.transfer(ens_name, 100).transact().executed()
assert erc20.caller.balanceOf(ens_name) == 100

@pytest.mark.xdist_group(name="account")

def test_cns_as_sender(w3: Web3, to_test_cns_write_api: bool, ens_account: LocalAccount, ens_name: bool):
if to_test_cns_write_api:
w3.wallet.add_account(ens_account)
Expand All @@ -61,7 +61,7 @@ def test_cns_as_sender(w3: Web3, to_test_cns_write_api: bool, ens_account: Local
"from": ens_name
}).executed()

@pytest.mark.xdist_group(name="account")

def test_cns_as_contract_address(w3: Web3, to_test_cns_write_api: bool):
if to_test_cns_write_api:
faucet = w3.cfx.contract("faucet.web3", name="Faucet", with_deployment_info=False)
Expand All @@ -84,7 +84,7 @@ def test_cns_owner(w3: Web3, use_testnet: bool, ens_name: str):
# w3.cfx.default_account = account
# w3.cns.setup_owner("test.web3", wrapped=True)

@pytest.mark.xdist_group(name="account")

def test_setup_address(w3: Web3, to_test_cns_write_api: bool, ens_account: LocalAccount):
if to_test_cns_write_api:
w3.cns.allow_unstable_api = True
Expand All @@ -103,7 +103,7 @@ def test_cns_wallet(w3: Web3, use_testnet: bool):
if use_testnet:
assert w3.wallet is w3.cns.w3.wallet

@pytest.mark.xdist_group(name="account")

def test_cns_default_account(w3: Web3, use_testnet: bool, account: LocalAccount):
if use_testnet:
w3.cfx.default_account = account
Expand Down
3 changes: 1 addition & 2 deletions tests/middleware/test_pending.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
if TYPE_CHECKING:
from conflux_web3 import Web3

@pytest.mark.order(1)
@pytest.mark.xdist_group(name="pending")
@pytest.mark.order(1)
def test_pending(w3: "Web3", account: LocalAccount, use_testnet: bool):
# activate by default
# w3.middleware_onion.add(PendingTransactionMiddleware)
Expand Down
16 changes: 8 additions & 8 deletions tests/middleware/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
SignAndSendRawMiddlewareBuilder
)

@pytest.mark.xdist_group(name="account")

def test_wallet_middleware_single_init(w3:Web3, account: LocalAccount):
wallet = construct_sign_and_send_raw_middleware(account, w3.cfx.chain_id)
w3.middleware_onion.add(wallet)
Expand All @@ -29,7 +29,7 @@ def test_wallet_middleware_single_init(w3:Web3, account: LocalAccount):
assert hash
w3.cfx.wait_for_transaction_receipt(hash)

@pytest.mark.xdist_group(name="account")

def test_wallet_middleware_single_init_by_builder(w3:Web3, account: LocalAccount):
wallet = SignAndSendRawMiddlewareBuilder.build(account, w3.cfx.chain_id)
w3.middleware_onion.inject(wallet, layer=0)
Expand All @@ -48,7 +48,7 @@ def test_wallet_middleware_single_init_by_builder(w3:Web3, account: LocalAccount
assert hash
w3.cfx.wait_for_transaction_receipt(hash)

@pytest.mark.xdist_group(name="account")

def test_no_chain_id_wallet_middleware_single_init(w3:Web3, account: LocalAccount):
wallet = construct_sign_and_send_raw_middleware(account)
w3.middleware_onion.add(wallet)
Expand All @@ -67,7 +67,7 @@ def test_no_chain_id_wallet_middleware_single_init(w3:Web3, account: LocalAccoun
assert hash
w3.cfx.wait_for_transaction_receipt(hash)

@pytest.mark.xdist_group(name="account")

def test_wallet_middleware_list_init(w3:Web3, account: LocalAccount):
wallet = Wallet([account], w3.cfx.chain_id)
w3.middleware_onion.add(wallet)
Expand All @@ -86,7 +86,7 @@ def test_wallet_middleware_list_init(w3:Web3, account: LocalAccount):
assert hash
w3.cfx.wait_for_transaction_receipt(hash)

@pytest.mark.xdist_group(name="account")

def test_wallet_middleware_adding(w3: Web3, account: LocalAccount):
wallet = Wallet(forced_chain_id=w3.cfx.chain_id)
wallet.add_accounts([account])
Expand All @@ -106,7 +106,7 @@ def test_wallet_middleware_adding(w3: Web3, account: LocalAccount):
assert hash
w3.cfx.wait_for_transaction_receipt(hash)

@pytest.mark.xdist_group(name="account")

def test_default_wallet_middleware_adding(w3: Web3, account: LocalAccount):
w3.wallet.add_accounts([account])
tx = {
Expand Down Expand Up @@ -178,7 +178,7 @@ def test_wallet_pop():
assert wallet.pop(account.address).address == account.address
assert account.address not in wallet

@pytest.mark.xdist_group(name="account")

def test_wallet_middleware_sign_1559_transaction(w3:Web3, account: LocalAccount):
wallet = construct_sign_and_send_raw_middleware(account, w3.cfx.chain_id)
w3.middleware_onion.add(wallet)
Expand All @@ -198,7 +198,7 @@ def test_wallet_middleware_sign_1559_transaction(w3:Web3, account: LocalAccount)
assert tx_data['type'] == 2
hash.executed()

@pytest.mark.xdist_group(name="account")

def test_wallet_middleware_sign_legacy_transaction(w3:Web3, account: LocalAccount):
wallet = construct_sign_and_send_raw_middleware(account, w3.cfx.chain_id)
w3.middleware_onion.add(wallet)
Expand Down
2 changes: 1 addition & 1 deletion tests/rpcs/cfx/filter/test_log_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def contract(self, moduled_w3: Web3):
assert contract_address is not None
return w3.cfx.contract(contract_address, name="ERC20")

@pytest.mark.xdist_group(name="account")

def test_log_filter(self, moduled_w3: Web3, contract: ConfluxContract):
log_filter_id = moduled_w3.cfx.new_filter(address = contract.address)
contract.functions.transfer(contract.address, 1**18).transact().executed()
Expand Down
2 changes: 1 addition & 1 deletion tests/rpcs/cfx/filter/test_pending_tx_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tests._test_helpers.type_check import TypeValidator

class TestPendingTxFilter:
@pytest.mark.xdist_group(name="account")

def test_pending_tx_filter(self, moduled_w3: Web3):
pending_tx_filter_id = moduled_w3.cfx.new_pending_transaction_filter()
constucted_pending_tx = moduled_w3.cfx.send_transaction({
Expand Down
22 changes: 11 additions & 11 deletions tests/rpcs/cfx/test_cfx_account_query_rpcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from tests._test_helpers.type_check import TypeValidator

class TestAccountQuery:
@pytest.mark.xdist_group(name="account")

def test_get_balance(self, w3: Web3, address: Base32Address):
balance = w3.cfx.get_balance(address, w3.cfx.epoch_number-5)
# the balance is supposed to be non-zero
Expand All @@ -19,14 +19,14 @@ def test_get_balance(self, w3: Web3, address: Base32Address):
# with pytest.raises(TypeError):
# w3.cfx.get_balance()

@pytest.mark.xdist_group(name="account")

def test_get_staking_balance(self, w3: Web3, address: Base32Address):
staking_balance = w3.cfx.get_staking_balance(address, w3.cfx.epoch_number-5)
assert staking_balance >= 0
assert isinstance(staking_balance, Drip)
# TODO: use staking balance contract

@pytest.mark.xdist_group(name="account")

def test_get_code(self, w3: Web3, contract_address: Base32Address):
# test different cases
# contract address / user address
Expand All @@ -36,7 +36,7 @@ def test_get_code(self, w3: Web3, contract_address: Base32Address):
user_code = w3.cfx.get_code(w3.cfx.account.create().address)
assert user_code == HexBytes("0x")

@pytest.mark.xdist_group(name="account")

def test_get_admin(self, w3: Web3, contract_address: Base32Address):
# test different cases
# contract address / user address
Expand All @@ -47,7 +47,7 @@ def test_get_admin(self, w3: Web3, contract_address: Base32Address):
user_admin = w3.cfx.get_admin(random_contract_address)
assert user_admin is None

@pytest.mark.xdist_group(name="account")

def test_get_storage_at(self, w3: Web3, contract_address: Base32Address, use_testnet: bool):
# TODO: a potential bug in RPC, at present we ignore the testing in local node
if use_testnet:
Expand All @@ -56,7 +56,7 @@ def test_get_storage_at(self, w3: Web3, contract_address: Base32Address, use_tes
else:
pass

@pytest.mark.xdist_group(name="account")

def test_get_storage_root(self, w3: Web3, contract_address: Base32Address):
root = w3.cfx.get_storage_root(contract_address, w3.cfx.epoch_number_by_tag("latest_state"))
TypeValidator.validate_typed_dict(root, "StorageRoot")
Expand All @@ -65,30 +65,30 @@ def test_get_storage_root(self, w3: Web3, contract_address: Base32Address):
# root = w3.cfx.get_storage_root(w3.account.create().address)
# assert not root

@pytest.mark.xdist_group(name="account")

def test_get_collateral_for_storage(self, w3: Web3, address: Base32Address):
storage = w3.cfx.get_collateral_for_storage(address, w3.cfx.epoch_number_by_tag("latest_state"))

assert isinstance(storage, int)

@pytest.mark.xdist_group(name="account")

def test_get_sponsor_info(self, w3: Web3, contract_address: Base32Address):
sponsor_info = w3.cfx.get_sponsor_info(contract_address, w3.cfx.epoch_number_by_tag("latest_state"))
# assert sponsor_info
TypeValidator.validate_typed_dict(sponsor_info, "SponsorInfo")

@pytest.mark.xdist_group(name="account")

def test_get_account(self, w3: Web3, address: Base32Address):
account_info = w3.cfx.get_account(address, w3.cfx.epoch_number_by_tag("latest_state"))
TypeValidator.validate_typed_dict(account_info, "AccountInfo")

@pytest.mark.xdist_group(name="account")

def test_get_deposit_list(self, w3:Web3, address: Base32Address):
deposit_list = w3.cfx.get_deposit_list(address)
for deposit_info in deposit_list:
TypeValidator.validate_typed_dict(deposit_info, "DepositInfo")

@pytest.mark.xdist_group(name="account")

def test_get_vote_list(self, w3:Web3, address: Base32Address):
vote_list = w3.cfx.get_vote_list(address, w3.cfx.epoch_number_by_tag("latest_state"))
for vote_info in vote_list:
Expand Down
16 changes: 8 additions & 8 deletions tests/rpcs/cfx/test_cfx_block_rpcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,37 @@ def no_full_block_data(self, w3:Web3, block_hash: bytes, use_testnet: bool):
block_data = preprocess_block_data(block_data, use_testnet)
return block_data

@pytest.mark.xdist_group(name="account")

def test_get_block_by_hash(self, block_data: BlockData, no_full_block_data: BlockData):
TypeValidator.validate_typed_dict(block_data, "BlockData")
TypeValidator.validate_typed_dict(no_full_block_data, "BlockData")

@pytest.mark.xdist_group(name="account")

def test_get_block_by_epoch_number(self, w3:Web3, block_data: BlockData, use_testnet: bool):
assert block_data['epochNumber'] is not None
data_ = w3.cfx.get_block_by_epoch_number(block_data['epochNumber'], True)
data_ = preprocess_block_data(data_, use_testnet)
TypeValidator.validate_typed_dict(data_, "BlockData")

@pytest.mark.xdist_group(name="account")

def test_get_block_by_block_number(self, w3:Web3, block_data: BlockData, use_testnet: bool):
assert block_data['blockNumber'] is not None
data_ = w3.cfx.get_block_by_block_number(block_data['blockNumber'], True)
data_ = preprocess_block_data(data_, use_testnet)
assert dict(data_) == dict(block_data)

@pytest.mark.xdist_group(name="account")

def test_get_best_block_hash(self, w3:Web3):
best_block_hash = w3.cfx.get_best_block_hash()
assert isinstance(best_block_hash, HexBytes)

@pytest.mark.xdist_group(name="account")

def test_get_blocks_by_epoch(self, w3: Web3):
blocks = w3.cfx.get_blocks_by_epoch("latest_state")
for block_hash in blocks:
assert isinstance(block_hash, bytes)

@pytest.mark.xdist_group(name="account")

def test_get_skipped_blocks(self, w3: Web3):
blocks = w3.cfx.get_skipped_blocks_by_epoch("latest_state")
for block_hash in blocks:
Expand All @@ -80,7 +80,7 @@ def test_get_blocks_by_hash_with_pivot_assumptions(self, w3: Web3, use_testnet:
block_data = preprocess_block_data(block_data, use_testnet)
TypeValidator.validate_typed_dict(block_data, "BlockData")

@pytest.mark.xdist_group(name="account")

def test_get_block(self, w3: Web3, block_data: BlockData, use_testnet: bool):
epoch_number = block_data["epochNumber"]
assert epoch_number is not None
Expand All @@ -91,7 +91,7 @@ def test_get_block(self, w3: Web3, block_data: BlockData, use_testnet: bool):
block = preprocess_block_data(block, use_testnet)
TypeValidator.validate_typed_dict(block, "BlockData")

@pytest.mark.xdist_group(name="account")

def test_epoch_receipts(self, w3: Web3, block_data: BlockData):
epoch_number = block_data["epochNumber"]
assert epoch_number is not None
Expand Down
8 changes: 4 additions & 4 deletions tests/rpcs/cfx/test_cfx_rpcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# Note that we only test if SDK works as expected, especially for request and result formatting.
# We don't test if RPC works as expected

@pytest.mark.xdist_group(name="account")

def test_get_tx(moduled_w3: Web3, contract_address: Base32Address):
"""test get_transaction(_by_hash) and get_transaction_receipt
"""
Expand Down Expand Up @@ -43,20 +43,20 @@ def test_accounts(w3: Web3, use_testnet: bool):
# """
# pass

@pytest.mark.xdist_group(name="account")

def test_get_confirmation_risk(w3: Web3, tx_hash: HexBytes):
blockHash = w3.cfx.wait_for_transaction_receipt(tx_hash)['blockHash']
risk = w3.cfx.get_confirmation_risk_by_hash(blockHash)
assert risk < 1


@pytest.mark.xdist_group(name="account")

def test_fee_history(moduled_w3: Web3):
w3 = moduled_w3
fee_history = w3.cfx.fee_history(5, "latest_state", [20,50])
TypeValidator.validate_typed_dict(fee_history, "FeeHistory")

@pytest.mark.xdist_group(name="account")

def test_max_priority_fee(moduled_w3: Web3):
w3 = moduled_w3
fee = w3.cfx.max_priority_fee
Expand Down
4 changes: 2 additions & 2 deletions tests/rpcs/test_pending_rpcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def future_tx(self, moduled_w3: Web3):
})
hash.executed()

@pytest.mark.xdist_group(name="account")

def test_get_account_pending_info(self, w3: Web3, address: str, future_tx: Any):
account_pending_info = w3.cfx.get_account_pending_info(address)
TypeValidator.validate_typed_dict(account_pending_info, "PendingInfo")

@pytest.mark.xdist_group(name="account")

def test_get_account_pending_transactions(self, w3: Web3, address:str , future_tx: Any):
nonce = w3.cfx.get_next_nonce(address)
info = w3.cfx.get_account_pending_transactions(address, nonce, 1)
Expand Down
4 changes: 2 additions & 2 deletions tests/transaction/contract/test_erc20.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def w3_(self, w3: Web3, account):
return w3

# warnings might be raised by web3.py, we just ignore these warnings
@pytest.mark.xdist_group(name="account")

def test_contract_deploy_and_transfer(self, w3_: Web3):
# test deployment
erc20_metadata = get_contract_metadata("ERC20")
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_contract_deploy_and_transfer(self, w3_: Web3):
)
assert new_processed_logs[0]["args"] == processed_log["args"]

@pytest.mark.xdist_group(name="account")

def test_contract_without_wallet(self, w3: Web3, account: LocalAccount):
erc20_metadata = get_contract_metadata("ERC20")

Expand Down
2 changes: 1 addition & 1 deletion tests/transaction/test_base_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from conflux_web3.types import Base32Address
from tests._test_helpers.type_check import TypeValidator

@pytest.mark.xdist_group(name="account")

def test_send_raw_transaction(w3: Web3, account: LocalAccount):
status = w3.cfx.get_status()

Expand Down

0 comments on commit c53edea

Please sign in to comment.