@@ -3,7 +3,6 @@ package routing
33import (
44 "bytes"
55 "crypto/sha256"
6- "encoding/binary"
76 "encoding/hex"
87 "encoding/json"
98 "errors"
@@ -25,6 +24,7 @@ import (
2524 "github.com/lightningnetwork/lnd/channeldb"
2625 "github.com/lightningnetwork/lnd/channeldb/models"
2726 "github.com/lightningnetwork/lnd/htlcswitch"
27+ switchhop "github.com/lightningnetwork/lnd/htlcswitch/hop"
2828 "github.com/lightningnetwork/lnd/kvdb"
2929 "github.com/lightningnetwork/lnd/lnwire"
3030 "github.com/lightningnetwork/lnd/record"
@@ -1030,7 +1030,8 @@ var basicGraphPathFindingTests = []basicGraphPathFindingTestCase{
10301030 // Basic route with fee limit.
10311031 {target : "sophon" , paymentAmt : 100 , feeLimit : 50 ,
10321032 expectFailureNoPath : true ,
1033- }}
1033+ },
1034+ }
10341035
10351036func runBasicGraphPathFinding (t * testing.T , useCache bool ) {
10361037 testGraphInstance , err := parseTestGraph (t , useCache , basicGraphFilePath )
@@ -1123,32 +1124,27 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
11231124
11241125 // Hops should point to the next hop
11251126 for i := 0 ; i < len (expectedHops )- 1 ; i ++ {
1126- var expectedHop [8 ]byte
1127- binary .BigEndian .PutUint64 (expectedHop [:], route .Hops [i + 1 ].ChannelID )
1128-
1129- hopData , err := sphinxPath [i ].HopPayload .HopData ()
1130- if err != nil {
1131- t .Fatalf ("unable to make hop data: %v" , err )
1132- }
1127+ payload , _ , err := switchhop .ParseTLVPayload (
1128+ bytes .NewReader (sphinxPath [i ].HopPayload .Payload ),
1129+ )
1130+ require .NoError (t , err )
11331131
1134- if ! bytes .Equal (hopData . NextAddress [:], expectedHop [:]) {
1135- t . Fatalf ( "first hop has incorrect next hop: expected %x, got %x" ,
1136- expectedHop [:], hopData . NextAddress [:])
1137- }
1132+ require .Equal (
1133+ t , route . Hops [ i + 1 ]. ChannelID ,
1134+ payload . FwdInfo . NextHop . ToUint64 (),
1135+ )
11381136 }
11391137
1140- // The final hop should have a next hop value of all zeroes in order
1141- // to indicate it's the exit hop.
1142- var exitHop [8 ]byte
11431138 lastHopIndex := len (expectedHops ) - 1
11441139
1145- hopData , err := sphinxPath [lastHopIndex ].HopPayload .HopData ()
1146- require .NoError (t , err , "unable to create hop data" )
1140+ payload , _ , err := switchhop .ParseTLVPayload (
1141+ bytes .NewReader (sphinxPath [lastHopIndex ].HopPayload .Payload ),
1142+ )
1143+ require .NoError (t , err )
11471144
1148- if ! bytes .Equal (hopData .NextAddress [:], exitHop [:]) {
1149- t .Fatalf ("first hop has incorrect next hop: expected %x, got %x" ,
1150- exitHop [:], hopData .NextAddress )
1151- }
1145+ // The final hop should have a next hop value of all zeroes in order
1146+ // to indicate it's the exit hop.
1147+ require .Zero (t , payload .FwdInfo .NextHop .ToUint64 ())
11521148
11531149 var expectedTotalFee lnwire.MilliSatoshi
11541150 for i := 0 ; i < expectedHopCount ; i ++ {
0 commit comments