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
7b739282
Commit
7b739282
authored
Apr 01, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved response tests
Actually verifies output as by regex
parent
25998cfc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
17 deletions
+117
-17
messages.go
rpc/messages.go
+5
-1
responses_test.go
rpc/responses_test.go
+112
-16
No files found.
rpc/messages.go
View file @
7b739282
...
@@ -50,8 +50,12 @@ func newHexData(input interface{}) *hexdata {
...
@@ -50,8 +50,12 @@ func newHexData(input interface{}) *hexdata {
d
.
data
=
input
.
([]
byte
)
d
.
data
=
input
.
([]
byte
)
case
common
.
Hash
:
case
common
.
Hash
:
d
.
data
=
input
.
(
common
.
Hash
)
.
Bytes
()
d
.
data
=
input
.
(
common
.
Hash
)
.
Bytes
()
case
*
common
.
Hash
:
d
.
data
=
input
.
(
*
common
.
Hash
)
.
Bytes
()
case
common
.
Address
:
case
common
.
Address
:
d
.
data
=
input
.
(
common
.
Address
)
.
Bytes
()
d
.
data
=
input
.
(
common
.
Address
)
.
Bytes
()
case
*
common
.
Address
:
d
.
data
=
input
.
(
*
common
.
Address
)
.
Bytes
()
case
*
big
.
Int
:
case
*
big
.
Int
:
d
.
data
=
input
.
(
*
big
.
Int
)
.
Bytes
()
d
.
data
=
input
.
(
*
big
.
Int
)
.
Bytes
()
case
int64
:
case
int64
:
...
@@ -62,7 +66,7 @@ func newHexData(input interface{}) *hexdata {
...
@@ -62,7 +66,7 @@ func newHexData(input interface{}) *hexdata {
d
.
data
=
big
.
NewInt
(
int64
(
input
.
(
int
)))
.
Bytes
()
d
.
data
=
big
.
NewInt
(
int64
(
input
.
(
int
)))
.
Bytes
()
case
uint
:
case
uint
:
d
.
data
=
big
.
NewInt
(
int64
(
input
.
(
uint
)))
.
Bytes
()
d
.
data
=
big
.
NewInt
(
int64
(
input
.
(
uint
)))
.
Bytes
()
case
string
:
case
string
:
// hexstring
d
.
data
=
common
.
Big
(
input
.
(
string
))
.
Bytes
()
d
.
data
=
common
.
Big
(
input
.
(
string
))
.
Bytes
()
default
:
default
:
d
.
data
=
nil
d
.
data
=
nil
...
...
rpc/responses_test.go
View file @
7b739282
package
rpc
package
rpc
import
(
import
(
"encoding/json"
"fmt"
"math/big"
"math/big"
"regexp"
"testing"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
...
@@ -9,6 +12,15 @@ import (
...
@@ -9,6 +12,15 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
)
)
const
(
reHash
=
`"0x[0-9a-f]{64}"`
// 32 bytes
reHashOpt
=
`"(0x[0-9a-f]{64})"|null`
// 32 bytes or null
reAddress
=
`"0x[0-9a-f]{40}"`
// 20 bytes
reAddressOpt
=
`"0x[0-9a-f]{40}"|null`
// 20 bytes or null
reNum
=
`"0x([1-9a-f][0-9a-f]{1,15})|0"`
// must not have left-padded zeros
reData
=
`"0x[0-9a-f]*"`
// can be "empty"
)
func
TestNewBlockRes
(
t
*
testing
.
T
)
{
func
TestNewBlockRes
(
t
*
testing
.
T
)
{
parentHash
:=
common
.
HexToHash
(
"0x01"
)
parentHash
:=
common
.
HexToHash
(
"0x01"
)
coinbase
:=
common
.
HexToAddress
(
"0x01"
)
coinbase
:=
common
.
HexToAddress
(
"0x01"
)
...
@@ -17,8 +29,35 @@ func TestNewBlockRes(t *testing.T) {
...
@@ -17,8 +29,35 @@ func TestNewBlockRes(t *testing.T) {
nonce
:=
uint64
(
1
)
nonce
:=
uint64
(
1
)
extra
:=
""
extra
:=
""
block
:=
types
.
NewBlock
(
parentHash
,
coinbase
,
root
,
difficulty
,
nonce
,
extra
)
block
:=
types
.
NewBlock
(
parentHash
,
coinbase
,
root
,
difficulty
,
nonce
,
extra
)
tests
:=
map
[
string
]
string
{
"number"
:
reNum
,
"hash"
:
reHash
,
"parentHash"
:
reHash
,
"nonce"
:
reNum
,
"sha3Uncles"
:
reHash
,
"logsBloom"
:
reData
,
"transactionRoot"
:
reHash
,
"stateRoot"
:
reHash
,
"miner"
:
reAddress
,
"difficulty"
:
`"0x1"`
,
"totalDifficulty"
:
reNum
,
"size"
:
reNum
,
"extraData"
:
reData
,
"gasLimit"
:
reNum
,
// "minGasPrice": "0x",
"gasUsed"
:
reNum
,
"timestamp"
:
reNum
,
}
_
=
NewBlockRes
(
block
)
v
:=
NewBlockRes
(
block
)
j
,
_
:=
json
.
Marshal
(
v
)
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. Got %s"
,
k
,
re
,
j
))
}
}
}
}
func
TestNewTransactionRes
(
t
*
testing
.
T
)
{
func
TestNewTransactionRes
(
t
*
testing
.
T
)
{
...
@@ -29,10 +68,80 @@ func TestNewTransactionRes(t *testing.T) {
...
@@ -29,10 +68,80 @@ func TestNewTransactionRes(t *testing.T) {
data
:=
[]
byte
{
1
,
2
,
3
}
data
:=
[]
byte
{
1
,
2
,
3
}
tx
:=
types
.
NewTransactionMessage
(
to
,
amount
,
gasAmount
,
gasPrice
,
data
)
tx
:=
types
.
NewTransactionMessage
(
to
,
amount
,
gasAmount
,
gasPrice
,
data
)
_
=
NewTransactionRes
(
tx
)
tests
:=
map
[
string
]
string
{
"hash"
:
reHash
,
"nonce"
:
reNum
,
"blockHash"
:
reHash
,
"blockNum"
:
reNum
,
"transactionIndex"
:
reNum
,
"from"
:
reAddress
,
"to"
:
reAddressOpt
,
"value"
:
reNum
,
"gas"
:
reNum
,
"gasPrice"
:
reNum
,
"input"
:
reData
,
}
v
:=
NewTransactionRes
(
tx
)
v
.
BlockHash
=
newHexData
(
common
.
HexToHash
(
"0x030201"
))
v
.
BlockNumber
=
newHexNum
(
5
)
v
.
TxIndex
=
newHexNum
(
0
)
j
,
_
:=
json
.
Marshal
(
v
)
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
MakeStateLog
(
num
int
)
state
.
Log
{
func
TestNewLogRes
(
t
*
testing
.
T
)
{
log
:=
makeStateLog
(
0
)
tests
:=
map
[
string
]
string
{
"address"
:
reAddress
,
// "topics": "[.*]"
"data"
:
reData
,
"blockNumber"
:
reNum
,
// "hash": reHash,
// "logIndex": reNum,
// "blockHash": reHash,
// "transactionHash": reHash,
"transactionIndex"
:
reNum
,
}
v
:=
NewLogRes
(
log
)
j
,
_
:=
json
.
Marshal
(
v
)
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. Got %s"
,
k
,
re
,
j
))
}
}
}
func
TestNewLogsRes
(
t
*
testing
.
T
)
{
logs
:=
make
([]
state
.
Log
,
3
)
logs
[
0
]
=
makeStateLog
(
1
)
logs
[
1
]
=
makeStateLog
(
2
)
logs
[
2
]
=
makeStateLog
(
3
)
tests
:=
map
[
string
]
string
{}
v
:=
NewLogsRes
(
logs
)
j
,
_
:=
json
.
Marshal
(
v
)
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. Got %s"
,
k
,
re
,
j
))
}
}
}
func
makeStateLog
(
num
int
)
state
.
Log
{
address
:=
common
.
HexToAddress
(
"0x0"
)
address
:=
common
.
HexToAddress
(
"0x0"
)
data
:=
[]
byte
{
1
,
2
,
3
}
data
:=
[]
byte
{
1
,
2
,
3
}
number
:=
uint64
(
num
)
number
:=
uint64
(
num
)
...
@@ -43,16 +152,3 @@ func MakeStateLog(num int) state.Log {
...
@@ -43,16 +152,3 @@ func MakeStateLog(num int) state.Log {
log
:=
state
.
NewLog
(
address
,
topics
,
data
,
number
)
log
:=
state
.
NewLog
(
address
,
topics
,
data
,
number
)
return
log
return
log
}
}
func
TestNewLogRes
(
t
*
testing
.
T
)
{
log
:=
MakeStateLog
(
0
)
_
=
NewLogRes
(
log
)
}
func
TestNewLogsRes
(
t
*
testing
.
T
)
{
logs
:=
make
([]
state
.
Log
,
3
)
logs
[
0
]
=
MakeStateLog
(
1
)
logs
[
1
]
=
MakeStateLog
(
2
)
logs
[
2
]
=
MakeStateLog
(
3
)
_
=
NewLogsRes
(
logs
)
}
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