|
|
@@ -324,6 +324,66 @@ func TestPack(t *testing.T) {
|
|
|
"foobar",
|
|
|
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000006666f6f6261720000000000000000000000000000000000000000000000000000"),
|
|
|
},
|
|
|
+ {
|
|
|
+ "string[]",
|
|
|
+ []string{"hello", "foobar"},
|
|
|
+ common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002" + // len(array) = 2
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i = 0
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000080" + // offset 128 to i = 1
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000005" + // len(str[0]) = 5
|
|
|
+ "68656c6c6f000000000000000000000000000000000000000000000000000000" + // str[0]
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000006" + // len(str[1]) = 6
|
|
|
+ "666f6f6261720000000000000000000000000000000000000000000000000000"), // str[1]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "string[2]",
|
|
|
+ []string{"hello", "foobar"},
|
|
|
+ common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040" + // offset to i = 0
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000080" + // offset to i = 1
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000005" + // len(str[0]) = 5
|
|
|
+ "68656c6c6f000000000000000000000000000000000000000000000000000000" + // str[0]
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000006" + // len(str[1]) = 6
|
|
|
+ "666f6f6261720000000000000000000000000000000000000000000000000000"), // str[1]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "bytes32[][]",
|
|
|
+ [][]common.Hash{{{1}, {2}}, {{3}, {4}, {5}}},
|
|
|
+ common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002" + // len(array) = 2
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i = 0
|
|
|
+ "00000000000000000000000000000000000000000000000000000000000000a0" + // offset 160 to i = 1
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000002" + // len(array[0]) = 2
|
|
|
+ "0100000000000000000000000000000000000000000000000000000000000000" + // array[0][0]
|
|
|
+ "0200000000000000000000000000000000000000000000000000000000000000" + // array[0][1]
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000003" + // len(array[1]) = 3
|
|
|
+ "0300000000000000000000000000000000000000000000000000000000000000" + // array[1][0]
|
|
|
+ "0400000000000000000000000000000000000000000000000000000000000000" + // array[1][1]
|
|
|
+ "0500000000000000000000000000000000000000000000000000000000000000"), // array[1][2]
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ "bytes32[][2]",
|
|
|
+ [][]common.Hash{{{1}, {2}}, {{3}, {4}, {5}}},
|
|
|
+ common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i = 0
|
|
|
+ "00000000000000000000000000000000000000000000000000000000000000a0" + // offset 160 to i = 1
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000002" + // len(array[0]) = 2
|
|
|
+ "0100000000000000000000000000000000000000000000000000000000000000" + // array[0][0]
|
|
|
+ "0200000000000000000000000000000000000000000000000000000000000000" + // array[0][1]
|
|
|
+ "0000000000000000000000000000000000000000000000000000000000000003" + // len(array[1]) = 3
|
|
|
+ "0300000000000000000000000000000000000000000000000000000000000000" + // array[1][0]
|
|
|
+ "0400000000000000000000000000000000000000000000000000000000000000" + // array[1][1]
|
|
|
+ "0500000000000000000000000000000000000000000000000000000000000000"), // array[1][2]
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ "bytes32[3][2]",
|
|
|
+ [][]common.Hash{{{1}, {2}, {3}}, {{3}, {4}, {5}}},
|
|
|
+ common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000" + // array[0][0]
|
|
|
+ "0200000000000000000000000000000000000000000000000000000000000000" + // array[0][1]
|
|
|
+ "0300000000000000000000000000000000000000000000000000000000000000" + // array[0][2]
|
|
|
+ "0300000000000000000000000000000000000000000000000000000000000000" + // array[1][0]
|
|
|
+ "0400000000000000000000000000000000000000000000000000000000000000" + // array[1][1]
|
|
|
+ "0500000000000000000000000000000000000000000000000000000000000000"), // array[1][2]
|
|
|
+ },
|
|
|
} {
|
|
|
typ, err := NewType(test.typ)
|
|
|
if err != nil {
|
|
|
@@ -336,7 +396,7 @@ func TestPack(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
if !bytes.Equal(output, test.output) {
|
|
|
- t.Errorf("%d failed. Expected bytes: '%x' Got: '%x'", i, test.output, output)
|
|
|
+ t.Errorf("input %d for typ: %v failed. Expected bytes: '%x' Got: '%x'", i, typ.String(), test.output, output)
|
|
|
}
|
|
|
}
|
|
|
}
|