diff --git a/accounts/abi/abi_test.go b/accounts/abi/abi_test.go index a3aa9446ef..2f687969bc 100644 --- a/accounts/abi/abi_test.go +++ b/accounts/abi/abi_test.go @@ -191,7 +191,7 @@ func TestMethodSignature(t *testing.T) { t.Errorf("expected ids to match %x != %x", m.Id(), idexp) } - uintt, _ := NewType("uint") + uintt, _ := NewType("uint256") m = Method{"foo", false, []Argument{{"bar", uintt, false}}, nil} exp = "foo(uint256)" if m.Sig() != exp { diff --git a/accounts/abi/error.go b/accounts/abi/error.go index 420acf4182..2333b8bfa0 100644 --- a/accounts/abi/error.go +++ b/accounts/abi/error.go @@ -39,22 +39,23 @@ func formatSliceString(kind reflect.Kind, sliceSize int) string { // type in t. func sliceTypeCheck(t Type, val reflect.Value) error { if val.Kind() != reflect.Slice && val.Kind() != reflect.Array { - return typeErr(formatSliceString(t.Kind, t.SliceSize), val.Type()) - } - if t.IsArray && val.Len() != t.SliceSize { - return typeErr(formatSliceString(t.Elem.Kind, t.SliceSize), formatSliceString(val.Type().Elem().Kind(), val.Len())) + return typeErr(formatSliceString(t.Kind, t.Size), val.Type()) } - if t.Elem.IsSlice { + if t.T == ArrayTy && val.Len() != t.Size { + return typeErr(formatSliceString(t.Elem.Kind, t.Size), formatSliceString(val.Type().Elem().Kind(), val.Len())) + } + + if t.Elem.T == SliceTy { if val.Len() > 0 { return sliceTypeCheck(*t.Elem, val.Index(0)) } - } else if t.Elem.IsArray { + } else if t.Elem.T == ArrayTy { return sliceTypeCheck(*t.Elem, val.Index(0)) } if elemKind := val.Type().Elem().Kind(); elemKind != t.Elem.Kind { - return typeErr(formatSliceString(t.Elem.Kind, t.SliceSize), val.Type()) + return typeErr(formatSliceString(t.Elem.Kind, t.Size), val.Type()) } return nil } @@ -62,15 +63,19 @@ func sliceTypeCheck(t Type, val reflect.Value) error { // typeCheck checks that the given reflection value can be assigned to the reflection // type in t. func typeCheck(t Type, value reflect.Value) error { - if t.IsSlice || t.IsArray { + if t.T == SliceTy || t.T == ArrayTy { return sliceTypeCheck(t, value) } // Check base type validity. Element types will be checked later on. if t.Kind != value.Kind() { return typeErr(t.Kind, value.Kind()) + } else if t.T == FixedBytesTy && t.Size != value.Len() { + return typeErr(t.Type, value.Type()) + } else { + return nil } - return nil + } // varErr returns a formatted error. diff --git a/accounts/abi/event_test.go b/accounts/abi/event_test.go index b5054a0329..7e2f13f763 100644 --- a/accounts/abi/event_test.go +++ b/accounts/abi/event_test.go @@ -31,7 +31,7 @@ func TestEventId(t *testing.T) { }{ { definition: `[ - { "type" : "event", "name" : "balance", "inputs": [{ "name" : "in", "type": "uint" }] }, + { "type" : "event", "name" : "balance", "inputs": [{ "name" : "in", "type": "uint256" }] }, { "type" : "event", "name" : "check", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] } ]`, expectations: map[string]common.Hash{ diff --git a/accounts/abi/numbers.go b/accounts/abi/numbers.go index 5d3efff52e..91f2c5d2a4 100644 --- a/accounts/abi/numbers.go +++ b/accounts/abi/numbers.go @@ -25,22 +25,22 @@ import ( ) var ( - big_t = reflect.TypeOf(big.Int{}) - ubig_t = reflect.TypeOf(big.Int{}) - byte_t = reflect.TypeOf(byte(0)) - byte_ts = reflect.TypeOf([]byte(nil)) - uint_t = reflect.TypeOf(uint(0)) - uint8_t = reflect.TypeOf(uint8(0)) - uint16_t = reflect.TypeOf(uint16(0)) - uint32_t = reflect.TypeOf(uint32(0)) - uint64_t = reflect.TypeOf(uint64(0)) - int_t = reflect.TypeOf(int(0)) - int8_t = reflect.TypeOf(int8(0)) - int16_t = reflect.TypeOf(int16(0)) - int32_t = reflect.TypeOf(int32(0)) - int64_t = reflect.TypeOf(int64(0)) - hash_t = reflect.TypeOf(common.Hash{}) - address_t = reflect.TypeOf(common.Address{}) + big_t = reflect.TypeOf(&big.Int{}) + derefbig_t = reflect.TypeOf(big.Int{}) + byte_t = reflect.TypeOf(byte(0)) + byte_ts = reflect.TypeOf([]byte(nil)) + uint_t = reflect.TypeOf(uint(0)) + uint8_t = reflect.TypeOf(uint8(0)) + uint16_t = reflect.TypeOf(uint16(0)) + uint32_t = reflect.TypeOf(uint32(0)) + uint64_t = reflect.TypeOf(uint64(0)) + int_t = reflect.TypeOf(int(0)) + int8_t = reflect.TypeOf(int8(0)) + int16_t = reflect.TypeOf(int16(0)) + int32_t = reflect.TypeOf(int32(0)) + int64_t = reflect.TypeOf(int64(0)) + hash_t = reflect.TypeOf(common.Hash{}) + address_t = reflect.TypeOf(common.Address{}) uint_ts = reflect.TypeOf([]uint(nil)) uint8_ts = reflect.TypeOf([]uint8(nil)) diff --git a/accounts/abi/pack_test.go b/accounts/abi/pack_test.go index c6cfb56ea0..fcb5c75a85 100644 --- a/accounts/abi/pack_test.go +++ b/accounts/abi/pack_test.go @@ -322,12 +322,12 @@ func TestPack(t *testing.T) { } { typ, err := NewType(test.typ) if err != nil { - t.Fatal("unexpected parse error:", err) + t.Fatalf("%v failed. Unexpected parse error: %v", i, err) } output, err := typ.pack(reflect.ValueOf(test.input)) if err != nil { - t.Fatal("unexpected pack error:", err) + t.Fatalf("%v failed. Unexpected pack error: %v", i, err) } if !bytes.Equal(output, test.output) { diff --git a/accounts/abi/reflect.go b/accounts/abi/reflect.go index 8fa75df07f..104d94232d 100644 --- a/accounts/abi/reflect.go +++ b/accounts/abi/reflect.go @@ -24,7 +24,7 @@ import ( // indirect recursively dereferences the value until it either gets the value // or finds a big.Int func indirect(v reflect.Value) reflect.Value { - if v.Kind() == reflect.Ptr && v.Elem().Type() != big_t { + if v.Kind() == reflect.Ptr && v.Elem().Type() != derefbig_t { return indirect(v.Elem()) } return v @@ -78,8 +78,8 @@ func set(dst, src reflect.Value, output Argument) error { case dstType.AssignableTo(src.Type()): dst.Set(src) case dstType.Kind() == reflect.Array && srcType.Kind() == reflect.Slice: - if dst.Len() < output.Type.SliceSize { - return fmt.Errorf("abi: cannot unmarshal src (len=%d) in to dst (len=%d)", output.Type.SliceSize, dst.Len()) + if dst.Len() < output.Type.Size { + return fmt.Errorf("abi: cannot unmarshal src (len=%d) in to dst (len=%d)", output.Type.Size, dst.Len()) } reflect.Copy(dst, src) case dstType.Kind() == reflect.Interface: