@@ -13,11 +13,22 @@ import (
1313 "github.com/ethereum/go-ethereum/rlp"
1414)
1515
16+ // RLPTest is the JSON structure of a single RLP test.
1617type RLPTest struct {
17- In interface {}
18+ // If the value of In is "INVALID" or "VALID", the test
19+ // checks whether Out can be decoded into a value of
20+ // type interface{}.
21+ //
22+ // For other JSON values, In is treated as a driver for
23+ // calls to rlp.Stream. The test also verifies that encoding
24+ // In produces the bytes in Out.
25+ In interface {}
26+
27+ // Out is a hex-encoded RLP value.
1828 Out string
1929}
2030
31+ // RunRLPTest runs the tests in the given file, skipping tests by name.
2132func RunRLPTest (file string , skip []string ) error {
2233 f , err := os .Open (file )
2334 if err != nil {
@@ -27,6 +38,7 @@ func RunRLPTest(file string, skip []string) error {
2738 return RunRLPTestWithReader (f , skip )
2839}
2940
41+ // RunRLPTest runs the tests encoded in r, skipping tests by name.
3042func RunRLPTestWithReader (r io.Reader , skip []string ) error {
3143 var tests map [string ]* RLPTest
3244 if err := readJson (r , & tests ); err != nil {
@@ -49,6 +61,8 @@ func (t *RLPTest) Run() error {
4961 if err != nil {
5062 return fmt .Errorf ("invalid hex in Out" )
5163 }
64+
65+ // Handle simple decoding tests with no actual In value.
5266 if t .In == "VALID" || t .In == "INVALID" {
5367 return checkDecodeInterface (outb , t .In == "VALID" )
5468 }
@@ -62,7 +76,7 @@ func (t *RLPTest) Run() error {
6276 if ! bytes .Equal (b , outb ) {
6377 return fmt .Errorf ("encode produced %x, want %x" , b , outb )
6478 }
65- // Test decoding from a stream.
79+ // Test stream decoding .
6680 s := rlp .NewStream (bytes .NewReader (outb ), 0 )
6781 return checkDecodeFromJSON (s , in )
6882}
@@ -103,8 +117,10 @@ func translateJSON(v interface{}) interface{} {
103117 }
104118}
105119
106- // checkDecodeFromJSON decodes from s guided by exp. For each JSON
107- // value, the value decoded from the RLP stream must match.
120+ // checkDecodeFromJSON decodes from s guided by exp. exp drives the
121+ // Stream by invoking decoding operations (Uint, Big, List, ...) based
122+ // on the type of each value. The value decoded from the RLP stream
123+ // must match the JSON value.
108124func checkDecodeFromJSON (s * rlp.Stream , exp interface {}) error {
109125 switch exp := exp .(type ) {
110126 case uint64 :
0 commit comments