From 56ab08de5f31fb81217b12e47cb1ddbeb7ca387d Mon Sep 17 00:00:00 2001 From: fselmo Date: Mon, 30 Jan 2023 14:19:53 -0700 Subject: [PATCH] Address comments on PR #2797 --- tests/core/contracts/conftest.py | 156 ++++++++--------- .../test_contract_ambiguous_functions.py | 6 +- .../test_contract_build_transaction.py | 10 +- .../contracts/test_contract_call_interface.py | 94 +++++----- .../test_contract_class_construction.py | 14 +- .../contracts/test_contract_constructor.py | 162 +++++++++--------- .../test_contract_constructor_encoding.py | 28 +-- .../contracts/test_contract_deployment.py | 52 +++--- tests/core/contracts/test_contract_init.py | 26 ++- .../test_contract_transact_interface.py | 2 - .../contracts/test_extracting_event_data.py | 10 +- .../test_extracting_event_data_old.py | 10 +- tests/core/contracts/test_offchain_lookup.py | 10 +- tests/core/contracts/utils.py | 12 +- tests/core/filtering/conftest.py | 12 +- .../filtering/test_contract_data_filters.py | 10 +- .../test_contract_on_event_filtering.py | 40 ++--- .../test_contract_past_event_filtering.py | 16 +- .../filtering/test_contract_topic_filters.py | 8 +- .../test_filters_against_many_blocks.py | 14 +- tests/core/filtering/utils.py | 18 +- .../tools/pytest_ethereum/test_deployer.py | 18 +- tests/ens/conftest.py | 2 +- 23 files changed, 357 insertions(+), 373 deletions(-) diff --git a/tests/core/contracts/conftest.py b/tests/core/contracts/conftest.py index f1c4fbe8c8..fd297e4c1d 100644 --- a/tests/core/contracts/conftest.py +++ b/tests/core/contracts/conftest.py @@ -68,42 +68,42 @@ def math_contract_abi(): @pytest.fixture -def math_contract_instance(w3): +def math_contract_factory(w3): return w3.eth.contract(**MATH_CONTRACT_DATA) @pytest.fixture -def math_contract(w3, math_contract_instance, address_conversion_func): - return deploy(w3, math_contract_instance, address_conversion_func) +def math_contract(w3, math_contract_factory, address_conversion_func): + return deploy(w3, math_contract_factory, address_conversion_func) @pytest.fixture -def simple_constructor_contract_instance(w3): +def simple_constructor_contract_factory(w3): return w3.eth.contract(**SIMPLE_CONSTRUCTOR_CONTRACT_DATA) @pytest.fixture -def contract_with_constructor_args_instance(w3): +def contract_with_constructor_args_factory(w3): return w3.eth.contract(**CONSTRUCTOR_WITH_ARGUMENTS_CONTRACT_DATA) @pytest.fixture -def non_strict_contract_with_constructor_args_instance(w3_non_strict_abi): +def non_strict_contract_with_constructor_args_factory(w3_non_strict_abi): return w3_non_strict_abi.eth.contract(**CONSTRUCTOR_WITH_ARGUMENTS_CONTRACT_DATA) @pytest.fixture -def contract_with_constructor_address_instance(w3): +def contract_with_constructor_address_factory(w3): return w3.eth.contract(**CONSTRUCTOR_WITH_ADDRESS_ARGUMENT_CONTRACT_DATA) @pytest.fixture def contract_with_constructor_address( - w3, contract_with_constructor_address_instance, address_conversion_func + w3, contract_with_constructor_address_factory, address_conversion_func ): return deploy( w3, - contract_with_constructor_address_instance, + contract_with_constructor_address_factory, address_conversion_func, args=["0xd3CdA913deB6f67967B99D67aCDFa1712C293601"], ) @@ -111,10 +111,10 @@ def contract_with_constructor_address( @pytest.fixture def address_reflector_contract(w3, address_conversion_func): - address_reflector_contract_instance = w3.eth.contract( + address_reflector_contract_factory = w3.eth.contract( **ADDRESS_REFLECTOR_CONTRACT_DATA ) - return deploy(w3, address_reflector_contract_instance, address_conversion_func) + return deploy(w3, address_reflector_contract_factory, address_conversion_func) @pytest.fixture(scope="session") @@ -123,14 +123,14 @@ def string_contract_data(): @pytest.fixture -def string_contract_instance(w3, string_contract_data): +def string_contract_factory(w3, string_contract_data): return w3.eth.contract(**STRING_CONTRACT_DATA) @pytest.fixture -def string_contract(w3, string_contract_instance, address_conversion_func): +def string_contract(w3, string_contract_factory, address_conversion_func): return deploy( - w3, string_contract_instance, address_conversion_func, args=["Caqalai"] + w3, string_contract_factory, address_conversion_func, args=["Caqalai"] ) @@ -138,12 +138,12 @@ def string_contract(w3, string_contract_instance, address_conversion_func): def non_strict_string_contract( w3_non_strict_abi, string_contract_data, address_conversion_func ): - _non_strict_string_contract_instance = w3_non_strict_abi.eth.contract( + _non_strict_string_contract_factory = w3_non_strict_abi.eth.contract( **string_contract_data ) return deploy( w3_non_strict_abi, - _non_strict_string_contract_instance, + _non_strict_string_contract_factory, address_conversion_func, args=["Caqalai"], ) @@ -157,21 +157,21 @@ def non_strict_emitter( wait_for_block, address_conversion_func, ): - non_strict_emitter_contract_instance = w3_non_strict_abi.eth.contract( + non_strict_emitter_contract_factory = w3_non_strict_abi.eth.contract( **emitter_contract_data ) w3 = w3_non_strict_abi wait_for_block(w3) - deploy_txn_hash = non_strict_emitter_contract_instance.constructor().transact( + deploy_txn_hash = non_strict_emitter_contract_factory.constructor().transact( {"gas": 10000000} ) deploy_receipt = wait_for_transaction(w3, deploy_txn_hash) contract_address = address_conversion_func(deploy_receipt["contractAddress"]) bytecode = w3.eth.get_code(contract_address) - assert bytecode == non_strict_emitter_contract_instance.bytecode_runtime - emitter_contract = non_strict_emitter_contract_instance(address=contract_address) + assert bytecode == non_strict_emitter_contract_factory.bytecode_runtime + emitter_contract = non_strict_emitter_contract_factory(address=contract_address) assert emitter_contract.address == contract_address return emitter_contract @@ -185,16 +185,16 @@ def event_contract( ): wait_for_block(w3) - event_contract_instance = w3.eth.contract(**EVENT_CONTRACT_DATA) - deploy_txn_hash = event_contract_instance.constructor().transact( + event_contract_factory = w3.eth.contract(**EVENT_CONTRACT_DATA) + deploy_txn_hash = event_contract_factory.constructor().transact( {"from": w3.eth.coinbase, "gas": 1000000} ) deploy_receipt = wait_for_transaction(w3, deploy_txn_hash) contract_address = address_conversion_func(deploy_receipt["contractAddress"]) bytecode = w3.eth.get_code(contract_address) - assert bytecode == event_contract_instance.bytecode_runtime - event_contract = event_contract_instance(address=contract_address) + assert bytecode == event_contract_factory.bytecode_runtime + event_contract = event_contract_factory(address=contract_address) assert event_contract.address == contract_address return event_contract @@ -205,16 +205,16 @@ def indexed_event_contract( ): wait_for_block(w3) - indexed_event_contract_instance = w3.eth.contract(**INDEXED_EVENT_CONTRACT_DATA) - deploy_txn_hash = indexed_event_contract_instance.constructor().transact( + indexed_event_contract_factory = w3.eth.contract(**INDEXED_EVENT_CONTRACT_DATA) + deploy_txn_hash = indexed_event_contract_factory.constructor().transact( {"from": w3.eth.coinbase, "gas": 1000000} ) deploy_receipt = wait_for_transaction(w3, deploy_txn_hash) contract_address = address_conversion_func(deploy_receipt["contractAddress"]) bytecode = w3.eth.get_code(contract_address) - assert bytecode == indexed_event_contract_instance.bytecode_runtime - indexed_event_contract = indexed_event_contract_instance(address=contract_address) + assert bytecode == indexed_event_contract_factory.bytecode_runtime + indexed_event_contract = indexed_event_contract_factory(address=contract_address) assert indexed_event_contract.address == contract_address return indexed_event_contract @@ -229,10 +229,10 @@ def indexed_event_contract( @pytest.fixture def arrays_contract(w3, address_conversion_func): - arrays_contract_instance = w3.eth.contract(**ARRAYS_CONTRACT_DATA) + arrays_contract_factory = w3.eth.contract(**ARRAYS_CONTRACT_DATA) return deploy( w3, - arrays_contract_instance, + arrays_contract_factory, address_conversion_func, args=[BYTES32_ARRAY, BYTES1_ARRAY], ) @@ -240,12 +240,12 @@ def arrays_contract(w3, address_conversion_func): @pytest.fixture def non_strict_arrays_contract(w3_non_strict_abi, address_conversion_func): - non_strict_arrays_contract_instance = w3_non_strict_abi.eth.contract( + non_strict_arrays_contract_factory = w3_non_strict_abi.eth.contract( **ARRAYS_CONTRACT_DATA ) return deploy( w3_non_strict_abi, - non_strict_arrays_contract_instance, + non_strict_arrays_contract_factory, address_conversion_func, args=[BYTES32_ARRAY, BYTES1_ARRAY], ) @@ -253,8 +253,8 @@ def non_strict_arrays_contract(w3_non_strict_abi, address_conversion_func): @pytest.fixture def payable_tester_contract(w3, address_conversion_func): - payable_tester_contract_instance = w3.eth.contract(**PAYABLE_TESTER_CONTRACT_DATA) - return deploy(w3, payable_tester_contract_instance, address_conversion_func) + payable_tester_contract_factory = w3.eth.contract(**PAYABLE_TESTER_CONTRACT_DATA) + return deploy(w3, payable_tester_contract_factory, address_conversion_func) # no matter the function selector, this will return back the 32 bytes of data supplied @@ -296,48 +296,48 @@ def payable_tester_contract(w3, address_conversion_func): @pytest.fixture def fixed_reflector_contract(w3, address_conversion_func): - fixed_reflector_contract_instance = w3.eth.contract( + fixed_reflector_contract_factory = w3.eth.contract( abi=FIXED_REFLECTOR_CONTRACT_ABI, bytecode=FIXED_REFLECTOR_CONTRACT_BYTECODE ) - return deploy(w3, fixed_reflector_contract_instance, address_conversion_func) + return deploy(w3, fixed_reflector_contract_factory, address_conversion_func) @pytest.fixture def fallback_function_contract(w3, address_conversion_func): - fallback_function_contract_instance = w3.eth.contract( + fallback_function_contract_factory = w3.eth.contract( **FALLBACK_FUNCTION_CONTRACT_DATA ) - return deploy(w3, fallback_function_contract_instance, address_conversion_func) + return deploy(w3, fallback_function_contract_factory, address_conversion_func) @pytest.fixture def receive_function_contract(w3, address_conversion_func): - receive_function_contract_instance = w3.eth.contract( + receive_function_contract_factory = w3.eth.contract( **RECEIVE_FUNCTION_CONTRACT_DATA ) - return deploy(w3, receive_function_contract_instance, address_conversion_func) + return deploy(w3, receive_function_contract_factory, address_conversion_func) @pytest.fixture def no_receive_function_contract(w3, address_conversion_func): - no_receive_function_contract_instance = w3.eth.contract( + no_receive_function_contract_factory = w3.eth.contract( **NO_RECEIVE_FUNCTION_CONTRACT_DATA ) - return deploy(w3, no_receive_function_contract_instance, address_conversion_func) + return deploy(w3, no_receive_function_contract_factory, address_conversion_func) @pytest.fixture def contract_caller_tester_contract(w3, address_conversion_func): - contract_caller_tester_contract_instance = w3.eth.contract( + contract_caller_tester_contract_factory = w3.eth.contract( **CONTRACT_CALLER_TESTER_DATA ) - return deploy(w3, contract_caller_tester_contract_instance, address_conversion_func) + return deploy(w3, contract_caller_tester_contract_factory, address_conversion_func) @pytest.fixture def revert_contract(w3, address_conversion_func): - revert_contract_instance = w3.eth.contract(**REVERT_CONTRACT_DATA) - return deploy(w3, revert_contract_instance, address_conversion_func) + revert_contract_factory = w3.eth.contract(**REVERT_CONTRACT_DATA) + return deploy(w3, revert_contract_factory, address_conversion_func) @pytest.fixture @@ -389,38 +389,38 @@ def estimate_gas(request): @pytest.fixture -def async_math_contract_instance(async_w3): +def async_math_contract_factory(async_w3): return async_w3.eth.contract(**MATH_CONTRACT_DATA) @pytest_asyncio.fixture async def async_math_contract( - async_w3, async_math_contract_instance, address_conversion_func + async_w3, async_math_contract_factory, address_conversion_func ): return await async_deploy( - async_w3, async_math_contract_instance, address_conversion_func + async_w3, async_math_contract_factory, address_conversion_func ) @pytest.fixture -def async_simple_constructor_contract_instance(async_w3): +def async_simple_constructor_contract_factory(async_w3): return async_w3.eth.contract(**SIMPLE_CONSTRUCTOR_CONTRACT_DATA) @pytest.fixture -def async_constructor_with_args_contract_instance(async_w3): +def async_constructor_with_args_contract_factory(async_w3): return async_w3.eth.contract(**CONSTRUCTOR_WITH_ARGUMENTS_CONTRACT_DATA) @pytest.fixture -def async_non_strict_constructor_with_args_contract_instance(async_w3_non_strict_abi): +def async_non_strict_constructor_with_args_contract_factory(async_w3_non_strict_abi): return async_w3_non_strict_abi.eth.contract( **CONSTRUCTOR_WITH_ARGUMENTS_CONTRACT_DATA ) @pytest.fixture -def async_constructor_with_address_arg_contract_instance(async_w3): +def async_constructor_with_address_arg_contract_factory(async_w3): return async_w3.eth.contract(**CONSTRUCTOR_WITH_ADDRESS_ARGUMENT_CONTRACT_DATA) @@ -429,12 +429,12 @@ async def async_constructor_with_address_argument_contract( async_w3, address_conversion_func, ): - async_constructor_with_address_arg_instance = async_w3.eth.contract( + async_constructor_with_address_arg_factory = async_w3.eth.contract( **CONSTRUCTOR_WITH_ADDRESS_ARGUMENT_CONTRACT_DATA ) return await async_deploy( async_w3, - async_constructor_with_address_arg_instance, + async_constructor_with_address_arg_factory, address_conversion_func, args=["0xd3CdA913deB6f67967B99D67aCDFa1712C293601"], ) @@ -442,26 +442,26 @@ async def async_constructor_with_address_argument_contract( @pytest_asyncio.fixture async def async_address_reflector_contract(async_w3, address_conversion_func): - async_address_reflector_contract_instance = async_w3.eth.contract( + async_address_reflector_contract_factory = async_w3.eth.contract( **ADDRESS_REFLECTOR_CONTRACT_DATA, ) return await async_deploy( - async_w3, async_address_reflector_contract_instance, address_conversion_func + async_w3, async_address_reflector_contract_factory, address_conversion_func ) @pytest.fixture -def async_string_contract_instance(async_w3): +def async_string_contract_factory(async_w3): return async_w3.eth.contract(**STRING_CONTRACT_DATA) @pytest_asyncio.fixture async def async_string_contract( - async_w3, async_string_contract_instance, address_conversion_func + async_w3, async_string_contract_factory, address_conversion_func ): return await async_deploy( async_w3, - async_string_contract_instance, + async_string_contract_factory, address_conversion_func, args=["Caqalai"], ) @@ -469,10 +469,10 @@ async def async_string_contract( @pytest_asyncio.fixture async def async_arrays_contract(async_w3, address_conversion_func): - async_arrays_contract_instance = async_w3.eth.contract(**ARRAYS_CONTRACT_DATA) + async_arrays_contract_factory = async_w3.eth.contract(**ARRAYS_CONTRACT_DATA) return await async_deploy( async_w3, - async_arrays_contract_instance, + async_arrays_contract_factory, address_conversion_func, args=[BYTES32_ARRAY, BYTES1_ARRAY], ) @@ -482,12 +482,12 @@ async def async_arrays_contract(async_w3, address_conversion_func): async def async_non_strict_arrays_contract( async_w3_non_strict_abi, address_conversion_func ): - async_non_strict_arrays_contract_instance = async_w3_non_strict_abi.eth.contract( + async_non_strict_arrays_contract_factory = async_w3_non_strict_abi.eth.contract( **ARRAYS_CONTRACT_DATA, ) return await async_deploy( async_w3_non_strict_abi, - async_non_strict_arrays_contract_instance, + async_non_strict_arrays_contract_factory, address_conversion_func, args=[BYTES32_ARRAY, BYTES1_ARRAY], ) @@ -495,71 +495,71 @@ async def async_non_strict_arrays_contract( @pytest_asyncio.fixture async def async_payable_tester_contract(async_w3, address_conversion_func): - async_payable_tester_contract_instance = async_w3.eth.contract( + async_payable_tester_contract_factory = async_w3.eth.contract( **PAYABLE_TESTER_CONTRACT_DATA ) return await async_deploy( - async_w3, async_payable_tester_contract_instance, address_conversion_func + async_w3, async_payable_tester_contract_factory, address_conversion_func ) @pytest_asyncio.fixture async def async_fixed_reflector_contract(async_w3, address_conversion_func): - async_fixed_reflector_contract_instance = async_w3.eth.contract( + async_fixed_reflector_contract_factory = async_w3.eth.contract( abi=FIXED_REFLECTOR_CONTRACT_ABI, bytecode=FIXED_REFLECTOR_CONTRACT_BYTECODE ) return await async_deploy( - async_w3, async_fixed_reflector_contract_instance, address_conversion_func + async_w3, async_fixed_reflector_contract_factory, address_conversion_func ) @pytest_asyncio.fixture async def async_fallback_function_contract(async_w3, address_conversion_func): - async_fallback_function_contract_instance = async_w3.eth.contract( + async_fallback_function_contract_factory = async_w3.eth.contract( **FALLBACK_FUNCTION_CONTRACT_DATA ) return await async_deploy( - async_w3, async_fallback_function_contract_instance, address_conversion_func + async_w3, async_fallback_function_contract_factory, address_conversion_func ) @pytest_asyncio.fixture async def async_no_receive_function_contract(async_w3, address_conversion_func): - async_no_receive_function_contract_instance = async_w3.eth.contract( + async_no_receive_function_contract_factory = async_w3.eth.contract( **NO_RECEIVE_FUNCTION_CONTRACT_DATA ) return await async_deploy( - async_w3, async_no_receive_function_contract_instance, address_conversion_func + async_w3, async_no_receive_function_contract_factory, address_conversion_func ) @pytest_asyncio.fixture async def async_receive_function_contract(async_w3, address_conversion_func): - async_receive_function_contract_instance = async_w3.eth.contract( + async_receive_function_contract_factory = async_w3.eth.contract( **RECEIVE_FUNCTION_CONTRACT_DATA ) return await async_deploy( - async_w3, async_receive_function_contract_instance, address_conversion_func + async_w3, async_receive_function_contract_factory, address_conversion_func ) @pytest_asyncio.fixture async def async_contract_caller_tester_contract(async_w3, address_conversion_func): - async_contract_caller_tester_contract_instance = async_w3.eth.contract( + async_contract_caller_tester_contract_factory = async_w3.eth.contract( **CONTRACT_CALLER_TESTER_DATA ) return await async_deploy( async_w3, - async_contract_caller_tester_contract_instance, + async_contract_caller_tester_contract_factory, address_conversion_func, ) @pytest_asyncio.fixture async def async_revert_contract(async_w3, address_conversion_func): - async_revert_contract_instance = async_w3.eth.contract(**REVERT_CONTRACT_DATA) + async_revert_contract_factory = async_w3.eth.contract(**REVERT_CONTRACT_DATA) return await async_deploy( - async_w3, async_revert_contract_instance, address_conversion_func + async_w3, async_revert_contract_factory, address_conversion_func ) diff --git a/tests/core/contracts/test_contract_ambiguous_functions.py b/tests/core/contracts/test_contract_ambiguous_functions.py index 14b5bf1feb..037d892a8c 100644 --- a/tests/core/contracts/test_contract_ambiguous_functions.py +++ b/tests/core/contracts/test_contract_ambiguous_functions.py @@ -46,12 +46,12 @@ @pytest.fixture -def string_contract(w3, string_contract_instance, address_conversion_func): - deploy_txn = string_contract_instance.constructor("Caqalai").transact() +def string_contract(w3, string_contract_factory, address_conversion_func): + deploy_txn = string_contract_factory.constructor("Caqalai").transact() deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) assert deploy_receipt is not None contract_address = address_conversion_func(deploy_receipt["contractAddress"]) - contract = string_contract_instance(address=contract_address) + contract = string_contract_factory(address=contract_address) assert contract.address == contract_address assert len(w3.eth.get_code(contract.address)) > 0 return contract diff --git a/tests/core/contracts/test_contract_build_transaction.py b/tests/core/contracts/test_contract_build_transaction.py index ad86a20b8b..754f5999d6 100644 --- a/tests/core/contracts/test_contract_build_transaction.py +++ b/tests/core/contracts/test_contract_build_transaction.py @@ -67,10 +67,10 @@ def test_build_transaction_with_contract_fallback_function( def test_build_transaction_with_contract_class_method( - w3, math_contract_instance, math_contract, build_transaction + w3, math_contract_factory, math_contract, build_transaction ): txn = build_transaction( - contract=math_contract_instance, + contract=math_contract_factory, contract_function="incrementCounter", tx_params={"to": math_contract.address}, ) @@ -326,12 +326,12 @@ async def test_async_build_transaction_with_contract_fallback_function( @pytest.mark.asyncio async def test_async_build_transaction_with_contract_class_method( async_w3, - async_math_contract_instance, + async_math_contract_factory, async_math_contract, async_build_transaction, ): txn = await async_build_transaction( - contract=async_math_contract_instance, + contract=async_math_contract_factory, contract_function="incrementCounter", tx_params={"to": async_math_contract.address}, ) @@ -403,7 +403,7 @@ async def test_async_build_transaction_with_contract_to_address_supplied_errors( contract=async_math_contract, contract_function="incrementCounter", tx_params={"to": "0xb2930B35844a230f00E51431aCAe96Fe543a0347"}, - ) # noqa: E501 + ) @pytest.mark.asyncio diff --git a/tests/core/contracts/test_contract_call_interface.py b/tests/core/contracts/test_contract_call_interface.py index ef2f785f09..4236d0766d 100644 --- a/tests/core/contracts/test_contract_call_interface.py +++ b/tests/core/contracts/test_contract_call_interface.py @@ -50,21 +50,21 @@ @pytest.fixture def tuple_contract(w3, address_conversion_func): - tuple_contract_instance = w3.eth.contract(**TUPLE_CONTRACT_DATA) - return deploy(w3, tuple_contract_instance, address_conversion_func) + tuple_contract_factory = w3.eth.contract(**TUPLE_CONTRACT_DATA) + return deploy(w3, tuple_contract_factory, address_conversion_func) @pytest.fixture def nested_tuple_contract(w3, address_conversion_func): - nested_tuple_contract_instance = w3.eth.contract(**NESTED_TUPLE_CONTRACT_DATA) - return deploy(w3, nested_tuple_contract_instance, address_conversion_func) + nested_tuple_contract_factory = w3.eth.contract(**NESTED_TUPLE_CONTRACT_DATA) + return deploy(w3, nested_tuple_contract_factory, address_conversion_func) @pytest.fixture(params=[b"\x04\x06", "0x0406"]) def bytes_contract(w3, request, address_conversion_func): - bytes_contract_instance = w3.eth.contract(**BYTES_CONTRACT_DATA) + bytes_contract_factory = w3.eth.contract(**BYTES_CONTRACT_DATA) return deploy( - w3, bytes_contract_instance, address_conversion_func, args=[request.param] + w3, bytes_contract_factory, address_conversion_func, args=[request.param] ) @@ -74,12 +74,12 @@ def non_strict_bytes_contract( request, address_conversion_func, ): - non_strict_bytes_contract_instance = w3_non_strict_abi.eth.contract( + non_strict_bytes_contract_factory = w3_non_strict_abi.eth.contract( **BYTES_CONTRACT_DATA ) return deploy( w3_non_strict_abi, - non_strict_bytes_contract_instance, + non_strict_bytes_contract_factory, address_conversion_func, args=[request.param], ) @@ -91,7 +91,7 @@ def call_transaction(): @pytest.fixture -def bytes32_contract_instance(w3): +def bytes32_contract_factory(w3): return w3.eth.contract(**BYTES32_CONTRACT_DATA) @@ -101,48 +101,48 @@ def bytes32_contract_instance(w3): HexBytes("0406040604060406040604060406040604060406040604060406040604060406"), ] ) -def bytes32_contract(w3, bytes32_contract_instance, request, address_conversion_func): +def bytes32_contract(w3, bytes32_contract_factory, request, address_conversion_func): return deploy( - w3, bytes32_contract_instance, address_conversion_func, args=[request.param] + w3, bytes32_contract_factory, address_conversion_func, args=[request.param] ) @pytest.fixture -def undeployed_math_contract(math_contract_instance, address_conversion_func): +def undeployed_math_contract(math_contract_factory, address_conversion_func): empty_address = address_conversion_func( "0x000000000000000000000000000000000000dEaD" ) - _undeployed_math_contract = math_contract_instance(address=empty_address) + _undeployed_math_contract = math_contract_factory(address=empty_address) return _undeployed_math_contract @pytest.fixture def mismatched_math_contract( - w3, string_contract_instance, math_contract_instance, address_conversion_func + w3, string_contract_factory, math_contract_factory, address_conversion_func ): - deploy_txn = string_contract_instance.constructor("Caqalai").transact() + deploy_txn = string_contract_factory.constructor("Caqalai").transact() deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) assert deploy_receipt is not None address = address_conversion_func(deploy_receipt["contractAddress"]) - _mismatched_math_contract = math_contract_instance(address=address) + _mismatched_math_contract = math_contract_factory(address=address) return _mismatched_math_contract def test_deploy_raises_due_to_strict_byte_checking_by_default( - w3, bytes32_contract_instance, address_conversion_func + w3, bytes32_contract_factory, address_conversion_func ): with pytest.raises(TypeError): deploy( w3, - bytes32_contract_instance, + bytes32_contract_factory, address_conversion_func, args=["0406040604060406040604060406040604060406040604060406040604060406"], ) -def test_invalid_address_in_deploy_arg(contract_with_constructor_address_instance): +def test_invalid_address_in_deploy_arg(contract_with_constructor_address_factory): with pytest.raises(InvalidAddress): - contract_with_constructor_address_instance.constructor( + contract_with_constructor_address_factory.constructor( "0xd3cda913deb6f67967b99d67acdfa1712c293601", ).transact() @@ -304,14 +304,14 @@ def test_call_read_address_variable(contract_with_constructor_address, call): assert result == "0xd3CdA913deB6f67967B99D67aCDFa1712C293601" -def test_init_with_ens_name_arg(w3, contract_with_constructor_address_instance, call): +def test_init_with_ens_name_arg(w3, contract_with_constructor_address_factory, call): with contract_ens_addresses( - contract_with_constructor_address_instance, + contract_with_constructor_address_factory, [("arg-name.eth", "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")], ): address_contract = deploy( w3, - contract_with_constructor_address_instance, + contract_with_constructor_address_factory, args=[ "arg-name.eth", ], @@ -1015,24 +1015,24 @@ def test_changing_default_block_identifier(w3, math_contract): @pytest_asyncio.fixture async def async_tuple_contract(async_w3, address_conversion_func): - async_tuple_contract_instance = async_w3.eth.contract(**TUPLE_CONTRACT_DATA) + async_tuple_contract_factory = async_w3.eth.contract(**TUPLE_CONTRACT_DATA) return await async_deploy( - async_w3, async_tuple_contract_instance, address_conversion_func + async_w3, async_tuple_contract_factory, address_conversion_func ) @pytest_asyncio.fixture async def async_nested_tuple_contract(async_w3, address_conversion_func): - async_nested_tuple_contract_instance = async_w3.eth.contract( + async_nested_tuple_contract_factory = async_w3.eth.contract( **NESTED_TUPLE_CONTRACT_DATA ) return await async_deploy( - async_w3, async_nested_tuple_contract_instance, address_conversion_func + async_w3, async_nested_tuple_contract_factory, address_conversion_func ) @pytest.fixture -def async_bytes_contract_instance(async_w3): +def async_bytes_contract_factory(async_w3): return async_w3.eth.contract(**BYTES_CONTRACT_DATA) @@ -1040,12 +1040,12 @@ def async_bytes_contract_instance(async_w3): async def async_bytes_contract( async_w3, request, - async_bytes_contract_instance, + async_bytes_contract_factory, address_conversion_func, ): return await async_deploy( async_w3, - async_bytes_contract_instance, + async_bytes_contract_factory, address_conversion_func, args=[request.param], ) @@ -1058,10 +1058,10 @@ async def async_bytes_contract( ], ) async def async_bytes32_contract(async_w3, request, address_conversion_func): - async_bytes32_contract_instance = async_w3.eth.contract(**BYTES32_CONTRACT_DATA) + async_bytes32_contract_factory = async_w3.eth.contract(**BYTES32_CONTRACT_DATA) return await async_deploy( async_w3, - async_bytes32_contract_instance, + async_bytes32_contract_factory, address_conversion_func, args=[request.param], ) @@ -1069,34 +1069,34 @@ async def async_bytes32_contract(async_w3, request, address_conversion_func): @pytest_asyncio.fixture async def async_undeployed_math_contract( - async_math_contract_instance, address_conversion_func + async_math_contract_factory, address_conversion_func ): empty_address = address_conversion_func( "0x000000000000000000000000000000000000dEaD" ) - _undeployed_math_contract = async_math_contract_instance(address=empty_address) + _undeployed_math_contract = async_math_contract_factory(address=empty_address) return _undeployed_math_contract @pytest_asyncio.fixture async def async_mismatched_math_contract( async_w3, - async_string_contract_instance, - async_math_contract_instance, + async_string_contract_factory, + async_math_contract_factory, address_conversion_func, ): - deploy_txn = await async_string_contract_instance.constructor("Caqalai").transact() + deploy_txn = await async_string_contract_factory.constructor("Caqalai").transact() deploy_receipt = await async_w3.eth.wait_for_transaction_receipt(deploy_txn) assert deploy_receipt is not None address = address_conversion_func(deploy_receipt["contractAddress"]) - _mismatched_math_contract = async_math_contract_instance(address=address) + _mismatched_math_contract = async_math_contract_factory(address=address) return _mismatched_math_contract @pytest.fixture @pytest.mark.asyncio async def test_async_deploy_raises_due_to_strict_byte_checking_by_default( - async_w3, async_bytes_contract_instance, address_conversion_func + async_w3, async_bytes_contract_factory, address_conversion_func ): with pytest.raises( TypeError, @@ -1105,7 +1105,7 @@ async def test_async_deploy_raises_due_to_strict_byte_checking_by_default( ): await async_deploy( async_w3, - async_bytes_contract_instance, + async_bytes_contract_factory, address_conversion_func, args=["0406"], ) @@ -1118,12 +1118,12 @@ async def test_async_deploy_with_non_strict_abi_check( address_conversion_func, args, ): - async_non_strict_bytes_contract_instance = async_w3_non_strict_abi.eth.contract( + async_non_strict_bytes_contract_factory = async_w3_non_strict_abi.eth.contract( **BYTES_CONTRACT_DATA ) deployed_contract = await async_deploy( async_w3_non_strict_abi, - async_non_strict_bytes_contract_instance, + async_non_strict_bytes_contract_factory, address_conversion_func, args=[args], ) @@ -1133,10 +1133,10 @@ async def test_async_deploy_with_non_strict_abi_check( @pytest.mark.asyncio async def test_async_invalid_address_in_deploy_arg( - async_constructor_with_address_arg_contract_instance, + async_constructor_with_address_arg_contract_factory, ): with pytest.raises(InvalidAddress): - await async_constructor_with_address_arg_contract_instance.constructor( + await async_constructor_with_address_arg_contract_factory.constructor( "0xd3cda913deb6f67967b99d67acdfa1712c293601", ).transact() @@ -1308,15 +1308,15 @@ async def test_async_call_read_address_variable( @pytest.mark.xfail @pytest.mark.asyncio async def test_async_init_with_ens_name_arg( - async_w3, async_constructor_with_address_arg_contract_instance, async_call + async_w3, async_constructor_with_address_arg_contract_factory, async_call ): with contract_ens_addresses( - async_constructor_with_address_arg_contract_instance, + async_constructor_with_address_arg_contract_factory, [("arg-name.eth", "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")], ): address_contract = await async_deploy( async_w3, - async_constructor_with_address_arg_contract_instance, + async_constructor_with_address_arg_contract_factory, args=[ "arg-name.eth", ], diff --git a/tests/core/contracts/test_contract_class_construction.py b/tests/core/contracts/test_contract_class_construction.py index 78d3cc0fe0..b0d0c296c1 100644 --- a/tests/core/contracts/test_contract_class_construction.py +++ b/tests/core/contracts/test_contract_class_construction.py @@ -16,15 +16,15 @@ def test_class_construction_sets_class_vars( w3, math_contract_abi, math_contract_bytecode, math_contract_runtime ): - math_contract_instance = w3.eth.contract( + math_contract_factory = w3.eth.contract( abi=math_contract_abi, bytecode=math_contract_bytecode, bytecode_runtime=math_contract_runtime, ) - assert math_contract_instance.w3 == w3 - assert math_contract_instance.bytecode == decode_hex(math_contract_bytecode) - assert math_contract_instance.bytecode_runtime == decode_hex(math_contract_runtime) + assert math_contract_factory.w3 == w3 + assert math_contract_factory.bytecode == decode_hex(math_contract_bytecode) + assert math_contract_factory.bytecode_runtime == decode_hex(math_contract_runtime) def test_error_to_instantiate_base_class(): @@ -35,10 +35,10 @@ def test_error_to_instantiate_base_class(): def test_abi_as_json_string(w3, math_contract_abi, some_address): abi_str = json.dumps(math_contract_abi) - math_contract_instance = w3.eth.contract(abi=abi_str) - assert math_contract_instance.abi == math_contract_abi + math_contract_factory = w3.eth.contract(abi=abi_str) + assert math_contract_factory.abi == math_contract_abi - math = math_contract_instance(some_address) + math = math_contract_factory(some_address) assert math.abi == math_contract_abi diff --git a/tests/core/contracts/test_contract_constructor.py b/tests/core/contracts/test_contract_constructor.py index cf4f2a48dc..7c66703926 100644 --- a/tests/core/contracts/test_contract_constructor.py +++ b/tests/core/contracts/test_contract_constructor.py @@ -19,28 +19,28 @@ def test_contract_constructor_abi_encoding_with_no_constructor_fn( - math_contract_instance, math_contract_bytecode + math_contract_factory, math_contract_bytecode ): - deploy_data = math_contract_instance.constructor()._encode_data_in_transaction() + deploy_data = math_contract_factory.constructor()._encode_data_in_transaction() assert deploy_data == math_contract_bytecode -def test_contract_constructor_gas_estimate_no_constructor(w3, math_contract_instance): - gas_estimate = math_contract_instance.constructor().estimate_gas() +def test_contract_constructor_gas_estimate_no_constructor(w3, math_contract_factory): + gas_estimate = math_contract_factory.constructor().estimate_gas() - deploy_txn = math_contract_instance.constructor().transact() + deploy_txn = math_contract_factory.constructor().transact() txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) gas_used = txn_receipt.get("gasUsed") assert abs(gas_estimate - gas_used) < 21000 -def test_contract_constructor_gas_estimate_with_block_id(w3, math_contract_instance): +def test_contract_constructor_gas_estimate_with_block_id(w3, math_contract_factory): block_identifier = None - gas_estimate = math_contract_instance.constructor().estimate_gas( + gas_estimate = math_contract_factory.constructor().estimate_gas( block_identifier=block_identifier ) - deploy_txn = math_contract_instance.constructor().transact() + deploy_txn = math_contract_factory.constructor().transact() txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) gas_used = txn_receipt.get("gasUsed") @@ -48,11 +48,11 @@ def test_contract_constructor_gas_estimate_with_block_id(w3, math_contract_insta def test_contract_constructor_gas_estimate_without_arguments( - w3, simple_constructor_contract_instance + w3, simple_constructor_contract_factory ): - gas_estimate = simple_constructor_contract_instance.constructor().estimate_gas() + gas_estimate = simple_constructor_contract_factory.constructor().estimate_gas() - deploy_txn = simple_constructor_contract_instance.constructor().transact() + deploy_txn = simple_constructor_contract_factory.constructor().transact() txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) gas_used = txn_receipt.get("gasUsed") @@ -70,15 +70,15 @@ def test_contract_constructor_gas_estimate_without_arguments( ) def test_contract_constructor_gas_estimate_with_arguments_non_strict( w3_non_strict_abi, - non_strict_contract_with_constructor_args_instance, + non_strict_contract_with_constructor_args_factory, constructor_args, constructor_kwargs, ): - gas_estimate = non_strict_contract_with_constructor_args_instance.constructor( + gas_estimate = non_strict_contract_with_constructor_args_factory.constructor( *constructor_args, **constructor_kwargs ).estimate_gas() - deploy_txn = non_strict_contract_with_constructor_args_instance.constructor( + deploy_txn = non_strict_contract_with_constructor_args_factory.constructor( *constructor_args, **constructor_kwargs ).transact() txn_receipt = w3_non_strict_abi.eth.wait_for_transaction_receipt(deploy_txn) @@ -88,13 +88,13 @@ def test_contract_constructor_gas_estimate_with_arguments_non_strict( def test_contract_constructor_gas_estimate_with_address_argument( - w3, contract_with_constructor_address_instance, address_conversion_func + w3, contract_with_constructor_address_factory, address_conversion_func ): - gas_estimate = contract_with_constructor_address_instance.constructor( + gas_estimate = contract_with_constructor_address_factory.constructor( address_conversion_func("0x16D9983245De15E7A9A73bC586E01FF6E08dE737") ).estimate_gas() - deploy_txn = contract_with_constructor_address_instance.constructor( + deploy_txn = contract_with_constructor_address_factory.constructor( address_conversion_func("0x16D9983245De15E7A9A73bC586E01FF6E08dE737") ).transact() txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) @@ -104,9 +104,9 @@ def test_contract_constructor_gas_estimate_with_address_argument( def test_contract_constructor_transact_no_constructor( - w3, math_contract_instance, math_contract_runtime, address_conversion_func + w3, math_contract_factory, math_contract_runtime, address_conversion_func ): - deploy_txn = math_contract_instance.constructor().transact() + deploy_txn = math_contract_factory.constructor().transact() txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) assert txn_receipt is not None @@ -120,10 +120,10 @@ def test_contract_constructor_transact_no_constructor( def test_contract_constructor_transact_without_arguments( w3, - simple_constructor_contract_instance, + simple_constructor_contract_factory, address_conversion_func, ): - deploy_txn = simple_constructor_contract_instance.constructor().transact() + deploy_txn = simple_constructor_contract_factory.constructor().transact() txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) assert txn_receipt is not None @@ -146,14 +146,14 @@ def test_contract_constructor_transact_without_arguments( ) def test_contract_constructor_transact_with_arguments_non_strict( w3_non_strict_abi, - non_strict_contract_with_constructor_args_instance, + non_strict_contract_with_constructor_args_factory, constructor_args, constructor_kwargs, expected_a, expected_b, address_conversion_func, ): - deploy_txn = non_strict_contract_with_constructor_args_instance.constructor( + deploy_txn = non_strict_contract_with_constructor_args_factory.constructor( *constructor_args, **constructor_kwargs ).transact() @@ -167,13 +167,13 @@ def test_contract_constructor_transact_with_arguments_non_strict( assert blockchain_code == decode_hex(CONSTRUCTOR_WITH_ARGUMENTS_CONTRACT_RUNTIME) assert ( expected_a - == non_strict_contract_with_constructor_args_instance(address=contract_address) + == non_strict_contract_with_constructor_args_factory(address=contract_address) .functions.data_a() .call() ) assert ( expected_b - == non_strict_contract_with_constructor_args_instance(address=contract_address) + == non_strict_contract_with_constructor_args_factory(address=contract_address) .functions.data_b() .call() ) @@ -181,10 +181,10 @@ def test_contract_constructor_transact_with_arguments_non_strict( def test_contract_constructor_transact_with_address_argument( w3, - contract_with_constructor_address_instance, + contract_with_constructor_address_factory, address_conversion_func, ): - deploy_txn = contract_with_constructor_address_instance.constructor( + deploy_txn = contract_with_constructor_address_factory.constructor( TEST_ADDRESS ).transact() txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) @@ -197,28 +197,26 @@ def test_contract_constructor_transact_with_address_argument( ) assert ( TEST_ADDRESS - == contract_with_constructor_address_instance(address=contract_address) + == contract_with_constructor_address_factory(address=contract_address) .functions.testAddr() .call() ) -def test_contract_constructor_build_transaction_to_field_error(math_contract_instance): +def test_contract_constructor_build_transaction_to_field_error(math_contract_factory): with pytest.raises(ValueError): - math_contract_instance.constructor().build_transaction({"to": "123"}) + math_contract_factory.constructor().build_transaction({"to": "123"}) def test_contract_constructor_build_transaction_no_constructor( - w3, math_contract_instance, address_conversion_func + w3, math_contract_factory, address_conversion_func ): - txn_hash = math_contract_instance.constructor().transact( + txn_hash = math_contract_factory.constructor().transact( {"from": address_conversion_func(w3.eth.accounts[0])} ) txn = w3.eth.get_transaction(txn_hash) nonce = w3.eth.get_transaction_count(w3.eth.coinbase) - unsent_txn = math_contract_instance.constructor().build_transaction( - {"nonce": nonce} - ) + unsent_txn = math_contract_factory.constructor().build_transaction({"nonce": nonce}) assert txn["data"] == unsent_txn["data"] new_txn_hash = w3.eth.send_transaction(unsent_txn) @@ -228,16 +226,14 @@ def test_contract_constructor_build_transaction_no_constructor( def test_contract_constructor_build_transaction_without_arguments( - w3, math_contract_instance, address_conversion_func + w3, math_contract_factory, address_conversion_func ): - txn_hash = math_contract_instance.constructor().transact( + txn_hash = math_contract_factory.constructor().transact( {"from": address_conversion_func(w3.eth.accounts[0])} ) txn = w3.eth.get_transaction(txn_hash) nonce = w3.eth.get_transaction_count(w3.eth.coinbase) - unsent_txn = math_contract_instance.constructor().build_transaction( - {"nonce": nonce} - ) + unsent_txn = math_contract_factory.constructor().build_transaction({"nonce": nonce}) assert txn["data"] == unsent_txn["data"] new_txn_hash = w3.eth.send_transaction(unsent_txn) @@ -257,17 +253,17 @@ def test_contract_constructor_build_transaction_without_arguments( ) def test_contract_constructor_build_transaction_with_arguments( w3_non_strict_abi, - non_strict_contract_with_constructor_args_instance, + non_strict_contract_with_constructor_args_factory, constructor_args, constructor_kwargs, address_conversion_func, ): - txn_hash = non_strict_contract_with_constructor_args_instance.constructor( + txn_hash = non_strict_contract_with_constructor_args_factory.constructor( *constructor_args, **constructor_kwargs ).transact({"from": address_conversion_func(w3_non_strict_abi.eth.accounts[0])}) txn = w3_non_strict_abi.eth.get_transaction(txn_hash) nonce = w3_non_strict_abi.eth.get_transaction_count(w3_non_strict_abi.eth.coinbase) - unsent_txn = non_strict_contract_with_constructor_args_instance.constructor( + unsent_txn = non_strict_contract_with_constructor_args_factory.constructor( *constructor_args, **constructor_kwargs ).build_transaction({"nonce": nonce}) assert txn["data"] == unsent_txn["data"] @@ -279,21 +275,21 @@ def test_contract_constructor_build_transaction_with_arguments( def test_async_contract_constructor_abi_encoding_with_no_constructor_fn( - async_math_contract_instance, math_contract_bytecode + async_math_contract_factory, math_contract_bytecode ): deploy_data = ( - async_math_contract_instance.constructor()._encode_data_in_transaction() + async_math_contract_factory.constructor()._encode_data_in_transaction() ) assert deploy_data == math_contract_bytecode @pytest.mark.asyncio async def test_async_contract_constructor_gas_estimate_no_constructor( - async_w3, async_math_contract_instance + async_w3, async_math_contract_factory ): - gas_estimate = await async_math_contract_instance.constructor().estimate_gas() + gas_estimate = await async_math_contract_factory.constructor().estimate_gas() - deploy_txn = await async_math_contract_instance.constructor().transact() + deploy_txn = await async_math_contract_factory.constructor().transact() txn_receipt = await async_w3.eth.wait_for_transaction_receipt(deploy_txn) gas_used = txn_receipt.get("gasUsed") @@ -302,13 +298,13 @@ async def test_async_contract_constructor_gas_estimate_no_constructor( @pytest.mark.asyncio async def test_async_contract_constructor_gas_estimate_with_block_id( - async_w3, async_math_contract_instance + async_w3, async_math_contract_factory ): block_identifier = None - gas_estimate = await async_math_contract_instance.constructor().estimate_gas( + gas_estimate = await async_math_contract_factory.constructor().estimate_gas( block_identifier=block_identifier ) - deploy_txn = await async_math_contract_instance.constructor().transact() + deploy_txn = await async_math_contract_factory.constructor().transact() txn_receipt = await async_w3.eth.wait_for_transaction_receipt(deploy_txn) gas_used = txn_receipt.get("gasUsed") @@ -317,14 +313,14 @@ async def test_async_contract_constructor_gas_estimate_with_block_id( @pytest.mark.asyncio async def test_async_contract_constructor_gas_estimate_without_arguments( - async_w3, async_simple_constructor_contract_instance + async_w3, async_simple_constructor_contract_factory ): gas_estimate = ( - await async_simple_constructor_contract_instance.constructor().estimate_gas() + await async_simple_constructor_contract_factory.constructor().estimate_gas() ) deploy_txn = ( - await async_simple_constructor_contract_instance.constructor().transact() + await async_simple_constructor_contract_factory.constructor().transact() ) txn_receipt = await async_w3.eth.wait_for_transaction_receipt(deploy_txn) gas_used = txn_receipt.get("gasUsed") @@ -344,18 +340,18 @@ async def test_async_contract_constructor_gas_estimate_without_arguments( ) async def test_async_contract_constructor_gas_estimate_with_arguments_non_strict( async_w3_non_strict_abi, - async_non_strict_constructor_with_args_contract_instance, + async_non_strict_constructor_with_args_contract_factory, constructor_args, constructor_kwargs, ): gas_estimate = ( - await async_non_strict_constructor_with_args_contract_instance.constructor( + await async_non_strict_constructor_with_args_contract_factory.constructor( *constructor_args, **constructor_kwargs ).estimate_gas() ) deploy_txn = ( - await async_non_strict_constructor_with_args_contract_instance.constructor( + await async_non_strict_constructor_with_args_contract_factory.constructor( *constructor_args, **constructor_kwargs ).transact() ) @@ -370,16 +366,16 @@ async def test_async_contract_constructor_gas_estimate_with_arguments_non_strict @pytest.mark.asyncio async def test_async_contract_constructor_with_address_argument_gas_estimate( async_w3, - async_constructor_with_address_arg_contract_instance, + async_constructor_with_address_arg_contract_factory, address_conversion_func, ): gas_estimate = ( - await async_constructor_with_address_arg_contract_instance.constructor( + await async_constructor_with_address_arg_contract_factory.constructor( address_conversion_func("0x16D9983245De15E7A9A73bC586E01FF6E08dE737") ).estimate_gas() ) - deploy_txn = await async_constructor_with_address_arg_contract_instance.constructor( + deploy_txn = await async_constructor_with_address_arg_contract_factory.constructor( address_conversion_func("0x16D9983245De15E7A9A73bC586E01FF6E08dE737") ).transact() txn_receipt = await async_w3.eth.wait_for_transaction_receipt(deploy_txn) @@ -391,11 +387,11 @@ async def test_async_contract_constructor_with_address_argument_gas_estimate( @pytest.mark.asyncio async def test_async_contract_constructor_transact_no_constructor( async_w3, - async_math_contract_instance, + async_math_contract_factory, math_contract_runtime, address_conversion_func, ): - deploy_txn = await async_math_contract_instance.constructor().transact() + deploy_txn = await async_math_contract_factory.constructor().transact() txn_receipt = await async_w3.eth.wait_for_transaction_receipt(deploy_txn) assert txn_receipt is not None @@ -410,11 +406,11 @@ async def test_async_contract_constructor_transact_no_constructor( @pytest.mark.asyncio async def test_async_contract_constructor_transact_without_arguments( async_w3, - async_simple_constructor_contract_instance, + async_simple_constructor_contract_factory, address_conversion_func, ): deploy_txn = ( - await async_simple_constructor_contract_instance.constructor().transact() + await async_simple_constructor_contract_factory.constructor().transact() ) txn_receipt = await async_w3.eth.wait_for_transaction_receipt(deploy_txn) @@ -439,7 +435,7 @@ async def test_async_contract_constructor_transact_without_arguments( ) async def test_async_contract_constructor_transact_with_arguments_non_strict( async_w3_non_strict_abi, - async_non_strict_constructor_with_args_contract_instance, + async_non_strict_constructor_with_args_contract_factory, constructor_args, constructor_kwargs, expected_a, @@ -447,7 +443,7 @@ async def test_async_contract_constructor_transact_with_arguments_non_strict( address_conversion_func, ): deploy_txn = ( - await async_non_strict_constructor_with_args_contract_instance.constructor( + await async_non_strict_constructor_with_args_contract_factory.constructor( *constructor_args, **constructor_kwargs ).transact() ) @@ -464,7 +460,7 @@ async def test_async_contract_constructor_transact_with_arguments_non_strict( assert blockchain_code == decode_hex(CONSTRUCTOR_WITH_ARGUMENTS_CONTRACT_RUNTIME) assert ( expected_a - == await async_non_strict_constructor_with_args_contract_instance( + == await async_non_strict_constructor_with_args_contract_factory( address=contract_address ) .functions.data_a() @@ -472,7 +468,7 @@ async def test_async_contract_constructor_transact_with_arguments_non_strict( ) assert ( expected_b - == await async_non_strict_constructor_with_args_contract_instance( + == await async_non_strict_constructor_with_args_contract_factory( address=contract_address ) .functions.data_b() @@ -483,10 +479,10 @@ async def test_async_contract_constructor_transact_with_arguments_non_strict( @pytest.mark.asyncio async def test_async_contract_constructor_transact_with_address_arguments( async_w3, - async_constructor_with_address_arg_contract_instance, + async_constructor_with_address_arg_contract_factory, address_conversion_func, ): - deploy_txn = await async_constructor_with_address_arg_contract_instance.constructor( + deploy_txn = await async_constructor_with_address_arg_contract_factory.constructor( TEST_ADDRESS ).transact() txn_receipt = await async_w3.eth.wait_for_transaction_receipt(deploy_txn) @@ -499,7 +495,7 @@ async def test_async_contract_constructor_transact_with_address_arguments( ) assert ( TEST_ADDRESS - == await async_constructor_with_address_arg_contract_instance( + == await async_constructor_with_address_arg_contract_factory( address=contract_address ) .functions.testAddr() @@ -509,26 +505,24 @@ async def test_async_contract_constructor_transact_with_address_arguments( @pytest.mark.asyncio async def test_async_contract_constructor_build_transaction_to_field_error( - async_math_contract_instance, + async_math_contract_factory, ): with pytest.raises(ValueError): - await async_math_contract_instance.constructor().build_transaction( - {"to": "123"} - ) + await async_math_contract_factory.constructor().build_transaction({"to": "123"}) @pytest.mark.asyncio async def test_async_contract_constructor_build_transaction_no_constructor( - async_w3, async_math_contract_instance, address_conversion_func + async_w3, async_math_contract_factory, address_conversion_func ): async_w3_accounts = await async_w3.eth.accounts - txn_hash = await async_math_contract_instance.constructor().transact( + txn_hash = await async_math_contract_factory.constructor().transact( {"from": address_conversion_func(async_w3_accounts[0])} ) txn = await async_w3.eth.get_transaction(txn_hash) async_w3_coinbase = await async_w3.eth.coinbase nonce = await async_w3.eth.get_transaction_count(async_w3_coinbase) - unsent_txn = await async_math_contract_instance.constructor().build_transaction( + unsent_txn = await async_math_contract_factory.constructor().build_transaction( {"nonce": nonce} ) assert txn["data"] == unsent_txn["data"] @@ -541,16 +535,16 @@ async def test_async_contract_constructor_build_transaction_no_constructor( @pytest.mark.asyncio async def test_async_contract_constructor_build_transaction_without_arguments( - async_w3, async_math_contract_instance, address_conversion_func + async_w3, async_math_contract_factory, address_conversion_func ): async_w3_accounts = await async_w3.eth.accounts - txn_hash = await async_math_contract_instance.constructor().transact( + txn_hash = await async_math_contract_factory.constructor().transact( {"from": address_conversion_func(async_w3_accounts[0])} ) txn = await async_w3.eth.get_transaction(txn_hash) async_w3_coinbase = await async_w3.eth.coinbase nonce = await async_w3.eth.get_transaction_count(async_w3_coinbase) - unsent_txn = await async_math_contract_instance.constructor().build_transaction( + unsent_txn = await async_math_contract_factory.constructor().build_transaction( {"nonce": nonce} ) assert txn["data"] == unsent_txn["data"] @@ -573,14 +567,14 @@ async def test_async_contract_constructor_build_transaction_without_arguments( ) async def test_async_contract_constructor_build_transaction_with_arguments( async_w3_non_strict_abi, - async_non_strict_constructor_with_args_contract_instance, + async_non_strict_constructor_with_args_contract_factory, constructor_args, constructor_kwargs, address_conversion_func, ): async_w3_accounts = await async_w3_non_strict_abi.eth.accounts txn_hash = ( - await async_non_strict_constructor_with_args_contract_instance.constructor( + await async_non_strict_constructor_with_args_contract_factory.constructor( *constructor_args, **constructor_kwargs ).transact({"from": address_conversion_func(async_w3_accounts[0])}) ) @@ -588,7 +582,7 @@ async def test_async_contract_constructor_build_transaction_with_arguments( async_w3_coinbase = await async_w3_non_strict_abi.eth.coinbase nonce = await async_w3_non_strict_abi.eth.get_transaction_count(async_w3_coinbase) unsent_txn = ( - await async_non_strict_constructor_with_args_contract_instance.constructor( + await async_non_strict_constructor_with_args_contract_factory.constructor( *constructor_args, **constructor_kwargs ).build_transaction({"nonce": nonce}) ) diff --git a/tests/core/contracts/test_contract_constructor_encoding.py b/tests/core/contracts/test_contract_constructor_encoding.py index 7f0054290b..ed8e9946a2 100644 --- a/tests/core/contracts/test_contract_constructor_encoding.py +++ b/tests/core/contracts/test_contract_constructor_encoding.py @@ -11,16 +11,16 @@ def test_contract_constructor_abi_encoding_with_no_constructor_fn( - math_contract_instance, math_contract_bytecode + math_contract_factory, math_contract_bytecode ): - deploy_data = math_contract_instance._encode_constructor_data() + deploy_data = math_contract_factory._encode_constructor_data() assert deploy_data == math_contract_bytecode def test_contract_constructor_abi_encoding_with_constructor_with_no_args( - simple_constructor_contract_instance, + simple_constructor_contract_factory, ): - deploy_data = simple_constructor_contract_instance._encode_constructor_data() + deploy_data = simple_constructor_contract_factory._encode_constructor_data() assert deploy_data == SIMPLE_CONSTRUCTOR_CONTRACT_BYTECODE @@ -32,10 +32,10 @@ def test_contract_constructor_abi_encoding_with_constructor_with_no_args( ), ) def test_contract_error_if_additional_args_are_supplied_with_no_constructor_fn( - math_contract_instance, args, kwargs + math_contract_factory, args, kwargs ): with pytest.raises(TypeError, match="Constructor args"): - math_contract_instance._encode_constructor_data(args, kwargs) + math_contract_factory._encode_constructor_data(args, kwargs) @pytest.mark.parametrize( @@ -50,10 +50,10 @@ def test_contract_error_if_additional_args_are_supplied_with_no_constructor_fn( ), ) def test_error_if_invalid_arguments_supplied( - contract_with_constructor_args_instance, arguments + contract_with_constructor_args_factory, arguments ): with pytest.raises(TypeError): - contract_with_constructor_args_instance._encode_constructor_data(arguments) + contract_with_constructor_args_factory._encode_constructor_data(arguments) @pytest.mark.parametrize( @@ -71,11 +71,11 @@ def test_error_if_invalid_arguments_supplied( ) def test_contract_constructor_encoding( w3, - contract_with_constructor_args_instance, + contract_with_constructor_args_factory, encoded_args, bytes_arg, ): - deploy_data = contract_with_constructor_args_instance._encode_constructor_data( + deploy_data = contract_with_constructor_args_factory._encode_constructor_data( [1234, bytes_arg] ) expected_ending = encode_hex( @@ -94,10 +94,10 @@ def test_contract_constructor_encoding( ), ) def test_contract_constructor_encoding_non_strict( - w3_non_strict_abi, non_strict_contract_with_constructor_args_instance, bytes_arg + w3_non_strict_abi, non_strict_contract_with_constructor_args_factory, bytes_arg ): deploy_data = ( - non_strict_contract_with_constructor_args_instance._encode_constructor_data( + non_strict_contract_with_constructor_args_factory._encode_constructor_data( [1234, bytes_arg] ) ) @@ -119,12 +119,12 @@ def test_contract_constructor_encoding_non_strict( ), ) def test_contract_constructor_encoding_strict_errors( - contract_with_constructor_args_instance, bytes_arg + contract_with_constructor_args_factory, bytes_arg ): with pytest.raises( TypeError, match="One or more arguments could not be encoded to the necessary ABI type.", ): - contract_with_constructor_args_instance._encode_constructor_data( + contract_with_constructor_args_factory._encode_constructor_data( [1234, bytes_arg] ) diff --git a/tests/core/contracts/test_contract_deployment.py b/tests/core/contracts/test_contract_deployment.py index 8149c9e721..956e646a3c 100644 --- a/tests/core/contracts/test_contract_deployment.py +++ b/tests/core/contracts/test_contract_deployment.py @@ -15,9 +15,9 @@ def test_contract_deployment_no_constructor( - w3, math_contract_instance, math_contract_runtime + w3, math_contract_factory, math_contract_runtime ): - deploy_txn = math_contract_instance.constructor().transact() + deploy_txn = math_contract_factory.constructor().transact() txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) assert txn_receipt is not None @@ -31,9 +31,9 @@ def test_contract_deployment_no_constructor( def test_contract_deployment_with_constructor_without_args( w3, - simple_constructor_contract_instance, + simple_constructor_contract_factory, ): - deploy_txn = simple_constructor_contract_instance.constructor().transact() + deploy_txn = simple_constructor_contract_factory.constructor().transact() txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) assert txn_receipt is not None @@ -54,10 +54,10 @@ def test_contract_deployment_with_constructor_without_args( ) def test_contract_deployment_with_constructor_with_arguments_strict_by_default( w3, - contract_with_constructor_args_instance, + contract_with_constructor_args_factory, constructor_arg, ): - deploy_txn = contract_with_constructor_args_instance.constructor( + deploy_txn = contract_with_constructor_args_factory.constructor( 1234, constructor_arg ).transact() @@ -73,9 +73,9 @@ def test_contract_deployment_with_constructor_with_arguments_strict_by_default( def test_contract_deployment_with_constructor_with_arguments_non_strict( w3_non_strict_abi, - non_strict_contract_with_constructor_args_instance, + non_strict_contract_with_constructor_args_factory, ): - deploy_txn = non_strict_contract_with_constructor_args_instance.constructor( + deploy_txn = non_strict_contract_with_constructor_args_factory.constructor( 1234, "abcd" ).transact() @@ -90,20 +90,20 @@ def test_contract_deployment_with_constructor_with_arguments_non_strict( def test_contract_deployment_with_constructor_with_arguments_strict_error( - contract_with_constructor_args_instance, + contract_with_constructor_args_factory, ): with pytest.raises( TypeError, match="One or more arguments could not be encoded to the necessary ABI type. Expected types are: uint256, bytes32", # noqa: E501 ): - contract_with_constructor_args_instance.constructor(1234, "abcd").transact() + contract_with_constructor_args_factory.constructor(1234, "abcd").transact() def test_contract_deployment_with_constructor_with_address_argument( w3, - contract_with_constructor_address_instance, + contract_with_constructor_address_factory, ): - deploy_txn = contract_with_constructor_address_instance.constructor( + deploy_txn = contract_with_constructor_address_factory.constructor( "0x16D9983245De15E7A9A73bC586E01FF6E08dE737", ).transact() @@ -121,9 +121,9 @@ def test_contract_deployment_with_constructor_with_address_argument( @pytest.mark.asyncio async def test_async_contract_deployment_no_constructor( - async_w3, async_math_contract_instance, math_contract_runtime + async_w3, async_math_contract_factory, math_contract_runtime ): - deploy_txn = await async_math_contract_instance.constructor().transact() + deploy_txn = await async_math_contract_factory.constructor().transact() txn_receipt = await async_w3.eth.wait_for_transaction_receipt(deploy_txn) assert txn_receipt is not None @@ -138,10 +138,10 @@ async def test_async_contract_deployment_no_constructor( @pytest.mark.asyncio async def test_async_contract_deployment_with_constructor_no_args( async_w3, - async_simple_constructor_contract_instance, + async_simple_constructor_contract_factory, ): deploy_txn = ( - await async_simple_constructor_contract_instance.constructor().transact() + await async_simple_constructor_contract_factory.constructor().transact() ) txn_receipt = await async_w3.eth.wait_for_transaction_receipt(deploy_txn) @@ -164,11 +164,11 @@ async def test_async_contract_deployment_with_constructor_no_args( ) async def test_async_contract_deployment_with_constructor_arguments( async_w3, - async_constructor_with_args_contract_instance, + async_constructor_with_args_contract_factory, constructor_arg, ): - deploy_txn = await async_constructor_with_args_contract_instance.constructor( + deploy_txn = await async_constructor_with_args_contract_factory.constructor( 1234, constructor_arg ).transact() @@ -185,13 +185,13 @@ async def test_async_contract_deployment_with_constructor_arguments( @pytest.mark.asyncio async def test_async_contract_deployment_with_constructor_with_arguments_non_strict( async_w3_non_strict_abi, - async_non_strict_constructor_with_args_contract_instance, + async_non_strict_constructor_with_args_contract_factory, ): deploy_txn = ( - await async_non_strict_constructor_with_args_contract_instance.constructor( + await async_non_strict_constructor_with_args_contract_factory.constructor( 1234, "abcd" ).transact() - ) # noqa: E501 + ) txn_receipt = await async_w3_non_strict_abi.eth.wait_for_transaction_receipt( deploy_txn @@ -207,13 +207,13 @@ async def test_async_contract_deployment_with_constructor_with_arguments_non_str @pytest.mark.asyncio async def test_async_contract_deployment_with_constructor_arguments_strict_error( - async_constructor_with_args_contract_instance, + async_constructor_with_args_contract_factory, ): with pytest.raises( TypeError, match="One or more arguments could not be encoded to the necessary ABI type. Expected types are: uint256, bytes32", # noqa: E501 ): - await async_constructor_with_args_contract_instance.constructor( + await async_constructor_with_args_contract_factory.constructor( 1234, "abcd" ).transact() @@ -221,9 +221,9 @@ async def test_async_contract_deployment_with_constructor_arguments_strict_error @pytest.mark.asyncio async def test_async_contract_deployment_with_constructor_with_address_argument( async_w3, - async_constructor_with_address_arg_contract_instance, -): # noqa: E501 - deploy_txn = await async_constructor_with_address_arg_contract_instance.constructor( + async_constructor_with_address_arg_contract_factory, +): + deploy_txn = await async_constructor_with_address_arg_contract_factory.constructor( "0x16D9983245De15E7A9A73bC586E01FF6E08dE737", ).transact() diff --git a/tests/core/contracts/test_contract_init.py b/tests/core/contracts/test_contract_init.py index 508a0762a1..e297dd5113 100644 --- a/tests/core/contracts/test_contract_init.py +++ b/tests/core/contracts/test_contract_init.py @@ -11,25 +11,23 @@ @pytest.fixture() -def math_addr(math_contract_instance, address_conversion_func): - w3 = math_contract_instance.w3 - deploy_txn = math_contract_instance.constructor().transact( - {"from": w3.eth.coinbase} - ) +def math_addr(math_contract_factory, address_conversion_func): + w3 = math_contract_factory.w3 + deploy_txn = math_contract_factory.constructor().transact({"from": w3.eth.coinbase}) deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) assert deploy_receipt is not None return address_conversion_func(deploy_receipt["contractAddress"]) -def test_contract_with_unset_address(math_contract_instance): - with contract_ens_addresses(math_contract_instance, []): +def test_contract_with_unset_address(math_contract_factory): + with contract_ens_addresses(math_contract_factory, []): with pytest.raises(NameNotFound): - math_contract_instance(address="unsetname.eth") + math_contract_factory(address="unsetname.eth") -def test_contract_with_name_address(math_contract_instance, math_addr): - with contract_ens_addresses(math_contract_instance, [("thedao.eth", math_addr)]): - mc = math_contract_instance(address="thedao.eth") +def test_contract_with_name_address(math_contract_factory, math_addr): + with contract_ens_addresses(math_contract_factory, [("thedao.eth", math_addr)]): + mc = math_contract_factory(address="thedao.eth") caller = mc.w3.eth.coinbase assert mc.address == "thedao.eth" assert mc.functions.return13().call({"from": caller}) == 13 @@ -55,10 +53,10 @@ def test_contract_with_name_address_from_eth_contract( assert mc.functions.return13().call({"from": caller}) == 13 -def test_contract_with_name_address_changing(math_contract_instance, math_addr): +def test_contract_with_name_address_changing(math_contract_factory, math_addr): # Contract address is validated once on creation - with contract_ens_addresses(math_contract_instance, [("thedao.eth", math_addr)]): - mc = math_contract_instance(address="thedao.eth") + with contract_ens_addresses(math_contract_factory, [("thedao.eth", math_addr)]): + mc = math_contract_factory(address="thedao.eth") caller = mc.w3.eth.coinbase assert mc.address == "thedao.eth" diff --git a/tests/core/contracts/test_contract_transact_interface.py b/tests/core/contracts/test_contract_transact_interface.py index 94f0d606f9..4c58d9ab88 100644 --- a/tests/core/contracts/test_contract_transact_interface.py +++ b/tests/core/contracts/test_contract_transact_interface.py @@ -166,7 +166,6 @@ def test_transacting_with_contract_with_bytes32_array_argument( assert final_value == new_bytes32_array -# TODO: strict by default def test_transacting_with_contract_with_byte_array_argument_strict( w3, arrays_contract, transact, call ): @@ -462,7 +461,6 @@ async def test_async_transacting_with_contract_with_bytes32_array_argument( assert final_value == new_bytes32_array -# TODO: strict by default @pytest.mark.asyncio async def test_async_transacting_with_contract_with_byte_array_argument( async_w3, diff --git a/tests/core/contracts/test_extracting_event_data.py b/tests/core/contracts/test_extracting_event_data.py index 60018d63cf..bc06909b58 100644 --- a/tests/core/contracts/test_extracting_event_data.py +++ b/tests/core/contracts/test_extracting_event_data.py @@ -44,18 +44,16 @@ def emitter( wait_for_block, address_conversion_func, ): - emitter_contract_instance = w3.eth.contract(**emitter_contract_data) + emitter_contract_factory = w3.eth.contract(**emitter_contract_data) wait_for_block(w3) - deploy_txn_hash = emitter_contract_instance.constructor().transact( - {"gas": 30029121} - ) + deploy_txn_hash = emitter_contract_factory.constructor().transact({"gas": 30029121}) deploy_receipt = wait_for_transaction(w3, deploy_txn_hash) contract_address = address_conversion_func(deploy_receipt["contractAddress"]) bytecode = w3.eth.get_code(contract_address) - assert bytecode == emitter_contract_instance.bytecode_runtime - _emitter = emitter_contract_instance(address=contract_address) + assert bytecode == emitter_contract_factory.bytecode_runtime + _emitter = emitter_contract_factory(address=contract_address) assert _emitter.address == contract_address return _emitter diff --git a/tests/core/contracts/test_extracting_event_data_old.py b/tests/core/contracts/test_extracting_event_data_old.py index 071e92238b..a2bf1cb747 100644 --- a/tests/core/contracts/test_extracting_event_data_old.py +++ b/tests/core/contracts/test_extracting_event_data_old.py @@ -17,18 +17,16 @@ def emitter( wait_for_block, address_conversion_func, ): - emitter_contract_instance = w3.eth.contract(**emitter_contract_data) + emitter_contract_factory = w3.eth.contract(**emitter_contract_data) wait_for_block(w3) - deploy_txn_hash = emitter_contract_instance.constructor().transact( - {"gas": 10000000} - ) + deploy_txn_hash = emitter_contract_factory.constructor().transact({"gas": 10000000}) deploy_receipt = wait_for_transaction(w3, deploy_txn_hash) contract_address = address_conversion_func(deploy_receipt["contractAddress"]) bytecode = w3.eth.get_code(contract_address) - assert bytecode == emitter_contract_instance.bytecode_runtime - _emitter = emitter_contract_instance(address=contract_address) + assert bytecode == emitter_contract_factory.bytecode_runtime + _emitter = emitter_contract_factory(address=contract_address) assert _emitter.address == contract_address return _emitter diff --git a/tests/core/contracts/test_offchain_lookup.py b/tests/core/contracts/test_offchain_lookup.py index 42e6aa1bde..a077ebf93b 100644 --- a/tests/core/contracts/test_offchain_lookup.py +++ b/tests/core/contracts/test_offchain_lookup.py @@ -26,7 +26,7 @@ @pytest.fixture -def offchain_lookup_contract_instance(w3): +def offchain_lookup_contract_factory(w3): return w3.eth.contract(**OFFCHAIN_LOOKUP_DATA) @@ -34,20 +34,20 @@ def offchain_lookup_contract_instance(w3): def offchain_lookup_contract( w3, wait_for_block, - offchain_lookup_contract_instance, + offchain_lookup_contract_factory, wait_for_transaction, address_conversion_func, ): wait_for_block(w3) - deploy_txn_hash = offchain_lookup_contract_instance.constructor().transact( + deploy_txn_hash = offchain_lookup_contract_factory.constructor().transact( {"gas": 10000000} ) deploy_receipt = wait_for_transaction(w3, deploy_txn_hash) contract_address = address_conversion_func(deploy_receipt["contractAddress"]) bytecode = w3.eth.get_code(contract_address) - assert bytecode == offchain_lookup_contract_instance.bytecode_runtime - deployed_offchain_lookup = offchain_lookup_contract_instance( + assert bytecode == offchain_lookup_contract_factory.bytecode_runtime + deployed_offchain_lookup = offchain_lookup_contract_factory( address=contract_address ) assert deployed_offchain_lookup.address == contract_address diff --git a/tests/core/contracts/utils.py b/tests/core/contracts/utils.py index 1edf353f49..165939cf86 100644 --- a/tests/core/contracts/utils.py +++ b/tests/core/contracts/utils.py @@ -3,25 +3,25 @@ ) -def deploy(w3, contract_instance, apply_func=identity, args=None): +def deploy(w3, contract_factory, apply_func=identity, args=None): args = args or [] - deploy_txn = contract_instance.constructor(*args).transact() + deploy_txn = contract_factory.constructor(*args).transact() deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn) assert deploy_receipt is not None address = apply_func(deploy_receipt["contractAddress"]) - contract = contract_instance(address=address) + contract = contract_factory(address=address) assert contract.address == address assert len(w3.eth.get_code(contract.address)) > 0 return contract -async def async_deploy(async_web3, contract_instance, apply_func=identity, args=None): +async def async_deploy(async_web3, contract_factory, apply_func=identity, args=None): args = args or [] - deploy_txn = await contract_instance.constructor(*args).transact() + deploy_txn = await contract_factory.constructor(*args).transact() deploy_receipt = await async_web3.eth.wait_for_transaction_receipt(deploy_txn) assert deploy_receipt is not None address = apply_func(deploy_receipt["contractAddress"]) - contract = contract_instance(address=address) + contract = contract_factory(address=address) assert contract.address == address assert len(await async_web3.eth.get_code(contract.address)) > 0 return contract diff --git a/tests/core/filtering/conftest.py b/tests/core/filtering/conftest.py index 78659ddb28..331381be2a 100644 --- a/tests/core/filtering/conftest.py +++ b/tests/core/filtering/conftest.py @@ -27,21 +27,21 @@ def w3(request): @pytest.fixture -def emitter_contract_instance(w3, emitter_contract_data): +def emitter_contract_factory(w3, emitter_contract_data): return w3.eth.contract(**emitter_contract_data) @pytest.fixture def emitter( w3, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, wait_for_block, address_conversion_func, ): return _emitter_fixture_logic( w3, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, wait_for_block, address_conversion_func, @@ -74,21 +74,21 @@ def async_w3(request): @pytest.fixture -def async_emitter_contract_instance(async_w3, emitter_contract_data): +def async_emitter_contract_factory(async_w3, emitter_contract_data): return async_w3.eth.contract(**emitter_contract_data) @pytest_asyncio.fixture async def async_emitter( async_w3, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, async_wait_for_block, address_conversion_func, ): return await _async_emitter_fixture_logic( async_w3, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, async_wait_for_block, address_conversion_func, diff --git a/tests/core/filtering/test_contract_data_filters.py b/tests/core/filtering/test_contract_data_filters.py index e1dd33063d..d35457ca5e 100644 --- a/tests/core/filtering/test_contract_data_filters.py +++ b/tests/core/filtering/test_contract_data_filters.py @@ -93,10 +93,10 @@ def emitter( wait_for_block, address_conversion_func, ): - emitter_contract_instance = w3.eth.contract(**emitter_contract_data) + emitter_contract_factory = w3.eth.contract(**emitter_contract_data) return _emitter_fixture_logic( w3, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, wait_for_block, address_conversion_func, @@ -289,7 +289,7 @@ def async_w3(request): @pytest.fixture(scope="module") -def async_emitter_contract_instance(async_w3, emitter_contract_data): +def async_emitter_contract_factory(async_w3, emitter_contract_data): async_w3.eth.contract(**emitter_contract_data) @@ -301,10 +301,10 @@ async def async_emitter( async_wait_for_block, address_conversion_func, ): - async_emitter_contract_instance = async_w3.eth.contract(**emitter_contract_data) + async_emitter_contract_factory = async_w3.eth.contract(**emitter_contract_data) return await _async_emitter_fixture_logic( async_w3, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, async_wait_for_block, address_conversion_func, diff --git a/tests/core/filtering/test_contract_on_event_filtering.py b/tests/core/filtering/test_contract_on_event_filtering.py index df95b2aaa7..d9fb47ad0d 100644 --- a/tests/core/filtering/test_contract_on_event_filtering.py +++ b/tests/core/filtering/test_contract_on_event_filtering.py @@ -8,12 +8,12 @@ @pytest.mark.parametrize("call_deployed_contract", (True, False)) def test_create_filter_address_parameter( - emitter, emitter_contract_instance, call_deployed_contract + emitter, emitter_contract_factory, call_deployed_contract ): if call_deployed_contract: event_filter = emitter.events.LogNoArguments.create_filter(fromBlock="latest") else: - event_filter = emitter_contract_instance.events.LogNoArguments.create_filter( + event_filter = emitter_contract_factory.events.LogNoArguments.create_filter( fromBlock="latest" ) @@ -30,7 +30,7 @@ def test_create_filter_address_parameter( def test_on_filter_using_get_entries_interface( w3, emitter, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -41,7 +41,7 @@ def test_on_filter_using_get_entries_interface( if call_deployed_contract: contract = emitter else: - contract = emitter_contract_instance + contract = emitter_contract_factory if api_style == "build_filter": event_filter = contract.events.LogNoArguments.build_filter().deploy(w3) @@ -67,7 +67,7 @@ def test_on_filter_using_get_entries_interface( def test_on_sync_filter_with_event_name_and_single_argument( w3, emitter, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -78,7 +78,7 @@ def test_on_sync_filter_with_event_name_and_single_argument( if call_deployed_contract: contract = emitter else: - contract = emitter_contract_instance + contract = emitter_contract_factory if api_style == "build_filter": builder = contract.events.LogTripleWithIndex.build_filter() @@ -115,7 +115,7 @@ def test_on_sync_filter_with_event_name_and_single_argument( def test_on_sync_filter_with_event_name_and_non_indexed_argument( w3, emitter, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -126,7 +126,7 @@ def test_on_sync_filter_with_event_name_and_non_indexed_argument( if call_deployed_contract: contract = emitter else: - contract = emitter_contract_instance + contract = emitter_contract_factory if api_style == "build_filter": builder = contract.events.LogTripleWithIndex.build_filter() @@ -186,7 +186,7 @@ def test_filter_with_contract_address( def test_on_sync_filter_with_topic_filter_options_on_old_apis( w3, emitter, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -196,7 +196,7 @@ def test_on_sync_filter_with_topic_filter_options_on_old_apis( if call_deployed_contract: contract = emitter else: - contract = emitter_contract_instance + contract = emitter_contract_factory event_filter = create_filter( contract, ["LogTripleWithIndex", {"filter": {"arg1": [1, 2], "arg2": [1, 2]}}] @@ -236,7 +236,7 @@ def event_loop(): @pytest.mark.asyncio @pytest.mark.parametrize("call_deployed_contract", (True, False)) async def test_async_create_filter_address_parameter( - async_emitter, async_emitter_contract_instance, call_deployed_contract + async_emitter, async_emitter_contract_factory, call_deployed_contract ): if call_deployed_contract: event_filter = await async_emitter.events.LogNoArguments.create_filter( @@ -244,7 +244,7 @@ async def test_async_create_filter_address_parameter( ) else: event_filter = ( - await async_emitter_contract_instance.events.LogNoArguments.create_filter( + await async_emitter_contract_factory.events.LogNoArguments.create_filter( fromBlock="latest" ) ) @@ -263,7 +263,7 @@ async def test_async_create_filter_address_parameter( async def test_on_async_filter_using_get_entries_interface( async_w3, async_emitter, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -274,7 +274,7 @@ async def test_on_async_filter_using_get_entries_interface( if call_deployed_contract: contract = async_emitter else: - contract = async_emitter_contract_instance + contract = async_emitter_contract_factory if api_style == "build_filter": event_filter = await contract.events.LogNoArguments.build_filter().deploy( @@ -303,7 +303,7 @@ async def test_on_async_filter_using_get_entries_interface( async def test_on_async_filter_with_event_name_and_single_argument( async_w3, async_emitter, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -314,7 +314,7 @@ async def test_on_async_filter_with_event_name_and_single_argument( if call_deployed_contract: contract = async_emitter else: - contract = async_emitter_contract_instance + contract = async_emitter_contract_factory if api_style == "build_filter": builder = contract.events.LogTripleWithIndex.build_filter() @@ -358,7 +358,7 @@ async def test_on_async_filter_with_event_name_and_single_argument( async def test_on_async_filter_with_event_name_and_non_indexed_argument( async_w3, async_emitter, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -369,7 +369,7 @@ async def test_on_async_filter_with_event_name_and_non_indexed_argument( if call_deployed_contract: contract = async_emitter else: - contract = async_emitter_contract_instance + contract = async_emitter_contract_factory if api_style == "build_filter": builder = contract.events.LogTripleWithIndex.build_filter() @@ -439,7 +439,7 @@ async def test_async_filter_with_contract_address( async def test_on_async_filter_with_topic_filter_options_on_old_apis( async_w3, async_emitter, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -449,7 +449,7 @@ async def test_on_async_filter_with_topic_filter_options_on_old_apis( if call_deployed_contract: contract = async_emitter else: - contract = async_emitter_contract_instance + contract = async_emitter_contract_factory event_filter = await async_create_filter( contract, ["LogTripleWithIndex", {"filter": {"arg1": [1, 2], "arg2": [1, 2]}}] diff --git a/tests/core/filtering/test_contract_past_event_filtering.py b/tests/core/filtering/test_contract_past_event_filtering.py index 1b5c54b0ab..011b4f2248 100644 --- a/tests/core/filtering/test_contract_past_event_filtering.py +++ b/tests/core/filtering/test_contract_past_event_filtering.py @@ -11,7 +11,7 @@ def test_on_filter_using_get_all_entries_interface( w3, emitter, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -21,7 +21,7 @@ def test_on_filter_using_get_all_entries_interface( if call_deployed_contract: contract = emitter else: - contract = emitter_contract_instance + contract = emitter_contract_factory if api_style == "build_filter": builder = contract.events.LogNoArguments.build_filter() @@ -54,7 +54,7 @@ def test_on_filter_using_get_all_entries_interface( def test_get_all_entries_returned_block_data( w3, emitter, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -69,7 +69,7 @@ def test_get_all_entries_returned_block_data( if call_deployed_contract: contract = emitter else: - contract = emitter_contract_instance + contract = emitter_contract_factory if api_style == "build_filter": builder = contract.events.LogNoArguments.build_filter() @@ -108,7 +108,7 @@ def event_loop(): async def test_on_async_filter_using_get_all_entries_interface( async_w3, async_emitter, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -118,7 +118,7 @@ async def test_on_async_filter_using_get_all_entries_interface( if call_deployed_contract: contract = async_emitter else: - contract = async_emitter_contract_instance + contract = async_emitter_contract_factory if api_style == "build_filter": builder = contract.events.LogNoArguments.build_filter() @@ -152,7 +152,7 @@ async def test_on_async_filter_using_get_all_entries_interface( async def test_async_get_all_entries_returned_block_data( async_w3, async_emitter, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, emitter_contract_event_ids, call_deployed_contract, @@ -167,7 +167,7 @@ async def test_async_get_all_entries_returned_block_data( if call_deployed_contract: contract = async_emitter else: - contract = async_emitter_contract_instance + contract = async_emitter_contract_factory if api_style == "build_filter": builder = contract.events.LogNoArguments.build_filter() diff --git a/tests/core/filtering/test_contract_topic_filters.py b/tests/core/filtering/test_contract_topic_filters.py index 93d3cadd54..6ba4673520 100644 --- a/tests/core/filtering/test_contract_topic_filters.py +++ b/tests/core/filtering/test_contract_topic_filters.py @@ -93,10 +93,10 @@ def emitter( wait_for_block, address_conversion_func, ): - emitter_contract_instance = w3.eth.contract(**emitter_contract_data) + emitter_contract_factory = w3.eth.contract(**emitter_contract_data) return _emitter_fixture_logic( w3, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, wait_for_block, address_conversion_func, @@ -277,11 +277,11 @@ async def async_emitter( async_wait_for_block, address_conversion_func, ): - async_emitter_contract_instance = async_w3.eth.contract(**emitter_contract_data) + async_emitter_contract_factory = async_w3.eth.contract(**emitter_contract_data) return await _async_emitter_fixture_logic( async_w3, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, async_wait_for_block, address_conversion_func, diff --git a/tests/core/filtering/test_filters_against_many_blocks.py b/tests/core/filtering/test_filters_against_many_blocks.py index 26db54d0f2..1a31532060 100644 --- a/tests/core/filtering/test_filters_against_many_blocks.py +++ b/tests/core/filtering/test_filters_against_many_blocks.py @@ -36,7 +36,7 @@ def single_transaction(w3): def test_event_filter_new_events( w3, emitter, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, emitter_contract_event_ids, api_style, @@ -103,7 +103,7 @@ def test_transaction_filter_without_mining(w3): def test_event_filter_new_events_many_deployed_contracts( w3, emitter, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, emitter_contract_event_ids, api_style, @@ -113,7 +113,7 @@ def test_event_filter_new_events_many_deployed_contracts( matching_transact = emitter.functions.logNoArgs(which=1).transact deployed_contract_addresses = deploy_contracts( - w3, emitter_contract_instance, wait_for_transaction + w3, emitter_contract_factory, wait_for_transaction ) def gen_non_matching_transact(): @@ -122,7 +122,7 @@ def gen_non_matching_transact(): random.randint(0, len(deployed_contract_addresses) - 1) ] yield w3.eth.contract( - address=contract_address, abi=emitter_contract_instance.abi + address=contract_address, abi=emitter_contract_factory.abi ).functions.logNoArgs(which=1).transact non_matching_transact = gen_non_matching_transact() @@ -267,7 +267,7 @@ async def test_async_transaction_filter_without_mining(async_w3): async def test_async_event_filter_new_events_many_deployed_contracts( async_w3, async_emitter, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, api_style, ): @@ -275,7 +275,7 @@ async def test_async_event_filter_new_events_many_deployed_contracts( matching_transact = async_emitter.functions.logNoArgs(which=1).transact deployed_contract_addresses = await async_deploy_contracts( - async_w3, async_emitter_contract_instance, async_wait_for_transaction + async_w3, async_emitter_contract_factory, async_wait_for_transaction ) async def gen_non_matching_transact(): @@ -284,7 +284,7 @@ async def gen_non_matching_transact(): random.randint(0, len(deployed_contract_addresses) - 1) ] yield async_w3.eth.contract( - address=contract_address, abi=async_emitter_contract_instance.abi + address=contract_address, abi=async_emitter_contract_factory.abi ).functions.logNoArgs(which=1).transact non_matching_transact = gen_non_matching_transact() diff --git a/tests/core/filtering/utils.py b/tests/core/filtering/utils.py index ed9a79ed26..ef54e97869 100644 --- a/tests/core/filtering/utils.py +++ b/tests/core/filtering/utils.py @@ -23,21 +23,19 @@ def _w3_fixture_logic(request): def _emitter_fixture_logic( w3, - emitter_contract_instance, + emitter_contract_factory, wait_for_transaction, wait_for_block, address_conversion_func, ): wait_for_block(w3) - deploy_txn_hash = emitter_contract_instance.constructor().transact( - {"gas": 10000000} - ) + deploy_txn_hash = emitter_contract_factory.constructor().transact({"gas": 10000000}) deploy_receipt = wait_for_transaction(w3, deploy_txn_hash) contract_address = address_conversion_func(deploy_receipt["contractAddress"]) bytecode = w3.eth.get_code(contract_address) - assert bytecode == emitter_contract_instance.bytecode_runtime - _emitter = emitter_contract_instance(address=contract_address) + assert bytecode == emitter_contract_factory.bytecode_runtime + _emitter = emitter_contract_factory(address=contract_address) assert _emitter.address == contract_address return _emitter @@ -57,20 +55,20 @@ def _async_w3_fixture_logic(request): async def _async_emitter_fixture_logic( async_w3, - async_emitter_contract_instance, + async_emitter_contract_factory, async_wait_for_transaction, async_wait_for_block, address_conversion_func, ): await async_wait_for_block(async_w3) - deploy_txn_hash = await async_emitter_contract_instance.constructor().transact( + deploy_txn_hash = await async_emitter_contract_factory.constructor().transact( {"gas": 10000000} ) deploy_receipt = await async_wait_for_transaction(async_w3, deploy_txn_hash) contract_address = address_conversion_func(deploy_receipt["contractAddress"]) bytecode = await async_w3.eth.get_code(contract_address) - assert bytecode == async_emitter_contract_instance.bytecode_runtime - _emitter = async_emitter_contract_instance(address=contract_address) + assert bytecode == async_emitter_contract_factory.bytecode_runtime + _emitter = async_emitter_contract_factory(address=contract_address) assert _emitter.address == contract_address return _emitter diff --git a/tests/core/tools/pytest_ethereum/test_deployer.py b/tests/core/tools/pytest_ethereum/test_deployer.py index 1f5ccbef8b..f03f535006 100644 --- a/tests/core/tools/pytest_ethereum/test_deployer.py +++ b/tests/core/tools/pytest_ethereum/test_deployer.py @@ -28,9 +28,9 @@ def greeter(deployer, pte_assets_dir): def test_user_code_with_fixture(greeter): - greeter_instance = greeter.deployments.get_instance("greeter") - assert isinstance(greeter_instance, web3.contract.Contract) - greeting = greeter_instance.functions.greet().call() + greeter_factory = greeter.deployments.get_factory("greeter") + assert isinstance(greeter_factory, web3.contract.Contract) + greeting = greeter_factory.functions.greet().call() assert greeting == b"Hello" @@ -48,8 +48,8 @@ def owned(deployer): def test_owned_deployer(owned): - owned_contract_instance = owned.deployments.get_instance("Owned") - assert is_address(owned_contract_instance.address) + owned_contract_factory = owned.deployments.get_factory("Owned") + assert is_address(owned_contract_factory.address) # CONSTRUCTOR ARGS @@ -63,8 +63,8 @@ def standard_token(deployer): def test_standard_token_deployer(standard_token): - standard_token_instance = standard_token.deployments.get_instance("StandardToken") - assert standard_token_instance.functions.totalSupply().call() == 100 + standard_token_factory = standard_token.deployments.get_factory("StandardToken") + assert standard_token_factory.functions.totalSupply().call() == 100 # LIBRARY @@ -76,8 +76,8 @@ def safe_math(deployer, ethpm_spec_dir): def test_safe_math_deployer(safe_math): - safe_math_instance = safe_math.deployments.get_instance("SafeMathLib") - assert is_address(safe_math_instance.address) + safe_math_factory = safe_math.deployments.get_factory("SafeMathLib") + assert is_address(safe_math_factory.address) def test_escrow_deployer_unlinked(escrow_deployer): diff --git a/tests/ens/conftest.py b/tests/ens/conftest.py index 7fe0eb23e1..cc00a4a5f9 100644 --- a/tests/ens/conftest.py +++ b/tests/ens/conftest.py @@ -173,7 +173,7 @@ def ens_setup(): ) reverse_tld_namehash = bytes32( 0xA097F6721CE401E757D1223A763FEF49B8B5F90BB18567DDB86FD205DFF71D34 - ) # noqa: E501 + ) reverser_namehash = bytes32( 0x91D1777781884D03A6757A803996E38DE2A42967FB37EEACA72729271025A9E2 )