From 27defc9d430b99ed074eb449a9eb938beee54ca3 Mon Sep 17 00:00:00 2001 From: RJ Catalano Date: Thu, 22 Jun 2017 14:03:36 -0500 Subject: [PATCH] account/abi: fix up rest of tests to hex Signed-off-by: RJ Catalano --- accounts/abi/pack_test.go | 30 ++++++++++++++--------------- accounts/abi/unpack_test.go | 38 ++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/accounts/abi/pack_test.go b/accounts/abi/pack_test.go index 6789fc16f8..c6cfb56ea0 100644 --- a/accounts/abi/pack_test.go +++ b/accounts/abi/pack_test.go @@ -409,25 +409,25 @@ func TestPackNumber(t *testing.T) { packed []byte }{ // Protocol limits - {reflect.ValueOf(0), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, - {reflect.ValueOf(1), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}}, - {reflect.ValueOf(-1), []byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}}, + {reflect.ValueOf(0), common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000")}, + {reflect.ValueOf(1), common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")}, + {reflect.ValueOf(-1), common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")}, // Type corner cases - {reflect.ValueOf(uint8(math.MaxUint8)), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255}}, - {reflect.ValueOf(uint16(math.MaxUint16)), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255}}, - {reflect.ValueOf(uint32(math.MaxUint32)), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255}}, - {reflect.ValueOf(uint64(math.MaxUint64)), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255}}, + {reflect.ValueOf(uint8(math.MaxUint8)), common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000ff")}, + {reflect.ValueOf(uint16(math.MaxUint16)), common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000ffff")}, + {reflect.ValueOf(uint32(math.MaxUint32)), common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000ffffffff")}, + {reflect.ValueOf(uint64(math.MaxUint64)), common.Hex2Bytes("000000000000000000000000000000000000000000000000ffffffffffffffff")}, - {reflect.ValueOf(int8(math.MaxInt8)), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127}}, - {reflect.ValueOf(int16(math.MaxInt16)), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255}}, - {reflect.ValueOf(int32(math.MaxInt32)), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255}}, - {reflect.ValueOf(int64(math.MaxInt64)), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 255, 255, 255, 255, 255, 255, 255}}, + {reflect.ValueOf(int8(math.MaxInt8)), common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000007f")}, + {reflect.ValueOf(int16(math.MaxInt16)), common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000007fff")}, + {reflect.ValueOf(int32(math.MaxInt32)), common.Hex2Bytes("000000000000000000000000000000000000000000000000000000007fffffff")}, + {reflect.ValueOf(int64(math.MaxInt64)), common.Hex2Bytes("0000000000000000000000000000000000000000000000007fffffffffffffff")}, - {reflect.ValueOf(int8(math.MinInt8)), []byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128}}, - {reflect.ValueOf(int16(math.MinInt16)), []byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 0}}, - {reflect.ValueOf(int32(math.MinInt32)), []byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 0, 0, 0}}, - {reflect.ValueOf(int64(math.MinInt64)), []byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 128, 0, 0, 0, 0, 0, 0, 0}}, + {reflect.ValueOf(int8(math.MinInt8)), common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80")}, + {reflect.ValueOf(int16(math.MinInt16)), common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000")}, + {reflect.ValueOf(int32(math.MinInt32)), common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000")}, + {reflect.ValueOf(int64(math.MinInt64)), common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000")}, } for i, tt := range tests { packed := packNum(tt.value) diff --git a/accounts/abi/unpack_test.go b/accounts/abi/unpack_test.go index 870dc41138..a33754ccc0 100644 --- a/accounts/abi/unpack_test.go +++ b/accounts/abi/unpack_test.go @@ -37,35 +37,35 @@ func TestSimpleMethodUnpack(t *testing.T) { }{ { `[ { "type": "bool" } ]`, - pad([]byte{1}, 32, true), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), bool(true), "bool", "", }, { `[ { "type": "uint32" } ]`, - pad([]byte{1}, 32, true), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), uint32(1), "uint32", "", }, { `[ { "type": "uint32" } ]`, - pad([]byte{1}, 32, true), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), nil, "uint16", "abi: cannot unmarshal uint32 in to uint16", }, { `[ { "type": "uint17" } ]`, - pad([]byte{1}, 32, true), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), nil, "uint16", "abi: cannot unmarshal *big.Int in to uint16", }, { `[ { "type": "uint17" } ]`, - pad([]byte{1}, 32, true), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), big.NewInt(1), "*big.Int", "", @@ -73,28 +73,28 @@ func TestSimpleMethodUnpack(t *testing.T) { { `[ { "type": "int32" } ]`, - pad([]byte{1}, 32, true), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), int32(1), "int32", "", }, { `[ { "type": "int32" } ]`, - pad([]byte{1}, 32, true), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), nil, "int16", "abi: cannot unmarshal int32 in to int16", }, { `[ { "type": "int17" } ]`, - pad([]byte{1}, 32, true), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), nil, "int16", "abi: cannot unmarshal *big.Int in to int16", }, { `[ { "type": "int17" } ]`, - pad([]byte{1}, 32, true), + common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), big.NewInt(1), "*big.Int", "", @@ -102,35 +102,35 @@ func TestSimpleMethodUnpack(t *testing.T) { { `[ { "type": "address" } ]`, - pad(pad([]byte{1}, 20, false), 32, true), + common.Hex2Bytes("0000000000000000000000000100000000000000000000000000000000000000"), common.Address{1}, "address", "", }, { `[ { "type": "bytes32" } ]`, - pad([]byte{1}, 32, false), - pad([]byte{1}, 32, false), + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), "bytes", "", }, { `[ { "type": "bytes32" } ]`, - pad([]byte{1}, 32, false), - pad([]byte{1}, 32, false), + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), "hash", "", }, { `[ { "type": "bytes32" } ]`, - pad([]byte{1}, 32, false), - pad([]byte{1}, 32, false), + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), "interface", "", }, { `[ { "type": "function" } ]`, - pad([]byte{1}, 32, false), + common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"), [24]byte{1}, "function", "", @@ -245,7 +245,7 @@ func TestUnpackSetInterfaceSlice(t *testing.T) { if err != nil { t.Fatal(err) } - marshalledReturn := append(pad([]byte{1}, 32, true), pad([]byte{2}, 32, true)...) + marshalledReturn := append(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")...) err = abi.Unpack(&out, "ints", marshalledReturn) if err != nil { t.Fatal(err) @@ -276,7 +276,7 @@ func TestUnpackSetInterfaceArrayOutput(t *testing.T) { if err != nil { t.Fatal(err) } - marshalledReturn := append(pad([]byte{1}, 32, true), pad([]byte{2}, 32, true)...) + marshalledReturn := append(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"), common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")...) err = abi.Unpack(&out, "ints", marshalledReturn) if err != nil { t.Fatal(err)