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
593b1b65
Commit
593b1b65
authored
Jul 17, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests: document RLP tests
parent
5da82077
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
+20
-4
rlp_test_util.go
tests/rlp_test_util.go
+20
-4
No files found.
tests/rlp_test_util.go
View file @
593b1b65
...
...
@@ -13,11 +13,22 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)
// RLPTest is the JSON structure of a single RLP test.
type
RLPTest
struct
{
In
interface
{}
// If the value of In is "INVALID" or "VALID", the test
// checks whether Out can be decoded into a value of
// type interface{}.
//
// For other JSON values, In is treated as a driver for
// calls to rlp.Stream. The test also verifies that encoding
// In produces the bytes in Out.
In
interface
{}
// Out is a hex-encoded RLP value.
Out
string
}
// RunRLPTest runs the tests in the given file, skipping tests by name.
func
RunRLPTest
(
file
string
,
skip
[]
string
)
error
{
f
,
err
:=
os
.
Open
(
file
)
if
err
!=
nil
{
...
...
@@ -27,6 +38,7 @@ func RunRLPTest(file string, skip []string) error {
return
RunRLPTestWithReader
(
f
,
skip
)
}
// RunRLPTest runs the tests encoded in r, skipping tests by name.
func
RunRLPTestWithReader
(
r
io
.
Reader
,
skip
[]
string
)
error
{
var
tests
map
[
string
]
*
RLPTest
if
err
:=
readJson
(
r
,
&
tests
);
err
!=
nil
{
...
...
@@ -49,6 +61,8 @@ func (t *RLPTest) Run() error {
if
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid hex in Out"
)
}
// Handle simple decoding tests with no actual In value.
if
t
.
In
==
"VALID"
||
t
.
In
==
"INVALID"
{
return
checkDecodeInterface
(
outb
,
t
.
In
==
"VALID"
)
}
...
...
@@ -62,7 +76,7 @@ func (t *RLPTest) Run() error {
if
!
bytes
.
Equal
(
b
,
outb
)
{
return
fmt
.
Errorf
(
"encode produced %x, want %x"
,
b
,
outb
)
}
// Test
decoding from a stream
.
// Test
stream decoding
.
s
:=
rlp
.
NewStream
(
bytes
.
NewReader
(
outb
),
0
)
return
checkDecodeFromJSON
(
s
,
in
)
}
...
...
@@ -103,8 +117,10 @@ func translateJSON(v interface{}) interface{} {
}
}
// checkDecodeFromJSON decodes from s guided by exp. For each JSON
// value, the value decoded from the RLP stream must match.
// checkDecodeFromJSON decodes from s guided by exp. exp drives the
// Stream by invoking decoding operations (Uint, Big, List, ...) based
// on the type of each value. The value decoded from the RLP stream
// must match the JSON value.
func
checkDecodeFromJSON
(
s
*
rlp
.
Stream
,
exp
interface
{})
error
{
switch
exp
:=
exp
.
(
type
)
{
case
uint64
:
...
...
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