routing/test: add channel id constants
This commit is contained in:
parent
338e12ecd0
commit
53e4876a1d
@ -2247,26 +2247,35 @@ func TestNewRouteFromEmptyHops(t *testing.T) {
|
|||||||
func TestRestrictOutgoingChannel(t *testing.T) {
|
func TestRestrictOutgoingChannel(t *testing.T) {
|
||||||
t.Parallel()
|
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
|
// 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{
|
testChannels := []*testChannel{
|
||||||
symmetricTestChannel("roasbeef", "a", 100000, &testChannelPolicy{
|
symmetricTestChannel("roasbeef", "a", 100000, &testChannelPolicy{
|
||||||
Expiry: 144,
|
Expiry: 144,
|
||||||
}, 1),
|
}, chanSourceA),
|
||||||
symmetricTestChannel("a", "target", 100000, &testChannelPolicy{
|
symmetricTestChannel("a", "target", 100000, &testChannelPolicy{
|
||||||
Expiry: 144,
|
Expiry: 144,
|
||||||
FeeRate: 400,
|
FeeRate: 400,
|
||||||
}, 4),
|
}, chanATarget),
|
||||||
symmetricTestChannel("roasbeef", "b", 100000, &testChannelPolicy{
|
symmetricTestChannel("roasbeef", "b", 100000, &testChannelPolicy{
|
||||||
Expiry: 144,
|
Expiry: 144,
|
||||||
}, 2),
|
}, chanSourceB1),
|
||||||
symmetricTestChannel("roasbeef", "b", 100000, &testChannelPolicy{
|
symmetricTestChannel("roasbeef", "b", 100000, &testChannelPolicy{
|
||||||
Expiry: 144,
|
Expiry: 144,
|
||||||
}, 3),
|
}, chanSourceB2),
|
||||||
symmetricTestChannel("b", "target", 100000, &testChannelPolicy{
|
symmetricTestChannel("b", "target", 100000, &testChannelPolicy{
|
||||||
Expiry: 144,
|
Expiry: 144,
|
||||||
FeeRate: 800,
|
FeeRate: 800,
|
||||||
}, 5),
|
}, chanBTarget),
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := newPathFindingTestContext(t, testChannels, "roasbeef")
|
ctx := newPathFindingTestContext(t, testChannels, "roasbeef")
|
||||||
@ -2279,32 +2288,22 @@ func TestRestrictOutgoingChannel(t *testing.T) {
|
|||||||
|
|
||||||
paymentAmt := lnwire.NewMSatFromSatoshis(100)
|
paymentAmt := lnwire.NewMSatFromSatoshis(100)
|
||||||
target := ctx.keyFromAlias("target")
|
target := ctx.keyFromAlias("target")
|
||||||
outgoingChannelID := uint64(2)
|
outgoingChannelID := uint64(chanSourceB1)
|
||||||
|
|
||||||
// Find the best path given the restriction to only use channel 2 as the
|
// Find the best path given the restriction to only use chanSourceB1 as
|
||||||
// outgoing channel.
|
// the outgoing channel.
|
||||||
ctx.restrictParams.OutgoingChannelID = &outgoingChannelID
|
ctx.restrictParams.OutgoingChannelID = &outgoingChannelID
|
||||||
path, err := ctx.findPath(target, paymentAmt)
|
path, err := ctx.findPath(target, paymentAmt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to find path: %v", err)
|
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
|
// Assert that the route starts with channel chanSourceB1, in line with
|
||||||
// specified restriction.
|
// the specified restriction.
|
||||||
if route.Hops[0].ChannelID != 2 {
|
if path[0].ChannelID != chanSourceB1 {
|
||||||
t.Fatalf("expected route to pass through channel 2, "+
|
t.Fatalf("expected route to pass through channel %v, "+
|
||||||
"but channel %v was selected instead", route.Hops[0].ChannelID)
|
"but channel %v was selected instead", chanSourceB1,
|
||||||
|
path[0].ChannelID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user