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
71e62eb6
Commit
71e62eb6
authored
Apr 04, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More test coverage for responses
parent
2b9b9e77
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
34 deletions
+111
-34
responses_test.go
rpc/responses_test.go
+111
-34
No files found.
rpc/responses_test.go
View file @
71e62eb6
...
...
@@ -26,13 +26,6 @@ const (
)
func
TestNewBlockRes
(
t
*
testing
.
T
)
{
parentHash
:=
common
.
HexToHash
(
"0x01"
)
coinbase
:=
common
.
HexToAddress
(
"0x01"
)
root
:=
common
.
HexToHash
(
"0x01"
)
difficulty
:=
common
.
Big1
nonce
:=
uint64
(
1
)
extra
:=
""
block
:=
types
.
NewBlock
(
parentHash
,
coinbase
,
root
,
difficulty
,
nonce
,
extra
)
tests
:=
map
[
string
]
string
{
"number"
:
reNum
,
"hash"
:
reHash
,
...
...
@@ -55,16 +48,8 @@ func TestNewBlockRes(t *testing.T) {
// "uncles": reListHash,
}
to
:=
common
.
HexToAddress
(
"0x02"
)
amount
:=
big
.
NewInt
(
1
)
gasAmount
:=
big
.
NewInt
(
1
)
gasPrice
:=
big
.
NewInt
(
1
)
data
:=
[]
byte
{
1
,
2
,
3
}
tx
:=
types
.
NewTransactionMessage
(
to
,
amount
,
gasAmount
,
gasPrice
,
data
)
block
:=
makeBlock
()
v
:=
NewBlockRes
(
block
,
false
)
v
.
Transactions
=
make
([]
*
TransactionRes
,
1
)
v
.
Transactions
[
0
]
=
NewTransactionRes
(
tx
)
j
,
_
:=
json
.
Marshal
(
v
)
for
k
,
re
:=
range
tests
{
...
...
@@ -75,14 +60,7 @@ func TestNewBlockRes(t *testing.T) {
}
}
func
TestNewBlockResWithTrans
(
t
*
testing
.
T
)
{
parentHash
:=
common
.
HexToHash
(
"0x01"
)
coinbase
:=
common
.
HexToAddress
(
"0x01"
)
root
:=
common
.
HexToHash
(
"0x01"
)
difficulty
:=
common
.
Big1
nonce
:=
uint64
(
1
)
extra
:=
""
block
:=
types
.
NewBlock
(
parentHash
,
coinbase
,
root
,
difficulty
,
nonce
,
extra
)
func
TestNewBlockResTxFull
(
t
*
testing
.
T
)
{
tests
:=
map
[
string
]
string
{
"number"
:
reNum
,
"hash"
:
reHash
,
...
...
@@ -101,20 +79,12 @@ func TestNewBlockResWithTrans(t *testing.T) {
// "minGasPrice": "0x",
"gasUsed"
:
reNum
,
"timestamp"
:
reNum
,
// "transactions":
`[{.*}]`
,
// "transactions":
reListHash
,
// "uncles": reListHash,
}
to
:=
common
.
HexToAddress
(
"0x02"
)
amount
:=
big
.
NewInt
(
1
)
gasAmount
:=
big
.
NewInt
(
1
)
gasPrice
:=
big
.
NewInt
(
1
)
data
:=
[]
byte
{
1
,
2
,
3
}
tx
:=
types
.
NewTransactionMessage
(
to
,
amount
,
gasAmount
,
gasPrice
,
data
)
block
:=
makeBlock
()
v
:=
NewBlockRes
(
block
,
true
)
v
.
Transactions
=
make
([]
*
TransactionRes
,
1
)
v
.
Transactions
[
0
]
=
NewTransactionRes
(
tx
)
j
,
_
:=
json
.
Marshal
(
v
)
for
k
,
re
:=
range
tests
{
...
...
@@ -125,6 +95,16 @@ func TestNewBlockResWithTrans(t *testing.T) {
}
}
func
TestBlockNil
(
t
*
testing
.
T
)
{
var
block
*
types
.
Block
block
=
nil
u
:=
NewBlockRes
(
block
,
false
)
j
,
_
:=
json
.
Marshal
(
u
)
if
string
(
j
)
!=
"null"
{
t
.
Errorf
(
"Expected null but got %v"
,
string
(
j
))
}
}
func
TestNewTransactionRes
(
t
*
testing
.
T
)
{
to
:=
common
.
HexToAddress
(
"0x02"
)
amount
:=
big
.
NewInt
(
1
)
...
...
@@ -161,6 +141,55 @@ func TestNewTransactionRes(t *testing.T) {
}
func
TestTransactionNil
(
t
*
testing
.
T
)
{
var
tx
*
types
.
Transaction
tx
=
nil
u
:=
NewTransactionRes
(
tx
)
j
,
_
:=
json
.
Marshal
(
u
)
if
string
(
j
)
!=
"null"
{
t
.
Errorf
(
"Expected null but got %v"
,
string
(
j
))
}
}
func
TestNewUncleRes
(
t
*
testing
.
T
)
{
header
:=
makeHeader
()
u
:=
NewUncleRes
(
header
)
tests
:=
map
[
string
]
string
{
"number"
:
reNum
,
"hash"
:
reHash
,
"parentHash"
:
reHash
,
"nonce"
:
reData
,
"sha3Uncles"
:
reHash
,
"receiptHash"
:
reHash
,
"transactionsRoot"
:
reHash
,
"stateRoot"
:
reHash
,
"miner"
:
reAddress
,
"difficulty"
:
reNum
,
"extraData"
:
reData
,
"gasLimit"
:
reNum
,
"gasUsed"
:
reNum
,
"timestamp"
:
reNum
,
}
j
,
_
:=
json
.
Marshal
(
u
)
for
k
,
re
:=
range
tests
{
match
,
_
:=
regexp
.
MatchString
(
fmt
.
Sprintf
(
`{.*"%s":%s.*}`
,
k
,
re
),
string
(
j
))
if
!
match
{
t
.
Error
(
fmt
.
Sprintf
(
"`%s` output json does not match format %s. Source %s"
,
k
,
re
,
j
))
}
}
}
func
TestUncleNil
(
t
*
testing
.
T
)
{
var
header
*
types
.
Header
header
=
nil
u
:=
NewUncleRes
(
header
)
j
,
_
:=
json
.
Marshal
(
u
)
if
string
(
j
)
!=
"null"
{
t
.
Errorf
(
"Expected null but got %v"
,
string
(
j
))
}
}
func
TestNewLogRes
(
t
*
testing
.
T
)
{
log
:=
makeStateLog
(
0
)
tests
:=
map
[
string
]
string
{
...
...
@@ -217,3 +246,51 @@ func makeStateLog(num int) state.Log {
log
:=
state
.
NewLog
(
address
,
topics
,
data
,
number
)
return
log
}
func
makeHeader
()
*
types
.
Header
{
header
:=
&
types
.
Header
{
ParentHash
:
common
.
StringToHash
(
"0x00"
),
UncleHash
:
common
.
StringToHash
(
"0x00"
),
Coinbase
:
common
.
StringToAddress
(
"0x00"
),
Root
:
common
.
StringToHash
(
"0x00"
),
TxHash
:
common
.
StringToHash
(
"0x00"
),
ReceiptHash
:
common
.
StringToHash
(
"0x00"
),
// Bloom:
Difficulty
:
big
.
NewInt
(
88888888
),
Number
:
big
.
NewInt
(
16
),
GasLimit
:
big
.
NewInt
(
70000
),
GasUsed
:
big
.
NewInt
(
25000
),
Time
:
124356789
,
Extra
:
""
,
MixDigest
:
common
.
StringToHash
(
"0x00"
),
Nonce
:
[
8
]
byte
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
},
}
return
header
}
func
makeBlock
()
*
types
.
Block
{
parentHash
:=
common
.
HexToHash
(
"0x01"
)
coinbase
:=
common
.
HexToAddress
(
"0x01"
)
root
:=
common
.
HexToHash
(
"0x01"
)
difficulty
:=
common
.
Big1
nonce
:=
uint64
(
1
)
extra
:=
""
block
:=
types
.
NewBlock
(
parentHash
,
coinbase
,
root
,
difficulty
,
nonce
,
extra
)
txto
:=
common
.
HexToAddress
(
"0x02"
)
txamount
:=
big
.
NewInt
(
1
)
txgasAmount
:=
big
.
NewInt
(
1
)
txgasPrice
:=
big
.
NewInt
(
1
)
txdata
:=
[]
byte
{
1
,
2
,
3
}
tx
:=
types
.
NewTransactionMessage
(
txto
,
txamount
,
txgasAmount
,
txgasPrice
,
txdata
)
txs
:=
make
([]
*
types
.
Transaction
,
1
)
txs
[
0
]
=
tx
block
.
SetTransactions
(
txs
)
uncles
:=
make
([]
*
types
.
Header
,
1
)
uncles
[
0
]
=
makeHeader
()
block
.
SetUncles
(
uncles
)
return
block
}
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