mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01:13:45 +00:00
Merge bd9e77f5df into 10181b57a9
This commit is contained in:
commit
1f6a4b76c7
10 changed files with 504 additions and 224 deletions
|
|
@ -191,7 +191,7 @@ func TestMethodSignature(t *testing.T) {
|
||||||
t.Errorf("expected ids to match %x != %x", m.Id(), idexp)
|
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}
|
m = Method{"foo", false, []Argument{{"bar", uintt, false}}, nil}
|
||||||
exp = "foo(uint256)"
|
exp = "foo(uint256)"
|
||||||
if m.Sig() != exp {
|
if m.Sig() != exp {
|
||||||
|
|
|
||||||
|
|
@ -39,22 +39,23 @@ func formatSliceString(kind reflect.Kind, sliceSize int) string {
|
||||||
// type in t.
|
// type in t.
|
||||||
func sliceTypeCheck(t Type, val reflect.Value) error {
|
func sliceTypeCheck(t Type, val reflect.Value) error {
|
||||||
if val.Kind() != reflect.Slice && val.Kind() != reflect.Array {
|
if val.Kind() != reflect.Slice && val.Kind() != reflect.Array {
|
||||||
return typeErr(formatSliceString(t.Kind, t.SliceSize), val.Type())
|
return typeErr(formatSliceString(t.Kind, t.Size), val.Type())
|
||||||
}
|
|
||||||
if t.IsArray && val.Len() != t.SliceSize {
|
|
||||||
return typeErr(formatSliceString(t.Elem.Kind, t.SliceSize), formatSliceString(val.Type().Elem().Kind(), val.Len()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
if val.Len() > 0 {
|
||||||
return sliceTypeCheck(*t.Elem, val.Index(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))
|
return sliceTypeCheck(*t.Elem, val.Index(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
if elemKind := val.Type().Elem().Kind(); elemKind != t.Elem.Kind {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -62,17 +63,21 @@ func sliceTypeCheck(t Type, val reflect.Value) error {
|
||||||
// typeCheck checks that the given reflection value can be assigned to the reflection
|
// typeCheck checks that the given reflection value can be assigned to the reflection
|
||||||
// type in t.
|
// type in t.
|
||||||
func typeCheck(t Type, value reflect.Value) error {
|
func typeCheck(t Type, value reflect.Value) error {
|
||||||
if t.IsSlice || t.IsArray {
|
if t.T == SliceTy || t.T == ArrayTy {
|
||||||
return sliceTypeCheck(t, value)
|
return sliceTypeCheck(t, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check base type validity. Element types will be checked later on.
|
// Check base type validity. Element types will be checked later on.
|
||||||
if t.Kind != value.Kind() {
|
if t.Kind != value.Kind() {
|
||||||
return typeErr(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.
|
// varErr returns a formatted error.
|
||||||
func varErr(expected, got reflect.Kind) error {
|
func varErr(expected, got reflect.Kind) error {
|
||||||
return typeErr(expected, got)
|
return typeErr(expected, got)
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ func TestEventId(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
definition: `[
|
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" }] }
|
{ "type" : "event", "name" : "check", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] }
|
||||||
]`,
|
]`,
|
||||||
expectations: map[string]common.Hash{
|
expectations: map[string]common.Hash{
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
big_t = reflect.TypeOf(big.Int{})
|
big_t = reflect.TypeOf(&big.Int{})
|
||||||
ubig_t = reflect.TypeOf(big.Int{})
|
derefbig_t = reflect.TypeOf(big.Int{})
|
||||||
byte_t = reflect.TypeOf(byte(0))
|
byte_t = reflect.TypeOf(byte(0))
|
||||||
byte_ts = reflect.TypeOf([]byte(nil))
|
byte_ts = reflect.TypeOf([]byte(nil))
|
||||||
uint_t = reflect.TypeOf(uint(0))
|
uint_t = reflect.TypeOf(uint(0))
|
||||||
|
|
|
||||||
|
|
@ -322,12 +322,12 @@ func TestPack(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
typ, err := NewType(test.typ)
|
typ, err := NewType(test.typ)
|
||||||
if err != nil {
|
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))
|
output, err := typ.pack(reflect.ValueOf(test.input))
|
||||||
if err != nil {
|
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) {
|
if !bytes.Equal(output, test.output) {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
// indirect recursively dereferences the value until it either gets the value
|
// indirect recursively dereferences the value until it either gets the value
|
||||||
// or finds a big.Int
|
// or finds a big.Int
|
||||||
func indirect(v reflect.Value) reflect.Value {
|
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 indirect(v.Elem())
|
||||||
}
|
}
|
||||||
return v
|
return v
|
||||||
|
|
@ -78,8 +78,8 @@ func set(dst, src reflect.Value, output Argument) error {
|
||||||
case dstType.AssignableTo(src.Type()):
|
case dstType.AssignableTo(src.Type()):
|
||||||
dst.Set(src)
|
dst.Set(src)
|
||||||
case dstType.Kind() == reflect.Array && srcType.Kind() == reflect.Slice:
|
case dstType.Kind() == reflect.Array && srcType.Kind() == reflect.Slice:
|
||||||
if dst.Len() < output.Type.SliceSize {
|
if dst.Len() < output.Type.Size {
|
||||||
return fmt.Errorf("abi: cannot unmarshal src (len=%d) in to dst (len=%d)", output.Type.SliceSize, dst.Len())
|
return fmt.Errorf("abi: cannot unmarshal src (len=%d) in to dst (len=%d)", output.Type.Size, dst.Len())
|
||||||
}
|
}
|
||||||
reflect.Copy(dst, src)
|
reflect.Copy(dst, src)
|
||||||
case dstType.Kind() == reflect.Interface:
|
case dstType.Kind() == reflect.Interface:
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -29,6 +30,7 @@ const (
|
||||||
BoolTy
|
BoolTy
|
||||||
StringTy
|
StringTy
|
||||||
SliceTy
|
SliceTy
|
||||||
|
ArrayTy
|
||||||
AddressTy
|
AddressTy
|
||||||
FixedBytesTy
|
FixedBytesTy
|
||||||
BytesTy
|
BytesTy
|
||||||
|
|
@ -39,9 +41,6 @@ const (
|
||||||
|
|
||||||
// Type is the reflection of the supported argument type
|
// Type is the reflection of the supported argument type
|
||||||
type Type struct {
|
type Type struct {
|
||||||
IsSlice, IsArray bool
|
|
||||||
SliceSize int
|
|
||||||
|
|
||||||
Elem *Type
|
Elem *Type
|
||||||
|
|
||||||
Kind reflect.Kind
|
Kind reflect.Kind
|
||||||
|
|
@ -53,54 +52,57 @@ type Type struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// fullTypeRegex parses the abi types
|
|
||||||
//
|
|
||||||
// Types can be in the format of:
|
|
||||||
//
|
|
||||||
// Input = Type [ "[" [ Number ] "]" ] Name .
|
|
||||||
// Type = [ "u" ] "int" [ Number ] [ x ] [ Number ].
|
|
||||||
//
|
|
||||||
// Examples:
|
|
||||||
//
|
|
||||||
// string int uint fixed
|
|
||||||
// string32 int8 uint8 uint[]
|
|
||||||
// address int256 uint256 fixed128x128[2]
|
|
||||||
fullTypeRegex = regexp.MustCompile(`([a-zA-Z0-9]+)(\[([0-9]*)\])?`)
|
|
||||||
// typeRegex parses the abi sub types
|
// typeRegex parses the abi sub types
|
||||||
typeRegex = regexp.MustCompile("([a-zA-Z]+)(([0-9]+)(x([0-9]+))?)?")
|
typeRegex = regexp.MustCompile("([a-zA-Z]+)(([0-9]+)(x([0-9]+))?)?")
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewType creates a new reflection type of abi type given in t.
|
// NewType creates a new reflection type of abi type given in t.
|
||||||
func NewType(t string) (typ Type, err error) {
|
func NewType(t string) (typ Type, err error) {
|
||||||
res := fullTypeRegex.FindAllStringSubmatch(t, -1)[0]
|
// check that array brackets are equal if they exist
|
||||||
// check if type is slice and parse type.
|
if strings.Count(t, "[") != strings.Count(t, "]") {
|
||||||
switch {
|
return Type{}, fmt.Errorf("invalid arg type in abi")
|
||||||
case res[3] != "":
|
|
||||||
// err is ignored. Already checked for number through the regexp
|
|
||||||
typ.SliceSize, _ = strconv.Atoi(res[3])
|
|
||||||
typ.IsArray = true
|
|
||||||
case res[2] != "":
|
|
||||||
typ.IsSlice, typ.SliceSize = true, -1
|
|
||||||
case res[0] == "":
|
|
||||||
return Type{}, fmt.Errorf("abi: type parse error: %s", t)
|
|
||||||
}
|
}
|
||||||
if typ.IsArray || typ.IsSlice {
|
|
||||||
sliceType, err := NewType(res[1])
|
typ.stringKind = t
|
||||||
|
|
||||||
|
// if there are brackets, get ready to go into slice/array mode and
|
||||||
|
// recursively create the type
|
||||||
|
if strings.Count(t, "[") != 0 {
|
||||||
|
i := strings.LastIndex(t, "[")
|
||||||
|
// recursively embed the type
|
||||||
|
embeddedType, err := NewType(t[:i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Type{}, err
|
return Type{}, err
|
||||||
}
|
}
|
||||||
typ.Elem = &sliceType
|
// grab the last cell and create a type from there
|
||||||
typ.stringKind = sliceType.stringKind + t[len(res[1]):]
|
sliced := t[i:]
|
||||||
// Although we know that this is an array, we cannot return
|
// grab the slice size with regexp
|
||||||
// as we don't know the type of the element, however, if it
|
re := regexp.MustCompile("[0-9]+")
|
||||||
// is still an array, then don't determine the type.
|
intz := re.FindAllString(sliced, -1)
|
||||||
if typ.Elem.IsArray || typ.Elem.IsSlice {
|
|
||||||
return typ, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if len(intz) == 0 {
|
||||||
|
// is a slice
|
||||||
|
typ.T = SliceTy
|
||||||
|
typ.Kind = reflect.Slice
|
||||||
|
typ.Elem = &embeddedType
|
||||||
|
typ.Type = reflect.SliceOf(embeddedType.Type)
|
||||||
|
} else if len(intz) == 1 {
|
||||||
|
// is a array
|
||||||
|
typ.T = ArrayTy
|
||||||
|
typ.Kind = reflect.Array
|
||||||
|
typ.Elem = &embeddedType
|
||||||
|
typ.Size, err = strconv.Atoi(intz[0])
|
||||||
|
if err != nil {
|
||||||
|
return Type{}, fmt.Errorf("abi: error parsing variable size: %v", err)
|
||||||
|
}
|
||||||
|
typ.Type = reflect.ArrayOf(typ.Size, embeddedType.Type)
|
||||||
|
} else {
|
||||||
|
return Type{}, fmt.Errorf("invalid formatting of array type")
|
||||||
|
}
|
||||||
|
return typ, err
|
||||||
|
} else {
|
||||||
// parse the type and size of the abi-type.
|
// parse the type and size of the abi-type.
|
||||||
parsedType := typeRegex.FindAllStringSubmatch(res[1], -1)[0]
|
parsedType := typeRegex.FindAllStringSubmatch(t, -1)[0]
|
||||||
// varSize is the size of the variable
|
// varSize is the size of the variable
|
||||||
var varSize int
|
var varSize int
|
||||||
if len(parsedType[3]) > 0 {
|
if len(parsedType[3]) > 0 {
|
||||||
|
|
@ -109,20 +111,15 @@ func NewType(t string) (typ Type, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Type{}, fmt.Errorf("abi: error parsing variable size: %v", err)
|
return Type{}, fmt.Errorf("abi: error parsing variable size: %v", err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if parsedType[0] == "uint" || parsedType[0] == "int" {
|
||||||
|
// this should fail because it means that there's something wrong with
|
||||||
|
// the abi type (the compiler should always format it to the size...always)
|
||||||
|
return Type{}, fmt.Errorf("unsupported arg type: %s", t)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// varType is the parsed abi type
|
// varType is the parsed abi type
|
||||||
varType := parsedType[1]
|
varType := parsedType[1]
|
||||||
// substitute canonical integer
|
|
||||||
if varSize == 0 && (varType == "int" || varType == "uint") {
|
|
||||||
varSize = 256
|
|
||||||
t += "256"
|
|
||||||
}
|
|
||||||
|
|
||||||
// only set stringKind if not array or slice, as for those,
|
|
||||||
// the correct string type has been set
|
|
||||||
if !(typ.IsArray || typ.IsSlice) {
|
|
||||||
typ.stringKind = t
|
|
||||||
}
|
|
||||||
|
|
||||||
switch varType {
|
switch varType {
|
||||||
case "int":
|
case "int":
|
||||||
|
|
@ -136,6 +133,7 @@ func NewType(t string) (typ Type, err error) {
|
||||||
case "bool":
|
case "bool":
|
||||||
typ.Kind = reflect.Bool
|
typ.Kind = reflect.Bool
|
||||||
typ.T = BoolTy
|
typ.T = BoolTy
|
||||||
|
typ.Type = reflect.TypeOf(bool(false))
|
||||||
case "address":
|
case "address":
|
||||||
typ.Kind = reflect.Array
|
typ.Kind = reflect.Array
|
||||||
typ.Type = address_t
|
typ.Type = address_t
|
||||||
|
|
@ -143,29 +141,28 @@ func NewType(t string) (typ Type, err error) {
|
||||||
typ.T = AddressTy
|
typ.T = AddressTy
|
||||||
case "string":
|
case "string":
|
||||||
typ.Kind = reflect.String
|
typ.Kind = reflect.String
|
||||||
typ.Size = -1
|
typ.Type = reflect.TypeOf("")
|
||||||
typ.T = StringTy
|
typ.T = StringTy
|
||||||
case "bytes":
|
case "bytes":
|
||||||
sliceType, _ := NewType("uint8")
|
|
||||||
typ.Elem = &sliceType
|
|
||||||
if varSize == 0 {
|
if varSize == 0 {
|
||||||
typ.IsSlice = true
|
|
||||||
typ.T = BytesTy
|
typ.T = BytesTy
|
||||||
typ.SliceSize = -1
|
typ.Kind = reflect.Slice
|
||||||
|
typ.Type = reflect.SliceOf(reflect.TypeOf(byte(0)))
|
||||||
} else {
|
} else {
|
||||||
typ.IsArray = true
|
|
||||||
typ.T = FixedBytesTy
|
typ.T = FixedBytesTy
|
||||||
typ.SliceSize = varSize
|
typ.Kind = reflect.Array
|
||||||
|
typ.Size = varSize
|
||||||
|
typ.Type = reflect.ArrayOf(varSize, reflect.TypeOf(byte(0)))
|
||||||
}
|
}
|
||||||
case "function":
|
case "function":
|
||||||
sliceType, _ := NewType("uint8")
|
typ.Kind = reflect.Array
|
||||||
typ.Elem = &sliceType
|
|
||||||
typ.IsArray = true
|
|
||||||
typ.T = FunctionTy
|
typ.T = FunctionTy
|
||||||
typ.SliceSize = 24
|
typ.Size = 24
|
||||||
|
typ.Type = reflect.ArrayOf(24, reflect.TypeOf(byte(0)))
|
||||||
default:
|
default:
|
||||||
return Type{}, fmt.Errorf("unsupported arg type: %s", t)
|
return Type{}, fmt.Errorf("unsupported arg type: %s", t)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +180,7 @@ func (t Type) pack(v reflect.Value) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.IsSlice || t.IsArray) && t.T != BytesTy && t.T != FixedBytesTy && t.T != FunctionTy {
|
if t.T == SliceTy || t.T == ArrayTy {
|
||||||
var packed []byte
|
var packed []byte
|
||||||
|
|
||||||
for i := 0; i < v.Len(); i++ {
|
for i := 0; i < v.Len(); i++ {
|
||||||
|
|
@ -193,18 +190,17 @@ func (t Type) pack(v reflect.Value) ([]byte, error) {
|
||||||
}
|
}
|
||||||
packed = append(packed, val...)
|
packed = append(packed, val...)
|
||||||
}
|
}
|
||||||
if t.IsSlice {
|
if t.T == SliceTy {
|
||||||
return packBytesSlice(packed, v.Len()), nil
|
return packBytesSlice(packed, v.Len()), nil
|
||||||
} else if t.IsArray {
|
} else if t.T == ArrayTy {
|
||||||
return packed, nil
|
return packed, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return packElement(t, v), nil
|
return packElement(t, v), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// requireLengthPrefix returns whether the type requires any sort of length
|
// requireLengthPrefix returns whether the type requires any sort of length
|
||||||
// prefixing.
|
// prefixing.
|
||||||
func (t Type) requiresLengthPrefix() bool {
|
func (t Type) requiresLengthPrefix() bool {
|
||||||
return t.T != FixedBytesTy && (t.T == StringTy || t.T == BytesTy || t.IsSlice)
|
return t.T == StringTy || t.T == BytesTy || t.T == SliceTy
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,50 +34,58 @@ func TestTypeRegexp(t *testing.T) {
|
||||||
blob string
|
blob string
|
||||||
kind Type
|
kind Type
|
||||||
}{
|
}{
|
||||||
{"bool", Type{Kind: reflect.Bool, T: BoolTy, stringKind: "bool"}},
|
{"bool", Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}},
|
||||||
{"bool[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Bool, T: BoolTy, Elem: &Type{Kind: reflect.Bool, T: BoolTy, stringKind: "bool"}, stringKind: "bool[]"}},
|
{"bool[]", Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]bool(nil)), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[]"}},
|
||||||
{"bool[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Bool, T: BoolTy, Elem: &Type{Kind: reflect.Bool, T: BoolTy, stringKind: "bool"}, stringKind: "bool[2]"}},
|
{"bool[2]", Type{Size: 2, Kind: reflect.Array, T: ArrayTy, Type: reflect.TypeOf([2]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[2]"}},
|
||||||
|
{"bool[2][]", Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([][2]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[2]"}, stringKind: "bool[2][]"}},
|
||||||
|
{"bool[][]", Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([][]bool{}), Elem: &Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[]"}, stringKind: "bool[][]"}},
|
||||||
|
{"bool[][2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][]bool{}), Elem: &Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[]"}, stringKind: "bool[][2]"}},
|
||||||
|
{"bool[2][2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][2]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[2]"}, stringKind: "bool[2][2]"}},
|
||||||
|
{"bool[2][][2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][][2]bool{}), Elem: &Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([][2]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[2]"}, stringKind: "bool[2][]"}, stringKind: "bool[2][][2]"}},
|
||||||
|
{"bool[2][2][2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][2][2]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][2]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[2]"}, stringKind: "bool[2][2]"}, stringKind: "bool[2][2][2]"}},
|
||||||
|
{"bool[][][]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([][][]bool{}), Elem: &Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([][]bool{}), Elem: &Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[]"}, stringKind: "bool[][]"}, stringKind: "bool[][][]"}},
|
||||||
|
{"bool[][2][]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([][2][]bool{}), Elem: &Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][]bool{}), Elem: &Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]bool{}), Elem: &Type{Kind: reflect.Bool, T: BoolTy, Type: reflect.TypeOf(bool(false)), stringKind: "bool"}, stringKind: "bool[]"}, stringKind: "bool[][2]"}, stringKind: "bool[][2][]"}},
|
||||||
{"int8", Type{Kind: reflect.Int8, Type: int8_t, Size: 8, T: IntTy, stringKind: "int8"}},
|
{"int8", Type{Kind: reflect.Int8, Type: int8_t, Size: 8, T: IntTy, stringKind: "int8"}},
|
||||||
{"int16", Type{Kind: reflect.Int16, Type: int16_t, Size: 16, T: IntTy, stringKind: "int16"}},
|
{"int16", Type{Kind: reflect.Int16, Type: int16_t, Size: 16, T: IntTy, stringKind: "int16"}},
|
||||||
{"int32", Type{Kind: reflect.Int32, Type: int32_t, Size: 32, T: IntTy, stringKind: "int32"}},
|
{"int32", Type{Kind: reflect.Int32, Type: int32_t, Size: 32, T: IntTy, stringKind: "int32"}},
|
||||||
{"int64", Type{Kind: reflect.Int64, Type: int64_t, Size: 64, T: IntTy, stringKind: "int64"}},
|
{"int64", Type{Kind: reflect.Int64, Type: int64_t, Size: 64, T: IntTy, stringKind: "int64"}},
|
||||||
{"int256", Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: IntTy, stringKind: "int256"}},
|
{"int256", Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: IntTy, stringKind: "int256"}},
|
||||||
{"int8[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Int8, Type: int8_t, Size: 8, T: IntTy, Elem: &Type{Kind: reflect.Int8, Type: int8_t, Size: 8, T: IntTy, stringKind: "int8"}, stringKind: "int8[]"}},
|
{"int8[]", Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]int8{}), Elem: &Type{Kind: reflect.Int8, Type: int8_t, Size: 8, T: IntTy, stringKind: "int8"}, stringKind: "int8[]"}},
|
||||||
{"int8[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Int8, Type: int8_t, Size: 8, T: IntTy, Elem: &Type{Kind: reflect.Int8, Type: int8_t, Size: 8, T: IntTy, stringKind: "int8"}, stringKind: "int8[2]"}},
|
{"int8[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]int8{}), Elem: &Type{Kind: reflect.Int8, Type: int8_t, Size: 8, T: IntTy, stringKind: "int8"}, stringKind: "int8[2]"}},
|
||||||
{"int16[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Int16, Type: int16_t, Size: 16, T: IntTy, Elem: &Type{Kind: reflect.Int16, Type: int16_t, Size: 16, T: IntTy, stringKind: "int16"}, stringKind: "int16[]"}},
|
{"int16[]", Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]int16{}), Elem: &Type{Kind: reflect.Int16, Type: int16_t, Size: 16, T: IntTy, stringKind: "int16"}, stringKind: "int16[]"}},
|
||||||
{"int16[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Int16, Type: int16_t, Size: 16, T: IntTy, Elem: &Type{Kind: reflect.Int16, Type: int16_t, Size: 16, T: IntTy, stringKind: "int16"}, stringKind: "int16[2]"}},
|
{"int16[2]", Type{Size: 2, Kind: reflect.Array, T: ArrayTy, Type: reflect.TypeOf([2]int16{}), Elem: &Type{Kind: reflect.Int16, Type: int16_t, Size: 16, T: IntTy, stringKind: "int16"}, stringKind: "int16[2]"}},
|
||||||
{"int32[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Int32, Type: int32_t, Size: 32, T: IntTy, Elem: &Type{Kind: reflect.Int32, Type: int32_t, Size: 32, T: IntTy, stringKind: "int32"}, stringKind: "int32[]"}},
|
{"int32[]", Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]int32{}), Elem: &Type{Kind: reflect.Int32, Type: int32_t, Size: 32, T: IntTy, stringKind: "int32"}, stringKind: "int32[]"}},
|
||||||
{"int32[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Int32, Type: int32_t, Size: 32, T: IntTy, Elem: &Type{Kind: reflect.Int32, Type: int32_t, Size: 32, T: IntTy, stringKind: "int32"}, stringKind: "int32[2]"}},
|
{"int32[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]int32{}), Elem: &Type{Kind: reflect.Int32, Type: int32_t, Size: 32, T: IntTy, stringKind: "int32"}, stringKind: "int32[2]"}},
|
||||||
{"int64[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Int64, Type: int64_t, Size: 64, T: IntTy, Elem: &Type{Kind: reflect.Int64, Type: int64_t, Size: 64, T: IntTy, stringKind: "int64"}, stringKind: "int64[]"}},
|
{"int64[]", Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]int64{}), Elem: &Type{Kind: reflect.Int64, Type: int64_t, Size: 64, T: IntTy, stringKind: "int64"}, stringKind: "int64[]"}},
|
||||||
{"int64[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Int64, Type: int64_t, Size: 64, T: IntTy, Elem: &Type{Kind: reflect.Int64, Type: int64_t, Size: 64, T: IntTy, stringKind: "int64"}, stringKind: "int64[2]"}},
|
{"int64[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]int64{}), Elem: &Type{Kind: reflect.Int64, Type: int64_t, Size: 64, T: IntTy, stringKind: "int64"}, stringKind: "int64[2]"}},
|
||||||
{"int256[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Ptr, Type: big_t, Size: 256, T: IntTy, Elem: &Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: IntTy, stringKind: "int256"}, stringKind: "int256[]"}},
|
{"int256[]", Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]*big.Int{}), Elem: &Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: IntTy, stringKind: "int256"}, stringKind: "int256[]"}},
|
||||||
{"int256[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Ptr, Type: big_t, Size: 256, T: IntTy, Elem: &Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: IntTy, stringKind: "int256"}, stringKind: "int256[2]"}},
|
{"int256[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]*big.Int{}), Elem: &Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: IntTy, stringKind: "int256"}, stringKind: "int256[2]"}},
|
||||||
{"uint8", Type{Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, stringKind: "uint8"}},
|
{"uint8", Type{Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, stringKind: "uint8"}},
|
||||||
{"uint16", Type{Kind: reflect.Uint16, Type: uint16_t, Size: 16, T: UintTy, stringKind: "uint16"}},
|
{"uint16", Type{Kind: reflect.Uint16, Type: uint16_t, Size: 16, T: UintTy, stringKind: "uint16"}},
|
||||||
{"uint32", Type{Kind: reflect.Uint32, Type: uint32_t, Size: 32, T: UintTy, stringKind: "uint32"}},
|
{"uint32", Type{Kind: reflect.Uint32, Type: uint32_t, Size: 32, T: UintTy, stringKind: "uint32"}},
|
||||||
{"uint64", Type{Kind: reflect.Uint64, Type: uint64_t, Size: 64, T: UintTy, stringKind: "uint64"}},
|
{"uint64", Type{Kind: reflect.Uint64, Type: uint64_t, Size: 64, T: UintTy, stringKind: "uint64"}},
|
||||||
{"uint256", Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: UintTy, stringKind: "uint256"}},
|
{"uint256", Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: UintTy, stringKind: "uint256"}},
|
||||||
{"uint8[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, Elem: &Type{Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, stringKind: "uint8"}, stringKind: "uint8[]"}},
|
{"uint8[]", Type{Kind: reflect.Slice, T: SliceTy, Type: reflect.TypeOf([]uint8{}), Elem: &Type{Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, stringKind: "uint8"}, stringKind: "uint8[]"}},
|
||||||
{"uint8[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, Elem: &Type{Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, stringKind: "uint8"}, stringKind: "uint8[2]"}},
|
{"uint8[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]uint8{}), Elem: &Type{Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, stringKind: "uint8"}, stringKind: "uint8[2]"}},
|
||||||
{"uint16[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Uint16, Type: uint16_t, Size: 16, T: UintTy, Elem: &Type{Kind: reflect.Uint16, Type: uint16_t, Size: 16, T: UintTy, stringKind: "uint16"}, stringKind: "uint16[]"}},
|
{"uint16[]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]uint16{}), Elem: &Type{Kind: reflect.Uint16, Type: uint16_t, Size: 16, T: UintTy, stringKind: "uint16"}, stringKind: "uint16[]"}},
|
||||||
{"uint16[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Uint16, Type: uint16_t, Size: 16, T: UintTy, Elem: &Type{Kind: reflect.Uint16, Type: uint16_t, Size: 16, T: UintTy, stringKind: "uint16"}, stringKind: "uint16[2]"}},
|
{"uint16[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]uint16{}), Elem: &Type{Kind: reflect.Uint16, Type: uint16_t, Size: 16, T: UintTy, stringKind: "uint16"}, stringKind: "uint16[2]"}},
|
||||||
{"uint32[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Uint32, Type: uint32_t, Size: 32, T: UintTy, Elem: &Type{Kind: reflect.Uint32, Type: uint32_t, Size: 32, T: UintTy, stringKind: "uint32"}, stringKind: "uint32[]"}},
|
{"uint32[]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]uint32{}), Elem: &Type{Kind: reflect.Uint32, Type: uint32_t, Size: 32, T: UintTy, stringKind: "uint32"}, stringKind: "uint32[]"}},
|
||||||
{"uint32[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Uint32, Type: uint32_t, Size: 32, T: UintTy, Elem: &Type{Kind: reflect.Uint32, Type: uint32_t, Size: 32, T: UintTy, stringKind: "uint32"}, stringKind: "uint32[2]"}},
|
{"uint32[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]uint32{}), Elem: &Type{Kind: reflect.Uint32, Type: uint32_t, Size: 32, T: UintTy, stringKind: "uint32"}, stringKind: "uint32[2]"}},
|
||||||
{"uint64[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Uint64, Type: uint64_t, Size: 64, T: UintTy, Elem: &Type{Kind: reflect.Uint64, Type: uint64_t, Size: 64, T: UintTy, stringKind: "uint64"}, stringKind: "uint64[]"}},
|
{"uint64[]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]uint64{}), Elem: &Type{Kind: reflect.Uint64, Type: uint64_t, Size: 64, T: UintTy, stringKind: "uint64"}, stringKind: "uint64[]"}},
|
||||||
{"uint64[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Uint64, Type: uint64_t, Size: 64, T: UintTy, Elem: &Type{Kind: reflect.Uint64, Type: uint64_t, Size: 64, T: UintTy, stringKind: "uint64"}, stringKind: "uint64[2]"}},
|
{"uint64[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]uint64{}), Elem: &Type{Kind: reflect.Uint64, Type: uint64_t, Size: 64, T: UintTy, stringKind: "uint64"}, stringKind: "uint64[2]"}},
|
||||||
{"uint256[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Ptr, Type: big_t, Size: 256, T: UintTy, Elem: &Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: UintTy, stringKind: "uint256"}, stringKind: "uint256[]"}},
|
{"uint256[]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]*big.Int{}), Elem: &Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: UintTy, stringKind: "uint256"}, stringKind: "uint256[]"}},
|
||||||
{"uint256[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Ptr, Type: big_t, Size: 256, T: UintTy, Elem: &Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: UintTy, stringKind: "uint256"}, stringKind: "uint256[2]"}},
|
{"uint256[2]", Type{Kind: reflect.Array, T: ArrayTy, Type: reflect.TypeOf([2]*big.Int{}), Size: 2, Elem: &Type{Kind: reflect.Ptr, Type: big_t, Size: 256, T: UintTy, stringKind: "uint256"}, stringKind: "uint256[2]"}},
|
||||||
{"bytes32", Type{IsArray: true, SliceSize: 32, Elem: &Type{Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, stringKind: "uint8"}, T: FixedBytesTy, stringKind: "bytes32"}},
|
{"bytes32", Type{Kind: reflect.Array, T: FixedBytesTy, Size: 32, Type: reflect.TypeOf([32]byte{}), stringKind: "bytes32"}},
|
||||||
{"bytes[]", Type{IsSlice: true, SliceSize: -1, Elem: &Type{IsSlice: true, SliceSize: -1, Elem: &Type{Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, stringKind: "uint8"}, T: BytesTy, stringKind: "bytes"}, stringKind: "bytes[]"}},
|
{"bytes[]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([][]byte{}), Elem: &Type{Kind: reflect.Slice, Type: reflect.TypeOf([]byte{}), T: BytesTy, stringKind: "bytes"}, stringKind: "bytes[]"}},
|
||||||
{"bytes[2]", Type{IsArray: true, SliceSize: 2, Elem: &Type{IsSlice: true, SliceSize: -1, Elem: &Type{Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, stringKind: "uint8"}, T: BytesTy, stringKind: "bytes"}, stringKind: "bytes[2]"}},
|
{"bytes[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][]byte{}), Elem: &Type{T: BytesTy, Type: reflect.TypeOf([]byte{}), Kind: reflect.Slice, stringKind: "bytes"}, stringKind: "bytes[2]"}},
|
||||||
{"bytes32[]", Type{IsSlice: true, SliceSize: -1, Elem: &Type{IsArray: true, SliceSize: 32, Elem: &Type{Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, stringKind: "uint8"}, T: FixedBytesTy, stringKind: "bytes32"}, stringKind: "bytes32[]"}},
|
{"bytes32[]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([][32]byte{}), Elem: &Type{Kind: reflect.Array, Type: reflect.TypeOf([32]byte{}), T: FixedBytesTy, Size: 32, stringKind: "bytes32"}, stringKind: "bytes32[]"}},
|
||||||
{"bytes32[2]", Type{IsArray: true, SliceSize: 2, Elem: &Type{IsArray: true, SliceSize: 32, Elem: &Type{Kind: reflect.Uint8, Type: uint8_t, Size: 8, T: UintTy, stringKind: "uint8"}, T: FixedBytesTy, stringKind: "bytes32"}, stringKind: "bytes32[2]"}},
|
{"bytes32[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2][32]byte{}), Elem: &Type{Kind: reflect.Array, T: FixedBytesTy, Size: 32, Type: reflect.TypeOf([32]byte{}), stringKind: "bytes32"}, stringKind: "bytes32[2]"}},
|
||||||
{"string", Type{Kind: reflect.String, Size: -1, T: StringTy, stringKind: "string"}},
|
{"string", Type{Kind: reflect.String, T: StringTy, Type: reflect.TypeOf(""), stringKind: "string"}},
|
||||||
{"string[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.String, T: StringTy, Size: -1, Elem: &Type{Kind: reflect.String, T: StringTy, Size: -1, stringKind: "string"}, stringKind: "string[]"}},
|
{"string[]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]string{}), Elem: &Type{Kind: reflect.String, Type: reflect.TypeOf(""), T: StringTy, stringKind: "string"}, stringKind: "string[]"}},
|
||||||
{"string[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.String, T: StringTy, Size: -1, Elem: &Type{Kind: reflect.String, T: StringTy, Size: -1, stringKind: "string"}, stringKind: "string[2]"}},
|
{"string[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]string{}), Elem: &Type{Kind: reflect.String, T: StringTy, Type: reflect.TypeOf(""), stringKind: "string"}, stringKind: "string[2]"}},
|
||||||
{"address", Type{Kind: reflect.Array, Type: address_t, Size: 20, T: AddressTy, stringKind: "address"}},
|
{"address", Type{Kind: reflect.Array, Type: address_t, Size: 20, T: AddressTy, stringKind: "address"}},
|
||||||
{"address[]", Type{IsSlice: true, SliceSize: -1, Kind: reflect.Array, Type: address_t, T: AddressTy, Size: 20, Elem: &Type{Kind: reflect.Array, Type: address_t, Size: 20, T: AddressTy, stringKind: "address"}, stringKind: "address[]"}},
|
{"address[]", Type{T: SliceTy, Kind: reflect.Slice, Type: reflect.TypeOf([]common.Address{}), Elem: &Type{Kind: reflect.Array, Type: address_t, Size: 20, T: AddressTy, stringKind: "address"}, stringKind: "address[]"}},
|
||||||
{"address[2]", Type{IsArray: true, SliceSize: 2, Kind: reflect.Array, Type: address_t, T: AddressTy, Size: 20, Elem: &Type{Kind: reflect.Array, Type: address_t, Size: 20, T: AddressTy, stringKind: "address"}, stringKind: "address[2]"}},
|
{"address[2]", Type{Kind: reflect.Array, T: ArrayTy, Size: 2, Type: reflect.TypeOf([2]common.Address{}), Elem: &Type{Kind: reflect.Array, Type: address_t, Size: 20, T: AddressTy, stringKind: "address"}, stringKind: "address[2]"}},
|
||||||
|
|
||||||
// TODO when fixed types are implemented properly
|
// TODO when fixed types are implemented properly
|
||||||
// {"fixed", Type{}},
|
// {"fixed", Type{}},
|
||||||
|
|
@ -93,7 +101,7 @@ func TestTypeRegexp(t *testing.T) {
|
||||||
t.Errorf("type %d: failed to parse type string: %v", i, err)
|
t.Errorf("type %d: failed to parse type string: %v", i, err)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(typ, tt.kind) {
|
if !reflect.DeepEqual(typ, tt.kind) {
|
||||||
t.Errorf("type %d: parsed type mismatch:\n have %+v\n want %+v", i, typeWithoutStringer(typ), typeWithoutStringer(tt.kind))
|
t.Errorf("type %d: parsed type mismatch:\n have %+v\n want %+v.\n more details:\n have %v\n want %v\n have %v\n want %v\n ", i, typeWithoutStringer(typ), typeWithoutStringer(tt.kind), typeWithoutStringer(*typ.Elem), typeWithoutStringer(*tt.kind.Elem))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -104,15 +112,90 @@ func TestTypeCheck(t *testing.T) {
|
||||||
input interface{}
|
input interface{}
|
||||||
err string
|
err string
|
||||||
}{
|
}{
|
||||||
{"uint", big.NewInt(1), ""},
|
{"uint", big.NewInt(1), "unsupported arg type: uint"},
|
||||||
{"int", big.NewInt(1), ""},
|
{"int", big.NewInt(1), "unsupported arg type: int"},
|
||||||
{"uint30", big.NewInt(1), ""},
|
{"uint256", big.NewInt(1), ""},
|
||||||
|
{"uint256[][3][]", [][3][]*big.Int{{{}}}, ""},
|
||||||
|
{"uint256[][][3]", [3][][]*big.Int{{{}}}, ""},
|
||||||
|
{"uint256[3][][]", [][][3]*big.Int{{{}}}, ""},
|
||||||
|
{"uint256[3][3][3]", [3][3][3]*big.Int{{{}}}, ""},
|
||||||
|
{"uint8[][]", [][]uint8{}, ""},
|
||||||
|
{"int256", big.NewInt(1), ""},
|
||||||
|
{"uint8", uint8(1), ""},
|
||||||
|
{"uint16", uint16(1), ""},
|
||||||
|
{"uint32", uint32(1), ""},
|
||||||
|
{"uint64", uint64(1), ""},
|
||||||
|
{"int8", int8(1), ""},
|
||||||
|
{"int16", int16(1), ""},
|
||||||
|
{"int32", int32(1), ""},
|
||||||
|
{"int64", int64(1), ""},
|
||||||
|
{"uint24", big.NewInt(1), ""},
|
||||||
|
{"uint40", big.NewInt(1), ""},
|
||||||
|
{"uint48", big.NewInt(1), ""},
|
||||||
|
{"uint56", big.NewInt(1), ""},
|
||||||
|
{"uint72", big.NewInt(1), ""},
|
||||||
|
{"uint80", big.NewInt(1), ""},
|
||||||
|
{"uint88", big.NewInt(1), ""},
|
||||||
|
{"uint96", big.NewInt(1), ""},
|
||||||
|
{"uint104", big.NewInt(1), ""},
|
||||||
|
{"uint112", big.NewInt(1), ""},
|
||||||
|
{"uint120", big.NewInt(1), ""},
|
||||||
|
{"uint128", big.NewInt(1), ""},
|
||||||
|
{"uint136", big.NewInt(1), ""},
|
||||||
|
{"uint144", big.NewInt(1), ""},
|
||||||
|
{"uint152", big.NewInt(1), ""},
|
||||||
|
{"uint160", big.NewInt(1), ""},
|
||||||
|
{"uint168", big.NewInt(1), ""},
|
||||||
|
{"uint176", big.NewInt(1), ""},
|
||||||
|
{"uint184", big.NewInt(1), ""},
|
||||||
|
{"uint192", big.NewInt(1), ""},
|
||||||
|
{"uint200", big.NewInt(1), ""},
|
||||||
|
{"uint208", big.NewInt(1), ""},
|
||||||
|
{"uint216", big.NewInt(1), ""},
|
||||||
|
{"uint224", big.NewInt(1), ""},
|
||||||
|
{"uint232", big.NewInt(1), ""},
|
||||||
|
{"uint240", big.NewInt(1), ""},
|
||||||
|
{"uint248", big.NewInt(1), ""},
|
||||||
|
{"int24", big.NewInt(1), ""},
|
||||||
|
{"int40", big.NewInt(1), ""},
|
||||||
|
{"int48", big.NewInt(1), ""},
|
||||||
|
{"int56", big.NewInt(1), ""},
|
||||||
|
{"int72", big.NewInt(1), ""},
|
||||||
|
{"int80", big.NewInt(1), ""},
|
||||||
|
{"int88", big.NewInt(1), ""},
|
||||||
|
{"int96", big.NewInt(1), ""},
|
||||||
|
{"int104", big.NewInt(1), ""},
|
||||||
|
{"int112", big.NewInt(1), ""},
|
||||||
|
{"int120", big.NewInt(1), ""},
|
||||||
|
{"int128", big.NewInt(1), ""},
|
||||||
|
{"int136", big.NewInt(1), ""},
|
||||||
|
{"int144", big.NewInt(1), ""},
|
||||||
|
{"int152", big.NewInt(1), ""},
|
||||||
|
{"int160", big.NewInt(1), ""},
|
||||||
|
{"int168", big.NewInt(1), ""},
|
||||||
|
{"int176", big.NewInt(1), ""},
|
||||||
|
{"int184", big.NewInt(1), ""},
|
||||||
|
{"int192", big.NewInt(1), ""},
|
||||||
|
{"int200", big.NewInt(1), ""},
|
||||||
|
{"int208", big.NewInt(1), ""},
|
||||||
|
{"int216", big.NewInt(1), ""},
|
||||||
|
{"int224", big.NewInt(1), ""},
|
||||||
|
{"int232", big.NewInt(1), ""},
|
||||||
|
{"int240", big.NewInt(1), ""},
|
||||||
|
{"int248", big.NewInt(1), ""},
|
||||||
{"uint30", uint8(1), "abi: cannot use uint8 as type ptr as argument"},
|
{"uint30", uint8(1), "abi: cannot use uint8 as type ptr as argument"},
|
||||||
|
{"uint8", uint16(1), "abi: cannot use uint16 as type uint8 as argument"},
|
||||||
|
{"uint8", uint32(1), "abi: cannot use uint32 as type uint8 as argument"},
|
||||||
|
{"uint8", uint64(1), "abi: cannot use uint64 as type uint8 as argument"},
|
||||||
|
{"uint8", int8(1), "abi: cannot use int8 as type uint8 as argument"},
|
||||||
|
{"uint8", int16(1), "abi: cannot use int16 as type uint8 as argument"},
|
||||||
|
{"uint8", int32(1), "abi: cannot use int32 as type uint8 as argument"},
|
||||||
|
{"uint8", int64(1), "abi: cannot use int64 as type uint8 as argument"},
|
||||||
{"uint16", uint16(1), ""},
|
{"uint16", uint16(1), ""},
|
||||||
{"uint16", uint8(1), "abi: cannot use uint8 as type uint16 as argument"},
|
{"uint16", uint8(1), "abi: cannot use uint8 as type uint16 as argument"},
|
||||||
{"uint16[]", []uint16{1, 2, 3}, ""},
|
{"uint16[]", []uint16{1, 2, 3}, ""},
|
||||||
{"uint16[]", [3]uint16{1, 2, 3}, ""},
|
{"uint16[]", [3]uint16{1, 2, 3}, ""},
|
||||||
{"uint16[]", []uint32{1, 2, 3}, "abi: cannot use []uint32 as type []uint16 as argument"},
|
{"uint16[]", []uint32{1, 2, 3}, "abi: cannot use []uint32 as type [0]uint16 as argument"},
|
||||||
{"uint16[3]", [3]uint32{1, 2, 3}, "abi: cannot use [3]uint32 as type [3]uint16 as argument"},
|
{"uint16[3]", [3]uint32{1, 2, 3}, "abi: cannot use [3]uint32 as type [3]uint16 as argument"},
|
||||||
{"uint16[3]", [4]uint16{1, 2, 3}, "abi: cannot use [4]uint16 as type [3]uint16 as argument"},
|
{"uint16[3]", [4]uint16{1, 2, 3}, "abi: cannot use [4]uint16 as type [3]uint16 as argument"},
|
||||||
{"uint16[3]", []uint16{1, 2, 3}, ""},
|
{"uint16[3]", []uint16{1, 2, 3}, ""},
|
||||||
|
|
@ -122,20 +205,61 @@ func TestTypeCheck(t *testing.T) {
|
||||||
{"address[1]", [1]common.Address{{1}}, ""},
|
{"address[1]", [1]common.Address{{1}}, ""},
|
||||||
{"address[2]", [1]common.Address{{1}}, "abi: cannot use [1]array as type [2]array as argument"},
|
{"address[2]", [1]common.Address{{1}}, "abi: cannot use [1]array as type [2]array as argument"},
|
||||||
{"bytes32", [32]byte{}, ""},
|
{"bytes32", [32]byte{}, ""},
|
||||||
|
{"bytes31", [31]byte{}, ""},
|
||||||
|
{"bytes30", [30]byte{}, ""},
|
||||||
|
{"bytes29", [29]byte{}, ""},
|
||||||
|
{"bytes28", [28]byte{}, ""},
|
||||||
|
{"bytes27", [27]byte{}, ""},
|
||||||
|
{"bytes26", [26]byte{}, ""},
|
||||||
|
{"bytes25", [25]byte{}, ""},
|
||||||
|
{"bytes24", [24]byte{}, ""},
|
||||||
|
{"bytes23", [23]byte{}, ""},
|
||||||
|
{"bytes22", [22]byte{}, ""},
|
||||||
|
{"bytes21", [21]byte{}, ""},
|
||||||
|
{"bytes20", [20]byte{}, ""},
|
||||||
|
{"bytes19", [19]byte{}, ""},
|
||||||
|
{"bytes18", [18]byte{}, ""},
|
||||||
|
{"bytes17", [17]byte{}, ""},
|
||||||
|
{"bytes16", [16]byte{}, ""},
|
||||||
|
{"bytes15", [15]byte{}, ""},
|
||||||
|
{"bytes14", [14]byte{}, ""},
|
||||||
|
{"bytes13", [13]byte{}, ""},
|
||||||
|
{"bytes12", [12]byte{}, ""},
|
||||||
|
{"bytes11", [11]byte{}, ""},
|
||||||
|
{"bytes10", [10]byte{}, ""},
|
||||||
|
{"bytes9", [9]byte{}, ""},
|
||||||
|
{"bytes8", [8]byte{}, ""},
|
||||||
|
{"bytes7", [7]byte{}, ""},
|
||||||
|
{"bytes6", [6]byte{}, ""},
|
||||||
|
{"bytes5", [5]byte{}, ""},
|
||||||
|
{"bytes4", [4]byte{}, ""},
|
||||||
|
{"bytes3", [3]byte{}, ""},
|
||||||
|
{"bytes2", [2]byte{}, ""},
|
||||||
|
{"bytes1", [1]byte{}, ""},
|
||||||
{"bytes32", [33]byte{}, "abi: cannot use [33]uint8 as type [32]uint8 as argument"},
|
{"bytes32", [33]byte{}, "abi: cannot use [33]uint8 as type [32]uint8 as argument"},
|
||||||
{"bytes32", common.Hash{1}, ""},
|
{"bytes32", common.Hash{1}, ""},
|
||||||
{"bytes31", [31]byte{}, ""},
|
{"bytes31", common.Hash{1}, "abi: cannot use common.Hash as type [31]uint8 as argument"},
|
||||||
{"bytes31", [32]byte{}, "abi: cannot use [32]uint8 as type [31]uint8 as argument"},
|
{"bytes31", [32]byte{}, "abi: cannot use [32]uint8 as type [31]uint8 as argument"},
|
||||||
{"bytes", []byte{0, 1}, ""},
|
{"bytes", []byte{0, 1}, ""},
|
||||||
{"bytes", [2]byte{0, 1}, ""},
|
{"bytes", [2]byte{0, 1}, "abi: cannot use array as type slice as argument"},
|
||||||
{"bytes", common.Hash{1}, ""},
|
{"bytes", common.Hash{1}, "abi: cannot use array as type slice as argument"},
|
||||||
{"string", "hello world", ""},
|
{"string", "hello world", ""},
|
||||||
|
{"string", string(""), ""},
|
||||||
|
{"string", []byte{}, "abi: cannot use slice as type string as argument"},
|
||||||
{"bytes32[]", [][32]byte{{}}, ""},
|
{"bytes32[]", [][32]byte{{}}, ""},
|
||||||
{"function", [24]byte{}, ""},
|
{"function", [24]byte{}, ""},
|
||||||
|
{"bytes20", common.Address{}, ""},
|
||||||
|
{"address", [20]byte{}, ""},
|
||||||
|
{"address", common.Address{}, ""},
|
||||||
} {
|
} {
|
||||||
typ, err := NewType(test.typ)
|
typ, err := NewType(test.typ)
|
||||||
if err != nil {
|
if err != nil && len(test.err) == 0 {
|
||||||
t.Fatal("unexpected parse error:", err)
|
t.Fatal("unexpected parse error:", err)
|
||||||
|
} else if err != nil && len(test.err) != 0 {
|
||||||
|
if err.Error() != test.err {
|
||||||
|
t.Errorf("%d failed. Expected err: '%v' got err: '%v'", i, test.err, err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = typeCheck(typ, reflect.ValueOf(test.input))
|
err = typeCheck(typ, reflect.ValueOf(test.input))
|
||||||
|
|
|
||||||
|
|
@ -34,49 +34,15 @@ func toGoSlice(i int, t Argument, output []byte) (interface{}, error) {
|
||||||
if index+32 > len(output) {
|
if index+32 > len(output) {
|
||||||
return nil, fmt.Errorf("abi: cannot marshal in to go slice: insufficient size output %d require %d", len(output), index+32)
|
return nil, fmt.Errorf("abi: cannot marshal in to go slice: insufficient size output %d require %d", len(output), index+32)
|
||||||
}
|
}
|
||||||
|
|
||||||
elem := t.Type.Elem
|
elem := t.Type.Elem
|
||||||
|
|
||||||
// first we need to create a slice of the type
|
// this value will become our slice or our array, depending on the type
|
||||||
var refSlice reflect.Value
|
var refSlice reflect.Value
|
||||||
switch elem.T {
|
|
||||||
case IntTy, UintTy, BoolTy:
|
|
||||||
// create a new reference slice matching the element type
|
|
||||||
switch t.Type.Kind {
|
|
||||||
case reflect.Bool:
|
|
||||||
refSlice = reflect.ValueOf([]bool(nil))
|
|
||||||
case reflect.Uint8:
|
|
||||||
refSlice = reflect.ValueOf([]uint8(nil))
|
|
||||||
case reflect.Uint16:
|
|
||||||
refSlice = reflect.ValueOf([]uint16(nil))
|
|
||||||
case reflect.Uint32:
|
|
||||||
refSlice = reflect.ValueOf([]uint32(nil))
|
|
||||||
case reflect.Uint64:
|
|
||||||
refSlice = reflect.ValueOf([]uint64(nil))
|
|
||||||
case reflect.Int8:
|
|
||||||
refSlice = reflect.ValueOf([]int8(nil))
|
|
||||||
case reflect.Int16:
|
|
||||||
refSlice = reflect.ValueOf([]int16(nil))
|
|
||||||
case reflect.Int32:
|
|
||||||
refSlice = reflect.ValueOf([]int32(nil))
|
|
||||||
case reflect.Int64:
|
|
||||||
refSlice = reflect.ValueOf([]int64(nil))
|
|
||||||
default:
|
|
||||||
refSlice = reflect.ValueOf([]*big.Int(nil))
|
|
||||||
}
|
|
||||||
case AddressTy: // address must be of slice Address
|
|
||||||
refSlice = reflect.ValueOf([]common.Address(nil))
|
|
||||||
case HashTy: // hash must be of slice hash
|
|
||||||
refSlice = reflect.ValueOf([]common.Hash(nil))
|
|
||||||
case FixedBytesTy:
|
|
||||||
refSlice = reflect.ValueOf([][]byte(nil))
|
|
||||||
default: // no other types are supported
|
|
||||||
return nil, fmt.Errorf("abi: unsupported slice type %v", elem.T)
|
|
||||||
}
|
|
||||||
|
|
||||||
var slice []byte
|
var slice []byte
|
||||||
var size int
|
var size int
|
||||||
var offset int
|
var offset int
|
||||||
if t.Type.IsSlice {
|
if t.Type.T == SliceTy {
|
||||||
// get the offset which determines the start of this array ...
|
// get the offset which determines the start of this array ...
|
||||||
offset = int(binary.BigEndian.Uint64(output[index+24 : index+32]))
|
offset = int(binary.BigEndian.Uint64(output[index+24 : index+32]))
|
||||||
if offset+32 > len(output) {
|
if offset+32 > len(output) {
|
||||||
|
|
@ -95,10 +61,13 @@ func toGoSlice(i int, t Argument, output []byte) (interface{}, error) {
|
||||||
|
|
||||||
// reslice to match the required size
|
// reslice to match the required size
|
||||||
slice = slice[:size*32]
|
slice = slice[:size*32]
|
||||||
} else if t.Type.IsArray {
|
// declare our slice
|
||||||
|
refSlice = reflect.MakeSlice(reflect.SliceOf(elem.Type), size, size)
|
||||||
|
} else if t.Type.T == ArrayTy {
|
||||||
//get the number of elements in the array
|
//get the number of elements in the array
|
||||||
size = t.Type.SliceSize
|
size = t.Type.Size
|
||||||
|
// declare our slice
|
||||||
|
refSlice = reflect.New(reflect.ArrayOf(size, elem.Type)).Elem()
|
||||||
//check to make sure array size matches up
|
//check to make sure array size matches up
|
||||||
if index+32*size > len(output) {
|
if index+32*size > len(output) {
|
||||||
return nil, fmt.Errorf("abi: cannot marshal in to go array: offset %d would go over slice boundary (len=%d)", len(output), index+32*size)
|
return nil, fmt.Errorf("abi: cannot marshal in to go array: offset %d would go over slice boundary (len=%d)", len(output), index+32*size)
|
||||||
|
|
@ -116,7 +85,7 @@ func toGoSlice(i int, t Argument, output []byte) (interface{}, error) {
|
||||||
// set inter to the correct type (cast)
|
// set inter to the correct type (cast)
|
||||||
switch elem.T {
|
switch elem.T {
|
||||||
case IntTy, UintTy:
|
case IntTy, UintTy:
|
||||||
inter = readInteger(t.Type.Kind, returnOutput)
|
inter = readInteger(elem.Kind, returnOutput)
|
||||||
case BoolTy:
|
case BoolTy:
|
||||||
inter, err = readBool(returnOutput)
|
inter, err = readBool(returnOutput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -128,9 +97,14 @@ func toGoSlice(i int, t Argument, output []byte) (interface{}, error) {
|
||||||
inter = common.BytesToHash(returnOutput)
|
inter = common.BytesToHash(returnOutput)
|
||||||
case FixedBytesTy:
|
case FixedBytesTy:
|
||||||
inter = returnOutput
|
inter = returnOutput
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("abi: unsupported slice type passed in")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fmt.Printf("type: %T, value: %v\n", inter, inter)
|
||||||
|
//fmt.Printf("%v\n", elem.stringKind)
|
||||||
// append the item to our reflect slice
|
// append the item to our reflect slice
|
||||||
refSlice = reflect.Append(refSlice, reflect.ValueOf(inter))
|
refSlice.Index(i).Set(reflect.ValueOf(inter))
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the interface
|
// return the interface
|
||||||
|
|
@ -185,7 +159,7 @@ func readBool(word []byte) (bool, error) {
|
||||||
// argument in T.
|
// argument in T.
|
||||||
func toGoType(i int, t Argument, output []byte) (interface{}, error) {
|
func toGoType(i int, t Argument, output []byte) (interface{}, error) {
|
||||||
// we need to treat slices differently
|
// we need to treat slices differently
|
||||||
if (t.Type.IsSlice || t.Type.IsArray) && t.Type.T != BytesTy && t.Type.T != StringTy && t.Type.T != FixedBytesTy && t.Type.T != FunctionTy {
|
if t.Type.T == SliceTy || t.Type.T == ArrayTy {
|
||||||
return toGoSlice(i, t, output)
|
return toGoSlice(i, t, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,187 @@ func TestSimpleMethodUnpack(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestArraysAndSlicesUnpack(t *testing.T) {
|
||||||
|
for i, test := range []struct {
|
||||||
|
def string // definition of the **output** ABI params
|
||||||
|
marshalledOutput []byte // evm return data
|
||||||
|
expectedOut interface{} // the expected output
|
||||||
|
outVar interface{} // the output variable (e.g. uint32, *big.Int, etc)
|
||||||
|
err string // empty or error if expected
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
`[ { "type": "uint8[]" } ]`,
|
||||||
|
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[]uint8{1, 2},
|
||||||
|
[]uint8{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "uint8[2]" } ]`,
|
||||||
|
common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[2]uint8{1, 2},
|
||||||
|
[2]uint8{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "uint16[]" } ]`,
|
||||||
|
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[]uint16{1, 2},
|
||||||
|
[]uint16{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "uint16[2]" } ]`,
|
||||||
|
common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[2]uint16{1, 2},
|
||||||
|
[2]uint16{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "uint32[]" } ]`,
|
||||||
|
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[]uint32{1, 2},
|
||||||
|
[]uint32{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "uint32[2]" } ]`,
|
||||||
|
common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[2]uint32{1, 2},
|
||||||
|
[2]uint32{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "uint64[]" } ]`,
|
||||||
|
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[]uint64{1, 2},
|
||||||
|
[]uint64{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "uint64[2]" } ]`,
|
||||||
|
common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[2]uint64{1, 2},
|
||||||
|
[2]uint64{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "uint256[]" } ]`,
|
||||||
|
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[]*big.Int{big.NewInt(1), big.NewInt(2)},
|
||||||
|
[]*big.Int{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "uint256[3]" } ]`,
|
||||||
|
append(pad([]byte{1}, 32, true), append(pad([]byte{2}, 32, true), pad([]byte{3}, 32, true)...)...),
|
||||||
|
[3]*big.Int{big.NewInt(1), big.NewInt(2), big.NewInt(3)},
|
||||||
|
[3]*big.Int{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "int8[]" } ]`,
|
||||||
|
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[]int8{1, 2},
|
||||||
|
[]int8{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "int8[2]" } ]`,
|
||||||
|
common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[2]int8{1, 2},
|
||||||
|
[2]int8{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "int16[]" } ]`,
|
||||||
|
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[]int16{1, 2},
|
||||||
|
[]int16{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "int16[2]" } ]`,
|
||||||
|
common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[2]int16{1, 2},
|
||||||
|
[2]int16{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "int32[]" } ]`,
|
||||||
|
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[]int32{1, 2},
|
||||||
|
[]int32{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "int32[2]" } ]`,
|
||||||
|
common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[2]int32{1, 2},
|
||||||
|
[2]int32{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "int64[]" } ]`,
|
||||||
|
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[]int64{1, 2},
|
||||||
|
[]int64{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "int64[2]" } ]`,
|
||||||
|
common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[2]int64{1, 2},
|
||||||
|
[2]int64{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "int256[]" } ]`,
|
||||||
|
common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||||
|
[]*big.Int{big.NewInt(1), big.NewInt(2)},
|
||||||
|
[]*big.Int{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "int256[3]" } ]`,
|
||||||
|
common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003"),
|
||||||
|
[3]*big.Int{big.NewInt(1), big.NewInt(2), big.NewInt(3)},
|
||||||
|
[3]*big.Int{},
|
||||||
|
"",
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
|
||||||
|
abiDefinition := fmt.Sprintf(`[{ "name" : "method", "outputs": %s}]`, test.def)
|
||||||
|
abi, err := JSON(strings.NewReader(abiDefinition))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%d failed. %v", i, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = abi.Unpack(&test.outVar, "method", test.marshalledOutput)
|
||||||
|
|
||||||
|
if err != nil && len(test.err) == 0 {
|
||||||
|
t.Errorf("%d failed. Expected no err but got: %v", i, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err == nil && len(test.err) != 0 {
|
||||||
|
t.Errorf("%d failed. Expected err: %v but got none", i, test.err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil && len(test.err) != 0 && err.Error() != test.err {
|
||||||
|
t.Errorf("%d failed. Expected err: '%v' got err: '%v'", i, test.err, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
if !reflect.DeepEqual(test.expectedOut, test.outVar) {
|
||||||
|
t.Errorf("%d failed. Output error: expected %v, got %v", i, test.expectedOut, test.outVar)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestUnpackSetInterfaceSlice(t *testing.T) {
|
func TestUnpackSetInterfaceSlice(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
var1 = new(uint8)
|
var1 = new(uint8)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue