Skip to content

Commit

Permalink
Fix bug in contract caller
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Dec 12, 2019
1 parent 06c1949 commit 4aa7808
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 11 additions & 1 deletion tests/core/contracts/test_contract_caller_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,19 @@ def test_caller_with_empty_abi(web3):
contract.caller.thisFunctionDoesNotExist()


def test_caller_raw_getattr_with_missing_element(math_contract):
with pytest.raises(MismatchedABI, match="not found in this contract's ABI"):
math_contract.caller.__getattr__('notafunction')


def test_caller_raw_getattr_with_present_element(math_contract):
attr = math_contract.caller.__getattr__('return13')
assert attr


def test_caller_with_a_nonexistent_function(math_contract):
contract = math_contract
with pytest.raises(MismatchedABI):
with pytest.raises(MismatchedABI, match="not found in this contract's ABI"):
contract.caller.thisFunctionDoesNotExist()


Expand Down
3 changes: 1 addition & 2 deletions web3/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,8 +1351,7 @@ def __getattr__(self, function_name: str) -> Any:
"The ABI for this contract contains no function definitions. ",
"Are you sure you provided the correct contract ABI?"
)
# type ignore b/c bug: fix coming in future pr
elif function_name not in self._functions: # type: ignore
elif function_name not in set(fn['name'] for fn in self._functions):
functions_available = ', '.join([fn['name'] for fn in self._functions])
raise MismatchedABI(
"The function '{}' was not found in this contract's ABI. ".format(function_name),
Expand Down

0 comments on commit 4aa7808

Please sign in to comment.