diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index de7c16c6..545aefd8 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -2247,26 +2247,35 @@ func TestNewRouteFromEmptyHops(t *testing.T) { func TestRestrictOutgoingChannel(t *testing.T) { t.Parallel() + // Define channel id constants + const ( + chanSourceA = 1 + chanATarget = 4 + chanSourceB1 = 2 + chanSourceB2 = 3 + chanBTarget = 5 + ) + // Set up a test graph with three possible paths from roasbeef to - // target. The path through channel 2 is the highest cost path. + // target. The path through chanSourceB1 is the highest cost path. testChannels := []*testChannel{ symmetricTestChannel("roasbeef", "a", 100000, &testChannelPolicy{ Expiry: 144, - }, 1), + }, chanSourceA), symmetricTestChannel("a", "target", 100000, &testChannelPolicy{ Expiry: 144, FeeRate: 400, - }, 4), + }, chanATarget), symmetricTestChannel("roasbeef", "b", 100000, &testChannelPolicy{ Expiry: 144, - }, 2), + }, chanSourceB1), symmetricTestChannel("roasbeef", "b", 100000, &testChannelPolicy{ Expiry: 144, - }, 3), + }, chanSourceB2), symmetricTestChannel("b", "target", 100000, &testChannelPolicy{ Expiry: 144, FeeRate: 800, - }, 5), + }, chanBTarget), } ctx := newPathFindingTestContext(t, testChannels, "roasbeef") @@ -2279,32 +2288,22 @@ func TestRestrictOutgoingChannel(t *testing.T) { paymentAmt := lnwire.NewMSatFromSatoshis(100) target := ctx.keyFromAlias("target") - outgoingChannelID := uint64(2) + outgoingChannelID := uint64(chanSourceB1) - // Find the best path given the restriction to only use channel 2 as the - // outgoing channel. + // Find the best path given the restriction to only use chanSourceB1 as + // the outgoing channel. ctx.restrictParams.OutgoingChannelID = &outgoingChannelID path, err := ctx.findPath(target, paymentAmt) if err != nil { t.Fatalf("unable to find path: %v", err) } - route, err := newRoute( - ctx.source, path, startingHeight, - finalHopParams{ - amt: paymentAmt, - cltvDelta: finalHopCLTV, - records: nil, - }, - ) - if err != nil { - t.Fatalf("unable to create path: %v", err) - } - // Assert that the route starts with channel 2, in line with the - // specified restriction. - if route.Hops[0].ChannelID != 2 { - t.Fatalf("expected route to pass through channel 2, "+ - "but channel %v was selected instead", route.Hops[0].ChannelID) + // Assert that the route starts with channel chanSourceB1, in line with + // the specified restriction. + if path[0].ChannelID != chanSourceB1 { + t.Fatalf("expected route to pass through channel %v, "+ + "but channel %v was selected instead", chanSourceB1, + path[0].ChannelID) } }