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
5c988c8e
Commit
5c988c8e
authored
Apr 04, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Increased test coverage for args
parent
435378e9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
214 additions
and
0 deletions
+214
-0
args_test.go
rpc/args_test.go
+214
-0
No files found.
rpc/args_test.go
View file @
5c988c8e
...
...
@@ -8,6 +8,61 @@ import (
"testing"
)
func
TestBlockheightInvalidString
(
t
*
testing
.
T
)
{
v
:=
"foo"
var
num
int64
str
:=
ExpectInvalidTypeError
(
blockHeight
(
v
,
&
num
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestBlockheightEarliest
(
t
*
testing
.
T
)
{
v
:=
"earliest"
e
:=
int64
(
0
)
var
num
int64
err
:=
blockHeight
(
v
,
&
num
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
num
!=
e
{
t
.
Errorf
(
"Expected %s but got %s"
,
e
,
num
)
}
}
func
TestBlockheightLatest
(
t
*
testing
.
T
)
{
v
:=
"latest"
e
:=
int64
(
-
1
)
var
num
int64
err
:=
blockHeight
(
v
,
&
num
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
num
!=
e
{
t
.
Errorf
(
"Expected %s but got %s"
,
e
,
num
)
}
}
func
TestBlockheightPending
(
t
*
testing
.
T
)
{
v
:=
"pending"
e
:=
int64
(
-
2
)
var
num
int64
err
:=
blockHeight
(
v
,
&
num
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
num
!=
e
{
t
.
Errorf
(
"Expected %s but got %s"
,
e
,
num
)
}
}
func
ExpectValidationError
(
err
error
)
string
{
var
str
string
switch
err
.
(
type
)
{
...
...
@@ -121,6 +176,26 @@ func TestGetBalanceArgs(t *testing.T) {
}
}
func
TestGetBalanceArgsBlocknumMissing
(
t
*
testing
.
T
)
{
input
:=
`["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
expected
:=
new
(
GetBalanceArgs
)
expected
.
Address
=
"0x407d73d8a49eeb85d32cf465507dd71d507100c1"
expected
.
BlockNumber
=
-
1
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
TestGetBalanceArgsLatest
(
t
*
testing
.
T
)
{
input
:=
`["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
expected
:=
new
(
GetBalanceArgs
)
...
...
@@ -231,6 +306,16 @@ func TestGetBlockByHashArgsHashInt(t *testing.T) {
}
}
func
TestGetBlockByHashArgsHashBool
(
t
*
testing
.
T
)
{
input
:=
`[false, true]`
args
:=
new
(
GetBlockByHashArgs
)
str
:=
ExpectInvalidTypeError
(
json
.
Unmarshal
([]
byte
(
input
),
&
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestGetBlockByNumberArgsBlockNum
(
t
*
testing
.
T
)
{
input
:=
`[436, false]`
expected
:=
new
(
GetBlockByNumberArgs
)
...
...
@@ -850,6 +935,26 @@ func TestGetStorageArgs(t *testing.T) {
}
}
func
TestGetStorageArgsMissingBlocknum
(
t
*
testing
.
T
)
{
input
:=
`["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
expected
:=
new
(
GetStorageArgs
)
expected
.
Address
=
"0x407d73d8a49eeb85d32cf465507dd71d507100c1"
expected
.
BlockNumber
=
-
1
args
:=
new
(
GetStorageArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
expected
.
Address
!=
args
.
Address
{
t
.
Errorf
(
"Address shoud be %#v but is %#v"
,
expected
.
Address
,
args
.
Address
)
}
if
expected
.
BlockNumber
!=
args
.
BlockNumber
{
t
.
Errorf
(
"BlockNumber shoud be %#v but is %#v"
,
expected
.
BlockNumber
,
args
.
BlockNumber
)
}
}
func
TestGetStorageInvalidArgs
(
t
*
testing
.
T
)
{
input
:=
`{}`
...
...
@@ -915,6 +1020,31 @@ func TestGetStorageAtArgs(t *testing.T) {
}
}
func
TestGetStorageAtArgsMissingBlocknum
(
t
*
testing
.
T
)
{
input
:=
`["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x0"]`
expected
:=
new
(
GetStorageAtArgs
)
expected
.
Address
=
"0x407d73d8a49eeb85d32cf465507dd71d507100c1"
expected
.
Key
=
"0x0"
expected
.
BlockNumber
=
-
1
args
:=
new
(
GetStorageAtArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
expected
.
Address
!=
args
.
Address
{
t
.
Errorf
(
"Address shoud be %#v but is %#v"
,
expected
.
Address
,
args
.
Address
)
}
if
expected
.
Key
!=
args
.
Key
{
t
.
Errorf
(
"Address shoud be %#v but is %#v"
,
expected
.
Address
,
args
.
Address
)
}
if
expected
.
BlockNumber
!=
args
.
BlockNumber
{
t
.
Errorf
(
"BlockNumber shoud be %#v but is %#v"
,
expected
.
BlockNumber
,
args
.
BlockNumber
)
}
}
func
TestGetStorageAtEmptyArgs
(
t
*
testing
.
T
)
{
input
:=
`[]`
...
...
@@ -1015,6 +1145,26 @@ func TestGetTxCountAddressNotString(t *testing.T) {
}
}
func
TestGetTxCountBlockheightMissing
(
t
*
testing
.
T
)
{
input
:=
`["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]`
expected
:=
new
(
GetTxCountArgs
)
expected
.
Address
=
"0x407d73d8a49eeb85d32cf465507dd71d507100c1"
expected
.
BlockNumber
=
-
1
args
:=
new
(
GetTxCountArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
expected
.
Address
!=
args
.
Address
{
t
.
Errorf
(
"Address shoud be %#v but is %#v"
,
expected
.
Address
,
args
.
Address
)
}
if
expected
.
BlockNumber
!=
args
.
BlockNumber
{
t
.
Errorf
(
"BlockNumber shoud be %#v but is %#v"
,
expected
.
BlockNumber
,
args
.
BlockNumber
)
}
}
func
TestGetTxCountBlockheightInvalid
(
t
*
testing
.
T
)
{
input
:=
`["0x407d73d8a49eeb85d32cf465507dd71d507100c1", {}]`
...
...
@@ -1045,6 +1195,26 @@ func TestGetDataArgs(t *testing.T) {
}
}
func
TestGetDataArgsBlocknumMissing
(
t
*
testing
.
T
)
{
input
:=
`["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"]`
expected
:=
new
(
GetDataArgs
)
expected
.
Address
=
"0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8"
expected
.
BlockNumber
=
-
1
args
:=
new
(
GetDataArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
expected
.
Address
!=
args
.
Address
{
t
.
Errorf
(
"Address shoud be %#v but is %#v"
,
expected
.
Address
,
args
.
Address
)
}
if
expected
.
BlockNumber
!=
args
.
BlockNumber
{
t
.
Errorf
(
"BlockNumber shoud be %#v but is %#v"
,
expected
.
BlockNumber
,
args
.
BlockNumber
)
}
}
func
TestGetDataArgsEmpty
(
t
*
testing
.
T
)
{
input
:=
`[]`
...
...
@@ -1995,6 +2165,50 @@ func TestWhisperIdentityArgsInt(t *testing.T) {
}
}
func
TestBlockNumArgs
(
t
*
testing
.
T
)
{
input
:=
`["0x29a"]`
expected
:=
new
(
BlockNumIndexArgs
)
expected
.
BlockNumber
=
666
args
:=
new
(
BlockNumArg
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
expected
.
BlockNumber
!=
args
.
BlockNumber
{
t
.
Errorf
(
"BlockNumber shoud be %#v but is %#v"
,
expected
.
BlockNumber
,
args
.
BlockNumber
)
}
}
func
TestBlockNumArgsInvalid
(
t
*
testing
.
T
)
{
input
:=
`{}`
args
:=
new
(
BlockNumArg
)
str
:=
ExpectDecodeParamError
(
json
.
Unmarshal
([]
byte
(
input
),
&
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestBlockNumArgsEmpty
(
t
*
testing
.
T
)
{
input
:=
`[]`
args
:=
new
(
BlockNumArg
)
str
:=
ExpectInsufficientParamsError
(
json
.
Unmarshal
([]
byte
(
input
),
&
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestBlockNumArgsBool
(
t
*
testing
.
T
)
{
input
:=
`[true]`
args
:=
new
(
BlockNumArg
)
str
:=
ExpectInvalidTypeError
(
json
.
Unmarshal
([]
byte
(
input
),
&
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestBlockNumIndexArgs
(
t
*
testing
.
T
)
{
input
:=
`["0x29a", "0x0"]`
expected
:=
new
(
BlockNumIndexArgs
)
...
...
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