8686 "2cf4f0731da13b8546d1d6d4f8d75b9fce6c2341a71b0ea6f780" +
8787 "df54bfdb0dd5cd9855179f602f917265f21f9190c70217774a6f" +
8888 "baaa7d63ad64199f4664813b955cff954949076dcf"
89+
90+ testLegacyRouteNumHops = 20
8991)
9092
9193func newTestRoute (numHops int ) ([]* Router , * PaymentPath , * []HopData , * OnionPacket , error ) {
@@ -214,7 +216,7 @@ func TestBolt4Packet(t *testing.T) {
214216}
215217
216218func TestSphinxCorrectness (t * testing.T ) {
217- nodes , _ , hopDatas , fwdMsg , err := newTestRoute (NumMaxHops )
219+ nodes , _ , hopDatas , fwdMsg , err := newTestRoute (testLegacyRouteNumHops )
218220 if err != nil {
219221 t .Fatalf ("unable to create random onion packet: %v" , err )
220222 }
@@ -307,7 +309,7 @@ func TestSphinxSingleHop(t *testing.T) {
307309func TestSphinxNodeRelpay (t * testing.T ) {
308310 // We'd like to ensure that the sphinx node itself rejects all replayed
309311 // packets which share the same shared secret.
310- nodes , _ , _ , fwdMsg , err := newTestRoute (NumMaxHops )
312+ nodes , _ , _ , fwdMsg , err := newTestRoute (testLegacyRouteNumHops )
311313 if err != nil {
312314 t .Fatalf ("unable to create test route: %v" , err )
313315 }
@@ -332,7 +334,7 @@ func TestSphinxNodeRelpay(t *testing.T) {
332334func TestSphinxNodeRelpaySameBatch (t * testing.T ) {
333335 // We'd like to ensure that the sphinx node itself rejects all replayed
334336 // packets which share the same shared secret.
335- nodes , _ , _ , fwdMsg , err := newTestRoute (NumMaxHops )
337+ nodes , _ , _ , fwdMsg , err := newTestRoute (testLegacyRouteNumHops )
336338 if err != nil {
337339 t .Fatalf ("unable to create test route: %v" , err )
338340 }
@@ -378,7 +380,7 @@ func TestSphinxNodeRelpaySameBatch(t *testing.T) {
378380func TestSphinxNodeRelpayLaterBatch (t * testing.T ) {
379381 // We'd like to ensure that the sphinx node itself rejects all replayed
380382 // packets which share the same shared secret.
381- nodes , _ , _ , fwdMsg , err := newTestRoute (NumMaxHops )
383+ nodes , _ , _ , fwdMsg , err := newTestRoute (testLegacyRouteNumHops )
382384 if err != nil {
383385 t .Fatalf ("unable to create test route: %v" , err )
384386 }
@@ -423,7 +425,7 @@ func TestSphinxNodeRelpayLaterBatch(t *testing.T) {
423425func TestSphinxNodeReplayBatchIdempotency (t * testing.T ) {
424426 // We'd like to ensure that the sphinx node itself rejects all replayed
425427 // packets which share the same shared secret.
426- nodes , _ , _ , fwdMsg , err := newTestRoute (NumMaxHops )
428+ nodes , _ , _ , fwdMsg , err := newTestRoute (testLegacyRouteNumHops )
427429 if err != nil {
428430 t .Fatalf ("unable to create test route: %v" , err )
429431 }
@@ -563,8 +565,7 @@ func newEOBRoute(numHops uint32,
563565 )
564566 fwdMsg , err := NewOnionPacket (& route , sessionKey , nil )
565567 if err != nil {
566- return nil , nil , fmt .Errorf ("unable to create forwarding " +
567- "message: %#v" , err )
568+ return nil , nil , err
568569 }
569570
570571 return fwdMsg , nodes , nil
@@ -587,8 +588,9 @@ func TestSphinxHopVariableSizedPayloads(t *testing.T) {
587588 t .Parallel ()
588589
589590 var testCases = []struct {
590- numNodes uint32
591- eobMapping map [int ]HopPayload
591+ numNodes uint32
592+ eobMapping map [int ]HopPayload
593+ expectedError error
592594 }{
593595 // A single hop route with a payload going to the last hop in
594596 // the route. The payload is enough to fit into what would be
@@ -598,7 +600,7 @@ func TestSphinxHopVariableSizedPayloads(t *testing.T) {
598600 eobMapping : map [int ]HopPayload {
599601 0 : HopPayload {
600602 Type : PayloadTLV ,
601- Payload : bytes .Repeat ([]byte ("a" ), HopDataSize - HMACSize ),
603+ Payload : bytes .Repeat ([]byte ("a" ), LegacyHopDataSize - HMACSize ),
602604 },
603605 },
604606 },
@@ -610,7 +612,7 @@ func TestSphinxHopVariableSizedPayloads(t *testing.T) {
610612 eobMapping : map [int ]HopPayload {
611613 0 : HopPayload {
612614 Type : PayloadTLV ,
613- Payload : bytes .Repeat ([]byte ("a" ), HopDataSize * 3 ),
615+ Payload : bytes .Repeat ([]byte ("a" ), LegacyHopDataSize * 3 ),
614616 },
615617 },
616618 },
@@ -631,7 +633,7 @@ func TestSphinxHopVariableSizedPayloads(t *testing.T) {
631633 }, nil ),
632634 1 : HopPayload {
633635 Type : PayloadTLV ,
634- Payload : bytes .Repeat ([]byte ("a" ), HopDataSize * 2 ),
636+ Payload : bytes .Repeat ([]byte ("a" ), LegacyHopDataSize * 2 ),
635637 },
636638 },
637639 },
@@ -678,16 +680,40 @@ func TestSphinxHopVariableSizedPayloads(t *testing.T) {
678680 },
679681 },
680682 },
683+
684+ // A 3 hop route (4 nodes) that carries more data then what fits
685+ // in the routing info.
686+ {
687+ numNodes : 3 ,
688+ eobMapping : map [int ]HopPayload {
689+ 0 : HopPayload {
690+ Type : PayloadTLV ,
691+ Payload : bytes .Repeat ([]byte ("a" ), 500 ),
692+ },
693+ 1 : HopPayload {
694+ Type : PayloadTLV ,
695+ Payload : bytes .Repeat ([]byte ("a" ), 500 ),
696+ },
697+ 2 : HopPayload {
698+ Type : PayloadTLV ,
699+ Payload : bytes .Repeat ([]byte ("a" ), 500 ),
700+ },
701+ },
702+ expectedError : ErrMaxRoutingInfoSizeExceeded ,
703+ },
681704 }
682705
683706 for testCaseNum , testCase := range testCases {
684707 nextPkt , routers , err := newEOBRoute (
685708 testCase .numNodes , testCase .eobMapping ,
686709 )
687- if err != nil {
710+ if testCase . expectedError != err {
688711 t .Fatalf ("#%v: unable to create eob " +
689712 "route: %v" , testCase , err )
690713 }
714+ if err != nil {
715+ continue
716+ }
691717
692718 // We'll now walk thru manually each actual hop within the
693719 // route. We use the size of the routers rather than the number
0 commit comments