accounts/abi: addressed comments

This commit is contained in:
Marius van der Wijden 2020-05-12 14:43:10 +02:00
parent 21b565e361
commit cdc2b87647
2 changed files with 18 additions and 8 deletions

View file

@ -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
}

View file

@ -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",