Skip to content

Commit 91b4e19

Browse files
committed
Add and pass test for tuple function lookup
1 parent 22a65f7 commit 91b4e19

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

tests/core/contracts/test_contract_method_to_argument_matching.py

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,82 @@
1313

1414
SINGLE_FN_NO_ARGS = json.loads('[{"constant":false,"inputs":[],"name":"a","outputs":[],"type":"function"}]') # noqa: E501
1515
SINGLE_FN_ONE_ARG = json.loads('[{"constant":false,"inputs":[{"name":"","type":"uint256"}],"name":"a","outputs":[],"type":"function"}]') # noqa: E501
16-
MULTIPLE_FUNCTIONS = json.loads('[{"constant":false,"inputs":[],"name":"a","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"","type":"bytes32"}],"name":"a","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"","type":"uint256"}],"name":"a","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"","type":"uint8"}],"name":"a","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"","type":"int8"}],"name":"a","outputs":[],"type":"function"}]') # noqa: E501
1716
FALLBACK_FUNCTION = json.loads('[{"constant": false, "inputs": [], "name": "getData", "outputs": [{"name": "r", "type": "uint256"}], "payable": false, "stateMutability": "nonpayable", "type": "function"}, {"payable": false, "stateMutability": "nonpayable", "type": "fallback"}]') # noqa: E501
17+
MULTIPLE_FUNCTIONS = json.loads('''
18+
[
19+
{
20+
"constant": false,
21+
"inputs": [],
22+
"name": "a",
23+
"outputs": [],
24+
"type": "function"
25+
},
26+
{
27+
"constant": false,
28+
"inputs": [
29+
{
30+
"name": "",
31+
"type": "bytes32"
32+
}
33+
],
34+
"name": "a",
35+
"outputs": [],
36+
"type": "function"
37+
},
38+
{
39+
"constant": false,
40+
"inputs": [
41+
{
42+
"name": "",
43+
"type": "uint256"
44+
}
45+
],
46+
"name": "a",
47+
"outputs": [],
48+
"type": "function"
49+
},
50+
{
51+
"constant": false,
52+
"inputs": [
53+
{
54+
"name": "",
55+
"type": "uint8"
56+
}
57+
],
58+
"name": "a",
59+
"outputs": [],
60+
"type": "function"
61+
},
62+
{
63+
"constant": false,
64+
"inputs": [
65+
{
66+
"name": "",
67+
"type": "int8"
68+
}
69+
],
70+
"name": "a",
71+
"outputs": [],
72+
"type": "function"
73+
},
74+
{
75+
"constant": false,
76+
"inputs": [
77+
{
78+
"name": "",
79+
"type": "tuple[]",
80+
"components": [
81+
{"name": "", "type": "int256"},
82+
{"name": "", "type": "bool"}
83+
]
84+
}
85+
],
86+
"name": "a",
87+
"outputs": [],
88+
"type": "function"
89+
}
90+
]
91+
''')
1892

1993

2094
def test_finds_single_function_without_args(web3):
@@ -57,6 +131,7 @@ def test_error_when_no_function_name_match(web3):
57131
([1234567890], ['uint256']),
58132
# ([255], ['uint8']), # TODO: enable
59133
([-1], ['int8']),
134+
([[(-1, True), (2, False)]], ['(int256,bool)[]']),
60135
)
61136
)
62137
def test_finds_function_with_matching_args(web3, arguments, expected_types):

web3/_utils/abi.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ def check_if_arguments_can_be_encoded(function_abi, args, kwargs):
233233
if len(function_abi.get('inputs', [])) != len(arguments):
234234
return False
235235

236-
types, arguments = get_abi_inputs(function_abi, arguments)
236+
try:
237+
types, arguments = get_abi_inputs(function_abi, arguments)
238+
except TypeError:
239+
return False
237240

238241
return all(
239242
is_encodable(_type, arg)

0 commit comments

Comments
 (0)