@@ -324,6 +324,66 @@ func TestPack(t *testing.T) {
324324 "foobar" ,
325325 common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000006666f6f6261720000000000000000000000000000000000000000000000000000" ),
326326 },
327+ {
328+ "string[]" ,
329+ []string {"hello" , "foobar" },
330+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000002" + // len(array) = 2
331+ "0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i = 0
332+ "0000000000000000000000000000000000000000000000000000000000000080" + // offset 128 to i = 1
333+ "0000000000000000000000000000000000000000000000000000000000000005" + // len(str[0]) = 5
334+ "68656c6c6f000000000000000000000000000000000000000000000000000000" + // str[0]
335+ "0000000000000000000000000000000000000000000000000000000000000006" + // len(str[1]) = 6
336+ "666f6f6261720000000000000000000000000000000000000000000000000000" ), // str[1]
337+ },
338+ {
339+ "string[2]" ,
340+ []string {"hello" , "foobar" },
341+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000040" + // offset to i = 0
342+ "0000000000000000000000000000000000000000000000000000000000000080" + // offset 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+ "bytes32[][]" ,
350+ [][]common.Hash {{{1 }, {2 }}, {{3 }, {4 }, {5 }}},
351+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000002" + // len(array) = 2
352+ "0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i = 0
353+ "00000000000000000000000000000000000000000000000000000000000000a0" + // offset 160 to i = 1
354+ "0000000000000000000000000000000000000000000000000000000000000002" + // len(array[0]) = 2
355+ "0100000000000000000000000000000000000000000000000000000000000000" + // array[0][0]
356+ "0200000000000000000000000000000000000000000000000000000000000000" + // array[0][1]
357+ "0000000000000000000000000000000000000000000000000000000000000003" + // len(array[1]) = 3
358+ "0300000000000000000000000000000000000000000000000000000000000000" + // array[1][0]
359+ "0400000000000000000000000000000000000000000000000000000000000000" + // array[1][1]
360+ "0500000000000000000000000000000000000000000000000000000000000000" ), // array[1][2]
361+ },
362+
363+ {
364+ "bytes32[][2]" ,
365+ [][]common.Hash {{{1 }, {2 }}, {{3 }, {4 }, {5 }}},
366+ common .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i = 0
367+ "00000000000000000000000000000000000000000000000000000000000000a0" + // offset 160 to i = 1
368+ "0000000000000000000000000000000000000000000000000000000000000002" + // len(array[0]) = 2
369+ "0100000000000000000000000000000000000000000000000000000000000000" + // array[0][0]
370+ "0200000000000000000000000000000000000000000000000000000000000000" + // array[0][1]
371+ "0000000000000000000000000000000000000000000000000000000000000003" + // len(array[1]) = 3
372+ "0300000000000000000000000000000000000000000000000000000000000000" + // array[1][0]
373+ "0400000000000000000000000000000000000000000000000000000000000000" + // array[1][1]
374+ "0500000000000000000000000000000000000000000000000000000000000000" ), // array[1][2]
375+ },
376+
377+ {
378+ "bytes32[3][2]" ,
379+ [][]common.Hash {{{1 }, {2 }, {3 }}, {{3 }, {4 }, {5 }}},
380+ common .Hex2Bytes ("0100000000000000000000000000000000000000000000000000000000000000" + // array[0][0]
381+ "0200000000000000000000000000000000000000000000000000000000000000" + // array[0][1]
382+ "0300000000000000000000000000000000000000000000000000000000000000" + // array[0][2]
383+ "0300000000000000000000000000000000000000000000000000000000000000" + // array[1][0]
384+ "0400000000000000000000000000000000000000000000000000000000000000" + // array[1][1]
385+ "0500000000000000000000000000000000000000000000000000000000000000" ), // array[1][2]
386+ },
327387 } {
328388 typ , err := NewType (test .typ )
329389 if err != nil {
@@ -336,7 +396,7 @@ func TestPack(t *testing.T) {
336396 }
337397
338398 if ! bytes .Equal (output , test .output ) {
339- t .Errorf ("%d failed. Expected bytes: '%x' Got: '%x'" , i , test .output , output )
399+ t .Errorf ("input %d for typ: %v failed. Expected bytes: '%x' Got: '%x'" , i , typ . String () , test .output , output )
340400 }
341401 }
342402}
0 commit comments