Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
6ab9f0a1
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,体验更适合开发者的 AI 搜索 >>
提交
6ab9f0a1
编写于
4月 04, 2018
作者:
R
Ricardo Domingos
提交者:
Felix Lange
4月 04, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
accounts/abi: improve test coverage (#16044)
上级
7aad81f8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
82 addition
and
62 deletion
+82
-62
accounts/abi/numbers.go
accounts/abi/numbers.go
+18
-18
accounts/abi/reflect.go
accounts/abi/reflect.go
+10
-10
accounts/abi/type.go
accounts/abi/type.go
+1
-1
accounts/abi/type_test.go
accounts/abi/type_test.go
+36
-33
accounts/abi/unpack_test.go
accounts/abi/unpack_test.go
+17
-0
未找到文件。
accounts/abi/numbers.go
浏览文件 @
6ab9f0a1
...
...
@@ -25,23 +25,23 @@ import (
)
var
(
big
_t
=
reflect
.
TypeOf
(
&
big
.
Int
{})
derefbig
_t
=
reflect
.
TypeOf
(
big
.
Int
{})
uint8
_t
=
reflect
.
TypeOf
(
uint8
(
0
))
uint16
_t
=
reflect
.
TypeOf
(
uint16
(
0
))
uint32
_t
=
reflect
.
TypeOf
(
uint32
(
0
))
uint64
_t
=
reflect
.
TypeOf
(
uint64
(
0
))
int
_t
=
reflect
.
TypeOf
(
int
(
0
))
int8
_t
=
reflect
.
TypeOf
(
int8
(
0
))
int16
_t
=
reflect
.
TypeOf
(
int16
(
0
))
int32
_t
=
reflect
.
TypeOf
(
int32
(
0
))
int64
_t
=
reflect
.
TypeOf
(
int64
(
0
))
address
_t
=
reflect
.
TypeOf
(
common
.
Address
{})
int
_ts
=
reflect
.
TypeOf
([]
int
(
nil
))
int8
_ts
=
reflect
.
TypeOf
([]
int8
(
nil
))
int16
_ts
=
reflect
.
TypeOf
([]
int16
(
nil
))
int32
_ts
=
reflect
.
TypeOf
([]
int32
(
nil
))
int64
_ts
=
reflect
.
TypeOf
([]
int64
(
nil
))
big
T
=
reflect
.
TypeOf
(
&
big
.
Int
{})
derefbig
T
=
reflect
.
TypeOf
(
big
.
Int
{})
uint8
T
=
reflect
.
TypeOf
(
uint8
(
0
))
uint16
T
=
reflect
.
TypeOf
(
uint16
(
0
))
uint32
T
=
reflect
.
TypeOf
(
uint32
(
0
))
uint64
T
=
reflect
.
TypeOf
(
uint64
(
0
))
int
T
=
reflect
.
TypeOf
(
int
(
0
))
int8
T
=
reflect
.
TypeOf
(
int8
(
0
))
int16
T
=
reflect
.
TypeOf
(
int16
(
0
))
int32
T
=
reflect
.
TypeOf
(
int32
(
0
))
int64
T
=
reflect
.
TypeOf
(
int64
(
0
))
address
T
=
reflect
.
TypeOf
(
common
.
Address
{})
int
TS
=
reflect
.
TypeOf
([]
int
(
nil
))
int8
TS
=
reflect
.
TypeOf
([]
int8
(
nil
))
int16
TS
=
reflect
.
TypeOf
([]
int16
(
nil
))
int32
TS
=
reflect
.
TypeOf
([]
int32
(
nil
))
int64
TS
=
reflect
.
TypeOf
([]
int64
(
nil
))
)
// U256 converts a big Int into a 256bit EVM number.
...
...
@@ -52,7 +52,7 @@ func U256(n *big.Int) []byte {
// checks whether the given reflect value is signed. This also works for slices with a number type
func
isSigned
(
v
reflect
.
Value
)
bool
{
switch
v
.
Type
()
{
case
int
_ts
,
int8_ts
,
int16_ts
,
int32_ts
,
int64_ts
,
int_t
,
int8_t
,
int16_t
,
int32_t
,
int64_t
:
case
int
TS
,
int8TS
,
int16TS
,
int32TS
,
int64TS
,
intT
,
int8T
,
int16T
,
int32T
,
int64T
:
return
true
}
return
false
...
...
accounts/abi/reflect.go
浏览文件 @
6ab9f0a1
...
...
@@ -24,7 +24,7 @@ import (
// indirect recursively dereferences the value until it either gets the value
// or finds a big.Int
func
indirect
(
v
reflect
.
Value
)
reflect
.
Value
{
if
v
.
Kind
()
==
reflect
.
Ptr
&&
v
.
Elem
()
.
Type
()
!=
derefbig
_t
{
if
v
.
Kind
()
==
reflect
.
Ptr
&&
v
.
Elem
()
.
Type
()
!=
derefbig
T
{
return
indirect
(
v
.
Elem
())
}
return
v
...
...
@@ -36,26 +36,26 @@ func reflectIntKindAndType(unsigned bool, size int) (reflect.Kind, reflect.Type)
switch
size
{
case
8
:
if
unsigned
{
return
reflect
.
Uint8
,
uint8
_t
return
reflect
.
Uint8
,
uint8
T
}
return
reflect
.
Int8
,
int8
_t
return
reflect
.
Int8
,
int8
T
case
16
:
if
unsigned
{
return
reflect
.
Uint16
,
uint16
_t
return
reflect
.
Uint16
,
uint16
T
}
return
reflect
.
Int16
,
int16
_t
return
reflect
.
Int16
,
int16
T
case
32
:
if
unsigned
{
return
reflect
.
Uint32
,
uint32
_t
return
reflect
.
Uint32
,
uint32
T
}
return
reflect
.
Int32
,
int32
_t
return
reflect
.
Int32
,
int32
T
case
64
:
if
unsigned
{
return
reflect
.
Uint64
,
uint64
_t
return
reflect
.
Uint64
,
uint64
T
}
return
reflect
.
Int64
,
int64
_t
return
reflect
.
Int64
,
int64
T
}
return
reflect
.
Ptr
,
big
_t
return
reflect
.
Ptr
,
big
T
}
// mustArrayToBytesSlice creates a new byte slice with the exact same size as value
...
...
accounts/abi/type.go
浏览文件 @
6ab9f0a1
...
...
@@ -135,7 +135,7 @@ func NewType(t string) (typ Type, err error) {
typ
.
Type
=
reflect
.
TypeOf
(
bool
(
false
))
case
"address"
:
typ
.
Kind
=
reflect
.
Array
typ
.
Type
=
address
_t
typ
.
Type
=
address
T
typ
.
Size
=
20
typ
.
T
=
AddressTy
case
"string"
:
...
...
accounts/abi/type_test.go
浏览文件 @
6ab9f0a1
...
...
@@ -46,36 +46,36 @@ func TestTypeRegexp(t *testing.T) {
{
"bool[2][2][2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
][
2
][
2
]
bool
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
][
2
]
bool
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
bool
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Bool
,
T
:
BoolTy
,
Type
:
reflect
.
TypeOf
(
bool
(
false
)),
stringKind
:
"bool"
},
stringKind
:
"bool[2]"
},
stringKind
:
"bool[2][2]"
},
stringKind
:
"bool[2][2][2]"
}},
{
"bool[][][]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([][][]
bool
{}),
Elem
:
&
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([][]
bool
{}),
Elem
:
&
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
bool
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Bool
,
T
:
BoolTy
,
Type
:
reflect
.
TypeOf
(
bool
(
false
)),
stringKind
:
"bool"
},
stringKind
:
"bool[]"
},
stringKind
:
"bool[][]"
},
stringKind
:
"bool[][][]"
}},
{
"bool[][2][]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([][
2
][]
bool
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
][]
bool
{}),
Elem
:
&
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
bool
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Bool
,
T
:
BoolTy
,
Type
:
reflect
.
TypeOf
(
bool
(
false
)),
stringKind
:
"bool"
},
stringKind
:
"bool[]"
},
stringKind
:
"bool[][2]"
},
stringKind
:
"bool[][2][]"
}},
{
"int8"
,
Type
{
Kind
:
reflect
.
Int8
,
Type
:
int8
_t
,
Size
:
8
,
T
:
IntTy
,
stringKind
:
"int8"
}},
{
"int16"
,
Type
{
Kind
:
reflect
.
Int16
,
Type
:
int16
_t
,
Size
:
16
,
T
:
IntTy
,
stringKind
:
"int16"
}},
{
"int32"
,
Type
{
Kind
:
reflect
.
Int32
,
Type
:
int32
_t
,
Size
:
32
,
T
:
IntTy
,
stringKind
:
"int32"
}},
{
"int64"
,
Type
{
Kind
:
reflect
.
Int64
,
Type
:
int64
_t
,
Size
:
64
,
T
:
IntTy
,
stringKind
:
"int64"
}},
{
"int256"
,
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
_t
,
Size
:
256
,
T
:
IntTy
,
stringKind
:
"int256"
}},
{
"int8[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
int8
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int8
,
Type
:
int8
_t
,
Size
:
8
,
T
:
IntTy
,
stringKind
:
"int8"
},
stringKind
:
"int8[]"
}},
{
"int8[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
int8
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int8
,
Type
:
int8
_t
,
Size
:
8
,
T
:
IntTy
,
stringKind
:
"int8"
},
stringKind
:
"int8[2]"
}},
{
"int16[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
int16
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int16
,
Type
:
int16
_t
,
Size
:
16
,
T
:
IntTy
,
stringKind
:
"int16"
},
stringKind
:
"int16[]"
}},
{
"int16[2]"
,
Type
{
Size
:
2
,
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Type
:
reflect
.
TypeOf
([
2
]
int16
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int16
,
Type
:
int16
_t
,
Size
:
16
,
T
:
IntTy
,
stringKind
:
"int16"
},
stringKind
:
"int16[2]"
}},
{
"int32[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
int32
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int32
,
Type
:
int32
_t
,
Size
:
32
,
T
:
IntTy
,
stringKind
:
"int32"
},
stringKind
:
"int32[]"
}},
{
"int32[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
int32
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int32
,
Type
:
int32
_t
,
Size
:
32
,
T
:
IntTy
,
stringKind
:
"int32"
},
stringKind
:
"int32[2]"
}},
{
"int64[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
int64
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int64
,
Type
:
int64
_t
,
Size
:
64
,
T
:
IntTy
,
stringKind
:
"int64"
},
stringKind
:
"int64[]"
}},
{
"int64[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
int64
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int64
,
Type
:
int64
_t
,
Size
:
64
,
T
:
IntTy
,
stringKind
:
"int64"
},
stringKind
:
"int64[2]"
}},
{
"int256[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
*
big
.
Int
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
_t
,
Size
:
256
,
T
:
IntTy
,
stringKind
:
"int256"
},
stringKind
:
"int256[]"
}},
{
"int256[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
*
big
.
Int
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
_t
,
Size
:
256
,
T
:
IntTy
,
stringKind
:
"int256"
},
stringKind
:
"int256[2]"
}},
{
"uint8"
,
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
uint8
_t
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
}},
{
"uint16"
,
Type
{
Kind
:
reflect
.
Uint16
,
Type
:
uint16
_t
,
Size
:
16
,
T
:
UintTy
,
stringKind
:
"uint16"
}},
{
"uint32"
,
Type
{
Kind
:
reflect
.
Uint32
,
Type
:
uint32
_t
,
Size
:
32
,
T
:
UintTy
,
stringKind
:
"uint32"
}},
{
"uint64"
,
Type
{
Kind
:
reflect
.
Uint64
,
Type
:
uint64
_t
,
Size
:
64
,
T
:
UintTy
,
stringKind
:
"uint64"
}},
{
"uint256"
,
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
_t
,
Size
:
256
,
T
:
UintTy
,
stringKind
:
"uint256"
}},
{
"uint8[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
uint8
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
uint8
_t
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
},
stringKind
:
"uint8[]"
}},
{
"uint8[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
uint8
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
uint8
_t
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
},
stringKind
:
"uint8[2]"
}},
{
"uint16[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
uint16
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint16
,
Type
:
uint16
_t
,
Size
:
16
,
T
:
UintTy
,
stringKind
:
"uint16"
},
stringKind
:
"uint16[]"
}},
{
"uint16[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
uint16
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint16
,
Type
:
uint16
_t
,
Size
:
16
,
T
:
UintTy
,
stringKind
:
"uint16"
},
stringKind
:
"uint16[2]"
}},
{
"uint32[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
uint32
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint32
,
Type
:
uint32
_t
,
Size
:
32
,
T
:
UintTy
,
stringKind
:
"uint32"
},
stringKind
:
"uint32[]"
}},
{
"uint32[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
uint32
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint32
,
Type
:
uint32
_t
,
Size
:
32
,
T
:
UintTy
,
stringKind
:
"uint32"
},
stringKind
:
"uint32[2]"
}},
{
"uint64[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
uint64
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint64
,
Type
:
uint64
_t
,
Size
:
64
,
T
:
UintTy
,
stringKind
:
"uint64"
},
stringKind
:
"uint64[]"
}},
{
"uint64[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
uint64
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint64
,
Type
:
uint64
_t
,
Size
:
64
,
T
:
UintTy
,
stringKind
:
"uint64"
},
stringKind
:
"uint64[2]"
}},
{
"uint256[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
*
big
.
Int
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
_t
,
Size
:
256
,
T
:
UintTy
,
stringKind
:
"uint256"
},
stringKind
:
"uint256[]"
}},
{
"uint256[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Type
:
reflect
.
TypeOf
([
2
]
*
big
.
Int
{}),
Size
:
2
,
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
_t
,
Size
:
256
,
T
:
UintTy
,
stringKind
:
"uint256"
},
stringKind
:
"uint256[2]"
}},
{
"int8"
,
Type
{
Kind
:
reflect
.
Int8
,
Type
:
int8
T
,
Size
:
8
,
T
:
IntTy
,
stringKind
:
"int8"
}},
{
"int16"
,
Type
{
Kind
:
reflect
.
Int16
,
Type
:
int16
T
,
Size
:
16
,
T
:
IntTy
,
stringKind
:
"int16"
}},
{
"int32"
,
Type
{
Kind
:
reflect
.
Int32
,
Type
:
int32
T
,
Size
:
32
,
T
:
IntTy
,
stringKind
:
"int32"
}},
{
"int64"
,
Type
{
Kind
:
reflect
.
Int64
,
Type
:
int64
T
,
Size
:
64
,
T
:
IntTy
,
stringKind
:
"int64"
}},
{
"int256"
,
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
T
,
Size
:
256
,
T
:
IntTy
,
stringKind
:
"int256"
}},
{
"int8[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
int8
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int8
,
Type
:
int8
T
,
Size
:
8
,
T
:
IntTy
,
stringKind
:
"int8"
},
stringKind
:
"int8[]"
}},
{
"int8[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
int8
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int8
,
Type
:
int8
T
,
Size
:
8
,
T
:
IntTy
,
stringKind
:
"int8"
},
stringKind
:
"int8[2]"
}},
{
"int16[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
int16
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int16
,
Type
:
int16
T
,
Size
:
16
,
T
:
IntTy
,
stringKind
:
"int16"
},
stringKind
:
"int16[]"
}},
{
"int16[2]"
,
Type
{
Size
:
2
,
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Type
:
reflect
.
TypeOf
([
2
]
int16
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int16
,
Type
:
int16
T
,
Size
:
16
,
T
:
IntTy
,
stringKind
:
"int16"
},
stringKind
:
"int16[2]"
}},
{
"int32[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
int32
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int32
,
Type
:
int32
T
,
Size
:
32
,
T
:
IntTy
,
stringKind
:
"int32"
},
stringKind
:
"int32[]"
}},
{
"int32[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
int32
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int32
,
Type
:
int32
T
,
Size
:
32
,
T
:
IntTy
,
stringKind
:
"int32"
},
stringKind
:
"int32[2]"
}},
{
"int64[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
int64
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int64
,
Type
:
int64
T
,
Size
:
64
,
T
:
IntTy
,
stringKind
:
"int64"
},
stringKind
:
"int64[]"
}},
{
"int64[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
int64
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Int64
,
Type
:
int64
T
,
Size
:
64
,
T
:
IntTy
,
stringKind
:
"int64"
},
stringKind
:
"int64[2]"
}},
{
"int256[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
*
big
.
Int
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
T
,
Size
:
256
,
T
:
IntTy
,
stringKind
:
"int256"
},
stringKind
:
"int256[]"
}},
{
"int256[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
*
big
.
Int
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
T
,
Size
:
256
,
T
:
IntTy
,
stringKind
:
"int256"
},
stringKind
:
"int256[2]"
}},
{
"uint8"
,
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
uint8
T
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
}},
{
"uint16"
,
Type
{
Kind
:
reflect
.
Uint16
,
Type
:
uint16
T
,
Size
:
16
,
T
:
UintTy
,
stringKind
:
"uint16"
}},
{
"uint32"
,
Type
{
Kind
:
reflect
.
Uint32
,
Type
:
uint32
T
,
Size
:
32
,
T
:
UintTy
,
stringKind
:
"uint32"
}},
{
"uint64"
,
Type
{
Kind
:
reflect
.
Uint64
,
Type
:
uint64
T
,
Size
:
64
,
T
:
UintTy
,
stringKind
:
"uint64"
}},
{
"uint256"
,
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
T
,
Size
:
256
,
T
:
UintTy
,
stringKind
:
"uint256"
}},
{
"uint8[]"
,
Type
{
Kind
:
reflect
.
Slice
,
T
:
SliceTy
,
Type
:
reflect
.
TypeOf
([]
uint8
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
uint8
T
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
},
stringKind
:
"uint8[]"
}},
{
"uint8[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
uint8
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint8
,
Type
:
uint8
T
,
Size
:
8
,
T
:
UintTy
,
stringKind
:
"uint8"
},
stringKind
:
"uint8[2]"
}},
{
"uint16[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
uint16
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint16
,
Type
:
uint16
T
,
Size
:
16
,
T
:
UintTy
,
stringKind
:
"uint16"
},
stringKind
:
"uint16[]"
}},
{
"uint16[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
uint16
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint16
,
Type
:
uint16
T
,
Size
:
16
,
T
:
UintTy
,
stringKind
:
"uint16"
},
stringKind
:
"uint16[2]"
}},
{
"uint32[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
uint32
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint32
,
Type
:
uint32
T
,
Size
:
32
,
T
:
UintTy
,
stringKind
:
"uint32"
},
stringKind
:
"uint32[]"
}},
{
"uint32[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
uint32
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint32
,
Type
:
uint32
T
,
Size
:
32
,
T
:
UintTy
,
stringKind
:
"uint32"
},
stringKind
:
"uint32[2]"
}},
{
"uint64[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
uint64
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint64
,
Type
:
uint64
T
,
Size
:
64
,
T
:
UintTy
,
stringKind
:
"uint64"
},
stringKind
:
"uint64[]"
}},
{
"uint64[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
uint64
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Uint64
,
Type
:
uint64
T
,
Size
:
64
,
T
:
UintTy
,
stringKind
:
"uint64"
},
stringKind
:
"uint64[2]"
}},
{
"uint256[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
*
big
.
Int
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
T
,
Size
:
256
,
T
:
UintTy
,
stringKind
:
"uint256"
},
stringKind
:
"uint256[]"
}},
{
"uint256[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Type
:
reflect
.
TypeOf
([
2
]
*
big
.
Int
{}),
Size
:
2
,
Elem
:
&
Type
{
Kind
:
reflect
.
Ptr
,
Type
:
big
T
,
Size
:
256
,
T
:
UintTy
,
stringKind
:
"uint256"
},
stringKind
:
"uint256[2]"
}},
{
"bytes32"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
FixedBytesTy
,
Size
:
32
,
Type
:
reflect
.
TypeOf
([
32
]
byte
{}),
stringKind
:
"bytes32"
}},
{
"bytes[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([][]
byte
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
byte
{}),
T
:
BytesTy
,
stringKind
:
"bytes"
},
stringKind
:
"bytes[]"
}},
{
"bytes[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
][]
byte
{}),
Elem
:
&
Type
{
T
:
BytesTy
,
Type
:
reflect
.
TypeOf
([]
byte
{}),
Kind
:
reflect
.
Slice
,
stringKind
:
"bytes"
},
stringKind
:
"bytes[2]"
}},
...
...
@@ -84,9 +84,9 @@ func TestTypeRegexp(t *testing.T) {
{
"string"
,
Type
{
Kind
:
reflect
.
String
,
T
:
StringTy
,
Type
:
reflect
.
TypeOf
(
""
),
stringKind
:
"string"
}},
{
"string[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
string
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
String
,
Type
:
reflect
.
TypeOf
(
""
),
T
:
StringTy
,
stringKind
:
"string"
},
stringKind
:
"string[]"
}},
{
"string[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
string
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
String
,
T
:
StringTy
,
Type
:
reflect
.
TypeOf
(
""
),
stringKind
:
"string"
},
stringKind
:
"string[2]"
}},
{
"address"
,
Type
{
Kind
:
reflect
.
Array
,
Type
:
address
_t
,
Size
:
20
,
T
:
AddressTy
,
stringKind
:
"address"
}},
{
"address[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
common
.
Address
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Array
,
Type
:
address
_t
,
Size
:
20
,
T
:
AddressTy
,
stringKind
:
"address"
},
stringKind
:
"address[]"
}},
{
"address[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
common
.
Address
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Array
,
Type
:
address
_t
,
Size
:
20
,
T
:
AddressTy
,
stringKind
:
"address"
},
stringKind
:
"address[2]"
}},
{
"address"
,
Type
{
Kind
:
reflect
.
Array
,
Type
:
address
T
,
Size
:
20
,
T
:
AddressTy
,
stringKind
:
"address"
}},
{
"address[]"
,
Type
{
T
:
SliceTy
,
Kind
:
reflect
.
Slice
,
Type
:
reflect
.
TypeOf
([]
common
.
Address
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Array
,
Type
:
address
T
,
Size
:
20
,
T
:
AddressTy
,
stringKind
:
"address"
},
stringKind
:
"address[]"
}},
{
"address[2]"
,
Type
{
Kind
:
reflect
.
Array
,
T
:
ArrayTy
,
Size
:
2
,
Type
:
reflect
.
TypeOf
([
2
]
common
.
Address
{}),
Elem
:
&
Type
{
Kind
:
reflect
.
Array
,
Type
:
address
T
,
Size
:
20
,
T
:
AddressTy
,
stringKind
:
"address"
},
stringKind
:
"address[2]"
}},
// TODO when fixed types are implemented properly
// {"fixed", Type{}},
// {"fixed128x128", Type{}},
...
...
@@ -252,6 +252,9 @@ func TestTypeCheck(t *testing.T) {
{
"bytes20"
,
common
.
Address
{},
""
},
{
"address"
,
[
20
]
byte
{},
""
},
{
"address"
,
common
.
Address
{},
""
},
{
"bytes32[]]"
,
""
,
"invalid arg type in abi"
},
{
"invalidType"
,
""
,
"unsupported arg type: invalidType"
},
{
"invalidSlice[]"
,
""
,
"unsupported arg type: invalidSlice"
},
}
{
typ
,
err
:=
NewType
(
test
.
typ
)
if
err
!=
nil
&&
len
(
test
.
err
)
==
0
{
...
...
accounts/abi/unpack_test.go
浏览文件 @
6ab9f0a1
...
...
@@ -56,6 +56,23 @@ var unpackTests = []unpackTest{
enc
:
"0000000000000000000000000000000000000000000000000000000000000001"
,
want
:
true
,
},
{
def
:
`[{ "type": "bool" }]`
,
enc
:
"0000000000000000000000000000000000000000000000000000000000000000"
,
want
:
false
,
},
{
def
:
`[{ "type": "bool" }]`
,
enc
:
"0000000000000000000000000000000000000000000000000001000000000001"
,
want
:
false
,
err
:
"abi: improperly encoded boolean value"
,
},
{
def
:
`[{ "type": "bool" }]`
,
enc
:
"0000000000000000000000000000000000000000000000000000000000000003"
,
want
:
false
,
err
:
"abi: improperly encoded boolean value"
,
},
{
def
:
`[{"type": "uint32"}]`
,
enc
:
"0000000000000000000000000000000000000000000000000000000000000001"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录