accounts/abi: added abi test cases, minor bug fixes (#20903)

* accounts/abi: added documentation

* accounts/abi: reduced usage of arguments.LengthNonIndexed

* accounts/abi: simplified reflection logic

* accounts/abi: moved testjson data into global declaration

* accounts/abi: removed duplicate test cases

* accounts/abi: reworked abi tests

* accounts/abi: added more tests for abi packing

* accounts/abi/bind: refactored base tests

* accounts/abi: run pack tests as subtests

* accounts/abi: removed duplicate tests

* accounts/abi: removed unnused arguments.LengthNonIndexed

Due to refactors to the code, we do not need the arguments.LengthNonIndexed function anymore.
You can still get the length by calling len(arguments.NonIndexed())

* accounts/abi: added type test

* accounts/abi: modified unpack test to pack test

* accounts/abi: length check on arrayTy

* accounts/abi: test invalid abi

* accounts/abi: fixed rebase error

* accounts/abi: fixed rebase errors

* accounts/abi: removed unused definition

* accounts/abi: merged packing/unpacking tests

* accounts/abi: fixed [][][32]bytes encoding

* accounts/abi: added tuple test cases

* accounts/abi: renamed getMockLog -> newMockLog

* accounts/abi: removed duplicate test

* accounts/abi: bools -> booleans
This commit is contained in:
Marius van der Wijden
2020-04-27 15:07:33 +02:00
committed by GitHub
parent 40283d0522
commit e32ee6ac05
10 changed files with 1333 additions and 1198 deletions

View File

@ -42,26 +42,26 @@ func indirectInterfaceOrPtr(v reflect.Value) reflect.Value {
// reflectIntKind returns the reflect using the given size and
// unsignedness.
func reflectIntKindAndType(unsigned bool, size int) (reflect.Kind, reflect.Type) {
switch size {
case 8:
if unsigned {
if unsigned {
switch size {
case 8:
return reflect.Uint8, uint8T
}
return reflect.Int8, int8T
case 16:
if unsigned {
case 16:
return reflect.Uint16, uint16T
}
return reflect.Int16, int16T
case 32:
if unsigned {
case 32:
return reflect.Uint32, uint32T
}
return reflect.Int32, int32T
case 64:
if unsigned {
case 64:
return reflect.Uint64, uint64T
}
}
switch size {
case 8:
return reflect.Int8, int8T
case 16:
return reflect.Int16, int16T
case 32:
return reflect.Int32, int32T
case 64:
return reflect.Int64, int64T
}
return reflect.Ptr, bigT
@ -88,8 +88,8 @@ func set(dst, src reflect.Value) error {
return set(dst.Elem(), src)
case srcType.AssignableTo(dstType) && dst.CanSet():
dst.Set(src)
case dstType.Kind() == reflect.Slice && srcType.Kind() == reflect.Slice:
return setSlice(dst, src)
case dstType.Kind() == reflect.Slice && srcType.Kind() == reflect.Slice && dst.CanSet():
setSlice(dst, src)
default:
return fmt.Errorf("abi: cannot unmarshal %v in to %v", src.Type(), dst.Type())
}
@ -98,15 +98,13 @@ func set(dst, src reflect.Value) error {
// setSlice attempts to assign src to dst when slices are not assignable by default
// e.g. src: [][]byte -> dst: [][15]byte
func setSlice(dst, src reflect.Value) error {
// setSlice ignores if we cannot copy all of src' elements.
func setSlice(dst, src reflect.Value) {
slice := reflect.MakeSlice(dst.Type(), src.Len(), src.Len())
for i := 0; i < src.Len(); i++ {
v := src.Index(i)
reflect.Copy(slice.Index(i), v)
reflect.Copy(slice.Index(i), src.Index(i))
}
dst.Set(slice)
return nil
}
// requireAssignable assures that `dest` is a pointer and it's not an interface.