mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
accounts/abi: Improve tests for provided fixes
This commit is contained in:
parent
7ed09ed0bc
commit
133ba15d98
2 changed files with 25 additions and 1 deletions
|
|
@ -77,7 +77,8 @@ func (e Event) tupleUnpack(v interface{}, output []byte) error {
|
|||
return err
|
||||
}
|
||||
if input.Type.T == ArrayTy {
|
||||
// need to move this up because they read sequentially
|
||||
// combined index ('i' + 'j') need to be adjusted only by size of array, thus
|
||||
// we need to decrement 'j' because 'i' was incremented
|
||||
j += input.Type.Size - 1
|
||||
}
|
||||
reflectValue := reflect.ValueOf(marshalledValue)
|
||||
|
|
|
|||
|
|
@ -17,11 +17,14 @@
|
|||
package abi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestEventId(t *testing.T) {
|
||||
|
|
@ -54,3 +57,23 @@ func TestEventId(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestEventMultiValueWithArrayUnpack verifies that array fields will be counted after parsing array.
|
||||
func TestEventMultiValueWithArrayUnpack(t *testing.T) {
|
||||
definition := `[{"name": "test", "type": "event", "inputs": [{"indexed": false, "name":"value1", "type":"uint8[2]"},{"indexed": false, "name":"value2", "type":"uint8"}]}]`
|
||||
type testStruct struct {
|
||||
Value1 [2]uint8
|
||||
Value2 uint8
|
||||
}
|
||||
abi, err := JSON(strings.NewReader(definition))
|
||||
require.NoError(t, err)
|
||||
var b bytes.Buffer
|
||||
var i uint8 = 1
|
||||
for ; i <= 3; i++ {
|
||||
b.Write(packNum(reflect.ValueOf(i)))
|
||||
}
|
||||
var rst testStruct
|
||||
require.NoError(t, abi.Unpack(&rst, "test", b.Bytes()))
|
||||
require.Equal(t, [2]uint8{1, 2}, rst.Value1)
|
||||
require.Equal(t, uint8(3), rst.Value2)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue