Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
Update exception messages to specify plurals
Revert to use `event_abi` variable
  • Loading branch information
reedsa committed Sep 24, 2024
1 parent a4cd1d4 commit 9dd0fd9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ def test_finds_function_with_matching_args_strict_type_checking_by_default(w3):
MismatchedABI,
match=re.escape(
"\nABI Not Found!\n"
"Multiple elements were found matching 1 arguments.\n"
"Multiple elements were found that accept 1 argument(s).\n"
"Provided argument types: (str)\n"
"Provided keyword argument types: {}\n\n"
"Encountered problems with the following elements named `a`.\n"
"Tried to find a matching ABI element `a`, but encountered the following "
"problems:\n"
"a()\n"
"Function `a` expects 0 arguments but 1 were given.\n"
"a(bytes32)\n"
Expand Down
10 changes: 5 additions & 5 deletions web3/contract/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,28 +182,28 @@ def get_logs(
same time as ``from_block`` or ``to_block``
:yield: Tuple of :class:`AttributeDict` instances
"""
abi = self._get_event_abi()
event_abi = self._get_event_abi()
# validate ``argument_filters`` if present
if argument_filters is not None:
event_arg_names = get_abi_input_names(abi)
event_arg_names = get_abi_input_names(event_abi)
if not all(arg in event_arg_names for arg in argument_filters.keys()):
raise Web3ValidationError(
"When filtering by argument names, all argument names must be "
"present in the contract's event ABI."
)

_filter_params = self._get_event_filter_params(
abi, argument_filters, from_block, to_block, block_hash
event_abi, argument_filters, from_block, to_block, block_hash
)
# call JSON-RPC API
logs = self.w3.eth.get_logs(_filter_params)

# convert raw binary data to Python proxy objects as described by ABI:
all_event_logs = tuple(
get_event_data(self.w3.codec, abi, entry) for entry in logs
get_event_data(self.w3.codec, event_abi, entry) for entry in logs
)
filtered_logs = self._process_get_logs_argument_filters(
abi,
event_abi,
all_event_logs,
argument_filters,
)
Expand Down
13 changes: 7 additions & 6 deletions web3/utils/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def _build_abi_input_error(
else:
error += (
f"Function `{abi_element_name}` expects "
f"{len(abi_element_input_types)} arguments but {num_args} were given.\n"
f"{len(abi_element_input_types)} argument(s) but received {num_args} "
"argument(s).\n"
)

return error
Expand Down Expand Up @@ -279,14 +280,14 @@ def _mismatched_abi_error_diagnosis(
if num_matches == 0 and num_abis_matching_arg_count == 0:
error += (
f"No declaration found for `{str(abi_element_identifier)}` with "
f"{num_args} arguments.\n"
f"{num_args} argument(s).\n"
)
elif num_matches > 1 or num_abis_matching_arg_count > 1:
error += f"Multiple elements were found matching {num_args} arguments.\n"
error += f"Multiple elements were found matching {num_args} argument(s).\n"
elif num_abis_matching_arg_count == 1:
error += (
f"Found {num_abis_matching_arg_count} elements named `{name}` that takes "
f"{num_args} arguments.\n"
f"Found {num_abis_matching_arg_count} element(s) named `{name}` that takes "
f"{num_args} argument(s).\n"
"The provided arguments do not match the expected types.\n"
)
elif num_matches == 0:
Expand All @@ -298,7 +299,7 @@ def _mismatched_abi_error_diagnosis(
kwarg_types = dict({(k, _extract_argument_types([v])) for k, v in kwargs.items()})
error += f"Provided argument types: ({arg_types})\n"
error += f"Provided keyword argument types: {kwarg_types}\n\n"
error += f"Encountered problems with the following elements named `{name}`.\n"
error += f"Encountered problems with the following element(s) named `{name}`:\n"

for abi_signature in abi_signatures_matching_names:
error += _build_abi_input_error(
Expand Down

0 comments on commit 9dd0fd9

Please sign in to comment.