Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
5da3d911
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,发现更多精彩内容 >>
提交
5da3d911
编写于
3月 06, 2015
作者:
T
Taylor Gerring
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Initial args tests
上级
18b07686
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
138 addition
and
13 deletion
+138
-13
rpc/args.go
rpc/args.go
+13
-13
rpc/args_test.go
rpc/args_test.go
+125
-0
未找到文件。
rpc/args.go
浏览文件 @
5da3d911
...
@@ -47,7 +47,7 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -47,7 +47,7 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
if
len
(
obj
)
<
1
{
if
len
(
obj
)
<
1
{
return
errArguments
return
errArguments
}
}
args
.
BlockNumber
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
(
string
)
))
args
.
BlockNumber
=
uint64
(
ethutil
.
Big
(
obj
[
0
]
.
(
string
))
.
Int64
(
))
if
len
(
obj
)
>
1
{
if
len
(
obj
)
>
1
{
args
.
Transactions
=
obj
[
1
]
.
(
bool
)
args
.
Transactions
=
obj
[
1
]
.
(
bool
)
...
@@ -110,7 +110,7 @@ func (args *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -110,7 +110,7 @@ func (args *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
args
.
Address
=
obj
[
0
]
.
(
string
)
args
.
Address
=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
>
1
{
if
len
(
obj
)
>
1
{
args
.
BlockNumber
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
1
]
.
(
string
)
))
args
.
BlockNumber
=
uint64
(
ethutil
.
Big
(
obj
[
1
]
.
(
string
))
.
Int64
(
))
}
}
return
nil
return
nil
...
@@ -179,7 +179,7 @@ func (args *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -179,7 +179,7 @@ func (args *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) {
args
.
Address
=
obj
[
0
]
.
(
string
)
args
.
Address
=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
>
1
{
if
len
(
obj
)
>
1
{
args
.
BlockNumber
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
1
]
.
(
string
)
))
args
.
BlockNumber
=
uint64
(
ethutil
.
Big
(
obj
[
1
]
.
(
string
))
.
Int64
(
))
}
}
return
nil
return
nil
...
@@ -210,7 +210,7 @@ func (args *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -210,7 +210,7 @@ func (args *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) {
args
.
Address
=
obj
[
0
]
.
(
string
)
args
.
Address
=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
>
1
{
if
len
(
obj
)
>
1
{
args
.
BlockNumber
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
1
]
.
(
string
)
))
args
.
BlockNumber
=
uint64
(
ethutil
.
Big
(
obj
[
1
]
.
(
string
))
.
Int64
(
))
}
}
return
nil
return
nil
...
@@ -241,7 +241,7 @@ func (args *GetDataArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -241,7 +241,7 @@ func (args *GetDataArgs) UnmarshalJSON(b []byte) (err error) {
args
.
Address
=
obj
[
0
]
.
(
string
)
args
.
Address
=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
>
1
{
if
len
(
obj
)
>
1
{
args
.
BlockNumber
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
1
]
.
(
string
)
))
args
.
BlockNumber
=
uint64
(
ethutil
.
Big
(
obj
[
1
]
.
(
string
))
.
Int64
(
))
}
}
return
nil
return
nil
...
@@ -299,10 +299,10 @@ func (args *FilterArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -299,10 +299,10 @@ func (args *FilterArgs) UnmarshalJSON(b []byte) (err error) {
if
len
(
obj
)
<
1
{
if
len
(
obj
)
<
1
{
return
errArguments
return
errArguments
}
}
args
.
FromBlock
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
FromBlock
))
args
.
FromBlock
=
uint64
(
ethutil
.
Big
(
obj
[
0
]
.
FromBlock
)
.
Int64
(
))
args
.
ToBlock
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
ToBlock
))
args
.
ToBlock
=
uint64
(
ethutil
.
Big
(
obj
[
0
]
.
ToBlock
)
.
Int64
(
))
args
.
Limit
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
Limit
))
args
.
Limit
=
uint64
(
ethutil
.
Big
(
obj
[
0
]
.
Limit
)
.
Int64
(
))
args
.
Offset
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
Offset
))
args
.
Offset
=
uint64
(
ethutil
.
Big
(
obj
[
0
]
.
Offset
)
.
Int64
(
))
args
.
Address
=
obj
[
0
]
.
Address
args
.
Address
=
obj
[
0
]
.
Address
args
.
Topics
=
obj
[
0
]
.
Topics
args
.
Topics
=
obj
[
0
]
.
Topics
...
@@ -335,10 +335,10 @@ func (args *FilterOptions) UnmarshalJSON(b []byte) (err error) {
...
@@ -335,10 +335,10 @@ func (args *FilterOptions) UnmarshalJSON(b []byte) (err error) {
if
len
(
obj
)
<
1
{
if
len
(
obj
)
<
1
{
return
errArguments
return
errArguments
}
}
args
.
Earliest
=
int64
(
ethutil
.
B
ytesToNumber
(
fromHex
(
obj
[
0
]
.
FromBlock
)
))
args
.
Earliest
=
int64
(
ethutil
.
B
ig
(
obj
[
0
]
.
FromBlock
)
.
Int64
(
))
args
.
Latest
=
int64
(
ethutil
.
B
ytesToNumber
(
fromHex
(
obj
[
0
]
.
ToBlock
)
))
args
.
Latest
=
int64
(
ethutil
.
B
ig
(
obj
[
0
]
.
ToBlock
)
.
Int64
(
))
args
.
Max
=
int
(
ethutil
.
B
ytesToNumber
(
fromHex
(
obj
[
0
]
.
Limit
)
))
args
.
Max
=
int
(
ethutil
.
B
ig
(
obj
[
0
]
.
Limit
)
.
Int64
(
))
args
.
Skip
=
int
(
ethutil
.
B
ytesToNumber
(
fromHex
(
obj
[
0
]
.
Offset
)
))
args
.
Skip
=
int
(
ethutil
.
B
ig
(
obj
[
0
]
.
Offset
)
.
Int64
(
))
args
.
Address
=
obj
[
0
]
.
Address
args
.
Address
=
obj
[
0
]
.
Address
args
.
Topic
=
obj
[
0
]
.
Topics
args
.
Topic
=
obj
[
0
]
.
Topics
...
...
rpc/args_test.go
0 → 100644
浏览文件 @
5da3d911
package
rpc
import
(
"bytes"
"encoding/json"
"math/big"
"testing"
)
func
TestSha3
(
t
*
testing
.
T
)
{
input
:=
`["0x68656c6c6f20776f726c64"]`
expected
:=
"0x68656c6c6f20776f726c64"
args
:=
new
(
Sha3Args
)
json
.
Unmarshal
([]
byte
(
input
),
&
args
)
if
args
.
Data
!=
expected
{
t
.
Error
(
"got %s expected %s"
,
input
,
expected
)
}
}
func
TestGetBalanceArgs
(
t
*
testing
.
T
)
{
input
:=
`["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x1f"]`
expected
:=
new
(
GetBalanceArgs
)
expected
.
Address
=
"0x407d73d8a49eeb85d32cf465507dd71d507100c1"
expected
.
BlockNumber
=
31
args
:=
new
(
GetBalanceArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
args
.
Address
!=
expected
.
Address
{
t
.
Errorf
(
"Address should be %v but is %v"
,
expected
.
Address
,
args
.
Address
)
}
if
args
.
BlockNumber
!=
expected
.
BlockNumber
{
t
.
Errorf
(
"BlockNumber should be %v but is %v"
,
expected
.
BlockNumber
,
args
.
BlockNumber
)
}
}
func
TestGetBlockByHashArgs
(
t
*
testing
.
T
)
{
input
:=
`["0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", true]`
expected
:=
new
(
GetBlockByHashArgs
)
expected
.
BlockHash
=
"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
expected
.
Transactions
=
true
args
:=
new
(
GetBlockByHashArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
args
.
BlockHash
!=
expected
.
BlockHash
{
t
.
Errorf
(
"BlockHash should be %v but is %v"
,
expected
.
BlockHash
,
args
.
BlockHash
)
}
if
args
.
Transactions
!=
expected
.
Transactions
{
t
.
Errorf
(
"Transactions should be %v but is %v"
,
expected
.
Transactions
,
args
.
Transactions
)
}
}
func
TestGetBlockByNumberArgs
(
t
*
testing
.
T
)
{
input
:=
`["0x1b4", false]`
expected
:=
new
(
GetBlockByNumberArgs
)
expected
.
BlockNumber
=
436
expected
.
Transactions
=
false
args
:=
new
(
GetBlockByNumberArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
args
.
BlockNumber
!=
expected
.
BlockNumber
{
t
.
Errorf
(
"BlockHash should be %v but is %v"
,
expected
.
BlockNumber
,
args
.
BlockNumber
)
}
if
args
.
Transactions
!=
expected
.
Transactions
{
t
.
Errorf
(
"Transactions should be %v but is %v"
,
expected
.
Transactions
,
args
.
Transactions
)
}
}
func
TestNewTxArgs
(
t
*
testing
.
T
)
{
input
:=
`[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
"gas": "0x76c0",
"gasPrice": "0x9184e72a000",
"value": "0x9184e72a000",
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}]`
expected
:=
new
(
NewTxArgs
)
expected
.
From
=
"0xb60e8dd61c5d32be8058bb8eb970870f07233155"
expected
.
To
=
"0xd46e8dd67c5d32be8058bb8eb970870f072445675"
expected
.
Gas
=
big
.
NewInt
(
30400
)
expected
.
GasPrice
=
big
.
NewInt
(
10000000000000
)
expected
.
Value
=
big
.
NewInt
(
10000000000000
)
expected
.
Data
=
"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
args
:=
new
(
NewTxArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
expected
.
From
!=
args
.
From
{
t
.
Errorf
(
"From shoud be %#v but is %#v"
,
expected
.
From
,
args
.
From
)
}
if
expected
.
To
!=
args
.
To
{
t
.
Errorf
(
"To shoud be %#v but is %#v"
,
expected
.
To
,
args
.
To
)
}
if
bytes
.
Compare
(
expected
.
Gas
.
Bytes
(),
args
.
Gas
.
Bytes
())
!=
0
{
t
.
Errorf
(
"Gas shoud be %#v but is %#v"
,
expected
.
Gas
.
Bytes
(),
args
.
Gas
.
Bytes
())
}
if
bytes
.
Compare
(
expected
.
GasPrice
.
Bytes
(),
args
.
GasPrice
.
Bytes
())
!=
0
{
t
.
Errorf
(
"GasPrice shoud be %#v but is %#v"
,
expected
.
GasPrice
,
args
.
GasPrice
)
}
if
bytes
.
Compare
(
expected
.
Value
.
Bytes
(),
args
.
Value
.
Bytes
())
!=
0
{
t
.
Errorf
(
"Value shoud be %#v but is %#v"
,
expected
.
Value
,
args
.
Value
)
}
if
expected
.
Data
!=
args
.
Data
{
t
.
Errorf
(
"Data shoud be %#v but is %#v"
,
expected
.
Data
,
args
.
Data
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录