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
493e0d7b
Commit
493e0d7b
authored
Mar 26, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved GetBlockByNumber tests
parent
93af30a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
4 deletions
+60
-4
args.go
rpc/args.go
+3
-1
args_test.go
rpc/args_test.go
+57
-3
No files found.
rpc/args.go
View file @
493e0d7b
...
...
@@ -81,8 +81,10 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
if
v
,
ok
:=
obj
[
0
]
.
(
float64
);
ok
{
args
.
BlockNumber
=
int64
(
v
)
}
else
if
v
,
ok
:=
obj
[
0
]
.
(
string
);
ok
{
args
.
BlockNumber
=
common
.
Big
(
v
)
.
Int64
()
}
else
{
args
.
BlockNumber
=
common
.
Big
(
obj
[
0
]
.
(
string
))
.
Int64
(
)
return
NewDecodeParamError
(
"blockNumber must be number or string"
)
}
if
len
(
obj
)
>
1
{
...
...
rpc/args_test.go
View file @
493e0d7b
...
...
@@ -145,7 +145,27 @@ func TestGetBlockByHashArgsHashInt(t *testing.T) {
}
}
func
TestGetBlockByNumberArgs
(
t
*
testing
.
T
)
{
func
TestGetBlockByNumberArgsBlockNum
(
t
*
testing
.
T
)
{
input
:=
`[436, false]`
expected
:=
new
(
GetBlockByNumberArgs
)
expected
.
BlockNumber
=
436
expected
.
IncludeTxs
=
false
args
:=
new
(
GetBlockByNumberArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
args
.
BlockNumber
!=
expected
.
BlockNumber
{
t
.
Errorf
(
"BlockNumber should be %v but is %v"
,
expected
.
BlockNumber
,
args
.
BlockNumber
)
}
if
args
.
IncludeTxs
!=
expected
.
IncludeTxs
{
t
.
Errorf
(
"IncludeTxs should be %v but is %v"
,
expected
.
IncludeTxs
,
args
.
IncludeTxs
)
}
}
func
TestGetBlockByNumberArgsBlockHex
(
t
*
testing
.
T
)
{
input
:=
`["0x1b4", false]`
expected
:=
new
(
GetBlockByNumberArgs
)
expected
.
BlockNumber
=
436
...
...
@@ -157,7 +177,7 @@ func TestGetBlockByNumberArgs(t *testing.T) {
}
if
args
.
BlockNumber
!=
expected
.
BlockNumber
{
t
.
Errorf
(
"Block
Hash
should be %v but is %v"
,
expected
.
BlockNumber
,
args
.
BlockNumber
)
t
.
Errorf
(
"Block
Number
should be %v but is %v"
,
expected
.
BlockNumber
,
args
.
BlockNumber
)
}
if
args
.
IncludeTxs
!=
expected
.
IncludeTxs
{
...
...
@@ -170,8 +190,42 @@ func TestGetBlockByNumberEmpty(t *testing.T) {
args
:=
new
(
GetBlockByNumberArgs
)
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
)
if
err
==
nil
{
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
InsufficientParamsError
:
break
default
:
t
.
Errorf
(
"Expected *rpc.InsufficientParamsError but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
func
TestGetBlockByNumberBool
(
t
*
testing
.
T
)
{
input
:=
`[true, true]`
args
:=
new
(
GetBlockByNumberArgs
)
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
)
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParamError
:
break
default
:
t
.
Errorf
(
"Expected *rpc.DecodeParamError but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
func
TestGetBlockByNumberBlockObject
(
t
*
testing
.
T
)
{
input
:=
`{}`
args
:=
new
(
GetBlockByNumberArgs
)
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
)
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParamError
:
break
default
:
t
.
Errorf
(
"Expected *rpc.DecodeParamError but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
...
...
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