From 133ba15d98b00aa02ff0d532c1dd0f5ba525166c Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Fri, 8 Dec 2017 12:39:00 +0200 Subject: [PATCH] accounts/abi: Improve tests for provided fixes --- accounts/abi/event.go | 3 ++- accounts/abi/event_test.go | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/accounts/abi/event.go b/accounts/abi/event.go index 860db06096..bd1098d878 100644 --- a/accounts/abi/event.go +++ b/accounts/abi/event.go @@ -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) diff --git a/accounts/abi/event_test.go b/accounts/abi/event_test.go index 7e2f13f763..a3899b4a6f 100644 --- a/accounts/abi/event_test.go +++ b/accounts/abi/event_test.go @@ -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) +}