4
4
import json
5
5
import pytest
6
6
7
- ABI_A = json .loads ('[{"constant":false,"inputs":[],"name":"a ","outputs":[],"type":"function"}]' )
8
- ABI_B = json .loads ('[{"constant":false,"inputs":[{"name":"","type":"uint256"}],"name":"a ","outputs":[],"type":"function"}]' ) # noqa: E501
9
- ABI_C = 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"}]' ) # noqa: E501
7
+ ABI_A = json .loads ('[{"constant":false,"inputs":[],"name":"noargfunc ","outputs":[],"type":"function"}]' ) # noqa: E501
8
+ ABI_B = json .loads ('[{"constant":false,"inputs":[{"name":"uintarg ","type":"uint256"}],"name":"uintfunc ","outputs":[],"type":"function"}]' ) # noqa: E501
9
+ ABI_C = json .loads ('[{"constant":false,"inputs":[],"name":"namesakefunc ","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"bytesarg ","type":"bytes32"}],"name":"namesakefunc ","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"uintarg ","type":"uint256"}],"name":"namesakefunc ","outputs":[],"type":"function"}]' ) # noqa: E501
10
10
ABI_D = json .loads ('[{ "constant": false, "inputs": [ { "name": "b", "type": "bytes32[]" } ], "name": "byte_array", "outputs": [], "payable": false, "type": "function" }]' ) # noqa: E501
11
11
ABI_BYTES = json .loads ('[{"constant":false,"inputs":[{"name":"bytesarg","type":"bytes"}],"name":"bytesfunc","outputs":[],"type":"function"}]' ) # noqa: E501
12
12
ABI_STRING = json .loads ('[{"constant":false,"inputs":[{"name":"stringarg","type":"string"}],"name":"stringfunc","outputs":[],"type":"function"}]' ) # noqa: E501
15
15
16
16
17
17
@pytest .mark .parametrize (
18
- 'abi,data,method,arguments, expected' ,
18
+ 'abi,data,method,expected' ,
19
19
(
20
20
(
21
21
ABI_A ,
22
- '0x0dbe671f' ,
23
- 'a' ,
24
- [],
22
+ '0xc4c1a40b' ,
23
+ 'noargfunc' ,
25
24
{},
26
25
),
27
26
(
28
27
ABI_B ,
29
- '0xf0fdf8340000000000000000000000000000000000000000000000000000000000000001' ,
30
- 'a' ,
31
- [1 ],
32
- {'' : 1 },
28
+ '0xcc6820de0000000000000000000000000000000000000000000000000000000000000001' ,
29
+ 'uintfunc' ,
30
+ {'uintarg' : 1 },
33
31
),
34
32
(
35
33
ABI_C ,
36
- '0xf0fdf8340000000000000000000000000000000000000000000000000000000000000001' ,
37
- 'a' ,
38
- [1 ],
39
- {'' : 1 },
40
- ),
41
- (
42
- ABI_C ,
43
- '0x9f3fab586100000000000000000000000000000000000000000000000000000000000000' ,
44
- 'a' ,
45
- [b'a' ],
46
- {'' : a32bytes },
47
- ),
48
- (
49
- ABI_C ,
50
- '0x9f3fab586100000000000000000000000000000000000000000000000000000000000000' ,
51
- 'a' ,
52
- ['0x61' ],
53
- {'' : a32bytes },
34
+ '0x22d86fa3' ,
35
+ 'namesakefunc' ,
36
+ {},
54
37
),
55
38
(
56
39
ABI_C ,
57
- '0x9f3fab586100000000000000000000000000000000000000000000000000000000000000' ,
58
- 'a' ,
59
- ['61' ],
60
- {'' : a32bytes },
40
+ '0x40c05b2f0000000000000000000000000000000000000000000000000000000000000001' ,
41
+ 'namesakefunc' ,
42
+ {'uintarg' : 1 },
61
43
),
62
44
(
63
45
ABI_C ,
64
- '0xf0fdf834000000000000000000000000000000000000000000000000000000000000007f' ,
65
- 'a' ,
66
- [127 ],
67
- {'' : 127 },
46
+ '0xf931d77c6100000000000000000000000000000000000000000000000000000000000000' ,
47
+ 'namesakefunc' ,
48
+ {'bytesarg' : a32bytes },
68
49
),
69
50
(
70
51
ABI_BYTES ,
71
52
'0xb606a9f6000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000016100000000000000000000000000000000000000000000000000000000000000' , # noqa: E501
72
53
'bytesfunc' ,
73
- [],
74
54
{'bytesarg' : b'a' },
75
55
),
76
56
(
77
57
ABI_STRING ,
78
58
'0x33b4005f000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000016100000000000000000000000000000000000000000000000000000000000000' , # noqa: E501
79
59
'stringfunc' ,
80
- [],
81
60
{'stringarg' : 'a' },
82
61
),
83
62
(
84
63
ABI_ADDRESS ,
85
64
'0x4767be6c000000000000000000000000ffffffffffffffffffffffffffffffffffffffff' ,
86
65
'addressfunc' ,
87
- [],
88
66
{'addressarg' : '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF' },
89
67
),
90
68
),
91
69
)
92
- def test_contract_abi_decoding (web3 , abi , data , method , arguments , expected ):
70
+ def test_contract_abi_decoding (web3 , abi , data , method , expected ):
93
71
contract = web3 .eth .contract (abi = abi )
94
72
func , params = contract .decode_function_input (data )
95
73
assert func .fn_name == method
@@ -107,10 +85,10 @@ def test_contract_abi_decoding(web3, abi, data, method, arguments, expected):
107
85
ABI_D ,
108
86
'byte_array' ,
109
87
{
110
- 'b' : (
88
+ 'b' : [
111
89
unhexlify ('5595c210956e7721f9b692e702708556aa9aabb14ea163e96afa56ffbe9fa809' ),
112
90
unhexlify ('6f8d2fa18448afbfe4f82143c384484ad09a0271f3a3c0eb9f629e703f883125' ),
113
- ) ,
91
+ ] ,
114
92
},
115
93
'0xf166d6f8000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000025595c210956e7721f9b692e702708556aa9aabb14ea163e96afa56ffbe9fa8096f8d2fa18448afbfe4f82143c384484ad09a0271f3a3c0eb9f629e703f883125' , # noqa: E501
116
94
),
0 commit comments