Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
da58afce
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
da58afce
编写于
12月 20, 2017
作者:
D
Dmitry Shulyak
提交者:
Felix Lange
12月 20, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
accounts/abi: update array length after parsing array (#15618)
Fixes #15617
上级
ce823c9f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
78 addition
and
26 deletion
+78
-26
accounts/abi/event.go
accounts/abi/event.go
+5
-3
accounts/abi/event_test.go
accounts/abi/event_test.go
+23
-0
accounts/abi/method.go
accounts/abi/method.go
+5
-4
accounts/abi/unpack_test.go
accounts/abi/unpack_test.go
+45
-19
未找到文件。
accounts/abi/event.go
浏览文件 @
da58afce
...
@@ -71,14 +71,16 @@ func (e Event) tupleUnpack(v interface{}, output []byte) error {
...
@@ -71,14 +71,16 @@ func (e Event) tupleUnpack(v interface{}, output []byte) error {
if
input
.
Indexed
{
if
input
.
Indexed
{
// can't read, continue
// can't read, continue
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
)
marshalledValue
,
err
:=
toGoType
((
i
+
j
)
*
32
,
input
.
Type
,
output
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
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
)
reflectValue
:=
reflect
.
ValueOf
(
marshalledValue
)
switch
value
.
Kind
()
{
switch
value
.
Kind
()
{
...
...
accounts/abi/event_test.go
浏览文件 @
da58afce
...
@@ -17,11 +17,14 @@
...
@@ -17,11 +17,14 @@
package
abi
package
abi
import
(
import
(
"bytes"
"reflect"
"strings"
"strings"
"testing"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/require"
)
)
func
TestEventId
(
t
*
testing
.
T
)
{
func
TestEventId
(
t
*
testing
.
T
)
{
...
@@ -54,3 +57,23 @@ 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
浏览文件 @
da58afce
...
@@ -95,14 +95,15 @@ func (method Method) tupleUnpack(v interface{}, output []byte) error {
...
@@ -95,14 +95,15 @@ func (method Method) tupleUnpack(v interface{}, output []byte) error {
j
:=
0
j
:=
0
for
i
:=
0
;
i
<
len
(
method
.
Outputs
);
i
++
{
for
i
:=
0
;
i
<
len
(
method
.
Outputs
);
i
++
{
toUnpack
:=
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
)
marshalledValue
,
err
:=
toGoType
((
i
+
j
)
*
32
,
toUnpack
.
Type
,
output
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
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
)
reflectValue
:=
reflect
.
ValueOf
(
marshalledValue
)
switch
value
.
Kind
()
{
switch
value
.
Kind
()
{
...
...
accounts/abi/unpack_test.go
浏览文件 @
da58afce
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"fmt"
"fmt"
"math/big"
"math/big"
"reflect"
"reflect"
"strconv"
"strings"
"strings"
"testing"
"testing"
...
@@ -261,25 +262,27 @@ var unpackTests = []unpackTest{
...
@@ -261,25 +262,27 @@ var unpackTests = []unpackTest{
func
TestUnpack
(
t
*
testing
.
T
)
{
func
TestUnpack
(
t
*
testing
.
T
)
{
for
i
,
test
:=
range
unpackTests
{
for
i
,
test
:=
range
unpackTests
{
def
:=
fmt
.
Sprintf
(
`[{ "name" : "method", "outputs": %s}]`
,
test
.
def
)
t
.
Run
(
strconv
.
Itoa
(
i
),
func
(
t
*
testing
.
T
)
{
abi
,
err
:=
JSON
(
strings
.
NewReader
(
def
))
def
:=
fmt
.
Sprintf
(
`[{ "name" : "method", "outputs": %s}]`
,
test
.
def
)
if
err
!=
nil
{
abi
,
err
:=
JSON
(
strings
.
NewReader
(
def
))
t
.
Fatalf
(
"invalid ABI definition %s: %v"
,
def
,
err
)
if
err
!=
nil
{
}
t
.
Fatalf
(
"invalid ABI definition %s: %v"
,
def
,
err
)
encb
,
err
:=
hex
.
DecodeString
(
test
.
enc
)
}
if
err
!=
nil
{
encb
,
err
:=
hex
.
DecodeString
(
test
.
enc
)
t
.
Fatalf
(
"invalid hex: %s"
+
test
.
enc
)
if
err
!=
nil
{
}
t
.
Fatalf
(
"invalid hex: %s"
+
test
.
enc
)
outptr
:=
reflect
.
New
(
reflect
.
TypeOf
(
test
.
want
))
}
err
=
abi
.
Unpack
(
outptr
.
Interface
(),
"method"
,
encb
)
outptr
:=
reflect
.
New
(
reflect
.
TypeOf
(
test
.
want
))
if
err
:=
test
.
checkError
(
err
);
err
!=
nil
{
err
=
abi
.
Unpack
(
outptr
.
Interface
(),
"method"
,
encb
)
t
.
Errorf
(
"test %d (%v) failed: %v"
,
i
,
test
.
def
,
err
)
if
err
:=
test
.
checkError
(
err
);
err
!=
nil
{
continue
t
.
Errorf
(
"test %d (%v) failed: %v"
,
i
,
test
.
def
,
err
)
}
return
out
:=
outptr
.
Elem
()
.
Interface
()
}
if
!
reflect
.
DeepEqual
(
test
.
want
,
out
)
{
out
:=
outptr
.
Elem
()
.
Interface
()
t
.
Errorf
(
"test %d (%v) failed: expected %v, got %v"
,
i
,
test
.
def
,
test
.
want
,
out
)
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) {
...
@@ -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
)
{
func
TestUnmarshal
(
t
*
testing
.
T
)
{
const
definition
=
`[
const
definition
=
`[
{ "name" : "int", "constant" : false, "outputs": [ { "type": "uint256" } ] },
{ "name" : "int", "constant" : false, "outputs": [ { "type": "uint256" } ] },
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录