diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 4241cd2..5a46786 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -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 diff --git a/.github/workflows/local-test.yml b/.github/workflows/local-test.yml index fb5aa34..f490d7c 100644 --- a/.github/workflows/local-test.yml +++ b/.github/workflows/local-test.yml @@ -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 diff --git a/.github/workflows/testnet-test.yml b/.github/workflows/testnet-test.yml index 84ffde7..8691e41 100644 --- a/.github/workflows/testnet-test.yml +++ b/.github/workflows/testnet-test.yml @@ -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 diff --git a/Makefile b/Makefile index 2c88120..07d6890 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/tests/cns/test_cns.py b/tests/cns/test_cns.py index f851d83..fea9944 100644 --- a/tests/cns/test_cns.py +++ b/tests/cns/test_cns.py @@ -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 @@ -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) @@ -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) @@ -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 @@ -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 diff --git a/tests/middleware/test_pending.py b/tests/middleware/test_pending.py index 2752526..5bea6be 100644 --- a/tests/middleware/test_pending.py +++ b/tests/middleware/test_pending.py @@ -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) diff --git a/tests/middleware/test_wallet.py b/tests/middleware/test_wallet.py index 58c7029..bccfebc 100644 --- a/tests/middleware/test_wallet.py +++ b/tests/middleware/test_wallet.py @@ -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) @@ -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) @@ -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) @@ -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) @@ -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]) @@ -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 = { @@ -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) @@ -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) diff --git a/tests/rpcs/cfx/filter/test_log_filter.py b/tests/rpcs/cfx/filter/test_log_filter.py index 2bb87f0..8fd095a 100644 --- a/tests/rpcs/cfx/filter/test_log_filter.py +++ b/tests/rpcs/cfx/filter/test_log_filter.py @@ -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() diff --git a/tests/rpcs/cfx/filter/test_pending_tx_filter.py b/tests/rpcs/cfx/filter/test_pending_tx_filter.py index a38c2c8..0107c70 100644 --- a/tests/rpcs/cfx/filter/test_pending_tx_filter.py +++ b/tests/rpcs/cfx/filter/test_pending_tx_filter.py @@ -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({ diff --git a/tests/rpcs/cfx/test_cfx_account_query_rpcs.py b/tests/rpcs/cfx/test_cfx_account_query_rpcs.py index 8f8ba24..b9f4c63 100644 --- a/tests/rpcs/cfx/test_cfx_account_query_rpcs.py +++ b/tests/rpcs/cfx/test_cfx_account_query_rpcs.py @@ -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 @@ -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 @@ -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 @@ -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: @@ -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") @@ -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: diff --git a/tests/rpcs/cfx/test_cfx_block_rpcs.py b/tests/rpcs/cfx/test_cfx_block_rpcs.py index d1f734a..40cc0bc 100644 --- a/tests/rpcs/cfx/test_cfx_block_rpcs.py +++ b/tests/rpcs/cfx/test_cfx_block_rpcs.py @@ -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: @@ -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 @@ -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 diff --git a/tests/rpcs/cfx/test_cfx_rpcs.py b/tests/rpcs/cfx/test_cfx_rpcs.py index 5d6f6d3..b1ad738 100644 --- a/tests/rpcs/cfx/test_cfx_rpcs.py +++ b/tests/rpcs/cfx/test_cfx_rpcs.py @@ -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 """ @@ -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 diff --git a/tests/rpcs/test_pending_rpcs.py b/tests/rpcs/test_pending_rpcs.py index d800ef1..acd5b62 100644 --- a/tests/rpcs/test_pending_rpcs.py +++ b/tests/rpcs/test_pending_rpcs.py @@ -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) diff --git a/tests/transaction/contract/test_erc20.py b/tests/transaction/contract/test_erc20.py index eb7dad2..271df68 100644 --- a/tests/transaction/contract/test_erc20.py +++ b/tests/transaction/contract/test_erc20.py @@ -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") @@ -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") diff --git a/tests/transaction/test_base_tx.py b/tests/transaction/test_base_tx.py index f40f008..dd2ed5f 100644 --- a/tests/transaction/test_base_tx.py +++ b/tests/transaction/test_base_tx.py @@ -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()