Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
da58afce
Commit
da58afce
authored
Dec 20, 2017
by
Dmitry Shulyak
Committed by
Felix Lange
Dec 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi: update array length after parsing array (#15618)
Fixes #15617
parent
ce823c9f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
26 deletions
+78
-26
event.go
accounts/abi/event.go
+5
-3
event_test.go
accounts/abi/event_test.go
+23
-0
method.go
accounts/abi/method.go
+5
-4
unpack_test.go
accounts/abi/unpack_test.go
+45
-19
No files found.
accounts/abi/event.go
View file @
da58afce
...
...
@@ -71,14 +71,16 @@ func (e Event) tupleUnpack(v interface{}, output []byte) error {
if
input
.
Indexed
{
// can't read, continue
continue
}
else
if
input
.
Type
.
T
==
ArrayTy
{
// need to move this up because they read sequentially
j
+=
input
.
Type
.
Size
}
marshalledValue
,
err
:=
toGoType
((
i
+
j
)
*
32
,
input
.
Type
,
output
)
if
err
!=
nil
{
return
err
}
if
input
.
Type
.
T
==
ArrayTy
{
// 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
)
switch
value
.
Kind
()
{
...
...
accounts/abi/event_test.go
View file @
da58afce
...
...
@@ -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
)
}
accounts/abi/method.go
View file @
da58afce
...
...
@@ -95,14 +95,15 @@ func (method Method) tupleUnpack(v interface{}, output []byte) error {
j
:=
0
for
i
:=
0
;
i
<
len
(
method
.
Outputs
);
i
++
{
toUnpack
:=
method
.
Outputs
[
i
]
if
toUnpack
.
Type
.
T
==
ArrayTy
{
// need to move this up because they read sequentially
j
+=
toUnpack
.
Type
.
Size
}
marshalledValue
,
err
:=
toGoType
((
i
+
j
)
*
32
,
toUnpack
.
Type
,
output
)
if
err
!=
nil
{
return
err
}
if
toUnpack
.
Type
.
T
==
ArrayTy
{
// combined index ('i' + 'j') need to be adjusted only by size of array, thus
// we need to decrement 'j' because 'i' was incremented
j
+=
toUnpack
.
Type
.
Size
-
1
}
reflectValue
:=
reflect
.
ValueOf
(
marshalledValue
)
switch
value
.
Kind
()
{
...
...
accounts/abi/unpack_test.go
View file @
da58afce
...
...
@@ -22,6 +22,7 @@ import (
"fmt"
"math/big"
"reflect"
"strconv"
"strings"
"testing"
...
...
@@ -261,6 +262,7 @@ var unpackTests = []unpackTest{
func
TestUnpack
(
t
*
testing
.
T
)
{
for
i
,
test
:=
range
unpackTests
{
t
.
Run
(
strconv
.
Itoa
(
i
),
func
(
t
*
testing
.
T
)
{
def
:=
fmt
.
Sprintf
(
`[{ "name" : "method", "outputs": %s}]`
,
test
.
def
)
abi
,
err
:=
JSON
(
strings
.
NewReader
(
def
))
if
err
!=
nil
{
...
...
@@ -274,12 +276,13 @@ func TestUnpack(t *testing.T) {
err
=
abi
.
Unpack
(
outptr
.
Interface
(),
"method"
,
encb
)
if
err
:=
test
.
checkError
(
err
);
err
!=
nil
{
t
.
Errorf
(
"test %d (%v) failed: %v"
,
i
,
test
.
def
,
err
)
continue
return
}
out
:=
outptr
.
Elem
()
.
Interface
()
if
!
reflect
.
DeepEqual
(
test
.
want
,
out
)
{
t
.
Errorf
(
"test %d (%v) failed: expected %v, got %v"
,
i
,
test
.
def
,
test
.
want
,
out
)
}
})
}
}
...
...
@@ -336,6 +339,29 @@ func TestMultiReturnWithStruct(t *testing.T) {
}
}
func
TestMultiReturnWithArray
(
t
*
testing
.
T
)
{
const
definition
=
`[{"name" : "multi", "outputs": [{"type": "uint64[3]"}, {"type": "uint64"}]}]`
abi
,
err
:=
JSON
(
strings
.
NewReader
(
definition
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
buff
:=
new
(
bytes
.
Buffer
)
buff
.
Write
(
common
.
Hex2Bytes
(
"000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000009"
))
buff
.
Write
(
common
.
Hex2Bytes
(
"0000000000000000000000000000000000000000000000000000000000000008"
))
ret1
,
ret1Exp
:=
new
([
3
]
uint64
),
[
3
]
uint64
{
9
,
9
,
9
}
ret2
,
ret2Exp
:=
new
(
uint64
),
uint64
(
8
)
if
err
:=
abi
.
Unpack
(
&
[]
interface
{}{
ret1
,
ret2
},
"multi"
,
buff
.
Bytes
());
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
reflect
.
DeepEqual
(
*
ret1
,
ret1Exp
)
{
t
.
Error
(
"array result"
,
*
ret1
,
"!= Expected"
,
ret1Exp
)
}
if
*
ret2
!=
ret2Exp
{
t
.
Error
(
"int result"
,
*
ret2
,
"!= Expected"
,
ret2Exp
)
}
}
func
TestUnmarshal
(
t
*
testing
.
T
)
{
const
definition
=
`[
{ "name" : "int", "constant" : false, "outputs": [ { "type": "uint256" } ] },
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment