Skip to content

Commit 131ccc3

Browse files
committed
Fix bug in contract caller
1 parent 06c1949 commit 131ccc3

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

newsfragments/1552.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Minor bugfix in how ContractCaller looks up abi functions.

tests/core/contracts/test_contract_caller_interface.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,19 @@ def test_caller_with_empty_abi(web3):
8282
contract.caller.thisFunctionDoesNotExist()
8383

8484

85+
def test_caller_raw_getattr_with_missing_element(math_contract):
86+
with pytest.raises(MismatchedABI, match="not found in this contract's ABI"):
87+
math_contract.caller.__getattr__('notafunction')
88+
89+
90+
def test_caller_raw_getattr_with_present_element(math_contract):
91+
attr = math_contract.caller.__getattr__('return13')
92+
assert attr
93+
94+
8595
def test_caller_with_a_nonexistent_function(math_contract):
8696
contract = math_contract
87-
with pytest.raises(MismatchedABI):
97+
with pytest.raises(MismatchedABI, match="not found in this contract's ABI"):
8898
contract.caller.thisFunctionDoesNotExist()
8999

90100

web3/contract.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,8 +1351,7 @@ def __getattr__(self, function_name: str) -> Any:
13511351
"The ABI for this contract contains no function definitions. ",
13521352
"Are you sure you provided the correct contract ABI?"
13531353
)
1354-
# type ignore b/c bug: fix coming in future pr
1355-
elif function_name not in self._functions: # type: ignore
1354+
elif function_name not in set(fn['name'] for fn in self._functions):
13561355
functions_available = ', '.join([fn['name'] for fn in self._functions])
13571356
raise MismatchedABI(
13581357
"The function '{}' was not found in this contract's ABI. ".format(function_name),

0 commit comments

Comments
 (0)