routing/test: add channel id constants

This commit is contained in:
Joost Jager 2020-05-08 13:53:22 +02:00
parent 338e12ecd0
commit 53e4876a1d
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -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)
}
}