mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
accounts/abi: add unpack into array test
This commit is contained in:
parent
882a32a5b7
commit
2aeb2555fa
5 changed files with 39 additions and 3 deletions
|
|
@ -18,10 +18,10 @@ package abi
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
|
@ -178,6 +178,16 @@ func TestEventTupleUnpack(t *testing.T) {
|
|||
jsonEventPledge,
|
||||
"",
|
||||
"Can unpack Pledge event into slice",
|
||||
}, {
|
||||
pledgeData1,
|
||||
&[3]interface{}{&common.Address{}, &bigint, &[3]byte{}},
|
||||
&[3]interface{}{
|
||||
&addr,
|
||||
&bigintExpected2,
|
||||
&[3]byte{'u', 's', 'd'}},
|
||||
jsonEventPledge,
|
||||
"",
|
||||
"Can unpack Pledge event into an array",
|
||||
}, {
|
||||
pledgeData1,
|
||||
&[]interface{}{new(int), 0, 0},
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ func (method Method) tupleUnpack(v interface{}, outputSlice []byte) error {
|
|||
|
||||
j := 0
|
||||
for i, output := range method.Outputs {
|
||||
marshalledValue, err := toGoType((i+j)*32, ouptut.Type, outputSlice)
|
||||
marshalledValue, err := toGoType((i+j)*32, output.Type, outputSlice)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,27 @@ func set(dst, src reflect.Value, output Argument) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// requireUnpackKind verifies preconditions for unpacking `args` into `kind`
|
||||
func requireUnpackKind(v reflect.Value, t reflect.Type, k reflect.Kind,
|
||||
args []Argument, ignoreIndexed bool) error {
|
||||
|
||||
switch k {
|
||||
case reflect.Struct:
|
||||
case reflect.Slice, reflect.Array:
|
||||
minLen := len(args)
|
||||
if ignoreIndexed {
|
||||
minLen = countNonIndexedArguments(args)
|
||||
}
|
||||
if v.Len() < minLen {
|
||||
return fmt.Errorf("abi: insufficient number of elements in the list/array for unpack, want %d, got %d",
|
||||
minLen, v.Len())
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("abi: cannot unmarshal tuple into %v", t)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// requireAssignable assures that `dest` is a pointer and it's not an interface.
|
||||
func requireAssignable(dst, src reflect.Value) error {
|
||||
if dst.Kind() != reflect.Ptr && dst.Kind() != reflect.Interface {
|
||||
|
|
|
|||
|
|
@ -336,6 +336,11 @@ func TestMethodMultiReturn(t *testing.T) {
|
|||
&[]interface{}{&expected.Int, &expected.String},
|
||||
"",
|
||||
"Can unpack into a slice",
|
||||
}, {
|
||||
&[2]interface{}{&bigint, new(string)},
|
||||
&[2]interface{}{&expected.Int, &expected.String},
|
||||
"",
|
||||
"Can unpack into an array",
|
||||
}, {
|
||||
&[]interface{}{new(int), new(int)},
|
||||
&[]interface{}{&expected.Int, &expected.String},
|
||||
|
|
|
|||
Loading…
Reference in a new issue