@@ -42,7 +42,7 @@ func TestPack(t *testing.T) {
42
42
{
43
43
"uint8[]" ,
44
44
[]uint8 {1 , 2 },
45
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
45
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
46
46
},
47
47
{
48
48
"uint16" ,
@@ -52,7 +52,7 @@ func TestPack(t *testing.T) {
52
52
{
53
53
"uint16[]" ,
54
54
[]uint16 {1 , 2 },
55
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
55
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
56
56
},
57
57
{
58
58
"uint32" ,
@@ -62,7 +62,7 @@ func TestPack(t *testing.T) {
62
62
{
63
63
"uint32[]" ,
64
64
[]uint32 {1 , 2 },
65
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
65
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
66
66
},
67
67
{
68
68
"uint64" ,
@@ -72,7 +72,7 @@ func TestPack(t *testing.T) {
72
72
{
73
73
"uint64[]" ,
74
74
[]uint64 {1 , 2 },
75
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
75
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
76
76
},
77
77
{
78
78
"uint256" ,
@@ -82,7 +82,7 @@ func TestPack(t *testing.T) {
82
82
{
83
83
"uint256[]" ,
84
84
[]* big.Int {big .NewInt (1 ), big .NewInt (2 )},
85
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
85
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
86
86
},
87
87
{
88
88
"int8" ,
@@ -92,7 +92,7 @@ func TestPack(t *testing.T) {
92
92
{
93
93
"int8[]" ,
94
94
[]int8 {1 , 2 },
95
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
95
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
96
96
},
97
97
{
98
98
"int16" ,
@@ -102,7 +102,7 @@ func TestPack(t *testing.T) {
102
102
{
103
103
"int16[]" ,
104
104
[]int16 {1 , 2 },
105
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
105
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
106
106
},
107
107
{
108
108
"int32" ,
@@ -112,7 +112,7 @@ func TestPack(t *testing.T) {
112
112
{
113
113
"int32[]" ,
114
114
[]int32 {1 , 2 },
115
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
115
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
116
116
},
117
117
{
118
118
"int64" ,
@@ -122,7 +122,7 @@ func TestPack(t *testing.T) {
122
122
{
123
123
"int64[]" ,
124
124
[]int64 {1 , 2 },
125
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
125
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
126
126
},
127
127
{
128
128
"int256" ,
@@ -132,7 +132,7 @@ func TestPack(t *testing.T) {
132
132
{
133
133
"int256[]" ,
134
134
[]* big.Int {big .NewInt (1 ), big .NewInt (2 )},
135
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
135
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002 " ),
136
136
},
137
137
{
138
138
"bytes1" ,
@@ -305,14 +305,21 @@ func TestPack(t *testing.T) {
305
305
common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001300000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000018" ),
306
306
},
307
307
{
308
+ //web3.eth.abi.encodeParameter('address[]', ['0x0100000000000000000000000000000000000000','0x0200000000000000000000000000000000000000']);
308
309
"address[]" ,
309
310
[]common.Address {{1 }, {2 }},
310
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000" ),
311
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020" +
312
+ "0000000000000000000000000000000000000000000000000000000000000002" +
313
+ "0000000000000000000000000100000000000000000000000000000000000000" +
314
+ "0000000000000000000000000200000000000000000000000000000000000000" ),
311
315
},
312
316
{
313
317
"bytes32[]" ,
314
318
[]common.Hash {{1 }, {2 }},
315
- common .Hex2Bytes ("000000000000000000000000000000000000000000000000000000000000000201000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000" ),
319
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020" + //offset: 32
320
+ "0000000000000000000000000000000000000000000000000000000000000002" + //len: 2
321
+ "0100000000000000000000000000000000000000000000000000000000000000" + // 1
322
+ "0200000000000000000000000000000000000000000000000000000000000000" ), // 2
316
323
},
317
324
{
318
325
"function" ,
@@ -322,7 +329,41 @@ func TestPack(t *testing.T) {
322
329
{
323
330
"string" ,
324
331
"foobar" ,
325
- common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000006666f6f6261720000000000000000000000000000000000000000000000000000" ),
332
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020" + // offset: 32
333
+ "0000000000000000000000000000000000000000000000000000000000000006" + // len: 6
334
+ "666f6f6261720000000000000000000000000000000000000000000000000000" ), // "foobar"
335
+ },
336
+ {
337
+ "string[]" ,
338
+ []string {"hello" , "foobar" },
339
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020" + // offset array 32
340
+ "0000000000000000000000000000000000000000000000000000000000000002" + // len(array) = 2
341
+ "0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i=0
342
+ "0000000000000000000000000000000000000000000000000000000000000080" + // offset 128 to i=1
343
+ "0000000000000000000000000000000000000000000000000000000000000005" + // len(str[0]) = 5
344
+ "68656c6c6f000000000000000000000000000000000000000000000000000000" + // str[0]
345
+ "0000000000000000000000000000000000000000000000000000000000000006" + // len(str[1]) = 6
346
+ "666f6f6261720000000000000000000000000000000000000000000000000000" ), // str[1]
347
+ },
348
+ {
349
+
350
+ //web3.eth.abi.encodeParameter('bytes32[][]', [['0x0100000000000000000000000000000000000000000000000000000000000000',
351
+ // '0x0200000000000000000000000000000000000000000000000000000000000000'],['0x0300000000000000000000000000000000000000000000000000000000000000',
352
+ // '0x0400000000000000000000000000000000000000000000000000000000000000','0x0500000000000000000000000000000000000000000000000000000000000000']]);
353
+ "bytes32[][]" ,
354
+ [][]common.Hash {{{1 }, {2 }}, {{3 }, {4 }, {5 }}},
355
+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000020" + // offset array 32
356
+ "0000000000000000000000000000000000000000000000000000000000000002" + // len(array) = 2
357
+ "0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i=0
358
+ "00000000000000000000000000000000000000000000000000000000000000a0" + // offset 160 to i=1
359
+ "0000000000000000000000000000000000000000000000000000000000000002" + // len(array[0]) = 2
360
+ "0100000000000000000000000000000000000000000000000000000000000000" + // array[0]
361
+ "0200000000000000000000000000000000000000000000000000000000000000" + // array[1]
362
+ "0000000000000000000000000000000000000000000000000000000000000003" + // len(array[1]) = 3
363
+ "0300000000000000000000000000000000000000000000000000000000000000" + // array[0]
364
+ "0400000000000000000000000000000000000000000000000000000000000000" + // array[1]
365
+ "0500000000000000000000000000000000000000000000000000000000000000" ), // array[2]
366
+
326
367
},
327
368
} {
328
369
typ , err := NewType (test .typ )
@@ -336,7 +377,7 @@ func TestPack(t *testing.T) {
336
377
}
337
378
338
379
if ! bytes .Equal (output , test .output ) {
339
- t .Errorf ("%d failed. Expected bytes: '%x' Got: '%x'" , i , test .output , output )
380
+ t .Errorf ("input %d for typ: %v failed. Expected bytes: '%x' Got: '%x'" , i , typ . String () , test .output , output )
340
381
}
341
382
}
342
383
}
0 commit comments