From a53d00fdd8bdf9afe0a12604fc2f691e41f6f9eb Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Wed, 21 Jun 2017 18:21:50 -0500 Subject: [PATCH] account/abi: change to hex string tests. Signed-off-by: RJ Catalano --- accounts/abi/pack_test.go | 292 +++++++++++++++++++++++++++++++++++++- 1 file changed, 285 insertions(+), 7 deletions(-) diff --git a/accounts/abi/pack_test.go b/accounts/abi/pack_test.go index b5e44a7e45..6789fc16f8 100644 --- a/accounts/abi/pack_test.go +++ b/accounts/abi/pack_test.go @@ -34,13 +34,291 @@ func TestPack(t *testing.T) { input interface{} output []byte }{ - {"uint16", uint16(2), pad([]byte{2}, 32, true)}, - {"uint16[]", []uint16{1, 2}, formatSliceOutput([]byte{1}, []byte{2})}, - {"bytes20", [20]byte{1}, pad([]byte{1}, 32, false)}, - {"uint256[]", []*big.Int{big.NewInt(1), big.NewInt(2)}, formatSliceOutput([]byte{1}, []byte{2})}, - {"address[]", []common.Address{{1}, {2}}, formatSliceOutput(pad([]byte{1}, 20, false), pad([]byte{2}, 20, false))}, - {"bytes32[]", []common.Hash{{1}, {2}}, formatSliceOutput(pad([]byte{1}, 32, false), pad([]byte{2}, 32, false))}, - {"function", [24]byte{1}, pad([]byte{1}, 32, false)}, + { + "uint8", + uint8(2), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "uint8[]", + []uint8{1, 2}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "uint16", + uint16(2), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "uint16[]", + []uint16{1, 2}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "uint32", + uint32(2), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "uint32[]", + []uint32{1, 2}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "uint64", + uint64(2), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "uint64[]", + []uint64{1, 2}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "uint256", + big.NewInt(2), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "uint256[]", + []*big.Int{big.NewInt(1), big.NewInt(2)}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "int8", + int8(2), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "int8[]", + []int8{1, 2}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "int16", + int16(2), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "int16[]", + []int16{1, 2}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "int32", + int32(2), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "int32[]", + []int32{1, 2}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "int64", + int64(2), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "int64[]", + []int64{1, 2}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "int256", + big.NewInt(2), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "int256[]", + []*big.Int{big.NewInt(1), big.NewInt(2)}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"), + }, + { + "bytes1", + [1]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes2", + [2]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes3", + [3]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes4", + [4]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes5", + [5]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes6", + [6]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes7", + [7]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes8", + [8]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes9", + [9]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes10", + [10]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes11", + [11]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes12", + [12]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes13", + [13]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes14", + [14]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes15", + [15]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes16", + [16]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes17", + [17]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes18", + [18]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes19", + [19]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes20", + [20]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes21", + [21]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes22", + [22]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes23", + [23]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes24", + [24]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes24", + [24]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes25", + [25]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes26", + [26]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes27", + [27]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes28", + [28]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes29", + [29]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes30", + [30]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes31", + [31]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "bytes32", + [32]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "address[]", + []common.Address{{1}, {2}}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000200000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000"), + }, + { + "bytes32[]", + []common.Hash{{1}, {2}}, + common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000201000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000"), + }, + { + "function", + [24]byte{1}, + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + }, + { + "string", + "foobar", + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000006666f6f6261720000000000000000000000000000000000000000000000000000"), + }, } { typ, err := NewType(test.typ) if err != nil {