Skip to content

Commit 9b7f6cb

Browse files
committed
Simple path
1 parent bc1011a commit 9b7f6cb

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

tests/core/contracts/test_contract_call_interface.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ def test_call_with_no_arguments(math_contract, call):
145145
assert result == 13
146146

147147

148+
def test_call_no_arguments_no_parens(math_contract):
149+
assert math_contract.functions.return13.call() == 13
150+
151+
148152
def test_call_with_one_argument(math_contract, call):
149153
result = call(contract=math_contract, contract_function="multiply7", func_args=[3])
150154
assert result == 21

tests/core/contracts/test_contract_estimate_gas.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ def test_contract_estimate_gas(w3, math_contract, estimate_gas, transact):
1818
assert abs(gas_estimate - gas_used) < 21000
1919

2020

21+
def test_estimate_gas_can_be_called_without_parens(
22+
w3, math_contract, estimate_gas, transact
23+
):
24+
gas_estimate = math_contract.functions.incrementCounter.estimate_gas()
25+
26+
txn_hash = transact(contract=math_contract, contract_function="incrementCounter")
27+
28+
txn_receipt = w3.eth.wait_for_transaction_receipt(txn_hash)
29+
gas_used = txn_receipt.get("gasUsed")
30+
31+
assert abs(gas_estimate - gas_used) < 21000
32+
33+
2134
def test_contract_fallback_estimate_gas(w3, fallback_function_contract):
2235
gas_estimate = fallback_function_contract.fallback.estimate_gas()
2336

web3/contract/contract.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,6 @@ def call(
308308

309309
block_id = parse_block_identifier(self.w3, block_identifier)
310310

311-
# ContractFunction that doesn't take args can be referenced
312-
# instead of called for the same result
313-
# ex. contract.functions.myFunction.call()
314-
if self.kwargs is None and self.args is None:
315-
self.kwargs = {}
316-
self.args = tuple()
317-
self._set_function_info()
318-
319311
return call_contract_function(
320312
self.w3,
321313
self.address,
@@ -328,21 +320,22 @@ def call(
328320
state_override,
329321
ccip_read_enabled,
330322
self.decode_tuples,
331-
*self.args,
332-
**self.kwargs,
323+
*self.args or (),
324+
**self.kwargs or {},
333325
)
334326

335327
def transact(self, transaction: Optional[TxParams] = None) -> HexBytes:
336328
setup_transaction = self._transact(transaction)
329+
337330
return transact_with_contract_function(
338331
self.address,
339332
self.w3,
340333
self.function_identifier,
341334
setup_transaction,
342335
self.contract_abi,
343336
self.abi,
344-
*self.args,
345-
**self.kwargs,
337+
*self.args or (),
338+
**self.kwargs or {},
346339
)
347340

348341
def estimate_gas(
@@ -361,21 +354,22 @@ def estimate_gas(
361354
self.abi,
362355
block_identifier,
363356
state_override,
364-
*self.args,
365-
**self.kwargs,
357+
*self.args or (),
358+
**self.kwargs or {},
366359
)
367360

368361
def build_transaction(self, transaction: Optional[TxParams] = None) -> TxParams:
369362
built_transaction = self._build_transaction(transaction)
363+
370364
return build_transaction_for_function(
371365
self.address,
372366
self.w3,
373367
self.function_identifier,
374368
built_transaction,
375369
self.contract_abi,
376370
self.abi,
377-
*self.args,
378-
**self.kwargs,
371+
*self.args or (),
372+
**self.kwargs or {},
379373
)
380374

381375
@staticmethod

0 commit comments

Comments
 (0)