diff options
author | Hang Su <hang.su@algorand.com> | 2021-10-19 15:39:08 -0400 |
---|---|---|
committer | Hang Su <hang.su@algorand.com> | 2021-10-19 15:39:08 -0400 |
commit | 9cf62a038cbdfb26a747c6f36df499c6d3e521f6 (patch) | |
tree | b21018010cc2ebd9de4a6265891bc46e33932229 | |
parent | d90886ee021c35d6ffaf872c9cce7c7bb0556fe0 (diff) |
resolve jj reviewfeature/abi-encoding
-rw-r--r-- | data/abi/abi_encode.go | 28 | ||||
-rw-r--r-- | data/abi/abi_encode_test.go | 2 |
2 files changed, 14 insertions, 16 deletions
diff --git a/data/abi/abi_encode.go b/data/abi/abi_encode.go index 41f392e3d..fc4790c13 100644 --- a/data/abi/abi_encode.go +++ b/data/abi/abi_encode.go @@ -135,36 +135,36 @@ func (t Type) Encode(value interface{}) ([]byte, error) { // encodeInt encodes int-alike golang values to bytes, following ABI encoding rules func encodeInt(intValue interface{}, bitSize uint16) ([]byte, error) { - var bigInt big.Int + var bigInt *big.Int switch intValue := intValue.(type) { case int8: - bigInt = *new(big.Int).SetInt64(int64(intValue)) + bigInt = big.NewInt(int64(intValue)) case uint8: - bigInt = *new(big.Int).SetUint64(uint64(intValue)) + bigInt = new(big.Int).SetUint64(uint64(intValue)) case int16: - bigInt = *new(big.Int).SetInt64(int64(intValue)) + bigInt = big.NewInt(int64(intValue)) case uint16: - bigInt = *new(big.Int).SetUint64(uint64(intValue)) + bigInt = new(big.Int).SetUint64(uint64(intValue)) case int32: - bigInt = *new(big.Int).SetInt64(int64(intValue)) + bigInt = big.NewInt(int64(intValue)) case uint32: - bigInt = *new(big.Int).SetUint64(uint64(intValue)) + bigInt = new(big.Int).SetUint64(uint64(intValue)) case int64: - bigInt = *new(big.Int).SetInt64(intValue) + bigInt = big.NewInt(intValue) case uint64: - bigInt = *new(big.Int).SetUint64(intValue) + bigInt = new(big.Int).SetUint64(intValue) case uint: - bigInt = *new(big.Int).SetUint64(uint64(intValue)) + bigInt = new(big.Int).SetUint64(uint64(intValue)) case int: - bigInt = *new(big.Int).SetInt64(int64(intValue)) + bigInt = big.NewInt(int64(intValue)) case *big.Int: - bigInt = *new(big.Int).Set(intValue) + bigInt = intValue default: return nil, fmt.Errorf("cannot infer go type for uint encode") } - if bigInt.Cmp(big.NewInt(0)) < 0 { + if bigInt.Sign() < 0 { return nil, fmt.Errorf("passed in numeric value should be non negative") } @@ -348,7 +348,7 @@ func (t Type) Decode(encoded []byte) (interface{}, error) { } else if encoded[0] == 0x80 { return true, nil } - return nil, fmt.Errorf("sinble boolean encoded byte should be of form 0x80 or 0x00") + return nil, fmt.Errorf("single boolean encoded byte should be of form 0x80 or 0x00") case Byte: if len(encoded) != 1 { return nil, fmt.Errorf("byte should be length 1") diff --git a/data/abi/abi_encode_test.go b/data/abi/abi_encode_test.go index 45f977ae3..fc7fbd841 100644 --- a/data/abi/abi_encode_test.go +++ b/data/abi/abi_encode_test.go @@ -469,8 +469,6 @@ func TestDecodeValid(t *testing.T) { uint64(5), uint64(6), uint64(7), uint64(8), } - //expected := []interface{}{1, 2, 3, 4, 5, 6, 7, 8} - //arrayEncoded, err := staticUintArrT.Encode(expected) arrayEncoded, err := staticUintArrT.Encode(inputUint) require.NoError(t, err, "uint64 static array encode should not return error") actual, err := staticUintArrT.Decode(arrayEncoded) |