diff --git a/newsfragments/2764.bugfix.rst b/newsfragments/2764.bugfix.rst new file mode 100644 index 0000000000..5f814ddcf1 --- /dev/null +++ b/newsfragments/2764.bugfix.rst @@ -0,0 +1 @@ +Fixing abi encoding for multidimensional arrays. \ No newline at end of file diff --git a/tests/core/utilities/test_abi.py b/tests/core/utilities/test_abi.py index ac7ae97a4d..8ea04f300a 100644 --- a/tests/core/utilities/test_abi.py +++ b/tests/core/utilities/test_abi.py @@ -112,6 +112,20 @@ def test_get_tuple_type_str_parts(input, expected): { "name": "a", "type": "uint256" + }, + { + "components": [ + { + "name": "x", + "type": "uint256" + }, + { + "name": "y", + "type": "uint256" + } + ], + "name": "b", + "type": "tuple[][]" } ], "name": "f", @@ -129,11 +143,13 @@ def test_get_tuple_type_str_parts(input, expected): "(uint256,uint256[],(uint256,uint256)[])", # Type of s "(uint256,uint256)", # Type of t "uint256", # Type of a + "(uint256,uint256)[][]", # Type of b ), ( (1, [2, 3, 4], [(5, 6), (7, 8), (9, 10)]), # Value for s (11, 12), # Value for t 13, # Value for a + [[(14, 15), (16, 17)], [(18, 19)]], # Value for b ), ) @@ -148,6 +164,7 @@ def test_get_tuple_type_str_parts(input, expected): }, "t": {"x": 11, "y": 12}, "a": 13, + "b": [[{"x": 14, "y": 15}, {"x": 16, "y": 17}], [{"x": 18, "y": 19}]], }, GET_ABI_INPUTS_OUTPUT, ), @@ -157,6 +174,7 @@ def test_get_tuple_type_str_parts(input, expected): "s": {"a": 1, "b": [2, 3, 4], "c": [(5, 6), (7, 8), {"x": 9, "y": 10}]}, "t": {"x": 11, "y": 12}, "a": 13, + "b": [[(14, 15), (16, 17)], [{"x": 18, "y": 19}]], }, GET_ABI_INPUTS_OUTPUT, ), @@ -166,6 +184,7 @@ def test_get_tuple_type_str_parts(input, expected): "s": {"a": 1, "b": [2, 3, 4], "c": [(5, 6), (7, 8), (9, 10)]}, "t": (11, 12), "a": 13, + "b": [[(14, 15), (16, 17)], [(18, 19)]], }, GET_ABI_INPUTS_OUTPUT, ), @@ -175,6 +194,7 @@ def test_get_tuple_type_str_parts(input, expected): "s": (1, [2, 3, 4], [(5, 6), (7, 8), (9, 10)]), "t": (11, 12), "a": 13, + "b": [[(14, 15), (16, 17)], [(18, 19)]], }, GET_ABI_INPUTS_OUTPUT, ), @@ -184,6 +204,7 @@ def test_get_tuple_type_str_parts(input, expected): (1, [2, 3, 4], [(5, 6), (7, 8), (9, 10)]), (11, 12), 13, + [[(14, 15), (16, 17)], [(18, 19)]], ), GET_ABI_INPUTS_OUTPUT, ), @@ -193,6 +214,10 @@ def test_get_tuple_type_str_parts(input, expected): "s": {"a": 1, "b": [2, 3, 4], "c": [(5, 6), (7, 8), MyXYTuple(x=9, y=10)]}, "t": MyXYTuple(x=11, y=12), "a": 13, + "b": [ + [MyXYTuple(x=14, y=15), MyXYTuple(x=16, y=17)], + [MyXYTuple(x=18, y=19)], + ], }, GET_ABI_INPUTS_OUTPUT, ), @@ -219,6 +244,7 @@ def test_get_aligned_abi_inputs(abi, args, expected): "s": {"a": 1, "b": [2, 3, 4], "c": ["56", (7, 8), (9, 10)]}, "t": (11, 12), "a": 13, + "b": [[(14, 15), (16, 17)], [(18, 19)]], }, ), ( @@ -227,6 +253,7 @@ def test_get_aligned_abi_inputs(abi, args, expected): "s": {"a": 1, "b": [2, 3, 4], "c": {(5, 6), (7, 8), (9, 10)}}, "t": (11, 12), "a": 13, + "b": [[(14, 15), (16, 17)], [(18, 19)]], }, ), ) diff --git a/web3/_utils/abi.py b/web3/_utils/abi.py index e3a9ac4fd1..08bd522eaa 100644 --- a/web3/_utils/abi.py +++ b/web3/_utils/abi.py @@ -519,10 +519,12 @@ def _align_abi_input(arg_abi: ABIFunctionParams, arg: Any) -> Tuple[Any, ...]: # according to its corresponding abi. sub_abis = arg_abi["components"] else: + num_dims = tuple_dims.count("[") + # Arg is list tuple. A non-list version of its abi will be used to # align each element in `arg`. new_abi = copy.copy(arg_abi) - new_abi["type"] = tuple_prefix + new_abi["type"] = tuple_prefix + "[]" * (num_dims - 1) sub_abis = itertools.repeat(new_abi) # type: ignore