From ddc8a818607c050c0b7f6c5a6995f162beef3111 Mon Sep 17 00:00:00 2001 From: voith Date: Fri, 22 Jun 2018 21:03:30 +0530 Subject: [PATCH] test contracts with binary addresses --- tests/core/contracts/conftest.py | 22 +++++-- tests/core/contracts/test_concise_contract.py | 5 +- .../test_contract_ambiguous_functions.py | 6 +- .../test_contract_buildTransaction.py | 12 ++-- .../contracts/test_contract_call_interface.py | 62 +++++++++++-------- .../contracts/test_contract_constructor.py | 60 ++++++++++++------ .../contracts/test_contract_estimateGas.py | 12 ++-- tests/core/contracts/test_contract_init.py | 19 +----- .../test_contract_transact_interface.py | 25 +++++--- .../contracts/test_extracting_event_data.py | 8 ++- .../test_extracting_event_data_old.py | 8 ++- .../core/contracts/test_implicit_contract.py | 8 ++- 12 files changed, 151 insertions(+), 96 deletions(-) diff --git a/tests/core/contracts/conftest.py b/tests/core/contracts/conftest.py index 24b0c6b455..3ca3415829 100644 --- a/tests/core/contracts/conftest.py +++ b/tests/core/contracts/conftest.py @@ -4,6 +4,11 @@ from eth_utils import ( event_signature_to_log_topic, + to_bytes, +) + +from web3.utils.toolz import ( + identity, ) CONTRACT_CODE = "0x606060405261022e806100126000396000f360606040523615610074576000357c01000000000000000000000000000000000000000000000000000000009004806316216f391461007657806361bc221a146100995780637cf5dab0146100bc578063a5f3c23b146100e8578063d09de08a1461011d578063dcf537b11461014057610074565b005b610083600480505061016c565b6040518082815260200191505060405180910390f35b6100a6600480505061017f565b6040518082815260200191505060405180910390f35b6100d26004808035906020019091905050610188565b6040518082815260200191505060405180910390f35b61010760048080359060200190919080359060200190919050506101ea565b6040518082815260200191505060405180910390f35b61012a6004805050610201565b6040518082815260200191505060405180910390f35b6101566004808035906020019091905050610217565b6040518082815260200191505060405180910390f35b6000600d9050805080905061017c565b90565b60006000505481565b6000816000600082828250540192505081905550600060005054905080507f3496c3ede4ec3ab3686712aa1c238593ea6a42df83f98a5ec7df9834cfa577c5816040518082815260200191505060405180910390a18090506101e5565b919050565b6000818301905080508090506101fb565b92915050565b600061020d6001610188565b9050610214565b90565b60006007820290508050809050610229565b91905056" # noqa: E501 @@ -15,6 +20,11 @@ CONTRACT_ABI = json.loads('[{"constant":false,"inputs":[],"name":"return13","outputs":[{"name":"result","type":"int256"}],"type":"function"},{"constant":true,"inputs":[],"name":"counter","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"amt","type":"uint256"}],"name":"increment","outputs":[{"name":"result","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"a","type":"int256"},{"name":"b","type":"int256"}],"name":"add","outputs":[{"name":"result","type":"int256"}],"type":"function"},{"constant":false,"inputs":[],"name":"increment","outputs":[{"name":"","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"a","type":"int256"}],"name":"multiply7","outputs":[{"name":"result","type":"int256"}],"type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"value","type":"uint256"}],"name":"Increased","type":"event"}]') # noqa: E501 +@pytest.fixture(params=[lambda x: to_bytes(hexstr=x), identity]) +def address_conversion_func(request): + return request.param + + @pytest.fixture(scope="session") def MATH_CODE(): return CONTRACT_CODE @@ -292,17 +302,19 @@ def Emitter(web3_empty, EMITTER): @pytest.fixture() -def emitter(web3_empty, Emitter, wait_for_transaction, wait_for_block): +def emitter(web3_empty, Emitter, wait_for_transaction, wait_for_block, address_conversion_func): web3 = web3_empty wait_for_block(web3) deploy_txn_hash = Emitter.constructor().transact({'from': web3.eth.coinbase, 'gas': 1000000}) deploy_receipt = wait_for_transaction(web3, deploy_txn_hash) - contract_address = deploy_receipt['contractAddress'] + contract_address = address_conversion_func(deploy_receipt['contractAddress']) bytecode = web3.eth.getCode(contract_address) assert bytecode == Emitter.bytecode_runtime - return Emitter(address=contract_address) + emitter_contract = Emitter(address=contract_address) + assert emitter_contract.address == contract_address + return emitter_contract CONTRACT_ARRAYS_SOURCE = """ @@ -527,8 +539,8 @@ def emitter_log_topics(): @pytest.fixture() -def some_address(): - return '0x5B2063246F2191f18F2675ceDB8b28102e957458' +def some_address(address_conversion_func): + return address_conversion_func('0x5B2063246F2191f18F2675ceDB8b28102e957458') def invoke_contract(api_style=None, diff --git a/tests/core/contracts/test_concise_contract.py b/tests/core/contracts/test_concise_contract.py index 7db0d5ca1b..982d36d731 100644 --- a/tests/core/contracts/test_concise_contract.py +++ b/tests/core/contracts/test_concise_contract.py @@ -25,8 +25,9 @@ def deploy(web3, Contract, args=None): @pytest.fixture() -def EMPTY_ADDR(): - return '0x' + '00' * 20 +def EMPTY_ADDR(address_conversion_func): + addr = '0x' + '00' * 20 + return address_conversion_func(addr) @pytest.fixture() diff --git a/tests/core/contracts/test_contract_ambiguous_functions.py b/tests/core/contracts/test_contract_ambiguous_functions.py index e97e3433aa..d7ab9c8d42 100644 --- a/tests/core/contracts/test_contract_ambiguous_functions.py +++ b/tests/core/contracts/test_contract_ambiguous_functions.py @@ -41,11 +41,13 @@ @pytest.fixture() -def string_contract(web3, StringContract): +def string_contract(web3, StringContract, address_conversion_func): deploy_txn = StringContract.constructor("Caqalai").transact() deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - contract = StringContract(address=deploy_receipt['contractAddress']) + contract_address = address_conversion_func(deploy_receipt['contractAddress']) + contract = StringContract(address=contract_address) + assert contract.address == contract_address assert len(web3.eth.getCode(contract.address)) > 0 return contract diff --git a/tests/core/contracts/test_contract_buildTransaction.py b/tests/core/contracts/test_contract_buildTransaction.py index 640e72880c..6707399ff7 100644 --- a/tests/core/contracts/test_contract_buildTransaction.py +++ b/tests/core/contracts/test_contract_buildTransaction.py @@ -11,20 +11,24 @@ @pytest.fixture() -def math_contract(web3, MathContract): +def math_contract(web3, MathContract, address_conversion_func): deploy_txn = MathContract.constructor().transact() deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - _math_contract = MathContract(address=deploy_receipt['contractAddress']) + math_contract_address = address_conversion_func(deploy_receipt['contractAddress']) + _math_contract = MathContract(address=math_contract_address) + assert _math_contract.address == math_contract_address return _math_contract @pytest.fixture() -def fallback_function_contract(web3, FallballFunctionContract): +def fallback_function_contract(web3, FallballFunctionContract, address_conversion_func): deploy_txn = FallballFunctionContract.constructor().transact() deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - _fallback_contract = FallballFunctionContract(address=deploy_receipt['contractAddress']) + fallback_contract_address = address_conversion_func(deploy_receipt['contractAddress']) + _fallback_contract = FallballFunctionContract(address=fallback_contract_address) + assert _fallback_contract.address == fallback_contract_address return _fallback_contract diff --git a/tests/core/contracts/test_contract_call_interface.py b/tests/core/contracts/test_contract_call_interface.py index 295145c5e5..8a567f3253 100644 --- a/tests/core/contracts/test_contract_call_interface.py +++ b/tests/core/contracts/test_contract_call_interface.py @@ -20,62 +20,70 @@ from web3.utils.ens import ( contract_ens_addresses, ) +from web3.utils.toolz import ( + identity, +) # Ignore warning in pyethereum 1.6 - will go away with the upgrade pytestmark = pytest.mark.filterwarnings("ignore:implicit cast from 'char *'") -def deploy(web3, Contract, args=None): +def deploy(web3, Contract, apply_func=identity, args=None): args = args or [] deploy_txn = Contract.constructor(*args).transact() deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - contract = Contract(address=deploy_receipt['contractAddress']) + address = apply_func(deploy_receipt['contractAddress']) + contract = Contract(address=address) + assert contract.address == address assert len(web3.eth.getCode(contract.address)) > 0 return contract @pytest.fixture() -def address_reflector_contract(web3, AddressReflectorContract): - return deploy(web3, AddressReflectorContract) +def address_reflector_contract(web3, AddressReflectorContract, address_conversion_func): + return deploy(web3, AddressReflectorContract, address_conversion_func) @pytest.fixture() -def math_contract(web3, MathContract): - return deploy(web3, MathContract) +def math_contract(web3, MathContract, address_conversion_func): + return deploy(web3, MathContract, address_conversion_func) @pytest.fixture() -def string_contract(web3, StringContract): - return deploy(web3, StringContract, args=["Caqalai"]) +def string_contract(web3, StringContract, address_conversion_func): + return deploy(web3, StringContract, address_conversion_func, args=["Caqalai"]) @pytest.fixture() -def arrays_contract(web3, ArraysContract): +def arrays_contract(web3, ArraysContract, address_conversion_func): # bytes_32 = [keccak('0'), keccak('1')] bytes32_array = [ b'\x04HR\xb2\xa6p\xad\xe5@~x\xfb(c\xc5\x1d\xe9\xfc\xb9eB\xa0q\x86\xfe:\xed\xa6\xbb\x8a\x11m', # noqa: E501 b'\xc8\x9e\xfd\xaaT\xc0\xf2\x0cz\xdfa(\x82\xdf\tP\xf5\xa9Qc~\x03\x07\xcd\xcbLg/)\x8b\x8b\xc6', # noqa: E501 ] byte_arr = [b'\xff', b'\xff', b'\xff', b'\xff'] - return deploy(web3, ArraysContract, args=[bytes32_array, byte_arr]) + return deploy(web3, ArraysContract, address_conversion_func, args=[bytes32_array, byte_arr]) @pytest.fixture() -def address_contract(web3, WithConstructorAddressArgumentsContract): - return deploy(web3, WithConstructorAddressArgumentsContract, args=[ - "0xd3CdA913deB6f67967B99D67aCDFa1712C293601", - ]) +def address_contract(web3, WithConstructorAddressArgumentsContract, address_conversion_func): + return deploy( + web3, + WithConstructorAddressArgumentsContract, + address_conversion_func, + args=["0xd3CdA913deB6f67967B99D67aCDFa1712C293601"] + ) @pytest.fixture(params=[b'\x04\x06', '0x0406', '0406']) -def bytes_contract(web3, BytesContract, request): - return deploy(web3, BytesContract, args=[request.param]) +def bytes_contract(web3, BytesContract, request, address_conversion_func): + return deploy(web3, BytesContract, address_conversion_func, args=[request.param]) @pytest.fixture() -def fixed_reflection_contract(web3, FixedReflectionContract): - return deploy(web3, FixedReflectionContract) +def fixed_reflection_contract(web3, FixedReflectionContract, address_conversion_func): + return deploy(web3, FixedReflectionContract, address_conversion_func) @pytest.fixture() @@ -91,30 +99,30 @@ def call_transaction(): '0406040604060406040604060406040604060406040604060406040604060406', HexBytes('0406040604060406040604060406040604060406040604060406040604060406'), ]) -def bytes32_contract(web3, Bytes32Contract, request): - return deploy(web3, Bytes32Contract, args=[request.param]) +def bytes32_contract(web3, Bytes32Contract, request, address_conversion_func): + return deploy(web3, Bytes32Contract, address_conversion_func, args=[request.param]) @pytest.fixture() -def undeployed_math_contract(web3, MathContract): - empty_address = "0x000000000000000000000000000000000000dEaD" +def undeployed_math_contract(web3, MathContract, address_conversion_func): + empty_address = address_conversion_func("0x000000000000000000000000000000000000dEaD") _undeployed_math_contract = MathContract(address=empty_address) return _undeployed_math_contract @pytest.fixture() -def mismatched_math_contract(web3, StringContract, MathContract): +def mismatched_math_contract(web3, StringContract, MathContract, address_conversion_func): deploy_txn = StringContract.constructor("Caqalai").transact() deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - - _mismatched_math_contract = MathContract(address=deploy_receipt['contractAddress']) + address = address_conversion_func(deploy_receipt['contractAddress']) + _mismatched_math_contract = MathContract(address=address) return _mismatched_math_contract @pytest.fixture() -def fallback_function_contract(web3, FallballFunctionContract): - return deploy(web3, FallballFunctionContract) +def fallback_function_contract(web3, FallballFunctionContract, address_conversion_func): + return deploy(web3, FallballFunctionContract, address_conversion_func) def test_invalid_address_in_deploy_arg(web3, WithConstructorAddressArgumentsContract): diff --git a/tests/core/contracts/test_contract_constructor.py b/tests/core/contracts/test_contract_constructor.py index 1c3b11e76c..62995de406 100644 --- a/tests/core/contracts/test_contract_constructor.py +++ b/tests/core/contracts/test_contract_constructor.py @@ -64,40 +64,48 @@ def test_contract_constructor_gas_estimate_with_constructor_with_arguments( def test_contract_constructor_gas_estimate_with_constructor_with_address_argument( web3, - WithConstructorAddressArgumentsContract): + WithConstructorAddressArgumentsContract, + address_conversion_func): gas_estimate = WithConstructorAddressArgumentsContract.constructor( - "0x16D9983245De15E7A9A73bC586E01FF6E08dE737").estimateGas() + address_conversion_func("0x16D9983245De15E7A9A73bC586E01FF6E08dE737")).estimateGas() deploy_txn = WithConstructorAddressArgumentsContract.constructor( - "0x16D9983245De15E7A9A73bC586E01FF6E08dE737").transact() + address_conversion_func("0x16D9983245De15E7A9A73bC586E01FF6E08dE737")).transact() txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) gas_used = txn_receipt.get('gasUsed') assert abs(gas_estimate - gas_used) < 21000 -def test_contract_constructor_transact_no_constructor(web3, MathContract, MATH_RUNTIME): +def test_contract_constructor_transact_no_constructor( + web3, + MathContract, + MATH_RUNTIME, + address_conversion_func): deploy_txn = MathContract.constructor().transact() txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert txn_receipt is not None assert txn_receipt['contractAddress'] - contract_address = txn_receipt['contractAddress'] + contract_address = address_conversion_func(txn_receipt['contractAddress']) blockchain_code = web3.eth.getCode(contract_address) assert blockchain_code == decode_hex(MATH_RUNTIME) def test_contract_constructor_transact_with_constructor_without_arguments( - web3, SimpleConstructorContract, SIMPLE_CONSTRUCTOR_RUNTIME): + web3, + SimpleConstructorContract, + SIMPLE_CONSTRUCTOR_RUNTIME, + address_conversion_func): deploy_txn = SimpleConstructorContract.constructor().transact() txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert txn_receipt is not None assert txn_receipt['contractAddress'] - contract_address = txn_receipt['contractAddress'] + contract_address = address_conversion_func(txn_receipt['contractAddress']) blockchain_code = web3.eth.getCode(contract_address) assert blockchain_code == decode_hex(SIMPLE_CONSTRUCTOR_RUNTIME) @@ -119,7 +127,8 @@ def test_contract_constructor_transact_with_constructor_with_arguments( constructor_args, constructor_kwargs, expected_a, - expected_b): + expected_b, + address_conversion_func): deploy_txn = WithConstructorArgumentsContract.constructor( *constructor_args, **constructor_kwargs).transact() @@ -127,7 +136,7 @@ def test_contract_constructor_transact_with_constructor_with_arguments( assert txn_receipt is not None assert txn_receipt['contractAddress'] - contract_address = txn_receipt['contractAddress'] + contract_address = address_conversion_func(txn_receipt['contractAddress']) blockchain_code = web3.eth.getCode(contract_address) assert blockchain_code == decode_hex(WITH_CONSTRUCTOR_ARGUMENTS_RUNTIME) @@ -138,12 +147,15 @@ def test_contract_constructor_transact_with_constructor_with_arguments( def test_contract_constructor_transact_with_constructor_with_address_arguments( - web3, WithConstructorAddressArgumentsContract, WITH_CONSTRUCTOR_ADDRESS_RUNTIME): + web3, + WithConstructorAddressArgumentsContract, + WITH_CONSTRUCTOR_ADDRESS_RUNTIME, + address_conversion_func): deploy_txn = WithConstructorAddressArgumentsContract.constructor(TEST_ADDRESS).transact() txn_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert txn_receipt is not None assert txn_receipt['contractAddress'] - contract_address = txn_receipt['contractAddress'] + contract_address = address_conversion_func(txn_receipt['contractAddress']) blockchain_code = web3.eth.getCode(contract_address) assert blockchain_code == decode_hex(WITH_CONSTRUCTOR_ADDRESS_RUNTIME) assert TEST_ADDRESS == WithConstructorAddressArgumentsContract( @@ -155,8 +167,13 @@ def test_contract_constructor_build_transaction_to_field_error(MathContract): MathContract.constructor().buildTransaction({'to': '123'}) -def test_contract_constructor_build_transaction_no_constructor(web3, MathContract): - txn_hash = MathContract.constructor().transact({'from': web3.eth.accounts[0]}) +def test_contract_constructor_build_transaction_no_constructor( + web3, + MathContract, + address_conversion_func): + txn_hash = MathContract.constructor().transact( + {'from': address_conversion_func(web3.eth.accounts[0])} + ) txn = web3.eth.getTransaction(txn_hash) nonce = web3.eth.getTransactionCount(web3.eth.coinbase) unsent_txn = MathContract.constructor().buildTransaction({'nonce': nonce}) @@ -168,9 +185,13 @@ def test_contract_constructor_build_transaction_no_constructor(web3, MathContrac assert new_txn['nonce'] == nonce -def test_contract_constructor_build_transaction_with_constructor_without_argument(web3, - MathContract): - txn_hash = MathContract.constructor().transact({'from': web3.eth.accounts[0]}) +def test_contract_constructor_build_transaction_with_constructor_without_argument( + web3, + MathContract, + address_conversion_func): + txn_hash = MathContract.constructor().transact( + {'from': address_conversion_func(web3.eth.accounts[0])} + ) txn = web3.eth.getTransaction(txn_hash) nonce = web3.eth.getTransactionCount(web3.eth.coinbase) unsent_txn = MathContract.constructor().buildTransaction({'nonce': nonce}) @@ -195,9 +216,12 @@ def test_contract_constructor_build_transaction_with_constructor_with_argument( web3, WithConstructorArgumentsContract, constructor_args, - constructor_kwargs): + constructor_kwargs, + address_conversion_func): txn_hash = WithConstructorArgumentsContract.constructor( - *constructor_args, **constructor_kwargs).transact({'from': web3.eth.accounts[0]}) + *constructor_args, **constructor_kwargs).transact( + {'from': address_conversion_func(web3.eth.accounts[0])} + ) txn = web3.eth.getTransaction(txn_hash) nonce = web3.eth.getTransactionCount(web3.eth.coinbase) unsent_txn = WithConstructorArgumentsContract.constructor( diff --git a/tests/core/contracts/test_contract_estimateGas.py b/tests/core/contracts/test_contract_estimateGas.py index 139120b994..841619a0a1 100644 --- a/tests/core/contracts/test_contract_estimateGas.py +++ b/tests/core/contracts/test_contract_estimateGas.py @@ -11,7 +11,8 @@ def math_contract(web3, MATH_ABI, MATH_CODE, MATH_RUNTIME, - wait_for_transaction): + wait_for_transaction, + address_conversion_func): MathContract = web3.eth.contract( abi=MATH_ABI, bytecode=MATH_CODE, @@ -21,10 +22,11 @@ def math_contract(web3, deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - contract_address = deploy_receipt['contractAddress'] + contract_address = address_conversion_func(deploy_receipt['contractAddress']) web3.isAddress(contract_address) _math_contract = MathContract(address=contract_address) + assert _math_contract.address == contract_address return _math_contract @@ -33,7 +35,8 @@ def fallback_function_contract(web3, FALLBACK_FUNCTION_ABI, FALLBACK_FUNCTION_CODE, FALLBACK_FUNCTION_RUNTIME, - wait_for_transaction): + wait_for_transaction, + address_conversion_func): fallback_contract = web3.eth.contract( abi=FALLBACK_FUNCTION_ABI, bytecode=FALLBACK_FUNCTION_CODE, @@ -43,10 +46,11 @@ def fallback_function_contract(web3, deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - contract_address = deploy_receipt['contractAddress'] + contract_address = address_conversion_func(deploy_receipt['contractAddress']) web3.isAddress(contract_address) _fallback_function_contract = fallback_contract(address=contract_address) + assert _fallback_function_contract.address == contract_address return _fallback_function_contract diff --git a/tests/core/contracts/test_contract_init.py b/tests/core/contracts/test_contract_init.py index 7be650561c..c70b80ceab 100644 --- a/tests/core/contracts/test_contract_init.py +++ b/tests/core/contracts/test_contract_init.py @@ -1,9 +1,5 @@ import pytest -from eth_utils import ( - to_bytes, -) - from web3.exceptions import ( BadFunctionCallOutput, NameNotFound, @@ -14,22 +10,13 @@ ) -@pytest.fixture -def math_deploy_receipt(MathContract): +@pytest.fixture() +def math_addr(MathContract, address_conversion_func): web3 = MathContract.web3 deploy_txn = MathContract.constructor().transact({'from': web3.eth.coinbase}) deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - return deploy_receipt - - -@pytest.fixture(params=['hex', 'bytes']) -def math_addr(request, math_deploy_receipt): - addr = math_deploy_receipt['contractAddress'] - if request.param == 'bytes': - return to_bytes(hexstr=addr) - else: - return addr + return address_conversion_func(deploy_receipt['contractAddress']) def test_contract_with_unset_address(MathContract): diff --git a/tests/core/contracts/test_contract_transact_interface.py b/tests/core/contracts/test_contract_transact_interface.py index e734bea18f..106221250d 100644 --- a/tests/core/contracts/test_contract_transact_interface.py +++ b/tests/core/contracts/test_contract_transact_interface.py @@ -15,34 +15,40 @@ @pytest.fixture() -def math_contract(web3, MathContract): +def math_contract(web3, MathContract, address_conversion_func): deploy_txn = MathContract.constructor().transact() deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - _math_contract = MathContract(address=deploy_receipt['contractAddress']) + address = address_conversion_func(deploy_receipt['contractAddress']) + _math_contract = MathContract(address=address) + assert _math_contract.address == address return _math_contract @pytest.fixture() -def string_contract(web3, StringContract): +def string_contract(web3, StringContract, address_conversion_func): deploy_txn = StringContract.constructor("Caqalai").transact() deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - _math_contract = StringContract(address=deploy_receipt['contractAddress']) - return _math_contract + address = address_conversion_func(deploy_receipt['contractAddress']) + _string_contract = StringContract(address=address) + assert _string_contract.address == address + return _string_contract @pytest.fixture() -def fallback_function_contract(web3, FallballFunctionContract): +def fallback_function_contract(web3, FallballFunctionContract, address_conversion_func): deploy_txn = FallballFunctionContract.constructor().transact() deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - _fallback_contract = FallballFunctionContract(address=deploy_receipt['contractAddress']) + address = address_conversion_func(deploy_receipt['contractAddress']) + _fallback_contract = FallballFunctionContract(address=address) + assert _fallback_contract.address == address return _fallback_contract @pytest.fixture() -def arrays_contract(web3, ArraysContract): +def arrays_contract(web3, ArraysContract, address_conversion_func): # bytes_32 = [keccak('0'), keccak('1')] bytes32_array = [ b'\x04HR\xb2\xa6p\xad\xe5@~x\xfb(c\xc5\x1d\xe9\xfc\xb9eB\xa0q\x86\xfe:\xed\xa6\xbb\x8a\x11m', # noqa: E501 @@ -52,7 +58,8 @@ def arrays_contract(web3, ArraysContract): deploy_txn = ArraysContract.constructor(bytes32_array, byte_arr).transact() deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn) assert deploy_receipt is not None - _arrays_contract = ArraysContract(address=deploy_receipt['contractAddress']) + address = address_conversion_func(deploy_receipt['contractAddress']) + _arrays_contract = ArraysContract(address=address) return _arrays_contract diff --git a/tests/core/contracts/test_extracting_event_data.py b/tests/core/contracts/test_extracting_event_data.py index ecb991b4c8..6d93535a6f 100644 --- a/tests/core/contracts/test_extracting_event_data.py +++ b/tests/core/contracts/test_extracting_event_data.py @@ -18,15 +18,17 @@ def Emitter(web3, EMITTER): @pytest.fixture() -def emitter(web3, Emitter, wait_for_transaction, wait_for_block): +def emitter(web3, Emitter, wait_for_transaction, wait_for_block, address_conversion_func): wait_for_block(web3) deploy_txn_hash = Emitter.constructor().transact({'from': web3.eth.coinbase, 'gas': 1000000}) deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn_hash) - contract_address = deploy_receipt['contractAddress'] + contract_address = address_conversion_func(deploy_receipt['contractAddress']) bytecode = web3.eth.getCode(contract_address) assert bytecode == Emitter.bytecode_runtime - return Emitter(address=contract_address) + _emitter = Emitter(address=contract_address) + assert _emitter.address == contract_address + return _emitter @pytest.mark.parametrize( diff --git a/tests/core/contracts/test_extracting_event_data_old.py b/tests/core/contracts/test_extracting_event_data_old.py index 38412a5724..791c181da2 100644 --- a/tests/core/contracts/test_extracting_event_data_old.py +++ b/tests/core/contracts/test_extracting_event_data_old.py @@ -18,15 +18,17 @@ def Emitter(web3, EMITTER): @pytest.fixture() -def emitter(web3, Emitter, wait_for_transaction, wait_for_block): +def emitter(web3, Emitter, wait_for_transaction, wait_for_block, address_conversion_func): wait_for_block(web3) deploy_txn_hash = Emitter.constructor().transact({'from': web3.eth.coinbase, 'gas': 1000000}) deploy_receipt = web3.eth.waitForTransactionReceipt(deploy_txn_hash) - contract_address = deploy_receipt['contractAddress'] + contract_address = address_conversion_func(deploy_receipt['contractAddress']) bytecode = web3.eth.getCode(contract_address) assert bytecode == Emitter.bytecode_runtime - return Emitter(address=contract_address) + _emitter = Emitter(address=contract_address) + assert _emitter.address == contract_address + return _emitter @pytest.mark.parametrize( diff --git a/tests/core/contracts/test_implicit_contract.py b/tests/core/contracts/test_implicit_contract.py index 5b5011348b..5defe47617 100644 --- a/tests/core/contracts/test_implicit_contract.py +++ b/tests/core/contracts/test_implicit_contract.py @@ -10,7 +10,7 @@ @pytest.fixture() -def math_contract(web3, MATH_ABI, MATH_CODE, MATH_RUNTIME): +def math_contract(web3, MATH_ABI, MATH_CODE, MATH_RUNTIME, address_conversion_func): # Deploy math contract # NOTE Must use non-specialized contract factory or else deploy() doesn't work MathContract = web3.eth.contract( @@ -20,7 +20,7 @@ def math_contract(web3, MATH_ABI, MATH_CODE, MATH_RUNTIME): ) tx_hash = MathContract.constructor().transact() tx_receipt = web3.eth.waitForTransactionReceipt(tx_hash) - math_address = tx_receipt['contractAddress'] + math_address = address_conversion_func(tx_receipt['contractAddress']) # Return interactive contract instance at deployed address # TODO Does parent class not implement 'deploy()' for a reason? MathContract = web3.eth.contract( @@ -29,7 +29,9 @@ def math_contract(web3, MATH_ABI, MATH_CODE, MATH_RUNTIME): bytecode_runtime=MATH_RUNTIME, ContractFactoryClass=ImplicitContract, ) - return MathContract(math_address) + contract = MathContract(math_address) + assert contract.address == math_address + return contract @pytest.fixture()