@@ -81,7 +81,7 @@ class RLPCodecsSpec extends AnyFlatSpec with Matchers {
81
81
82
82
// The following tests demonstrate what each payload looks like when encoded to RLP,
83
83
// because the auto-derivation makes it opaque.
84
- abstract class EncodeFixture [T <: Payload : RLPEncoder : ClassTag ] {
84
+ abstract class RLPFixture [T <: Payload : RLPEncoder : RLPDecoder : ClassTag ] {
85
85
// Structrual equality checker for RLPEncodeable.
86
86
// It has different wrappers for items based on whether it was hand crafted or generated
87
87
// by codecs, and the RLPValue has mutable arrays inside.
@@ -104,11 +104,12 @@ class RLPCodecsSpec extends AnyFlatSpec with Matchers {
104
104
def p : T
105
105
def e : RLPEncodeable
106
106
107
- def test = RLPEncoder .encode(p) should equal(e)
107
+ def testEncode = RLPEncoder .encode(p) should equal(e)
108
+ def testDecode = RLPDecoder .decode[T ](e) should equal(p)
108
109
}
109
110
110
111
val examples = List (
111
- new EncodeFixture [Payload .Ping ] {
112
+ new RLPFixture [Payload .Ping ] {
112
113
override val p = Payload .Ping (
113
114
version = 4 ,
114
115
from = Node .Address (localhost, 30000 , 40000 ),
@@ -125,7 +126,7 @@ class RLPCodecsSpec extends AnyFlatSpec with Matchers {
125
126
p.enrSeq.get
126
127
)
127
128
},
128
- new EncodeFixture [Payload .Pong ] {
129
+ new RLPFixture [Payload .Pong ] {
129
130
override val p = Payload .Pong (
130
131
to = Node .Address (localhost, 30001 , 0 ),
131
132
pingHash = Hash (randomBytes(32 )),
@@ -144,15 +145,15 @@ class RLPCodecsSpec extends AnyFlatSpec with Matchers {
144
145
p.enrSeq.get
145
146
)
146
147
},
147
- new EncodeFixture [Payload .FindNode ] {
148
+ new RLPFixture [Payload .FindNode ] {
148
149
override val p = Payload .FindNode (
149
150
target = PublicKey (randomBytes(64 )),
150
151
expiration = System .currentTimeMillis
151
152
)
152
153
153
154
override val e = RLPList (p.target, p.expiration)
154
155
},
155
- new EncodeFixture [Payload .Neighbors ] {
156
+ new RLPFixture [Payload .Neighbors ] {
156
157
override val p = Payload .Neighbors (
157
158
nodes = List (
158
159
Node (id = PublicKey (randomBytes(64 )), address = Node .Address (localhost, 30001 , 40001 )),
@@ -169,7 +170,7 @@ class RLPCodecsSpec extends AnyFlatSpec with Matchers {
169
170
p.expiration
170
171
)
171
172
},
172
- new EncodeFixture [Payload .ENRRequest ] {
173
+ new RLPFixture [Payload .ENRRequest ] {
173
174
override val p = Payload .ENRRequest (
174
175
expiration = System .currentTimeMillis
175
176
)
@@ -178,7 +179,7 @@ class RLPCodecsSpec extends AnyFlatSpec with Matchers {
178
179
p.expiration
179
180
)
180
181
},
181
- new EncodeFixture [Payload .ENRResponse ] {
182
+ new RLPFixture [Payload .ENRResponse ] {
182
183
val (publicKey, privateKey) = sigalg.newKeyPair
183
184
val node = Node (
184
185
id = publicKey,
@@ -215,7 +216,11 @@ class RLPCodecsSpec extends AnyFlatSpec with Matchers {
215
216
216
217
examples.foreach { example =>
217
218
it should s " encode the example ${example.name}" in {
218
- example.test
219
+ example.testEncode
220
+ }
221
+
222
+ it should s " decode the example ${example.name}" in {
223
+ example.testDecode
219
224
}
220
225
}
221
226
}
0 commit comments