good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
7b739282
Commit
7b739282
authored
Apr 1, 2015
by
Taylor Gerring
Browse files
Options
Downloads
Patches
Plain Diff
Improved response tests
Actually verifies output as by regex
parent
25998cfc
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
rpc/messages.go
+5
-1
5 additions, 1 deletion
rpc/messages.go
rpc/responses_test.go
+112
-16
112 additions, 16 deletions
rpc/responses_test.go
with
117 additions
and
17 deletions
rpc/messages.go
+
5
−
1
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
...
...
This diff is collapsed.
Click to expand it.
rpc/responses_test.go
+
112
−
16
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
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
M
akeStateLog
(
num
int
)
state
.
Log
{
func
m
akeStateLog
(
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
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment