diff --git a/accounts/abi/reflect.go b/accounts/abi/reflect.go index bc1c79df77..2ecd729704 100644 --- a/accounts/abi/reflect.go +++ b/accounts/abi/reflect.go @@ -116,7 +116,11 @@ func setSlice(dst, src reflect.Value) error { func setArray(dst, src reflect.Value) error { array := reflect.New(dst.Type()).Elem() - for i := 0; i < min(src.Len(), dst.Len()); i++ { + min := src.Len() + if src.Len() > dst.Len() { + min = dst.Len() + } + for i := 0; i < min; i++ { if err := set(array.Index(i), src.Index(i)); err != nil { return err } @@ -228,10 +232,3 @@ func mapArgNamesToStructFields(argNames []string, value reflect.Value) (map[stri } return abi2struct, nil } - -func min(a, b int) int { - if a < b { - return a - } - return b -} diff --git a/accounts/abi/unpack_test.go b/accounts/abi/unpack_test.go index babe1cb73a..767d1540e6 100644 --- a/accounts/abi/unpack_test.go +++ b/accounts/abi/unpack_test.go @@ -117,12 +117,25 @@ var unpackTests = []unpackTest{ want: int16(0), err: "abi: cannot unmarshal *big.Int in to int16", }, + { + def: `[{"type": "bytes"}]`, + enc: "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200100000000000000000000000000000000000000000000000000000000000000", + want: [32]byte{1}, + }, { def: `[{"type": "bytes32"}]`, enc: "000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200100000000000000000000000000000000000000000000000000000000000000", want: []byte(nil), err: "abi: cannot unmarshal [32]uint8 in to []uint8", }, + { + def: `[{"name":"___","type":"int256"}]`, + enc: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + want: struct { + IntOne *big.Int + Intone *big.Int + }{IntOne: big.NewInt(1)}, + }, { def: `[{"name":"int_one","type":"int256"},{"name":"IntOne","type":"int256"}]`, enc: "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",