Skip to content

Commit 56ab08d

Browse files
committed
Address comments on PR #2797
1 parent 932c7d6 commit 56ab08d

23 files changed

+357
-373
lines changed

tests/core/contracts/conftest.py

Lines changed: 78 additions & 78 deletions
Large diffs are not rendered by default.

tests/core/contracts/test_contract_ambiguous_functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@
4646

4747

4848
@pytest.fixture
49-
def string_contract(w3, string_contract_instance, address_conversion_func):
50-
deploy_txn = string_contract_instance.constructor("Caqalai").transact()
49+
def string_contract(w3, string_contract_factory, address_conversion_func):
50+
deploy_txn = string_contract_factory.constructor("Caqalai").transact()
5151
deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn)
5252
assert deploy_receipt is not None
5353
contract_address = address_conversion_func(deploy_receipt["contractAddress"])
54-
contract = string_contract_instance(address=contract_address)
54+
contract = string_contract_factory(address=contract_address)
5555
assert contract.address == contract_address
5656
assert len(w3.eth.get_code(contract.address)) > 0
5757
return contract

tests/core/contracts/test_contract_build_transaction.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def test_build_transaction_with_contract_fallback_function(
6767

6868

6969
def test_build_transaction_with_contract_class_method(
70-
w3, math_contract_instance, math_contract, build_transaction
70+
w3, math_contract_factory, math_contract, build_transaction
7171
):
7272
txn = build_transaction(
73-
contract=math_contract_instance,
73+
contract=math_contract_factory,
7474
contract_function="incrementCounter",
7575
tx_params={"to": math_contract.address},
7676
)
@@ -326,12 +326,12 @@ async def test_async_build_transaction_with_contract_fallback_function(
326326
@pytest.mark.asyncio
327327
async def test_async_build_transaction_with_contract_class_method(
328328
async_w3,
329-
async_math_contract_instance,
329+
async_math_contract_factory,
330330
async_math_contract,
331331
async_build_transaction,
332332
):
333333
txn = await async_build_transaction(
334-
contract=async_math_contract_instance,
334+
contract=async_math_contract_factory,
335335
contract_function="incrementCounter",
336336
tx_params={"to": async_math_contract.address},
337337
)
@@ -403,7 +403,7 @@ async def test_async_build_transaction_with_contract_to_address_supplied_errors(
403403
contract=async_math_contract,
404404
contract_function="incrementCounter",
405405
tx_params={"to": "0xb2930B35844a230f00E51431aCAe96Fe543a0347"},
406-
) # noqa: E501
406+
)
407407

408408

409409
@pytest.mark.asyncio

tests/core/contracts/test_contract_call_interface.py

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,21 @@
5050

5151
@pytest.fixture
5252
def tuple_contract(w3, address_conversion_func):
53-
tuple_contract_instance = w3.eth.contract(**TUPLE_CONTRACT_DATA)
54-
return deploy(w3, tuple_contract_instance, address_conversion_func)
53+
tuple_contract_factory = w3.eth.contract(**TUPLE_CONTRACT_DATA)
54+
return deploy(w3, tuple_contract_factory, address_conversion_func)
5555

5656

5757
@pytest.fixture
5858
def nested_tuple_contract(w3, address_conversion_func):
59-
nested_tuple_contract_instance = w3.eth.contract(**NESTED_TUPLE_CONTRACT_DATA)
60-
return deploy(w3, nested_tuple_contract_instance, address_conversion_func)
59+
nested_tuple_contract_factory = w3.eth.contract(**NESTED_TUPLE_CONTRACT_DATA)
60+
return deploy(w3, nested_tuple_contract_factory, address_conversion_func)
6161

6262

6363
@pytest.fixture(params=[b"\x04\x06", "0x0406"])
6464
def bytes_contract(w3, request, address_conversion_func):
65-
bytes_contract_instance = w3.eth.contract(**BYTES_CONTRACT_DATA)
65+
bytes_contract_factory = w3.eth.contract(**BYTES_CONTRACT_DATA)
6666
return deploy(
67-
w3, bytes_contract_instance, address_conversion_func, args=[request.param]
67+
w3, bytes_contract_factory, address_conversion_func, args=[request.param]
6868
)
6969

7070

@@ -74,12 +74,12 @@ def non_strict_bytes_contract(
7474
request,
7575
address_conversion_func,
7676
):
77-
non_strict_bytes_contract_instance = w3_non_strict_abi.eth.contract(
77+
non_strict_bytes_contract_factory = w3_non_strict_abi.eth.contract(
7878
**BYTES_CONTRACT_DATA
7979
)
8080
return deploy(
8181
w3_non_strict_abi,
82-
non_strict_bytes_contract_instance,
82+
non_strict_bytes_contract_factory,
8383
address_conversion_func,
8484
args=[request.param],
8585
)
@@ -91,7 +91,7 @@ def call_transaction():
9191

9292

9393
@pytest.fixture
94-
def bytes32_contract_instance(w3):
94+
def bytes32_contract_factory(w3):
9595
return w3.eth.contract(**BYTES32_CONTRACT_DATA)
9696

9797

@@ -101,48 +101,48 @@ def bytes32_contract_instance(w3):
101101
HexBytes("0406040604060406040604060406040604060406040604060406040604060406"),
102102
]
103103
)
104-
def bytes32_contract(w3, bytes32_contract_instance, request, address_conversion_func):
104+
def bytes32_contract(w3, bytes32_contract_factory, request, address_conversion_func):
105105
return deploy(
106-
w3, bytes32_contract_instance, address_conversion_func, args=[request.param]
106+
w3, bytes32_contract_factory, address_conversion_func, args=[request.param]
107107
)
108108

109109

110110
@pytest.fixture
111-
def undeployed_math_contract(math_contract_instance, address_conversion_func):
111+
def undeployed_math_contract(math_contract_factory, address_conversion_func):
112112
empty_address = address_conversion_func(
113113
"0x000000000000000000000000000000000000dEaD"
114114
)
115-
_undeployed_math_contract = math_contract_instance(address=empty_address)
115+
_undeployed_math_contract = math_contract_factory(address=empty_address)
116116
return _undeployed_math_contract
117117

118118

119119
@pytest.fixture
120120
def mismatched_math_contract(
121-
w3, string_contract_instance, math_contract_instance, address_conversion_func
121+
w3, string_contract_factory, math_contract_factory, address_conversion_func
122122
):
123-
deploy_txn = string_contract_instance.constructor("Caqalai").transact()
123+
deploy_txn = string_contract_factory.constructor("Caqalai").transact()
124124
deploy_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn)
125125
assert deploy_receipt is not None
126126
address = address_conversion_func(deploy_receipt["contractAddress"])
127-
_mismatched_math_contract = math_contract_instance(address=address)
127+
_mismatched_math_contract = math_contract_factory(address=address)
128128
return _mismatched_math_contract
129129

130130

131131
def test_deploy_raises_due_to_strict_byte_checking_by_default(
132-
w3, bytes32_contract_instance, address_conversion_func
132+
w3, bytes32_contract_factory, address_conversion_func
133133
):
134134
with pytest.raises(TypeError):
135135
deploy(
136136
w3,
137-
bytes32_contract_instance,
137+
bytes32_contract_factory,
138138
address_conversion_func,
139139
args=["0406040604060406040604060406040604060406040604060406040604060406"],
140140
)
141141

142142

143-
def test_invalid_address_in_deploy_arg(contract_with_constructor_address_instance):
143+
def test_invalid_address_in_deploy_arg(contract_with_constructor_address_factory):
144144
with pytest.raises(InvalidAddress):
145-
contract_with_constructor_address_instance.constructor(
145+
contract_with_constructor_address_factory.constructor(
146146
"0xd3cda913deb6f67967b99d67acdfa1712c293601",
147147
).transact()
148148

@@ -304,14 +304,14 @@ def test_call_read_address_variable(contract_with_constructor_address, call):
304304
assert result == "0xd3CdA913deB6f67967B99D67aCDFa1712C293601"
305305

306306

307-
def test_init_with_ens_name_arg(w3, contract_with_constructor_address_instance, call):
307+
def test_init_with_ens_name_arg(w3, contract_with_constructor_address_factory, call):
308308
with contract_ens_addresses(
309-
contract_with_constructor_address_instance,
309+
contract_with_constructor_address_factory,
310310
[("arg-name.eth", "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")],
311311
):
312312
address_contract = deploy(
313313
w3,
314-
contract_with_constructor_address_instance,
314+
contract_with_constructor_address_factory,
315315
args=[
316316
"arg-name.eth",
317317
],
@@ -1015,37 +1015,37 @@ def test_changing_default_block_identifier(w3, math_contract):
10151015

10161016
@pytest_asyncio.fixture
10171017
async def async_tuple_contract(async_w3, address_conversion_func):
1018-
async_tuple_contract_instance = async_w3.eth.contract(**TUPLE_CONTRACT_DATA)
1018+
async_tuple_contract_factory = async_w3.eth.contract(**TUPLE_CONTRACT_DATA)
10191019
return await async_deploy(
1020-
async_w3, async_tuple_contract_instance, address_conversion_func
1020+
async_w3, async_tuple_contract_factory, address_conversion_func
10211021
)
10221022

10231023

10241024
@pytest_asyncio.fixture
10251025
async def async_nested_tuple_contract(async_w3, address_conversion_func):
1026-
async_nested_tuple_contract_instance = async_w3.eth.contract(
1026+
async_nested_tuple_contract_factory = async_w3.eth.contract(
10271027
**NESTED_TUPLE_CONTRACT_DATA
10281028
)
10291029
return await async_deploy(
1030-
async_w3, async_nested_tuple_contract_instance, address_conversion_func
1030+
async_w3, async_nested_tuple_contract_factory, address_conversion_func
10311031
)
10321032

10331033

10341034
@pytest.fixture
1035-
def async_bytes_contract_instance(async_w3):
1035+
def async_bytes_contract_factory(async_w3):
10361036
return async_w3.eth.contract(**BYTES_CONTRACT_DATA)
10371037

10381038

10391039
@pytest_asyncio.fixture(params=[b"\x04\x06", "0x0406"])
10401040
async def async_bytes_contract(
10411041
async_w3,
10421042
request,
1043-
async_bytes_contract_instance,
1043+
async_bytes_contract_factory,
10441044
address_conversion_func,
10451045
):
10461046
return await async_deploy(
10471047
async_w3,
1048-
async_bytes_contract_instance,
1048+
async_bytes_contract_factory,
10491049
address_conversion_func,
10501050
args=[request.param],
10511051
)
@@ -1058,45 +1058,45 @@ async def async_bytes_contract(
10581058
],
10591059
)
10601060
async def async_bytes32_contract(async_w3, request, address_conversion_func):
1061-
async_bytes32_contract_instance = async_w3.eth.contract(**BYTES32_CONTRACT_DATA)
1061+
async_bytes32_contract_factory = async_w3.eth.contract(**BYTES32_CONTRACT_DATA)
10621062
return await async_deploy(
10631063
async_w3,
1064-
async_bytes32_contract_instance,
1064+
async_bytes32_contract_factory,
10651065
address_conversion_func,
10661066
args=[request.param],
10671067
)
10681068

10691069

10701070
@pytest_asyncio.fixture
10711071
async def async_undeployed_math_contract(
1072-
async_math_contract_instance, address_conversion_func
1072+
async_math_contract_factory, address_conversion_func
10731073
):
10741074
empty_address = address_conversion_func(
10751075
"0x000000000000000000000000000000000000dEaD"
10761076
)
1077-
_undeployed_math_contract = async_math_contract_instance(address=empty_address)
1077+
_undeployed_math_contract = async_math_contract_factory(address=empty_address)
10781078
return _undeployed_math_contract
10791079

10801080

10811081
@pytest_asyncio.fixture
10821082
async def async_mismatched_math_contract(
10831083
async_w3,
1084-
async_string_contract_instance,
1085-
async_math_contract_instance,
1084+
async_string_contract_factory,
1085+
async_math_contract_factory,
10861086
address_conversion_func,
10871087
):
1088-
deploy_txn = await async_string_contract_instance.constructor("Caqalai").transact()
1088+
deploy_txn = await async_string_contract_factory.constructor("Caqalai").transact()
10891089
deploy_receipt = await async_w3.eth.wait_for_transaction_receipt(deploy_txn)
10901090
assert deploy_receipt is not None
10911091
address = address_conversion_func(deploy_receipt["contractAddress"])
1092-
_mismatched_math_contract = async_math_contract_instance(address=address)
1092+
_mismatched_math_contract = async_math_contract_factory(address=address)
10931093
return _mismatched_math_contract
10941094

10951095

10961096
@pytest.fixture
10971097
@pytest.mark.asyncio
10981098
async def test_async_deploy_raises_due_to_strict_byte_checking_by_default(
1099-
async_w3, async_bytes_contract_instance, address_conversion_func
1099+
async_w3, async_bytes_contract_factory, address_conversion_func
11001100
):
11011101
with pytest.raises(
11021102
TypeError,
@@ -1105,7 +1105,7 @@ async def test_async_deploy_raises_due_to_strict_byte_checking_by_default(
11051105
):
11061106
await async_deploy(
11071107
async_w3,
1108-
async_bytes_contract_instance,
1108+
async_bytes_contract_factory,
11091109
address_conversion_func,
11101110
args=["0406"],
11111111
)
@@ -1118,12 +1118,12 @@ async def test_async_deploy_with_non_strict_abi_check(
11181118
address_conversion_func,
11191119
args,
11201120
):
1121-
async_non_strict_bytes_contract_instance = async_w3_non_strict_abi.eth.contract(
1121+
async_non_strict_bytes_contract_factory = async_w3_non_strict_abi.eth.contract(
11221122
**BYTES_CONTRACT_DATA
11231123
)
11241124
deployed_contract = await async_deploy(
11251125
async_w3_non_strict_abi,
1126-
async_non_strict_bytes_contract_instance,
1126+
async_non_strict_bytes_contract_factory,
11271127
address_conversion_func,
11281128
args=[args],
11291129
)
@@ -1133,10 +1133,10 @@ async def test_async_deploy_with_non_strict_abi_check(
11331133

11341134
@pytest.mark.asyncio
11351135
async def test_async_invalid_address_in_deploy_arg(
1136-
async_constructor_with_address_arg_contract_instance,
1136+
async_constructor_with_address_arg_contract_factory,
11371137
):
11381138
with pytest.raises(InvalidAddress):
1139-
await async_constructor_with_address_arg_contract_instance.constructor(
1139+
await async_constructor_with_address_arg_contract_factory.constructor(
11401140
"0xd3cda913deb6f67967b99d67acdfa1712c293601",
11411141
).transact()
11421142

@@ -1308,15 +1308,15 @@ async def test_async_call_read_address_variable(
13081308
@pytest.mark.xfail
13091309
@pytest.mark.asyncio
13101310
async def test_async_init_with_ens_name_arg(
1311-
async_w3, async_constructor_with_address_arg_contract_instance, async_call
1311+
async_w3, async_constructor_with_address_arg_contract_factory, async_call
13121312
):
13131313
with contract_ens_addresses(
1314-
async_constructor_with_address_arg_contract_instance,
1314+
async_constructor_with_address_arg_contract_factory,
13151315
[("arg-name.eth", "0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413")],
13161316
):
13171317
address_contract = await async_deploy(
13181318
async_w3,
1319-
async_constructor_with_address_arg_contract_instance,
1319+
async_constructor_with_address_arg_contract_factory,
13201320
args=[
13211321
"arg-name.eth",
13221322
],

tests/core/contracts/test_contract_class_construction.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
def test_class_construction_sets_class_vars(
1717
w3, math_contract_abi, math_contract_bytecode, math_contract_runtime
1818
):
19-
math_contract_instance = w3.eth.contract(
19+
math_contract_factory = w3.eth.contract(
2020
abi=math_contract_abi,
2121
bytecode=math_contract_bytecode,
2222
bytecode_runtime=math_contract_runtime,
2323
)
2424

25-
assert math_contract_instance.w3 == w3
26-
assert math_contract_instance.bytecode == decode_hex(math_contract_bytecode)
27-
assert math_contract_instance.bytecode_runtime == decode_hex(math_contract_runtime)
25+
assert math_contract_factory.w3 == w3
26+
assert math_contract_factory.bytecode == decode_hex(math_contract_bytecode)
27+
assert math_contract_factory.bytecode_runtime == decode_hex(math_contract_runtime)
2828

2929

3030
def test_error_to_instantiate_base_class():
@@ -35,10 +35,10 @@ def test_error_to_instantiate_base_class():
3535
def test_abi_as_json_string(w3, math_contract_abi, some_address):
3636
abi_str = json.dumps(math_contract_abi)
3737

38-
math_contract_instance = w3.eth.contract(abi=abi_str)
39-
assert math_contract_instance.abi == math_contract_abi
38+
math_contract_factory = w3.eth.contract(abi=abi_str)
39+
assert math_contract_factory.abi == math_contract_abi
4040

41-
math = math_contract_instance(some_address)
41+
math = math_contract_factory(some_address)
4242
assert math.abi == math_contract_abi
4343

4444

0 commit comments

Comments
 (0)