@@ -246,6 +246,60 @@ func TestTLVPayloadMessagePacket(t *testing.T) {
246
246
hex .EncodeToString (finalPacket ), hex .EncodeToString (b .Bytes ()))
247
247
}
248
248
249
+ // TestProcessOnionMessageZeroLengthPayload tests that we can properly process an
250
+ // onion message that has a zero-length payload.
251
+ func TestProcessOnionMessageZeroLengthPayload (t * testing.T ) {
252
+ t .Parallel ()
253
+
254
+ // First, create a router that will be the destination of the onion
255
+ // message.
256
+ privKey , err := btcec .NewPrivateKey ()
257
+ require .NoError (t , err )
258
+
259
+ router := NewRouter (& PrivKeyECDH {privKey }, NewMemoryReplayLog ())
260
+ err = router .Start ()
261
+ require .NoError (t , err )
262
+ defer router .Stop ()
263
+
264
+ // Next, create a session key for the onion packet.
265
+ sessionKey , err := btcec .NewPrivateKey ()
266
+ require .NoError (t , err )
267
+
268
+ // We'll create a simple one-hop path.
269
+ path := & PaymentPath {
270
+ {
271
+ NodePub : * privKey .PubKey (),
272
+ },
273
+ }
274
+
275
+ // The hop payload will be an empty TLV payload.
276
+ payload , err := NewTLVHopPayload (nil )
277
+ require .NoError (t , err )
278
+ path [0 ].HopPayload = payload
279
+
280
+ // Now, create the onion packet.
281
+ onionPacket , err := NewOnionPacket (
282
+ path , sessionKey , nil , DeterministicPacketFiller ,
283
+ )
284
+ require .NoError (t , err )
285
+
286
+ // We'll now process the packet, making sure to indicate that this is
287
+ // an onion message.
288
+ processedPacket , err := router .ProcessOnionPacket (
289
+ onionPacket , nil , 0 , WithIsOnionMessage (),
290
+ )
291
+ require .NoError (t , err )
292
+
293
+ // The packet should be decoded as an exit node.
294
+ require .EqualValues (t , ExitNode , processedPacket .Action )
295
+
296
+ // The payload should be of type TLV.
297
+ require .Equal (t , PayloadTLV , processedPacket .Payload .Type )
298
+
299
+ // And the payload should be empty.
300
+ require .Empty (t , processedPacket .Payload .Payload )
301
+ }
302
+
249
303
func TestSphinxCorrectness (t * testing.T ) {
250
304
nodes , _ , hopDatas , fwdMsg , err := newTestRoute (testLegacyRouteNumHops )
251
305
if err != nil {
0 commit comments