Skip to content

Commit 5887604

Browse files
dbfreempacrob
authored and
pacrob
committed
Feature/asyncify contract (ethereum#2405)
* renaming deprecated methods
1 parent fef9e43 commit 5887604

11 files changed

+77
-112
lines changed

ens/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def resolver(self, normal_name: str) -> Optional['Contract']:
270270
if is_none_or_zero_address(resolver_addr):
271271
return None
272272
# TODO: look at possibly removing type ignore when AsyncENS is written
273-
return self._resolverContract(address=resolver_addr)
273+
return self._resolverContract(address=resolver_addr) # type: ignore
274274

275275
def reverser(self, target_address: ChecksumAddress) -> Optional['Contract']:
276276
reversed_domain = address_to_reverse_domain(target_address)
@@ -451,7 +451,7 @@ def _set_resolver(
451451
resolver_addr
452452
).transact(transact)
453453
# TODO: look at possibly removing type ignore when AsyncENS is written
454-
return self._resolverContract(address=resolver_addr)
454+
return self._resolverContract(address=resolver_addr) # type: ignore
455455

456456
def _setup_reverse(
457457
self, name: str, address: ChecksumAddress, transact: Optional["TxParams"] = None

ethpm/package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def get_contract_instance(self, name: ContractName, address: Address) -> Contrac
310310
address=address, **contract_kwargs
311311
)
312312
# TODO: type ignore may be able to be removed after more of AsynContract is finished
313-
return contract_instance
313+
return contract_instance # type: ignore
314314

315315
#
316316
# Build Dependencies

tests/core/contracts/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ def invoke_contract(api_call_desig='call',
10151015
func_args=[],
10161016
func_kwargs={},
10171017
tx_params={}):
1018-
allowable_call_desig = ['call', 'transact', 'estimateGas', 'buildTransaction']
1018+
allowable_call_desig = ['call', 'transact', 'estimate_gas', 'build_transaction']
10191019
if api_call_desig not in allowable_call_desig:
10201020
raise ValueError(f"allowable_invoke_method must be one of: {allowable_call_desig}")
10211021

@@ -1036,13 +1036,13 @@ def call(request):
10361036

10371037

10381038
@pytest.fixture
1039-
def estimateGas(request):
1040-
return functools.partial(invoke_contract, api_call_desig='estimateGas')
1039+
def estimate_gas(request):
1040+
return functools.partial(invoke_contract, api_call_desig='estimate_gas')
10411041

10421042

10431043
@pytest.fixture
1044-
def buildTransaction(request):
1045-
return functools.partial(invoke_contract, api_call_desig='buildTransaction')
1044+
def build_transaction(request):
1045+
return functools.partial(invoke_contract, api_call_desig='build_transaction')
10461046

10471047

10481048
async def async_deploy(async_web3, Contract, apply_func=identity, args=None):

tests/core/contracts/test_contract_ambiguous_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ def test_contract_function_methods(string_contract):
181181
get_value_func = string_contract.get_function_by_signature('getValue()')
182182
assert isinstance(set_value_func('Hello').transact(), HexBytes)
183183
assert get_value_func().call() == 'Hello'
184-
assert isinstance(set_value_func('Hello World').estimateGas(), int)
185-
assert isinstance(set_value_func('Hello World').buildTransaction(), dict)
184+
assert isinstance(set_value_func('Hello World').estimate_gas(), int)
185+
assert isinstance(set_value_func('Hello World').build_transaction(), dict)
186186

187187

188188
def test_diff_between_fn_and_fn_called(string_contract):

tests/core/contracts/test_contract_buildTransaction.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ def payable_tester_contract(w3, PayableTesterContract, address_conversion_func):
4545
def test_build_transaction_not_paying_to_nonpayable_function(
4646
w3,
4747
payable_tester_contract,
48-
buildTransaction):
49-
txn = buildTransaction(contract=payable_tester_contract,
50-
contract_function='doNoValueCall')
48+
build_transaction):
49+
txn = build_transaction(contract=payable_tester_contract,
50+
contract_function='doNoValueCall')
5151
assert dissoc(txn, 'gas') == {
5252
'to': payable_tester_contract.address,
5353
'data': '0xe4cb8f5c',
@@ -61,15 +61,15 @@ def test_build_transaction_not_paying_to_nonpayable_function(
6161
def test_build_transaction_paying_to_nonpayable_function(
6262
w3,
6363
payable_tester_contract,
64-
buildTransaction):
64+
build_transaction):
6565
with pytest.raises(ValidationError):
66-
buildTransaction(contract=payable_tester_contract,
67-
contract_function='doNoValueCall',
68-
tx_params={'value': 1})
66+
build_transaction(contract=payable_tester_contract,
67+
contract_function='doNoValueCall',
68+
tx_params={'value': 1})
6969

7070

71-
def test_build_transaction_with_contract_no_arguments(w3, math_contract, buildTransaction):
72-
txn = buildTransaction(contract=math_contract, contract_function='increment')
71+
def test_build_transaction_with_contract_no_arguments(w3, math_contract, build_transaction):
72+
txn = build_transaction(contract=math_contract, contract_function='increment')
7373
assert dissoc(txn, 'gas') == {
7474
'to': math_contract.address,
7575
'data': '0xd09de08a',
@@ -81,7 +81,7 @@ def test_build_transaction_with_contract_no_arguments(w3, math_contract, buildTr
8181

8282

8383
def test_build_transaction_with_contract_fallback_function(w3, fallback_function_contract):
84-
txn = fallback_function_contract.fallback.buildTransaction()
84+
txn = fallback_function_contract.fallback.build_transaction()
8585
assert dissoc(txn, 'gas') == {
8686
'to': fallback_function_contract.address,
8787
'data': '0x',
@@ -96,8 +96,8 @@ def test_build_transaction_with_contract_class_method(
9696
w3,
9797
MathContract,
9898
math_contract,
99-
buildTransaction):
100-
txn = buildTransaction(
99+
build_transaction):
100+
txn = build_transaction(
101101
contract=MathContract,
102102
contract_function='increment',
103103
tx_params={'to': math_contract.address},
@@ -115,8 +115,8 @@ def test_build_transaction_with_contract_class_method(
115115
def test_build_transaction_with_contract_default_account_is_set(
116116
w3,
117117
math_contract,
118-
buildTransaction):
119-
txn = buildTransaction(contract=math_contract, contract_function='increment')
118+
build_transaction):
119+
txn = build_transaction(contract=math_contract, contract_function='increment')
120120
assert dissoc(txn, 'gas') == {
121121
'to': math_contract.address,
122122
'data': '0xd09de08a',
@@ -127,11 +127,11 @@ def test_build_transaction_with_contract_default_account_is_set(
127127
}
128128

129129

130-
def test_build_transaction_with_gas_price_strategy_set(w3, math_contract, buildTransaction):
130+
def test_build_transaction_with_gas_price_strategy_set(w3, math_contract, build_transaction):
131131
def my_gas_price_strategy(w3, transaction_params):
132132
return 5
133133
w3.eth.set_gas_price_strategy(my_gas_price_strategy)
134-
txn = buildTransaction(contract=math_contract, contract_function='increment')
134+
txn = build_transaction(contract=math_contract, contract_function='increment')
135135
assert dissoc(txn, 'gas') == {
136136
'to': math_contract.address,
137137
'data': '0xd09de08a',
@@ -143,20 +143,20 @@ def my_gas_price_strategy(w3, transaction_params):
143143

144144
def test_build_transaction_with_contract_data_supplied_errors(w3,
145145
math_contract,
146-
buildTransaction):
146+
build_transaction):
147147
with pytest.raises(ValueError):
148-
buildTransaction(contract=math_contract,
149-
contract_function='increment',
150-
tx_params={'data': '0x000'})
148+
build_transaction(contract=math_contract,
149+
contract_function='increment',
150+
tx_params={'data': '0x000'})
151151

152152

153153
def test_build_transaction_with_contract_to_address_supplied_errors(w3,
154154
math_contract,
155-
buildTransaction):
155+
build_transaction):
156156
with pytest.raises(ValueError):
157-
buildTransaction(contract=math_contract,
158-
contract_function='increment',
159-
tx_params={'to': '0xb2930B35844a230f00E51431aCAe96Fe543a0347'})
157+
build_transaction(contract=math_contract,
158+
contract_function='increment',
159+
tx_params={'to': '0xb2930B35844a230f00E51431aCAe96Fe543a0347'})
160160

161161

162162
@pytest.mark.parametrize(
@@ -219,15 +219,15 @@ def test_build_transaction_with_contract_with_arguments(w3, skip_if_testrpc, mat
219219
method_kwargs,
220220
expected,
221221
skip_testrpc,
222-
buildTransaction):
222+
build_transaction):
223223
if skip_testrpc:
224224
skip_if_testrpc(w3)
225225

226-
txn = buildTransaction(contract=math_contract,
227-
contract_function='increment',
228-
func_args=method_args,
229-
func_kwargs=method_kwargs,
230-
tx_params=transaction_args)
226+
txn = build_transaction(contract=math_contract,
227+
contract_function='increment',
228+
func_args=method_args,
229+
func_kwargs=method_kwargs,
230+
tx_params=transaction_args)
231231
expected['to'] = math_contract.address
232232
assert txn is not None
233233
if 'gas' in transaction_args:

tests/core/contracts/test_contract_class_construction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def test_error_to_call_non_existent_fallback(w3,
5353
bytecode_runtime=MATH_RUNTIME,
5454
)
5555
with pytest.raises(FallbackNotFound):
56-
math_contract.fallback.estimateGas()
56+
math_contract.fallback.estimate_gas()

tests/core/contracts/test_contract_constructor.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_contract_constructor_abi_encoding_with_no_constructor_fn(MathContract,
1616

1717

1818
def test_contract_constructor_gas_estimate_no_constructor(w3, MathContract):
19-
gas_estimate = MathContract.constructor().estimateGas()
19+
gas_estimate = MathContract.constructor().estimate_gas()
2020

2121
deploy_txn = MathContract.constructor().transact()
2222
txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn)
@@ -27,7 +27,7 @@ def test_contract_constructor_gas_estimate_no_constructor(w3, MathContract):
2727

2828
def test_contract_constructor_gas_estimate_with_block_id(w3, MathContract):
2929
block_identifier = None
30-
gas_estimate = MathContract.constructor().estimateGas(block_identifier=block_identifier)
30+
gas_estimate = MathContract.constructor().estimate_gas(block_identifier=block_identifier)
3131
deploy_txn = MathContract.constructor().transact()
3232
txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn)
3333
gas_used = txn_receipt.get('gasUsed')
@@ -38,7 +38,7 @@ def test_contract_constructor_gas_estimate_with_block_id(w3, MathContract):
3838
def test_contract_constructor_gas_estimate_with_constructor_without_arguments(
3939
w3,
4040
SimpleConstructorContract):
41-
gas_estimate = SimpleConstructorContract.constructor().estimateGas()
41+
gas_estimate = SimpleConstructorContract.constructor().estimate_gas()
4242

4343
deploy_txn = SimpleConstructorContract.constructor().transact()
4444
txn_receipt = w3.eth.wait_for_transaction_receipt(deploy_txn)
@@ -62,7 +62,7 @@ def test_contract_constructor_gas_estimate_with_constructor_with_arguments(
6262
constructor_args,
6363
constructor_kwargs):
6464
gas_estimate = WithConstructorArgumentsContract.constructor(
65-
*constructor_args, **constructor_kwargs).estimateGas()
65+
*constructor_args, **constructor_kwargs).estimate_gas()
6666

6767
deploy_txn = WithConstructorArgumentsContract.constructor(
6868
*constructor_args, **constructor_kwargs).transact()
@@ -77,7 +77,7 @@ def test_contract_constructor_gas_estimate_with_constructor_with_address_argumen
7777
WithConstructorAddressArgumentsContract,
7878
address_conversion_func):
7979
gas_estimate = WithConstructorAddressArgumentsContract.constructor(
80-
address_conversion_func("0x16D9983245De15E7A9A73bC586E01FF6E08dE737")).estimateGas()
80+
address_conversion_func("0x16D9983245De15E7A9A73bC586E01FF6E08dE737")).estimate_gas()
8181

8282
deploy_txn = WithConstructorAddressArgumentsContract.constructor(
8383
address_conversion_func("0x16D9983245De15E7A9A73bC586E01FF6E08dE737")).transact()
@@ -174,7 +174,7 @@ def test_contract_constructor_transact_with_constructor_with_address_arguments(
174174

175175
def test_contract_constructor_build_transaction_to_field_error(MathContract):
176176
with pytest.raises(ValueError):
177-
MathContract.constructor().buildTransaction({'to': '123'})
177+
MathContract.constructor().build_transaction({'to': '123'})
178178

179179

180180
def test_contract_constructor_build_transaction_no_constructor(
@@ -186,7 +186,7 @@ def test_contract_constructor_build_transaction_no_constructor(
186186
)
187187
txn = w3.eth.get_transaction(txn_hash)
188188
nonce = w3.eth.get_transaction_count(w3.eth.coinbase)
189-
unsent_txn = MathContract.constructor().buildTransaction({'nonce': nonce})
189+
unsent_txn = MathContract.constructor().build_transaction({'nonce': nonce})
190190
assert txn['data'] == unsent_txn['data']
191191

192192
new_txn_hash = w3.eth.send_transaction(unsent_txn)
@@ -204,7 +204,7 @@ def test_contract_constructor_build_transaction_with_constructor_without_argumen
204204
)
205205
txn = w3.eth.get_transaction(txn_hash)
206206
nonce = w3.eth.get_transaction_count(w3.eth.coinbase)
207-
unsent_txn = MathContract.constructor().buildTransaction({'nonce': nonce})
207+
unsent_txn = MathContract.constructor().build_transaction({'nonce': nonce})
208208
assert txn['data'] == unsent_txn['data']
209209

210210
new_txn_hash = w3.eth.send_transaction(unsent_txn)
@@ -235,7 +235,7 @@ def test_contract_constructor_build_transaction_with_constructor_with_argument(
235235
txn = w3.eth.get_transaction(txn_hash)
236236
nonce = w3.eth.get_transaction_count(w3.eth.coinbase)
237237
unsent_txn = WithConstructorArgumentsContract.constructor(
238-
*constructor_args, **constructor_kwargs).buildTransaction({'nonce': nonce})
238+
*constructor_args, **constructor_kwargs).build_transaction({'nonce': nonce})
239239
assert txn['data'] == unsent_txn['data']
240240

241241
new_txn_hash = w3.eth.send_transaction(unsent_txn)

tests/core/contracts/test_contract_estimateGas.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def payable_tester_contract(w3, PayableTesterContract, address_conversion_func):
7171
return _payable_tester
7272

7373

74-
def test_contract_estimateGas(w3, math_contract, estimateGas, transact):
75-
gas_estimate = estimateGas(contract=math_contract,
76-
contract_function='increment')
74+
def test_contract_estimate_gas(w3, math_contract, estimate_gas, transact):
75+
gas_estimate = estimate_gas(contract=math_contract,
76+
contract_function='increment')
7777

7878
txn_hash = transact(
7979
contract=math_contract,
@@ -85,8 +85,8 @@ def test_contract_estimateGas(w3, math_contract, estimateGas, transact):
8585
assert abs(gas_estimate - gas_used) < 21000
8686

8787

88-
def test_contract_fallback_estimateGas(w3, fallback_function_contract):
89-
gas_estimate = fallback_function_contract.fallback.estimateGas()
88+
def test_contract_fallback_estimate_gas(w3, fallback_function_contract):
89+
gas_estimate = fallback_function_contract.fallback.estimate_gas()
9090

9191
txn_hash = fallback_function_contract.fallback.transact()
9292

@@ -96,10 +96,10 @@ def test_contract_fallback_estimateGas(w3, fallback_function_contract):
9696
assert abs(gas_estimate - gas_used) < 21000
9797

9898

99-
def test_contract_estimateGas_with_arguments(w3, math_contract, estimateGas, transact):
100-
gas_estimate = estimateGas(contract=math_contract,
101-
contract_function='add',
102-
func_args=[5, 6])
99+
def test_contract_estimate_gas_with_arguments(w3, math_contract, estimate_gas, transact):
100+
gas_estimate = estimate_gas(contract=math_contract,
101+
contract_function='add',
102+
func_args=[5, 6])
103103

104104
txn_hash = transact(
105105
contract=math_contract,
@@ -111,13 +111,13 @@ def test_contract_estimateGas_with_arguments(w3, math_contract, estimateGas, tra
111111
assert abs(gas_estimate - gas_used) < 21000
112112

113113

114-
def test_estimateGas_not_sending_ether_to_nonpayable_function(
114+
def test_estimate_gas_not_sending_ether_to_nonpayable_function(
115115
w3,
116116
payable_tester_contract,
117-
estimateGas,
117+
estimate_gas,
118118
transact):
119-
gas_estimate = estimateGas(contract=payable_tester_contract,
120-
contract_function='doNoValueCall')
119+
gas_estimate = estimate_gas(contract=payable_tester_contract,
120+
contract_function='doNoValueCall')
121121

122122
txn_hash = transact(
123123
contract=payable_tester_contract,
@@ -129,18 +129,18 @@ def test_estimateGas_not_sending_ether_to_nonpayable_function(
129129
assert abs(gas_estimate - gas_used) < 21000
130130

131131

132-
def test_estimateGas_sending_ether_to_nonpayable_function(
132+
def test_estimate_gas_sending_ether_to_nonpayable_function(
133133
w3,
134134
payable_tester_contract,
135-
estimateGas):
135+
estimate_gas):
136136
with pytest.raises(ValidationError):
137-
estimateGas(contract=payable_tester_contract,
138-
contract_function='doNoValueCall',
139-
tx_params={'value': 1})
137+
estimate_gas(contract=payable_tester_contract,
138+
contract_function='doNoValueCall',
139+
tx_params={'value': 1})
140140

141141

142-
def test_estimateGas_accepts_latest_block(w3, math_contract, transact):
143-
gas_estimate = math_contract.functions.counter().estimateGas(block_identifier='latest')
142+
def test_estimate_gas_accepts_latest_block(w3, math_contract, transact):
143+
gas_estimate = math_contract.functions.counter().estimate_gas(block_identifier='latest')
144144

145145
txn_hash = transact(
146146
contract=math_contract,
@@ -152,14 +152,14 @@ def test_estimateGas_accepts_latest_block(w3, math_contract, transact):
152152
assert abs(gas_estimate - gas_used) < 21000
153153

154154

155-
def test_estimateGas_block_identifier_unique_estimates(w3, math_contract, transact):
155+
def test_estimate_gas_block_identifier_unique_estimates(w3, math_contract, transact):
156156
txn_hash = transact(contract=math_contract, contract_function="increment")
157157
w3.eth.wait_for_transaction_receipt(txn_hash)
158158

159-
latest_gas_estimate = math_contract.functions.counter().estimateGas(
159+
latest_gas_estimate = math_contract.functions.counter().estimate_gas(
160160
block_identifier="latest"
161161
)
162-
earliest_gas_estimate = math_contract.functions.counter().estimateGas(
162+
earliest_gas_estimate = math_contract.functions.counter().estimate_gas(
163163
block_identifier="earliest"
164164
)
165165

tests/core/contracts/test_contract_method_abi_decoding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_contract_abi_decoding(w3, abi, data, method, expected):
8888
assert params == expected
8989

9090
reinvoke_func = contract.functions[func.fn_name](**params)
91-
rebuild_txn = reinvoke_func.buildTransaction({'gas': 0, 'nonce': 0, 'to': '\x00' * 20})
91+
rebuild_txn = reinvoke_func.build_transaction({'gas': 0, 'nonce': 0, 'to': '\x00' * 20})
9292
assert rebuild_txn['data'] == data
9393

9494

@@ -115,5 +115,5 @@ def test_contract_abi_encoding_kwargs(w3, abi, method, expected, data):
115115
assert params == expected
116116

117117
reinvoke_func = contract.functions[func.fn_name](**params)
118-
rebuild_txn = reinvoke_func.buildTransaction({'gas': 0, 'nonce': 0, 'to': '\x00' * 20})
118+
rebuild_txn = reinvoke_func.build_transaction({'gas': 0, 'nonce': 0, 'to': '\x00' * 20})
119119
assert rebuild_txn['data'] == data

0 commit comments

Comments
 (0)