Skip to content

Commit b77e2f4

Browse files
committed
Incorporate review suggestions
1 parent 808fa92 commit b77e2f4

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

tests/core/utilities/test_abi.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from web3._utils.abi import (
55
abi_data_tree,
6-
get_abi_inputs,
6+
get_aligned_abi_inputs,
77
get_tuple_type_str_parts,
88
map_abi_data,
99
)
@@ -177,8 +177,8 @@ def test_get_tuple_type_str_parts(input, expected):
177177
'abi, args, expected',
178178
GET_ABI_INPUTS_TESTS,
179179
)
180-
def test_get_abi_inputs(abi, args, expected):
181-
assert get_abi_inputs(abi, args) == expected
180+
def test_get_aligned_abi_inputs(abi, args, expected):
181+
assert get_aligned_abi_inputs(abi, args) == expected
182182

183183

184184
GET_ABI_INPUTS_RAISING_TESTS = (
@@ -205,9 +205,9 @@ def test_get_abi_inputs(abi, args, expected):
205205
'abi, args',
206206
GET_ABI_INPUTS_RAISING_TESTS,
207207
)
208-
def test_get_abi_inputs_raises_type_error(abi, args):
208+
def test_get_aligned_abi_inputs_raises_type_error(abi, args):
209209
with pytest.raises(TypeError):
210-
get_abi_inputs(abi, args)
210+
get_aligned_abi_inputs(abi, args)
211211

212212

213213
@pytest.mark.parametrize(

web3/_utils/abi.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ def check_if_arguments_can_be_encoded(function_abi, args, kwargs):
235235
return False
236236

237237
try:
238-
types, arguments = get_abi_inputs(function_abi, arguments)
238+
types, aligned_args = get_aligned_abi_inputs(function_abi, arguments)
239239
except TypeError:
240240
return False
241241

242242
return all(
243243
is_encodable(_type, arg)
244-
for _type, arg in zip(types, arguments)
244+
for _type, arg in zip(types, aligned_args)
245245
)
246246

247247

@@ -332,13 +332,13 @@ def get_tuple_type_str_parts(s: str) -> Optional[Tuple[str, Optional[str]]]:
332332
return None
333333

334334

335-
def _convert_abi_input(comp, arg):
335+
def _convert_abi_input(arg_abi, arg):
336336
"""
337-
Converts an argument ``arg`` corresponding to an ABI component ``comp``
337+
Converts an argument ``arg`` corresponding to an ABI component ``arg_abi``
338338
into a plain value (for non-tuple components) or a properly converted and
339339
ordered sequence (for tuple list components or tuple components).
340340
"""
341-
tuple_parts = get_tuple_type_str_parts(comp['type'])
341+
tuple_parts = get_tuple_type_str_parts(arg_abi['type'])
342342

343343
if tuple_parts is None:
344344
# Component is non-tuple. Just return value.
@@ -348,37 +348,37 @@ def _convert_abi_input(comp, arg):
348348
if tuple_dims is None:
349349
# Component is non-list tuple. Each sub component of tuple will be
350350
# applied to each element in `arg`.
351-
sub_comps = comp['components']
351+
sub_abis = arg_abi['components']
352352
else:
353353
# Component is list tuple. A non-list version of this component will be
354354
# repeatedly applied to each element in `arg`.
355-
new_comp = copy.copy(comp)
356-
new_comp['type'] = tuple_prefix
355+
new_abi = copy.copy(arg_abi)
356+
new_abi['type'] = tuple_prefix
357357

358-
sub_comps = itertools.repeat(new_comp)
358+
sub_abis = itertools.repeat(new_abi)
359359

360360
if isinstance(arg, abc.Mapping):
361361
# Arg is mapping. Convert to properly ordered sequence.
362-
arg = tuple(arg[c['name']] for c in sub_comps)
362+
arg = tuple(arg[c['name']] for c in sub_abis)
363363

364364
if not is_list_like(arg):
365365
raise TypeError(
366366
'Expected non-string sequence for "{}" component type: got {}'.format(
367-
comp['type'],
367+
arg_abi['type'],
368368
arg,
369369
),
370370
)
371371

372-
return type(arg)(_convert_abi_input(c, a) for c, a in zip(sub_comps, arg))
372+
return type(arg)(_convert_abi_input(c, a) for c, a in zip(sub_abis, arg))
373373

374374

375-
def get_abi_inputs(abi, args):
375+
def get_aligned_abi_inputs(abi, args):
376376
"""
377-
Takes a function ABI (``abi``) and a sequence or mapping of args
378-
(``args``). Returns a list of canonical type names for the function's
379-
inputs and a list of arguments in corresponding order. The args contained
380-
in ``args`` may contain nested mappings or sequences corresponding to
381-
tuple-encoded values in ``abi``.
377+
Takes a function ABI (``abi``) and a sequence or mapping of args (``args``).
378+
Returns a list of type strings for the function's inputs and a list of
379+
arguments which have been aligned to the layout of those types. The args
380+
contained in ``args`` may contain nested mappings or sequences corresponding
381+
to tuple-encoded values in ``abi``.
382382
"""
383383
inputs = abi.get('inputs', [])
384384

web3/_utils/contracts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
filter_by_name,
2323
filter_by_type,
2424
get_abi_input_types,
25-
get_abi_inputs,
25+
get_aligned_abi_inputs,
2626
get_fallback_func_abi,
2727
map_abi_data,
2828
merge_args_and_kwargs,
@@ -241,9 +241,9 @@ def get_function_info(fn_name, contract_abi=None, fn_abi=None, args=None, kwargs
241241

242242
fn_arguments = merge_args_and_kwargs(fn_abi, args, kwargs)
243243

244-
_, fn_arguments = get_abi_inputs(fn_abi, fn_arguments)
244+
_, aligned_fn_arguments = get_aligned_abi_inputs(fn_abi, fn_arguments)
245245

246-
return fn_abi, fn_selector, fn_arguments
246+
return fn_abi, fn_selector, aligned_fn_arguments
247247

248248

249249
def validate_payable(transaction, abi):

0 commit comments

Comments
 (0)