From 2ed49d8176e8f47a2d95b421276626e6961050f0 Mon Sep 17 00:00:00 2001 From: kclowes Date: Mon, 27 Jun 2022 15:08:41 -0600 Subject: [PATCH 1/3] Add black to tests/integration --- tests/integration/common.py | 7 +- tests/integration/generate_fixtures/common.py | 78 ++--- .../generate_fixtures/go_ethereum.py | 209 +++++++------ tests/integration/go_ethereum/common.py | 23 +- tests/integration/go_ethereum/conftest.py | 97 +++--- .../go_ethereum/test_goethereum_http.py | 73 +++-- .../go_ethereum/test_goethereum_ipc.py | 35 ++- .../go_ethereum/test_goethereum_ws.py | 51 +-- tests/integration/test_ethereum_tester.py | 291 +++++++++++------- tox.ini | 2 +- 10 files changed, 494 insertions(+), 372 deletions(-) diff --git a/tests/integration/common.py b/tests/integration/common.py index 218d9a4291..94331dac0f 100644 --- a/tests/integration/common.py +++ b/tests/integration/common.py @@ -8,10 +8,11 @@ class MiscWebsocketTest: - def test_websocket_max_size_error(self, w3, endpoint_uri): - w3 = Web3(Web3.WebsocketProvider( - endpoint_uri=endpoint_uri, websocket_kwargs={'max_size': 1}) + w3 = Web3( + Web3.WebsocketProvider( + endpoint_uri=endpoint_uri, websocket_kwargs={"max_size": 1} + ) ) with pytest.raises((OSError, ConnectionClosed)): w3.eth.get_block(0) diff --git a/tests/integration/generate_fixtures/common.py b/tests/integration/generate_fixtures/common.py index a6bc487e6b..b8b4a142a5 100644 --- a/tests/integration/generate_fixtures/common.py +++ b/tests/integration/generate_fixtures/common.py @@ -19,18 +19,20 @@ TransactionNotFound, ) -COINBASE = '0xdc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd' -COINBASE_PK = '0x58d23b55bc9cdce1f18c2500f40ff4ab7245df9a89505e9b1fa4851f623d241d' +COINBASE = "0xdc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd" +COINBASE_PK = "0x58d23b55bc9cdce1f18c2500f40ff4ab7245df9a89505e9b1fa4851f623d241d" KEYFILE_DATA = '{"address":"dc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd","crypto":{"cipher":"aes-128-ctr","ciphertext":"52e06bc9397ea9fa2f0dae8de2b3e8116e92a2ecca9ad5ff0061d1c449704e98","cipherparams":{"iv":"aa5d0a5370ef65395c1a6607af857124"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"9fdf0764eb3645ffc184e166537f6fe70516bf0e34dc7311dea21f100f0c9263"},"mac":"4e0b51f42b865c15c485f4faefdd1f01a38637e5247f8c75ffe6a8c0eba856f6"},"id":"5a6124e0-10f1-4c1c-ae3e-d903eacb740a","version":3}' # noqa: E501 -KEYFILE_PW = 'web3py-test' -KEYFILE_FILENAME = 'UTC--2017-08-24T19-42-47.517572178Z--dc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd' # noqa: E501 +KEYFILE_PW = "web3py-test" +KEYFILE_FILENAME = "UTC--2017-08-24T19-42-47.517572178Z--dc544d1aa88ff8bbd2f2aec754b1f1e99e1812fd" # noqa: E501 -RAW_TXN_ACCOUNT = '0x39EEed73fb1D3855E90Cbd42f348b3D7b340aAA6' +RAW_TXN_ACCOUNT = "0x39EEed73fb1D3855E90Cbd42f348b3D7b340aAA6" -UNLOCKABLE_PRIVATE_KEY = '0x392f63a79b1ff8774845f3fa69de4a13800a59e7083f5187f1558f0797ad0f01' -UNLOCKABLE_ACCOUNT = '0x12efdc31b1a8fa1a1e756dfd8a1601055c971e13' +UNLOCKABLE_PRIVATE_KEY = ( + "0x392f63a79b1ff8774845f3fa69de4a13800a59e7083f5187f1558f0797ad0f01" +) +UNLOCKABLE_ACCOUNT = "0x12efdc31b1a8fa1a1e756dfd8a1601055c971e13" UNLOCKABLE_ACCOUNT_PW = KEYFILE_PW GENESIS_DATA = { @@ -65,7 +67,7 @@ "gasLimit": "0x3b9aca00", # 1,000,000,000 "difficulty": "0x10000", "mixhash": constants.HASH_ZERO, - "coinbase": COINBASE + "coinbase": COINBASE, } @@ -94,17 +96,17 @@ def get_geth_binary(): install_geth, ) - if 'GETH_BINARY' in os.environ: - return os.environ['GETH_BINARY'] - elif 'GETH_VERSION' in os.environ: - geth_version = os.environ['GETH_VERSION'] + if "GETH_BINARY" in os.environ: + return os.environ["GETH_BINARY"] + elif "GETH_VERSION" in os.environ: + geth_version = os.environ["GETH_VERSION"] _geth_binary = get_executable_path(geth_version) if not os.path.exists(_geth_binary): install_geth(geth_version) assert os.path.exists(_geth_binary) return _geth_binary else: - return 'geth' + return "geth" def wait_for_popen(proc, timeout): @@ -144,21 +146,18 @@ def wait_for_socket(ipc_path, timeout=30): @contextlib.contextmanager -def get_geth_process(geth_binary, - datadir, - genesis_file_path, - ipc_path, - port, - networkid, - skip_init=False): +def get_geth_process( + geth_binary, datadir, genesis_file_path, ipc_path, port, networkid, skip_init=False +): if not skip_init: init_datadir_command = ( geth_binary, - '--datadir', datadir, - 'init', + "--datadir", + datadir, + "init", genesis_file_path, ) - print(' '.join(init_datadir_command)) + print(" ".join(init_datadir_command)) subprocess.check_output( init_datadir_command, stdin=subprocess.PIPE, @@ -167,14 +166,19 @@ def get_geth_process(geth_binary, run_geth_command = ( geth_binary, - '--datadir', datadir, - '--ipcpath', ipc_path, - '--nodiscover', - '--port', port, - '--networkid', networkid, - '--etherbase', COINBASE[2:], + "--datadir", + datadir, + "--ipcpath", + ipc_path, + "--nodiscover", + "--port", + port, + "--networkid", + networkid, + "--etherbase", + COINBASE[2:], ) - print(' '.join(run_geth_command)) + print(" ".join(run_geth_command)) try: proc = get_process(run_geth_command) yield proc @@ -228,17 +232,19 @@ def mine_transaction_hash(w3, txn_hash): else: time.sleep(0.1) else: - raise ValueError("Math contract deploy transaction not mined during wait period") + raise ValueError( + "Math contract deploy transaction not mined during wait period" + ) def deploy_contract(w3, name, factory): name = name.upper() w3.geth.personal.unlock_account(w3.eth.coinbase, KEYFILE_PW) - deploy_txn_hash = factory.constructor().transact({'from': w3.eth.coinbase}) - print(f'{name}_CONTRACT_DEPLOY_HASH: {deploy_txn_hash}') + deploy_txn_hash = factory.constructor().transact({"from": w3.eth.coinbase}) + print(f"{name}_CONTRACT_DEPLOY_HASH: {deploy_txn_hash}") deploy_receipt = mine_transaction_hash(w3, deploy_txn_hash) - print(f'{name}_CONTRACT_DEPLOY_TRANSACTION_MINED') - contract_address = deploy_receipt['contractAddress'] + print(f"{name}_CONTRACT_DEPLOY_TRANSACTION_MINED") + contract_address = deploy_receipt["contractAddress"] assert is_checksum_address(contract_address) - print(f'{name}_CONTRACT_ADDRESS: {contract_address}') + print(f"{name}_CONTRACT_ADDRESS: {contract_address}") return deploy_receipt diff --git a/tests/integration/generate_fixtures/go_ethereum.py b/tests/integration/generate_fixtures/go_ethereum.py index cbe431c8a9..f1093422bd 100644 --- a/tests/integration/generate_fixtures/go_ethereum.py +++ b/tests/integration/generate_fixtures/go_ethereum.py @@ -44,7 +44,7 @@ def get_open_port(): sock = socket.socket() - sock.bind(('127.0.0.1', 0)) + sock.bind(("127.0.0.1", 0)) port = sock.getsockname()[1] sock.close() return str(port) @@ -59,15 +59,12 @@ def graceful_kill_on_exit(proc): @contextlib.contextmanager -def get_geth_process(geth_binary, - datadir, - genesis_file_path, - geth_ipc_path, - geth_port): +def get_geth_process(geth_binary, datadir, genesis_file_path, geth_ipc_path, geth_port): init_datadir_command = ( geth_binary, - '--datadir', datadir, - 'init', + "--datadir", + datadir, + "init", genesis_file_path, ) subprocess.check_output( @@ -78,13 +75,19 @@ def get_geth_process(geth_binary, run_geth_command = ( geth_binary, - '--datadir', datadir, - '--ipcpath', geth_ipc_path, - '--ethash.dagsondisk', '1', - '--gcmode', 'archive', - '--nodiscover', - '--port', geth_port, - '--miner.etherbase', common.COINBASE[2:], + "--datadir", + datadir, + "--ipcpath", + geth_ipc_path, + "--ethash.dagsondisk", + "1", + "--gcmode", + "archive", + "--nodiscover", + "--port", + geth_port, + "--miner.etherbase", + common.COINBASE[2:], ) popen_proc = subprocess.Popen( @@ -110,37 +113,38 @@ def write_config_json(config, datadir): bytes_to_hex = apply_formatter_if(is_bytes, to_hex) config_json_dict = valmap(bytes_to_hex, config) - config_path = os.path.join(datadir, 'config.json') - with open(config_path, 'w') as config_file: + config_path = os.path.join(datadir, "config.json") + with open(config_path, "w") as config_file: config_file.write(json.dumps(config_json_dict)) - config_file.write('\n') + config_file.write("\n") def generate_go_ethereum_fixture(destination_dir): with contextlib.ExitStack() as stack: datadir = stack.enter_context(common.tempdir()) - keystore_dir = os.path.join(datadir, 'keystore') + keystore_dir = os.path.join(datadir, "keystore") common.ensure_path_exists(keystore_dir) keyfile_path = os.path.join(keystore_dir, common.KEYFILE_FILENAME) - with open(keyfile_path, 'w') as keyfile: + with open(keyfile_path, "w") as keyfile: keyfile.write(common.KEYFILE_DATA) - genesis_file_path = os.path.join(datadir, 'genesis.json') - with open(genesis_file_path, 'w') as genesis_file: + genesis_file_path = os.path.join(datadir, "genesis.json") + with open(genesis_file_path, "w") as genesis_file: genesis_file.write(json.dumps(common.GENESIS_DATA)) geth_ipc_path_dir = stack.enter_context(common.tempdir()) - geth_ipc_path = os.path.join(geth_ipc_path_dir, 'geth.ipc') + geth_ipc_path = os.path.join(geth_ipc_path_dir, "geth.ipc") geth_port = get_open_port() geth_binary = common.get_geth_binary() with get_geth_process( - geth_binary=geth_binary, - datadir=datadir, - genesis_file_path=genesis_file_path, - geth_ipc_path=geth_ipc_path, - geth_port=geth_port): + geth_binary=geth_binary, + datadir=datadir, + genesis_file_path=genesis_file_path, + geth_ipc_path=geth_ipc_path, + geth_port=geth_port, + ): common.wait_for_socket(geth_ipc_path) w3 = Web3(Web3.IPCProvider(geth_ipc_path)) @@ -152,30 +156,31 @@ def generate_go_ethereum_fixture(destination_dir): # verify that chain state is still valid after closing # and re-opening geth with get_geth_process( - geth_binary=geth_binary, - datadir=datadir, - genesis_file_path=genesis_file_path, - geth_ipc_path=geth_ipc_path, - geth_port=geth_port): + geth_binary=geth_binary, + datadir=datadir, + genesis_file_path=genesis_file_path, + geth_ipc_path=geth_ipc_path, + geth_port=geth_port, + ): common.wait_for_socket(geth_ipc_path) w3 = Web3(Web3.IPCProvider(geth_ipc_path)) verify_chain_state(w3, chain_data) static_data = { - 'raw_txn_account': common.RAW_TXN_ACCOUNT, - 'keyfile_pw': common.KEYFILE_PW, + "raw_txn_account": common.RAW_TXN_ACCOUNT, + "keyfile_pw": common.KEYFILE_PW, } config = merge(chain_data, static_data) pprint.pprint(config) write_config_json(config, datadir) - shutil.make_archive(destination_dir, 'zip', datadir) + shutil.make_archive(destination_dir, "zip", datadir) def verify_chain_state(w3, chain_data): - receipt = w3.eth.wait_for_transaction_receipt(chain_data['mined_txn_hash']) - latest = w3.eth.get_block('latest') + receipt = w3.eth.wait_for_transaction_receipt(chain_data["mined_txn_hash"]) + latest = w3.eth.get_block("latest") assert receipt.blockNumber <= latest.number @@ -215,7 +220,7 @@ def setup_chain_state(w3): abi=MATH_ABI, bytecode=MATH_BYTECODE, ) - math_deploy_receipt = common.deploy_contract(w3, 'math', math_contract_factory) + math_deploy_receipt = common.deploy_contract(w3, "math", math_contract_factory) assert is_dict(math_deploy_receipt) # @@ -225,18 +230,26 @@ def setup_chain_state(w3): abi=CONTRACT_EMITTER_ABI, bytecode=CONTRACT_EMITTER_CODE, ) - emitter_deploy_receipt = common.deploy_contract(w3, 'emitter', emitter_contract_factory) - emitter_contract = emitter_contract_factory(emitter_deploy_receipt['contractAddress']) + emitter_deploy_receipt = common.deploy_contract( + w3, "emitter", emitter_contract_factory + ) + emitter_contract = emitter_contract_factory( + emitter_deploy_receipt["contractAddress"] + ) txn_hash_with_log = emitter_contract.functions.logDouble( - which=EMITTER_ENUM['LogDoubleWithIndex'], arg0=12345, arg1=54321, - ).transact({ - 'from': w3.eth.coinbase, - }) - print('TXN_HASH_WITH_LOG:', txn_hash_with_log) + which=EMITTER_ENUM["LogDoubleWithIndex"], + arg0=12345, + arg1=54321, + ).transact( + { + "from": w3.eth.coinbase, + } + ) + print("TXN_HASH_WITH_LOG:", txn_hash_with_log) txn_receipt_with_log = mine_transaction_hash(w3, txn_hash_with_log) - block_with_log = w3.eth.get_block(txn_receipt_with_log['blockHash']) - print('BLOCK_HASH_WITH_LOG:', block_with_log['hash']) + block_with_log = w3.eth.get_block(txn_receipt_with_log["blockHash"]) + print("BLOCK_HASH_WITH_LOG:", block_with_log["hash"]) # # Revert Contract @@ -245,28 +258,40 @@ def setup_chain_state(w3): abi=_REVERT_CONTRACT_ABI, bytecode=REVERT_CONTRACT_BYTECODE, ) - revert_deploy_receipt = common.deploy_contract(w3, 'revert', revert_contract_factory) - revert_contract = revert_contract_factory(revert_deploy_receipt['contractAddress']) + revert_deploy_receipt = common.deploy_contract( + w3, "revert", revert_contract_factory + ) + revert_contract = revert_contract_factory(revert_deploy_receipt["contractAddress"]) txn_hash_normal_function = revert_contract.functions.normalFunction().transact( - {'gas': 320000, 'from': w3.eth.coinbase} + {"gas": 320000, "from": w3.eth.coinbase} ) - print('TXN_HASH_REVERT_NORMAL:', txn_hash_normal_function) + print("TXN_HASH_REVERT_NORMAL:", txn_hash_normal_function) txn_hash_revert_with_msg = revert_contract.functions.revertWithMessage().transact( - {'gas': 320000, 'from': w3.eth.coinbase} + {"gas": 320000, "from": w3.eth.coinbase} + ) + print("TXN_HASH_REVERT_WITH_MSG:", txn_hash_revert_with_msg) + txn_receipt_revert_with_msg = common.mine_transaction_hash( + w3, txn_hash_revert_with_msg ) - print('TXN_HASH_REVERT_WITH_MSG:', txn_hash_revert_with_msg) - txn_receipt_revert_with_msg = common.mine_transaction_hash(w3, txn_hash_revert_with_msg) - block_hash_revert_with_msg = w3.eth.get_block(txn_receipt_revert_with_msg['blockHash']) - print('BLOCK_HASH_REVERT_WITH_MSG:', block_hash_revert_with_msg['hash']) + block_hash_revert_with_msg = w3.eth.get_block( + txn_receipt_revert_with_msg["blockHash"] + ) + print("BLOCK_HASH_REVERT_WITH_MSG:", block_hash_revert_with_msg["hash"]) - txn_hash_revert_with_no_msg = revert_contract.functions.revertWithoutMessage().transact( - {'gas': 320000, 'from': w3.eth.coinbase} + txn_hash_revert_with_no_msg = ( + revert_contract.functions.revertWithoutMessage().transact( + {"gas": 320000, "from": w3.eth.coinbase} + ) + ) + print("TXN_HASH_REVERT_WITH_NO_MSG:", txn_hash_revert_with_no_msg) + txn_receipt_revert_with_no_msg = common.mine_transaction_hash( + w3, txn_hash_revert_with_no_msg + ) + block_hash_revert_no_msg = w3.eth.get_block( + txn_receipt_revert_with_no_msg["blockHash"] ) - print('TXN_HASH_REVERT_WITH_NO_MSG:', txn_hash_revert_with_no_msg) - txn_receipt_revert_with_no_msg = common.mine_transaction_hash(w3, txn_hash_revert_with_no_msg) - block_hash_revert_no_msg = w3.eth.get_block(txn_receipt_revert_with_no_msg['blockHash']) - print('BLOCK_HASH_REVERT_NO_MSG:', block_hash_revert_no_msg['hash']) + print("BLOCK_HASH_REVERT_NO_MSG:", block_hash_revert_no_msg["hash"]) # # Offchain Lookup Contract @@ -276,7 +301,7 @@ def setup_chain_state(w3): bytecode=OFFCHAIN_LOOKUP_BYTECODE, ) offchain_lookup_deploy_receipt = common.deploy_contract( - w3, 'offchain_lookup', offchain_lookup_factory + w3, "offchain_lookup", offchain_lookup_factory ) assert is_dict(offchain_lookup_deploy_receipt) @@ -284,47 +309,49 @@ def setup_chain_state(w3): # Empty Block # empty_block_number = mine_block(w3) - print('MINED_EMPTY_BLOCK') + print("MINED_EMPTY_BLOCK") empty_block = w3.eth.get_block(empty_block_number) assert is_dict(empty_block) - assert not empty_block['transactions'] - print('EMPTY_BLOCK_HASH:', empty_block['hash']) + assert not empty_block["transactions"] + print("EMPTY_BLOCK_HASH:", empty_block["hash"]) # # Block with Transaction # w3.geth.personal.unlock_account(coinbase, common.KEYFILE_PW) w3.geth.miner.start(1) - mined_txn_hash = w3.eth.send_transaction({ - 'from': coinbase, - 'to': coinbase, - 'value': 1, - 'gas': 21000, - 'gas_price': w3.eth.gas_price, - }) + mined_txn_hash = w3.eth.send_transaction( + { + "from": coinbase, + "to": coinbase, + "value": 1, + "gas": 21000, + "gas_price": w3.eth.gas_price, + } + ) mined_txn_receipt = mine_transaction_hash(w3, mined_txn_hash) - print('MINED_TXN_HASH:', mined_txn_hash) - block_with_txn = w3.eth.get_block(mined_txn_receipt['blockHash']) - print('BLOCK_WITH_TXN_HASH:', block_with_txn['hash']) + print("MINED_TXN_HASH:", mined_txn_hash) + block_with_txn = w3.eth.get_block(mined_txn_receipt["blockHash"]) + print("BLOCK_WITH_TXN_HASH:", block_with_txn["hash"]) geth_fixture = { - 'math_deploy_txn_hash': math_deploy_receipt['transactionHash'], - 'math_address': math_deploy_receipt['contractAddress'], - 'emitter_deploy_txn_hash': emitter_deploy_receipt['transactionHash'], - 'emitter_address': emitter_deploy_receipt['contractAddress'], - 'offchain_lookup_address': offchain_lookup_deploy_receipt['contractAddress'], - 'txn_hash_with_log': txn_hash_with_log, - 'block_hash_with_log': block_with_log['hash'], - 'empty_block_hash': empty_block['hash'], - 'mined_txn_hash': mined_txn_hash, - 'block_with_txn_hash': block_with_txn['hash'], - 'revert_address': revert_deploy_receipt['contractAddress'], - 'block_hash_revert_with_msg': block_hash_revert_with_msg['hash'], - 'block_hash_revert_no_msg': block_hash_revert_no_msg['hash'], + "math_deploy_txn_hash": math_deploy_receipt["transactionHash"], + "math_address": math_deploy_receipt["contractAddress"], + "emitter_deploy_txn_hash": emitter_deploy_receipt["transactionHash"], + "emitter_address": emitter_deploy_receipt["contractAddress"], + "offchain_lookup_address": offchain_lookup_deploy_receipt["contractAddress"], + "txn_hash_with_log": txn_hash_with_log, + "block_hash_with_log": block_with_log["hash"], + "empty_block_hash": empty_block["hash"], + "mined_txn_hash": mined_txn_hash, + "block_with_txn_hash": block_with_txn["hash"], + "revert_address": revert_deploy_receipt["contractAddress"], + "block_hash_revert_with_msg": block_hash_revert_with_msg["hash"], + "block_hash_revert_no_msg": block_hash_revert_no_msg["hash"], } return geth_fixture -if __name__ == '__main__': +if __name__ == "__main__": fixture_dir = sys.argv[1] generate_go_ethereum_fixture(fixture_dir) diff --git a/tests/integration/go_ethereum/common.py b/tests/integration/go_ethereum/common.py index 71884c77d4..7df6450315 100644 --- a/tests/integration/go_ethereum/common.py +++ b/tests/integration/go_ethereum/common.py @@ -30,45 +30,48 @@ class GoEthereumTest(Web3ModuleTest): def _check_web3_clientVersion(self, client_version): - assert client_version.startswith('Geth/') + assert client_version.startswith("Geth/") class GoEthereumEthModuleTest(EthModuleTest): - @pytest.mark.xfail(reason='eth_signTypedData has not been released in geth') + @pytest.mark.xfail(reason="eth_signTypedData has not been released in geth") def test_eth_sign_typed_data(self, w3, unlocked_account_dual_type): super().test_eth_sign_typed_data(w3, unlocked_account_dual_type) - @pytest.mark.xfail(reason='eth_signTypedData has not been released in geth') + @pytest.mark.xfail(reason="eth_signTypedData has not been released in geth") def test_invalid_eth_sign_typed_data(self, w3, unlocked_account_dual_type): super().test_invalid_eth_sign_typed_data(w3, unlocked_account_dual_type) - @pytest.mark.xfail(reason='Inconsistently creating timeout issues.', strict=False) + @pytest.mark.xfail(reason="Inconsistently creating timeout issues.", strict=False) def test_eth_estimate_gas( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: super().test_eth_estimate_gas(w3, unlocked_account_dual_type) - @pytest.mark.xfail(reason='Inconsistently creating timeout issues.', strict=False) + @pytest.mark.xfail(reason="Inconsistently creating timeout issues.", strict=False) def test_eth_estimate_gas_with_block( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: super().test_eth_estimate_gas_with_block(w3, unlocked_account_dual_type) - @pytest.mark.xfail(reason='Inconsistently creating timeout issues.', strict=False) + @pytest.mark.xfail(reason="Inconsistently creating timeout issues.", strict=False) def test_eth_get_transaction_receipt_unmined( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: super().test_eth_get_transaction_receipt_unmined(w3, unlocked_account_dual_type) - @pytest.mark.xfail(reason='Inconsistently creating timeout issues.', strict=False) + @pytest.mark.xfail(reason="Inconsistently creating timeout issues.", strict=False) def test_eth_wait_for_transaction_receipt_unmined( self, w3: "Web3", unlocked_account_dual_type: ChecksumAddress ) -> None: - super().test_eth_wait_for_transaction_receipt_unmined(w3, unlocked_account_dual_type) + super().test_eth_wait_for_transaction_receipt_unmined( + w3, unlocked_account_dual_type + ) - @pytest.mark.xfail(reason='Inconsistently creating timeout issues.', strict=False) + @pytest.mark.xfail(reason="Inconsistently creating timeout issues.", strict=False) def test_eth_get_raw_transaction_by_block( - self, w3: "Web3", + self, + w3: "Web3", unlocked_account_dual_type: ChecksumAddress, block_with_txn: BlockData, ) -> None: diff --git a/tests/integration/go_ethereum/conftest.py b/tests/integration/go_ethereum/conftest.py index 02031f3f78..d5323267c2 100644 --- a/tests/integration/go_ethereum/conftest.py +++ b/tests/integration/go_ethereum/conftest.py @@ -17,42 +17,45 @@ kill_proc_gracefully, ) -KEYFILE_PW = 'web3py-test' +KEYFILE_PW = "web3py-test" -GETH_FIXTURE_ZIP = 'geth-1.10.17-fixture.zip' +GETH_FIXTURE_ZIP = "geth-1.10.17-fixture.zip" -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def geth_binary(): from geth.install import ( get_executable_path, install_geth, ) - if 'GETH_BINARY' in os.environ: - return os.environ['GETH_BINARY'] - elif 'GETH_VERSION' in os.environ: - geth_version = os.environ['GETH_VERSION'] + if "GETH_BINARY" in os.environ: + return os.environ["GETH_BINARY"] + elif "GETH_VERSION" in os.environ: + geth_version = os.environ["GETH_VERSION"] _geth_binary = get_executable_path(geth_version) if not os.path.exists(_geth_binary): install_geth(geth_version) assert os.path.exists(_geth_binary) return _geth_binary else: - return 'geth' + return "geth" def absolute_datadir(directory_name): - return os.path.abspath(os.path.join( - os.path.dirname(__file__), - '..', - directory_name, - )) + return os.path.abspath( + os.path.join( + os.path.dirname(__file__), + "..", + directory_name, + ) + ) @pytest.fixture(scope="module") def get_geth_version(geth_binary): from geth import get_geth_version + return get_geth_version(geth_executable=os.path.expanduser(geth_binary)) @@ -60,9 +63,10 @@ def get_geth_version(geth_binary): def base_geth_command_arguments(geth_binary, datadir): return ( geth_binary, - '--datadir', str(datadir), - '--nodiscover', - '--fakepow', + "--datadir", + str(datadir), + "--nodiscover", + "--fakepow", ) @@ -73,34 +77,35 @@ def geth_zipfile_version(get_geth_version): raise AssertionError("Unsupported geth version") -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def datadir(tmpdir_factory, geth_zipfile_version): zipfile_path = absolute_datadir(geth_zipfile_version) - base_dir = tmpdir_factory.mktemp('goethereum') - tmp_datadir = os.path.join(str(base_dir), 'datadir') - with zipfile.ZipFile(zipfile_path, 'r') as zip_ref: + base_dir = tmpdir_factory.mktemp("goethereum") + tmp_datadir = os.path.join(str(base_dir), "datadir") + with zipfile.ZipFile(zipfile_path, "r") as zip_ref: zip_ref.extractall(tmp_datadir) return tmp_datadir @pytest.fixture(scope="module") def geth_fixture_data(datadir): - config_file_path = Path(datadir) / 'config.json' + config_file_path = Path(datadir) / "config.json" return json.loads(config_file_path.read_text()) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def genesis_file(datadir): - genesis_file_path = os.path.join(datadir, 'genesis.json') + genesis_file_path = os.path.join(datadir, "genesis.json") return genesis_file_path -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def geth_process(geth_binary, datadir, genesis_file, geth_command_arguments): init_datadir_command = ( geth_binary, - '--datadir', str(datadir), - 'init', + "--datadir", + str(datadir), + "init", str(genesis_file), ) subprocess.check_output( @@ -126,19 +131,19 @@ def geth_process(geth_binary, datadir, genesis_file, geth_command_arguments): ) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def coinbase(w3): return w3.eth.coinbase @pytest.fixture(scope="module") def math_contract_deploy_txn_hash(geth_fixture_data): - return geth_fixture_data['math_deploy_txn_hash'] + return geth_fixture_data["math_deploy_txn_hash"] @pytest.fixture(scope="module") def math_contract(math_contract_factory, geth_fixture_data): - return math_contract_factory(address=geth_fixture_data['math_address']) + return math_contract_factory(address=geth_fixture_data["math_address"]) @pytest.fixture(scope="module") @@ -148,7 +153,7 @@ def math_contract_address(math_contract, address_conversion_func): @pytest.fixture(scope="module") def emitter_contract(emitter_contract_factory, geth_fixture_data): - return emitter_contract_factory(address=geth_fixture_data['emitter_address']) + return emitter_contract_factory(address=geth_fixture_data["emitter_address"]) @pytest.fixture(scope="module") @@ -163,9 +168,9 @@ def unlocked_account(w3, unlockable_account, unlockable_account_pw): w3.geth.personal.lock_account(unlockable_account) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def unlockable_account_pw(geth_fixture_data): - return geth_fixture_data['keyfile_pw'] + return geth_fixture_data["keyfile_pw"] @pytest.fixture(scope="module") @@ -187,64 +192,68 @@ def unlocked_account_dual_type(w3, unlockable_account_dual_type, unlockable_acco @pytest.fixture(scope="module") def funded_account_for_raw_txn(geth_fixture_data): - account = geth_fixture_data['raw_txn_account'] + account = geth_fixture_data["raw_txn_account"] assert is_checksum_address(account) return account @pytest.fixture(scope="module") def empty_block(w3, geth_fixture_data): - block = w3.eth.get_block(geth_fixture_data['empty_block_hash']) + block = w3.eth.get_block(geth_fixture_data["empty_block_hash"]) assert is_dict(block) return block @pytest.fixture(scope="module") def block_with_txn(w3, geth_fixture_data): - block = w3.eth.get_block(geth_fixture_data['block_with_txn_hash']) + block = w3.eth.get_block(geth_fixture_data["block_with_txn_hash"]) assert is_dict(block) return block @pytest.fixture(scope="module") def mined_txn_hash(geth_fixture_data): - return geth_fixture_data['mined_txn_hash'] + return geth_fixture_data["mined_txn_hash"] @pytest.fixture(scope="module") def block_with_txn_with_log(w3, geth_fixture_data): - block = w3.eth.get_block(geth_fixture_data['block_hash_with_log']) + block = w3.eth.get_block(geth_fixture_data["block_hash_with_log"]) assert is_dict(block) return block @pytest.fixture(scope="module") def txn_hash_with_log(geth_fixture_data): - return geth_fixture_data['txn_hash_with_log'] + return geth_fixture_data["txn_hash_with_log"] @pytest.fixture(scope="module") def block_hash_revert_no_msg(geth_fixture_data): - return geth_fixture_data['block_hash_revert_no_msg'] + return geth_fixture_data["block_hash_revert_no_msg"] @pytest.fixture(scope="module") def block_hash_revert_with_msg(geth_fixture_data): - return geth_fixture_data['block_hash_revert_with_msg'] + return geth_fixture_data["block_hash_revert_with_msg"] @pytest.fixture(scope="module") def revert_contract(revert_contract_factory, geth_fixture_data): - return revert_contract_factory(address=geth_fixture_data['revert_address']) + return revert_contract_factory(address=geth_fixture_data["revert_address"]) @pytest.fixture(scope="module") def offchain_lookup_contract(offchain_lookup_contract_factory, geth_fixture_data): - return offchain_lookup_contract_factory(address=geth_fixture_data['offchain_lookup_address']) + return offchain_lookup_contract_factory( + address=geth_fixture_data["offchain_lookup_address"] + ) @pytest.fixture(scope="module") -def async_offchain_lookup_contract(async_offchain_lookup_contract_factory, geth_fixture_data): +def async_offchain_lookup_contract( + async_offchain_lookup_contract_factory, geth_fixture_data +): return async_offchain_lookup_contract_factory( - address=geth_fixture_data['offchain_lookup_address'] + address=geth_fixture_data["offchain_lookup_address"] ) diff --git a/tests/integration/go_ethereum/test_goethereum_http.py b/tests/integration/go_ethereum/test_goethereum_http.py index 8489804133..adceec36fe 100644 --- a/tests/integration/go_ethereum/test_goethereum_http.py +++ b/tests/integration/go_ethereum/test_goethereum_http.py @@ -57,34 +57,30 @@ def rpc_port(): @pytest.fixture(scope="module") def endpoint_uri(rpc_port): - return f'http://localhost:{rpc_port}' + return f"http://localhost:{rpc_port}" -def _geth_command_arguments(rpc_port, - base_geth_command_arguments, - geth_version): +def _geth_command_arguments(rpc_port, base_geth_command_arguments, geth_version): yield from base_geth_command_arguments if geth_version.major == 1: yield from ( - '--http', - '--http.port', rpc_port, - '--http.api', 'admin,eth,net,web3,personal,miner,txpool', - '--ipcdisable', - '--allow-insecure-unlock' + "--http", + "--http.port", + rpc_port, + "--http.api", + "admin,eth,net,web3,personal,miner,txpool", + "--ipcdisable", + "--allow-insecure-unlock", ) else: raise AssertionError("Unsupported Geth version") -@pytest.fixture(scope='module') -def geth_command_arguments(rpc_port, - base_geth_command_arguments, - get_geth_version): +@pytest.fixture(scope="module") +def geth_command_arguments(rpc_port, base_geth_command_arguments, get_geth_version): return _geth_command_arguments( - rpc_port, - base_geth_command_arguments, - get_geth_version + rpc_port, base_geth_command_arguments, get_geth_version ) @@ -100,23 +96,27 @@ class TestGoEthereumTest(GoEthereumTest): class TestGoEthereumAdminModuleTest(GoEthereumAdminModuleTest): - @pytest.mark.xfail(reason="running geth with the --nodiscover flag doesn't allow peer addition") + @pytest.mark.xfail( + reason="running geth with the --nodiscover flag doesn't allow peer addition" + ) def test_admin_peers(self, w3: "Web3") -> None: super().test_admin_peers(w3) def test_admin_start_stop_http(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one HTTP endpoint is allowed to be active at any time') + pytest.xfail( + reason="Only one HTTP endpoint is allowed to be active at any time" + ) super().test_admin_start_stop_http(w3) def test_admin_start_stop_ws(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one WS endpoint is allowed to be active at any time') + pytest.xfail(reason="Only one WS endpoint is allowed to be active at any time") super().test_admin_start_stop_ws(w3) def test_admin_start_stop_rpc(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one RPC endpoint is allowed to be active at any time') + pytest.xfail(reason="Only one RPC endpoint is allowed to be active at any time") super().test_admin_start_stop_rpc(w3) @@ -138,6 +138,7 @@ class TestGoEthereumTxPoolModuleTest(GoEthereumTxPoolModuleTest): # -- async -- # + @pytest_asyncio.fixture(scope="module") async def async_w3(geth_process, endpoint_uri): await wait_for_aiohttp(endpoint_uri) @@ -148,40 +149,48 @@ async def async_w3(geth_process, endpoint_uri): async_gas_price_strategy_middleware, async_validation_middleware, ], - modules={'eth': AsyncEth, - 'async_net': AsyncNet, - 'geth': (Geth, - {'txpool': (AsyncGethTxPool,), - 'personal': (AsyncGethPersonal,), - 'admin': (AsyncGethAdmin,)} - ) - } + modules={ + "eth": AsyncEth, + "async_net": AsyncNet, + "geth": ( + Geth, + { + "txpool": (AsyncGethTxPool,), + "personal": (AsyncGethPersonal,), + "admin": (AsyncGethAdmin,), + }, + ), + }, ) return _w3 class TestGoEthereumAsyncAdminModuleTest(GoEthereumAsyncAdminModuleTest): @pytest.mark.asyncio - @pytest.mark.xfail(reason="running geth with the --nodiscover flag doesn't allow peer addition") + @pytest.mark.xfail( + reason="running geth with the --nodiscover flag doesn't allow peer addition" + ) async def test_admin_peers(self, w3: "Web3") -> None: await super().test_admin_peers(w3) @pytest.mark.asyncio async def test_admin_start_stop_http(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one HTTP endpoint is allowed to be active at any time') + pytest.xfail( + reason="Only one HTTP endpoint is allowed to be active at any time" + ) await super().test_admin_start_stop_http(w3) @pytest.mark.asyncio async def test_admin_start_stop_ws(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one WS endpoint is allowed to be active at any time') + pytest.xfail(reason="Only one WS endpoint is allowed to be active at any time") await super().test_admin_start_stop_ws(w3) @pytest.mark.asyncio async def test_admin_start_stop_rpc(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one RPC endpoint is allowed to be active at any time') + pytest.xfail(reason="Only one RPC endpoint is allowed to be active at any time") await super().test_admin_start_stop_rpc(w3) diff --git a/tests/integration/go_ethereum/test_goethereum_ipc.py b/tests/integration/go_ethereum/test_goethereum_ipc.py index eb56719792..d7979f2966 100644 --- a/tests/integration/go_ethereum/test_goethereum_ipc.py +++ b/tests/integration/go_ethereum/test_goethereum_ipc.py @@ -19,31 +19,28 @@ ) -def _geth_command_arguments(geth_ipc_path, - base_geth_command_arguments): +def _geth_command_arguments(geth_ipc_path, base_geth_command_arguments): geth_port = get_open_port() yield from base_geth_command_arguments yield from ( - '--port', geth_port, - '--ipcpath', geth_ipc_path, + "--port", + geth_port, + "--ipcpath", + geth_ipc_path, ) -@pytest.fixture(scope='module') -def geth_command_arguments(geth_ipc_path, - base_geth_command_arguments): +@pytest.fixture(scope="module") +def geth_command_arguments(geth_ipc_path, base_geth_command_arguments): - return _geth_command_arguments( - geth_ipc_path, - base_geth_command_arguments - ) + return _geth_command_arguments(geth_ipc_path, base_geth_command_arguments) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def geth_ipc_path(datadir): geth_ipc_dir_path = tempfile.mkdtemp() - _geth_ipc_path = os.path.join(geth_ipc_dir_path, 'geth.ipc') + _geth_ipc_path = os.path.join(geth_ipc_dir_path, "geth.ipc") yield _geth_ipc_path if os.path.exists(_geth_ipc_path): @@ -62,23 +59,27 @@ class TestGoEthereumTest(GoEthereumTest): class TestGoEthereumAdminModuleTest(GoEthereumAdminModuleTest): - @pytest.mark.xfail(reason="running geth with the --nodiscover flag doesn't allow peer addition") + @pytest.mark.xfail( + reason="running geth with the --nodiscover flag doesn't allow peer addition" + ) def test_admin_peers(w3): super().test_admin_peers(w3) def test_admin_start_stop_http(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one HTTP endpoint is allowed to be active at any time') + pytest.xfail( + reason="Only one HTTP endpoint is allowed to be active at any time" + ) super().test_admin_start_stop_http(w3) def test_admin_start_stop_ws(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one WS endpoint is allowed to be active at any time') + pytest.xfail(reason="Only one WS endpoint is allowed to be active at any time") super().test_admin_start_stop_ws(w3) def test_admin_start_stop_rpc(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one RPC endpoint is allowed to be active at any time') + pytest.xfail(reason="Only one RPC endpoint is allowed to be active at any time") super().test_admin_start_stop_rpc(w3) diff --git a/tests/integration/go_ethereum/test_goethereum_ws.py b/tests/integration/go_ethereum/test_goethereum_ws.py index 0baafd073a..721d513aa1 100644 --- a/tests/integration/go_ethereum/test_goethereum_ws.py +++ b/tests/integration/go_ethereum/test_goethereum_ws.py @@ -26,21 +26,22 @@ def ws_port(): @pytest.fixture(scope="module") def endpoint_uri(ws_port): - return f'ws://localhost:{ws_port}' + return f"ws://localhost:{ws_port}" -def _geth_command_arguments(ws_port, - base_geth_command_arguments, - geth_version): +def _geth_command_arguments(ws_port, base_geth_command_arguments, geth_version): yield from base_geth_command_arguments if geth_version.major == 1: yield from ( - '--ws', - '--ws.port', ws_port, - '--ws.api', 'admin,eth,net,web3,personal,miner', - '--ws.origins', '*', - '--ipcdisable', - '--allow-insecure-unlock', + "--ws", + "--ws.port", + ws_port, + "--ws.api", + "admin,eth,net,web3,personal,miner", + "--ws.origins", + "*", + "--ipcdisable", + "--allow-insecure-unlock", ) if geth_version.minor not in [10]: raise AssertionError("Unsupported Geth version") @@ -48,17 +49,13 @@ def _geth_command_arguments(ws_port, raise AssertionError("Unsupported Geth version") -@pytest.fixture(scope='module') -def geth_command_arguments(geth_binary, - get_geth_version, - datadir, - ws_port, - base_geth_command_arguments): +@pytest.fixture(scope="module") +def geth_command_arguments( + geth_binary, get_geth_version, datadir, ws_port, base_geth_command_arguments +): return _geth_command_arguments( - ws_port, - base_geth_command_arguments, - get_geth_version + ws_port, base_geth_command_arguments, get_geth_version ) @@ -75,22 +72,30 @@ class TestGoEthereumTest(GoEthereumTest): class TestGoEthereumAdminModuleTest(GoEthereumAdminModuleTest): - @pytest.mark.xfail(reason="running geth with the --nodiscover flag doesn't allow peer addition") + @pytest.mark.xfail( + reason="running geth with the --nodiscover flag doesn't allow peer addition" + ) def test_admin_peers(self, w3: "Web3") -> None: super().test_admin_peers(w3) def test_admin_start_stop_http(self, w3: "Web3") -> None: # This test causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one HTTP endpoint is allowed to be active at any time') + pytest.xfail( + reason="Only one HTTP endpoint is allowed to be active at any time" + ) super().test_admin_start_stop_http(w3) def test_admin_start_stop_ws(self, w3: "Web3") -> None: # This test inconsistently causes all tests after it to fail on CI if it's allowed to run - pytest.xfail(reason='Only one WebSocket endpoint is allowed to be active at any time') + pytest.xfail( + reason="Only one WebSocket endpoint is allowed to be active at any time" + ) super().test_admin_start_stop_ws(w3) def test_admin_start_stop_rpc(self, w3: "Web3") -> None: - pytest.xfail(reason="This test inconsistently causes all tests after it on CI to fail if it's allowed to run") # noqa: E501 + pytest.xfail( + reason="This test inconsistently causes all tests after it on CI to fail if it's allowed to run" # noqa: E501 + ) super().test_admin_start_stop_rpc(w3) diff --git a/tests/integration/test_ethereum_tester.py b/tests/integration/test_ethereum_tester.py index bb53435b6c..c3fef25fdc 100644 --- a/tests/integration/test_ethereum_tester.py +++ b/tests/integration/test_ethereum_tester.py @@ -54,7 +54,9 @@ def w3(eth_tester_provider): # @pytest.fixture(scope="module") def math_contract_deploy_txn_hash(w3, math_contract_factory): - deploy_txn_hash = math_contract_factory.constructor().transact({'from': w3.eth.coinbase}) + deploy_txn_hash = math_contract_factory.constructor().transact( + {"from": w3.eth.coinbase} + ) return deploy_txn_hash @@ -62,7 +64,7 @@ def math_contract_deploy_txn_hash(w3, math_contract_factory): def math_contract(w3, math_contract_factory, math_contract_deploy_txn_hash): deploy_receipt = w3.eth.wait_for_transaction_receipt(math_contract_deploy_txn_hash) assert is_dict(deploy_receipt) - contract_address = deploy_receipt['contractAddress'] + contract_address = deploy_receipt["contractAddress"] assert is_checksum_address(contract_address) return math_contract_factory(contract_address) @@ -71,6 +73,7 @@ def math_contract(w3, math_contract_factory, math_contract_deploy_txn_hash): def math_contract_address(math_contract, address_conversion_func): return address_conversion_func(math_contract.address) + # # Emitter Contract Setup # @@ -78,15 +81,19 @@ def math_contract_address(math_contract, address_conversion_func): @pytest.fixture(scope="module") def emitter_contract_deploy_txn_hash(w3, emitter_contract_factory): - deploy_txn_hash = emitter_contract_factory.constructor().transact({'from': w3.eth.coinbase}) + deploy_txn_hash = emitter_contract_factory.constructor().transact( + {"from": w3.eth.coinbase} + ) return deploy_txn_hash @pytest.fixture(scope="module") def emitter_contract(w3, emitter_contract_factory, emitter_contract_deploy_txn_hash): - deploy_receipt = w3.eth.wait_for_transaction_receipt(emitter_contract_deploy_txn_hash) + deploy_receipt = w3.eth.wait_for_transaction_receipt( + emitter_contract_deploy_txn_hash + ) assert is_dict(deploy_receipt) - contract_address = deploy_receipt['contractAddress'] + contract_address = deploy_receipt["contractAddress"] assert is_checksum_address(contract_address) return emitter_contract_factory(contract_address) @@ -100,44 +107,50 @@ def emitter_contract_address(emitter_contract, address_conversion_func): def empty_block(w3): w3.testing.mine() block = w3.eth.get_block("latest") - assert not block['transactions'] + assert not block["transactions"] return block @pytest.fixture(scope="module") def block_with_txn(w3): - txn_hash = w3.eth.send_transaction({ - 'from': w3.eth.coinbase, - 'to': w3.eth.coinbase, - 'value': 1, - 'gas': 21000, - 'gas_price': 1000000000, # needs to be greater than base_fee post London - }) + txn_hash = w3.eth.send_transaction( + { + "from": w3.eth.coinbase, + "to": w3.eth.coinbase, + "value": 1, + "gas": 21000, + "gas_price": 1000000000, # needs to be greater than base_fee post London + } + ) txn = w3.eth.get_transaction(txn_hash) - block = w3.eth.get_block(txn['blockNumber']) + block = w3.eth.get_block(txn["blockNumber"]) return block @pytest.fixture(scope="module") def mined_txn_hash(block_with_txn): - return block_with_txn['transactions'][0] + return block_with_txn["transactions"][0] @pytest.fixture(scope="module") def block_with_txn_with_log(w3, emitter_contract): txn_hash = emitter_contract.functions.logDouble( - which=EMITTER_ENUM['LogDoubleWithIndex'], arg0=12345, arg1=54321, - ).transact({ - 'from': w3.eth.coinbase, - }) + which=EMITTER_ENUM["LogDoubleWithIndex"], + arg0=12345, + arg1=54321, + ).transact( + { + "from": w3.eth.coinbase, + } + ) txn = w3.eth.get_transaction(txn_hash) - block = w3.eth.get_block(txn['blockNumber']) + block = w3.eth.get_block(txn["blockNumber"]) return block @pytest.fixture(scope="module") def txn_hash_with_log(block_with_txn_with_log): - return block_with_txn_with_log['transactions'][0] + return block_with_txn_with_log["transactions"][0] # @@ -145,15 +158,19 @@ def txn_hash_with_log(block_with_txn_with_log): # @pytest.fixture(scope="module") def revert_contract_deploy_txn_hash(w3, revert_contract_factory): - deploy_txn_hash = revert_contract_factory.constructor().transact({'from': w3.eth.coinbase}) + deploy_txn_hash = revert_contract_factory.constructor().transact( + {"from": w3.eth.coinbase} + ) return deploy_txn_hash @pytest.fixture(scope="module") def revert_contract(w3, revert_contract_factory, revert_contract_deploy_txn_hash): - deploy_receipt = w3.eth.wait_for_transaction_receipt(revert_contract_deploy_txn_hash) + deploy_receipt = w3.eth.wait_for_transaction_receipt( + revert_contract_deploy_txn_hash + ) assert is_dict(deploy_receipt) - contract_address = deploy_receipt['contractAddress'] + contract_address = deploy_receipt["contractAddress"] assert is_checksum_address(contract_address) return revert_contract_factory(contract_address) @@ -164,32 +181,38 @@ def revert_contract(w3, revert_contract_factory, revert_contract_deploy_txn_hash @pytest.fixture(scope="module") def offchain_lookup_contract(w3, offchain_lookup_contract_factory): deploy_txn_hash = offchain_lookup_contract_factory.constructor().transact( - {'from': w3.eth.coinbase} + {"from": w3.eth.coinbase} ) deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn_hash) assert is_dict(deploy_receipt) - contract_address = deploy_receipt['contractAddress'] + contract_address = deploy_receipt["contractAddress"] assert is_checksum_address(contract_address) return offchain_lookup_contract_factory(contract_address) -UNLOCKABLE_PRIVATE_KEY = '0x392f63a79b1ff8774845f3fa69de4a13800a59e7083f5187f1558f0797ad0f01' +UNLOCKABLE_PRIVATE_KEY = ( + "0x392f63a79b1ff8774845f3fa69de4a13800a59e7083f5187f1558f0797ad0f01" +) -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def unlockable_account_pw(): - return 'web3-testing' + return "web3-testing" -@pytest.fixture(scope='module') +@pytest.fixture(scope="module") def unlockable_account(w3, unlockable_account_pw): - account = w3.geth.personal.import_raw_key(UNLOCKABLE_PRIVATE_KEY, unlockable_account_pw) - w3.eth.send_transaction({ - 'from': w3.eth.coinbase, - 'to': account, - 'value': w3.toWei(10, 'ether'), - 'gas': 21000, - }) + account = w3.geth.personal.import_raw_key( + UNLOCKABLE_PRIVATE_KEY, unlockable_account_pw + ) + w3.eth.send_transaction( + { + "from": w3.eth.coinbase, + "to": account, + "value": w3.toWei(10, "ether"), + "gas": 21000, + } + ) yield account @@ -214,20 +237,22 @@ def unlocked_account_dual_type(w3, unlockable_account_dual_type, unlockable_acco @pytest.fixture(scope="module") def funded_account_for_raw_txn(w3): - account = '0x39EEed73fb1D3855E90Cbd42f348b3D7b340aAA6' - w3.eth.send_transaction({ - 'from': w3.eth.coinbase, - 'to': account, - 'value': w3.toWei(10, 'ether'), - 'gas': 21000, - 'gas_price': 1, - }) + account = "0x39EEed73fb1D3855E90Cbd42f348b3D7b340aAA6" + w3.eth.send_transaction( + { + "from": w3.eth.coinbase, + "to": account, + "value": w3.toWei(10, "ether"), + "gas": 21000, + "gas_price": 1, + } + ) return account class TestEthereumTesterWeb3Module(Web3ModuleTest): def _check_web3_clientVersion(self, client_version): - assert client_version.startswith('EthereumTester/') + assert client_version.startswith("EthereumTester/") def not_implemented(method, exc_type=NotImplementedError): @@ -235,6 +260,7 @@ def not_implemented(method, exc_type=NotImplementedError): def inner(*args, **kwargs): with pytest.raises(exc_type): method(*args, **kwargs) + return inner @@ -249,39 +275,45 @@ def func_wrapper(self, eth_tester, *args, **kwargs): eth_tester.enable_auto_mine_transactions() eth_tester.mine_block() eth_tester.revert_to_snapshot(snapshot) + return func_wrapper class TestEthereumTesterEthModule(EthModuleTest): test_eth_max_priority_fee_with_fee_history_calculation = not_implemented( - EthModuleTest.test_eth_max_priority_fee_with_fee_history_calculation, - ValueError + EthModuleTest.test_eth_max_priority_fee_with_fee_history_calculation, ValueError ) test_eth_sign = not_implemented(EthModuleTest.test_eth_sign, ValueError) test_eth_sign_ens_names = not_implemented( EthModuleTest.test_eth_sign_ens_names, ValueError ) test_eth_sign_typed_data = not_implemented( - EthModuleTest.test_eth_sign_typed_data, - ValueError + EthModuleTest.test_eth_sign_typed_data, ValueError ) test_eth_sign_transaction_legacy = not_implemented( - EthModuleTest.test_eth_sign_transaction_legacy, - ValueError + EthModuleTest.test_eth_sign_transaction_legacy, ValueError + ) + test_eth_sign_transaction = not_implemented( + EthModuleTest.test_eth_sign_transaction, ValueError ) - test_eth_sign_transaction = not_implemented(EthModuleTest.test_eth_sign_transaction, ValueError) test_eth_sign_transaction_hex_fees = not_implemented( EthModuleTest.test_eth_sign_transaction_hex_fees, ValueError ) test_eth_sign_transaction_ens_names = not_implemented( EthModuleTest.test_eth_sign_transaction_ens_names, ValueError ) - test_eth_submit_hashrate = not_implemented(EthModuleTest.test_eth_submit_hashrate, ValueError) - test_eth_submit_work = not_implemented(EthModuleTest.test_eth_submit_work, ValueError) + test_eth_submit_hashrate = not_implemented( + EthModuleTest.test_eth_submit_hashrate, ValueError + ) + test_eth_submit_work = not_implemented( + EthModuleTest.test_eth_submit_work, ValueError + ) test_eth_get_raw_transaction = not_implemented( - EthModuleTest.test_eth_get_raw_transaction, ValueError) + EthModuleTest.test_eth_get_raw_transaction, ValueError + ) test_eth_get_raw_transaction_raises_error = not_implemented( - EthModuleTest.test_eth_get_raw_transaction, ValueError) + EthModuleTest.test_eth_get_raw_transaction, ValueError + ) test_eth_get_raw_transaction_by_block = not_implemented( EthModuleTest.test_eth_get_raw_transaction_by_block, ValueError ) @@ -292,26 +324,26 @@ class TestEthereumTesterEthModule(EthModuleTest): EthModuleTest.test_eth_replace_transaction_already_mined, ValueError ) - def test_eth_getBlockByHash_pending( - self, w3: "Web3" - ) -> None: - block = w3.eth.get_block('pending') - assert block['hash'] is not None + def test_eth_getBlockByHash_pending(self, w3: "Web3") -> None: + block = w3.eth.get_block("pending") + assert block["hash"] is not None - @pytest.mark.xfail(reason='eth_feeHistory is not implemented on eth-tester') + @pytest.mark.xfail(reason="eth_feeHistory is not implemented on eth-tester") def test_eth_fee_history(self, w3: "Web3"): super().test_eth_fee_history(w3) - @pytest.mark.xfail(reason='eth_feeHistory is not implemented on eth-tester') + @pytest.mark.xfail(reason="eth_feeHistory is not implemented on eth-tester") def test_eth_fee_history_with_integer(self, w3: "Web3"): super().test_eth_fee_history_with_integer(w3) - @pytest.mark.xfail(reason='eth_feeHistory is not implemented on eth-tester') + @pytest.mark.xfail(reason="eth_feeHistory is not implemented on eth-tester") def test_eth_fee_history_no_reward_percentiles(self, w3: "Web3"): super().test_eth_fee_history_no_reward_percentiles(w3) @disable_auto_mine - def test_eth_get_transaction_receipt_unmined(self, eth_tester, w3, unlocked_account): + def test_eth_get_transaction_receipt_unmined( + self, eth_tester, w3, unlocked_account + ): super().test_eth_get_transaction_receipt_unmined(w3, unlocked_account) @disable_auto_mine @@ -323,40 +355,47 @@ def test_eth_replace_transaction(self, eth_tester, w3, unlocked_account): super().test_eth_replace_transaction(w3, unlocked_account) @disable_auto_mine - @pytest.mark.xfail(reason='py-evm does not raise on EIP-1559 transaction underpriced') + @pytest.mark.xfail( + reason="py-evm does not raise on EIP-1559 transaction underpriced" + ) # TODO: This might also be an issue in py-evm worth looking into. See reason above. - def test_eth_replace_transaction_underpriced(self, eth_tester, w3, unlocked_account): + def test_eth_replace_transaction_underpriced( + self, eth_tester, w3, unlocked_account + ): super().test_eth_replace_transaction_underpriced(w3, unlocked_account) @disable_auto_mine - def test_eth_replace_transaction_incorrect_nonce(self, eth_tester, w3, unlocked_account): + def test_eth_replace_transaction_incorrect_nonce( + self, eth_tester, w3, unlocked_account + ): super().test_eth_replace_transaction_incorrect_nonce(w3, unlocked_account) @disable_auto_mine - def test_eth_replace_transaction_gas_price_too_low(self, eth_tester, w3, unlocked_account): + def test_eth_replace_transaction_gas_price_too_low( + self, eth_tester, w3, unlocked_account + ): super().test_eth_replace_transaction_gas_price_too_low(w3, unlocked_account) @disable_auto_mine - def test_eth_replace_transaction_gas_price_defaulting_minimum(self, - eth_tester, - w3, - unlocked_account): - super().test_eth_replace_transaction_gas_price_defaulting_minimum(w3, unlocked_account) + def test_eth_replace_transaction_gas_price_defaulting_minimum( + self, eth_tester, w3, unlocked_account + ): + super().test_eth_replace_transaction_gas_price_defaulting_minimum( + w3, unlocked_account + ) @disable_auto_mine - def test_eth_replace_transaction_gas_price_defaulting_strategy_higher(self, - eth_tester, - w3, - unlocked_account): + def test_eth_replace_transaction_gas_price_defaulting_strategy_higher( + self, eth_tester, w3, unlocked_account + ): super().test_eth_replace_transaction_gas_price_defaulting_strategy_higher( w3, unlocked_account ) @disable_auto_mine - def test_eth_replace_transaction_gas_price_defaulting_strategy_lower(self, - eth_tester, - w3, - unlocked_account): + def test_eth_replace_transaction_gas_price_defaulting_strategy_lower( + self, eth_tester, w3, unlocked_account + ): super().test_eth_replace_transaction_gas_price_defaulting_strategy_lower( w3, unlocked_account ) @@ -370,33 +409,35 @@ def test_eth_modify_transaction(self, eth_tester, w3, unlocked_account): super().test_eth_modify_transaction(w3, unlocked_account) @disable_auto_mine - def test_eth_call_old_contract_state(self, eth_tester, w3, math_contract, unlocked_account): + def test_eth_call_old_contract_state( + self, eth_tester, w3, math_contract, unlocked_account + ): # For now, ethereum tester cannot give call results in the pending block. # Once that feature is added, then delete the except/else blocks. try: - super().test_eth_call_old_contract_state(w3, math_contract, unlocked_account) + super().test_eth_call_old_contract_state( + w3, math_contract, unlocked_account + ) except AssertionError as err: if str(err) == "pending call result was 0 instead of 1": pass else: raise err else: - raise AssertionError("eth-tester was unexpectedly able to give the pending call result") + raise AssertionError( + "eth-tester was unexpectedly able to give the pending call result" + ) - @pytest.mark.xfail(reason='json-rpc method is not implemented on eth-tester') + @pytest.mark.xfail(reason="json-rpc method is not implemented on eth-tester") def test_eth_get_storage_at(self, w3, emitter_contract_address): super().test_eth_get_storage_at(w3, emitter_contract_address) - @pytest.mark.xfail(reason='json-rpc method is not implemented on eth-tester') + @pytest.mark.xfail(reason="json-rpc method is not implemented on eth-tester") def test_eth_get_storage_at_ens_name(self, w3, emitter_contract_address): super().test_eth_get_storage_at_ens_name(w3, emitter_contract_address) - def test_eth_estimate_gas_with_block(self, - w3, - unlocked_account_dual_type): - super().test_eth_estimate_gas_with_block( - w3, unlocked_account_dual_type - ) + def test_eth_estimate_gas_with_block(self, w3, unlocked_account_dual_type): + super().test_eth_estimate_gas_with_block(w3, unlocked_account_dual_type) def test_eth_chain_id(self, w3): chain_id = w3.eth.chain_id @@ -404,19 +445,23 @@ def test_eth_chain_id(self, w3): assert chain_id == 131277322940537 @disable_auto_mine - def test_eth_wait_for_transaction_receipt_unmined(self, - eth_tester, - w3, - unlocked_account_dual_type): - super().test_eth_wait_for_transaction_receipt_unmined(w3, unlocked_account_dual_type) + def test_eth_wait_for_transaction_receipt_unmined( + self, eth_tester, w3, unlocked_account_dual_type + ): + super().test_eth_wait_for_transaction_receipt_unmined( + w3, unlocked_account_dual_type + ) - @pytest.mark.xfail(raises=TypeError, reason="call override param not implemented on eth-tester") + @pytest.mark.xfail( + raises=TypeError, reason="call override param not implemented on eth-tester" + ) def test_eth_call_with_override(self, w3, revert_contract): super().test_eth_call_with_override(w3, revert_contract) def test_eth_call_revert_with_msg(self, w3, revert_contract, unlocked_account): - with pytest.raises(TransactionFailed, - match='execution reverted: Function has been reverted'): + with pytest.raises( + TransactionFailed, match="execution reverted: Function has been reverted" + ): txn_params = revert_contract._prepare_transaction( fn_name="revertWithMessage", transaction={ @@ -437,9 +482,12 @@ def test_eth_call_revert_without_msg(self, w3, revert_contract, unlocked_account ) w3.eth.call(txn_params) - def test_eth_estimate_gas_revert_with_msg(self, w3, revert_contract, unlocked_account): - with pytest.raises(TransactionFailed, - match='execution reverted: Function has been reverted'): + def test_eth_estimate_gas_revert_with_msg( + self, w3, revert_contract, unlocked_account + ): + with pytest.raises( + TransactionFailed, match="execution reverted: Function has been reverted" + ): txn_params = revert_contract._prepare_transaction( fn_name="revertWithMessage", transaction={ @@ -449,7 +497,9 @@ def test_eth_estimate_gas_revert_with_msg(self, w3, revert_contract, unlocked_ac ) w3.eth.estimate_gas(txn_params) - def test_eth_estimate_gas_revert_without_msg(self, w3, revert_contract, unlocked_account): + def test_eth_estimate_gas_revert_without_msg( + self, w3, revert_contract, unlocked_account + ): with pytest.raises(TransactionFailed, match="execution reverted"): txn_params = revert_contract._prepare_transaction( fn_name="revertWithoutMessage", @@ -473,9 +523,15 @@ def test_eth_send_raw_transaction(self, eth_tester, w3, unlocked_account): super().test_eth_send_raw_transaction(w3, unlocked_account) @disable_auto_mine - @pytest.mark.parametrize("max_fee", (1000000000, None), ids=["with_max_fee", "without_max_fee"]) + @pytest.mark.parametrize( + "max_fee", (1000000000, None), ids=["with_max_fee", "without_max_fee"] + ) def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn( - self, eth_tester, w3, unlocked_account, max_fee, + self, + eth_tester, + w3, + unlocked_account, + max_fee, ): super().test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn( w3, unlocked_account, max_fee @@ -486,10 +542,13 @@ def test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn_no_tip( self, eth_tester, w3, unlocked_account ): super().test_gas_price_from_strategy_bypassed_for_dynamic_fee_txn_no_tip( - w3, unlocked_account, + w3, + unlocked_account, ) - @pytest.mark.xfail(raises=ValueError, reason="eth-tester does not have miner_start support") + @pytest.mark.xfail( + raises=ValueError, reason="eth-tester does not have miner_start support" + ) def test_eth_send_transaction_with_nonce(self, eth_tester, w3, unlocked_account): super().test_eth_send_transaction_with_nonce(w3, unlocked_account) @@ -522,12 +581,14 @@ class TestEthereumTesterPersonalModule(GoEthereumPersonalModuleTest): ) # Test overridden here since eth-tester returns False rather than None for failed unlock - def test_personal_unlock_account_failure(self, - w3, - unlockable_account_dual_type): - result = w3.geth.personal.unlock_account(unlockable_account_dual_type, 'bad-password') + def test_personal_unlock_account_failure(self, w3, unlockable_account_dual_type): + result = w3.geth.personal.unlock_account( + unlockable_account_dual_type, "bad-password" + ) assert result is False - @pytest.mark.xfail(raises=ValueError, reason="list_wallets not implemented in eth-tester") + @pytest.mark.xfail( + raises=ValueError, reason="list_wallets not implemented in eth-tester" + ) def test_personal_list_wallets(self, w3: "Web3") -> None: super().test_personal_list_wallets(w3) diff --git a/tox.ini b/tox.ini index 8857d45f73..31909562d3 100644 --- a/tox.ini +++ b/tox.ini @@ -64,7 +64,7 @@ basepython=python extras=linter commands= flake8 {toxinidir}/web3 {toxinidir}/ens {toxinidir}/ethpm {toxinidir}/tests --exclude {toxinidir}/ethpm/ethpm-spec - black {toxinidir}/ethpm {toxinidir}/web3 {toxinidir}/tests/beacon/ {toxinidir}/tests/ens {toxinidir}/tests/ethpm --exclude {toxinidir}/ethpm/ethpm-spec --check + black {toxinidir}/ethpm {toxinidir}/web3 {toxinidir}/tests/beacon/ {toxinidir}/tests/ens {toxinidir}/tests/ethpm {toxinidir}/tests/integration --exclude {toxinidir}/ethpm/ethpm-spec --check isort --recursive --check-only --diff {toxinidir}/web3/ {toxinidir}/ens/ {toxinidir}/ethpm/ {toxinidir}/tests/ mypy -p web3 -p ethpm -p ens --config-file {toxinidir}/mypy.ini From f08edbc0330b0ab7a37eb392860bf708fb4a887c Mon Sep 17 00:00:00 2001 From: kclowes Date: Mon, 27 Jun 2022 15:10:54 -0600 Subject: [PATCH 2/3] Add black to tests/utils.py --- tests/utils.py | 2 +- tox.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index 268d33d6be..43a9a1aa2e 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -7,7 +7,7 @@ def get_open_port(): sock = socket.socket() - sock.bind(('127.0.0.1', 0)) + sock.bind(("127.0.0.1", 0)) port = sock.getsockname()[1] sock.close() return str(port) diff --git a/tox.ini b/tox.ini index 31909562d3..eb1de8ed0b 100644 --- a/tox.ini +++ b/tox.ini @@ -64,7 +64,7 @@ basepython=python extras=linter commands= flake8 {toxinidir}/web3 {toxinidir}/ens {toxinidir}/ethpm {toxinidir}/tests --exclude {toxinidir}/ethpm/ethpm-spec - black {toxinidir}/ethpm {toxinidir}/web3 {toxinidir}/tests/beacon/ {toxinidir}/tests/ens {toxinidir}/tests/ethpm {toxinidir}/tests/integration --exclude {toxinidir}/ethpm/ethpm-spec --check + black {toxinidir}/ethpm {toxinidir}/web3 {toxinidir}/tests/utils.py {toxinidir}/tests/beacon/ {toxinidir}/tests/ens {toxinidir}/tests/ethpm {toxinidir}/tests/integration --exclude {toxinidir}/ethpm/ethpm-spec --check isort --recursive --check-only --diff {toxinidir}/web3/ {toxinidir}/ens/ {toxinidir}/ethpm/ {toxinidir}/tests/ mypy -p web3 -p ethpm -p ens --config-file {toxinidir}/mypy.ini From 9f67280ac2f65ba059ae22d1a494db4519ecc190 Mon Sep 17 00:00:00 2001 From: kclowes Date: Mon, 27 Jun 2022 15:25:48 -0600 Subject: [PATCH 3/3] Add newsfragment --- newsfragments/2544.misc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/2544.misc.rst diff --git a/newsfragments/2544.misc.rst b/newsfragments/2544.misc.rst new file mode 100644 index 0000000000..94d43fc454 --- /dev/null +++ b/newsfragments/2544.misc.rst @@ -0,0 +1 @@ +Add black to ``tests/integration`` directory