@@ -120,23 +120,31 @@ func newTestVarSizeRoute(numHops int, extraPayloadSize []int) ([]*Router, *Payme
120120
121121 copy (hopData .NextAddress [:], bytes .Repeat ([]byte {byte (i )}, 8 ))
122122
123+ var extraData []byte
124+
125+ // If we were told to increase the payload with some extra data
126+ // do it now.
127+ if extraPayloadSize [i ] > 0 {
128+ extraData = bytes .Repeat ([]byte {'A' }, extraPayloadSize [i ])
129+ }
130+
131+ hopPayload , err := NewHopPayload (0 , & hopData , extraData )
132+ if err != nil {
133+ return nil , nil , nil , nil , fmt .Errorf ("unable to " +
134+ "create new hop payload: %v" , err )
135+ }
136+
123137 route [i ] = OnionHop {
124- NodePub : * nodes [i ].onionKey .PubKey (),
125- HopData : hopData ,
138+ NodePub : * nodes [i ].onionKey .PubKey (),
139+ HopPayload : hopPayload ,
126140 }
127141 }
128142
129- // If we were told to increase the payload with some extra data do it
130- // now:
131143 for i := 0 ; i < route .TrueRouteLength (); i ++ {
132- if extraPayloadSize [i ] > 0 {
133- extra := bytes .Repeat ([]byte {'A' }, extraPayloadSize [i ])
134- route [i ].HopPayload .Payload = append (route [i ].HopPayload .Payload , extra ... )
135- }
136144 }
137145
138146 // Generate a forwarding message to route to the final node via the
139- // generated intermdiates nodes above. Destination should be Hash160,
147+ // generated intermediate nodes above. Destination should be Hash160,
140148 // adding padding so parsing still works.
141149 sessionKey , _ := btcec .PrivKeyFromBytes (
142150 btcec .S256 (), bytes .Repeat ([]byte {'A' }, 32 ),
@@ -172,18 +180,22 @@ func TestBolt4Packet(t *testing.T) {
172180 }
173181
174182 hopData := HopData {
175- Realm : [1 ]byte {0x00 },
176183 ForwardAmount : uint64 (i ),
177184 OutgoingCltv : uint32 (i ),
178185 }
179186 copy (hopData .NextAddress [:], bytes .Repeat ([]byte {byte (i )}, 8 ))
180187 hopsData = append (hopsData , hopData )
181188
189+ hopPayload , err := NewHopPayload (0 , & hopData , nil )
190+ if err != nil {
191+ t .Fatalf ("unable to make hop payload: %v" , err )
192+ }
193+
182194 pubKey .Curve = nil
183195
184196 route [i ] = OnionHop {
185- NodePub : * pubKey ,
186- HopData : hopData ,
197+ NodePub : * pubKey ,
198+ HopPayload : hopPayload ,
187199 }
188200 }
189201
@@ -548,7 +560,7 @@ func TestMultiFrameEncodeDecode(t *testing.T) {
548560 t .Logf ("Processing at hop: %v \n " , i )
549561 onionPacket , err := hop .ProcessOnionPacket (fwdMsg , nil , uint32 (i )+ 1 )
550562 if err != nil {
551- t .Fatalf ("Node %v was unable to process the " +
563+ t .Fatalf ("node %v was unable to process the " +
552564 "forwarding message: %v" , i , err )
553565 }
554566
0 commit comments