Skip to content

Commit 9334bde

Browse files
committed
add named tests
1 parent 16afd51 commit 9334bde

File tree

5 files changed

+66
-12
lines changed

5 files changed

+66
-12
lines changed

rlp/rlpgen/gen_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func init() {
4747
}
4848
}
4949

50-
var tests = []string{"uints", "nil", "rawvalue", "optional", "bigint", "uint256", "alias"}
50+
var tests = []string{"uints", "nil", "rawvalue", "optional", "bigint", "uint256", "alias", "named"}
5151

5252
func TestOutput(t *testing.T) {
5353
for _, test := range tests {
@@ -66,7 +66,7 @@ func TestOutput(t *testing.T) {
6666

6767
// Set this environment variable to regenerate the test outputs.
6868
if os.Getenv("WRITE_TEST_FILES") != "" {
69-
os.WriteFile(outputFile, output, 0644)
69+
os.WriteFile(outputFile, output, 0o644)
7070
}
7171

7272
// Check if output matches.

rlp/rlpgen/testdata/alias.in.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ type (
1414
// Demonstrate recursive unaliasing
1515
intermediate = uint256.Int
1616
Uint256 = intermediate
17-
Uint64T uint64 // This is not an alias, it's a new type
1817
)
1918

2019
type Test struct {
2120
BigAlias Big
2221
Uint256Alias Uint256
23-
Uint64NewT Uint64T
2422
}

rlp/rlpgen/testdata/alias.out.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ func (obj *Test) EncodeRLP(_w io.Writer) error {
1212
}
1313
w.WriteBigInt(&obj.BigAlias)
1414
w.WriteUint256(&obj.Uint256Alias)
15-
w.WriteUint64(uint64(obj.Uint64NewT))
1615
w.ListEnd(_tmp0)
1716
return w.Flush()
1817
}
@@ -35,13 +34,6 @@ func (obj *Test) DecodeRLP(dec *rlp.Stream) error {
3534
return err
3635
}
3736
_tmp0.Uint256Alias = _tmp2
38-
// Uint64NewT:
39-
_tmp3, err := dec.Uint64()
40-
if err != nil {
41-
return err
42-
}
43-
_tmp4 := Uint64T(_tmp3)
44-
_tmp0.Uint64NewT = _tmp4
4537
if err := dec.ListEnd(); err != nil {
4638
return err
4739
}

rlp/rlpgen/testdata/named.in.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// -*- mode: go -*-
2+
3+
package test
4+
5+
type (
6+
BoolT bool
7+
Uint64T uint64
8+
StringT string
9+
)
10+
11+
type Test struct {
12+
BoolNewT BoolT
13+
Uint64NewT Uint64T
14+
StringNewT StringT
15+
}

rlp/rlpgen/testdata/named.out.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package test
2+
3+
import "github.com/ava-labs/libevm/rlp"
4+
import "io"
5+
6+
func (obj *Test) EncodeRLP(_w io.Writer) error {
7+
w := rlp.NewEncoderBuffer(_w)
8+
_tmp0 := w.List()
9+
w.WriteBool(bool(obj.BoolNewT))
10+
w.WriteUint64(uint64(obj.Uint64NewT))
11+
w.WriteString(string(obj.StringNewT))
12+
w.ListEnd(_tmp0)
13+
return w.Flush()
14+
}
15+
16+
func (obj *Test) DecodeRLP(dec *rlp.Stream) error {
17+
var _tmp0 Test
18+
{
19+
if _, err := dec.List(); err != nil {
20+
return err
21+
}
22+
// BoolNewT:
23+
_tmp1, err := dec.Bool()
24+
if err != nil {
25+
return err
26+
}
27+
_tmp2 := BoolT(_tmp1)
28+
_tmp0.BoolNewT = _tmp2
29+
// Uint64NewT:
30+
_tmp3, err := dec.Uint64()
31+
if err != nil {
32+
return err
33+
}
34+
_tmp4 := Uint64T(_tmp3)
35+
_tmp0.Uint64NewT = _tmp4
36+
// StringNewT:
37+
_tmp5, err := dec.String()
38+
if err != nil {
39+
return err
40+
}
41+
_tmp6 := StringT(_tmp5)
42+
_tmp0.StringNewT = _tmp6
43+
if err := dec.ListEnd(); err != nil {
44+
return err
45+
}
46+
}
47+
*obj = _tmp0
48+
return nil
49+
}

0 commit comments

Comments
 (0)