@@ -110,8 +110,9 @@ class RLPCodecsSpec extends AnyFlatSpec {
110
110
// Test the original Mantis types to make sure we're on the right track.
111
111
EIP8TestVectors .foreach { case EIP8TestVector (description, data, _) =>
112
112
it should s " decode a ${description} into an original Mantis type " in {
113
- import io .iohk .ethereum .network .discovery .Packet
114
113
import akka .util .ByteString
114
+ import io .iohk .ethereum .network .discovery .Packet
115
+
115
116
val bits = BitVector .fromHex(data).get
116
117
val bytes = ByteString (bits.toByteArray)
117
118
val packet = Packet (bytes)
@@ -120,18 +121,27 @@ class RLPCodecsSpec extends AnyFlatSpec {
120
121
}
121
122
122
123
// Test the RLP decoders in isolation, without crypto.
123
- EIP8TestVectors .take( 5 ). foreach { case EIP8TestVector (description, data, test) =>
124
+ EIP8TestVectors .foreach { case EIP8TestVector (description, data, test) =>
124
125
it should s " decode/encode a ${description}" in {
125
126
val bits = BitVector .fromHex(data).get
126
127
val packet = Codec [Packet ].decodeValue(bits).require
127
128
val payload = Codec [Payload ].decodeValue(packet.data).require
129
+
128
130
test(payload)
131
+
132
+ val encoded = Codec [Payload ].encode(payload).require
133
+ // The packet type should match.
134
+ encoded.take(8 ) shouldBe packet.data.take(8 )
135
+ // The first couple of bytes encode the length,
136
+ // which in the test vector is different ecause it has random data appended to it.
137
+ // Check RLP.encodeLength for details, here I'm just skipping some and see if the rest matches.
138
+ encoded.drop(32 ) shouldBe packet.data.take(encoded.length).drop(32 )
129
139
}
130
140
}
131
141
132
142
// Test the whole Packet unpack function, with RLP and crypto.
133
143
EIP8TestVectors .foreach { case EIP8TestVector (description, data, test) =>
134
- ignore should s " unpack a ${description}" in {
144
+ ignore should s " unpack/pack a ${description}" in {
135
145
val privateKey = PrivateKey (
136
146
BitVector .fromHex(" b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" ).get
137
147
)
@@ -143,6 +153,14 @@ class RLPCodecsSpec extends AnyFlatSpec {
143
153
144
154
// Test again to make sure `unpack` works correctly.
145
155
test(payload)
156
+
157
+ // See if it survives a roundtrip.
158
+ val bits2 = Codec [Packet ].encode(Packet .pack(payload, privateKey).require).require
159
+ val packet2 = Codec [Packet ].decodeValue(bits2).require
160
+ val (payload2, publicKey2) = Packet .unpack(packet).require
161
+
162
+ payload2 shouldBe payload
163
+ publicKey2 shouldBe publicKey
146
164
}
147
165
}
148
166
0 commit comments