Skip to content

Commit

Permalink
Address comments on PR ethereum#2797
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Jan 30, 2023
1 parent 932c7d6 commit 56ab08d
Show file tree
Hide file tree
Showing 23 changed files with 357 additions and 373 deletions.
156 changes: 78 additions & 78 deletions tests/core/contracts/conftest.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions tests/core/contracts/test_contract_ambiguous_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/core/contracts/test_contract_build_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
)
Expand Down Expand Up @@ -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},
)
Expand Down Expand Up @@ -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
Expand Down
94 changes: 47 additions & 47 deletions tests/core/contracts/test_contract_call_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)


Expand All @@ -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],
)
Expand All @@ -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)


Expand All @@ -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()

Expand Down Expand Up @@ -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",
],
Expand Down Expand Up @@ -1015,37 +1015,37 @@ 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)


@pytest_asyncio.fixture(params=[b"\x04\x06", "0x0406"])
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],
)
Expand All @@ -1058,45 +1058,45 @@ 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],
)


@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,
Expand All @@ -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"],
)
Expand All @@ -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],
)
Expand All @@ -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()

Expand Down Expand Up @@ -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",
],
Expand Down
14 changes: 7 additions & 7 deletions tests/core/contracts/test_contract_class_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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


Expand Down
Loading

0 comments on commit 56ab08d

Please sign in to comment.