Skip to content

Commit 4bc0aee

Browse files
committed
routing: improve TestFindBlindedPaths readability
Add a helper so that we can refer to channels by using the aliases of the nodes that own the channel instead of needing to use the raw channel ID.
1 parent da37fe2 commit 4bc0aee

File tree

1 file changed

+54
-18
lines changed

1 file changed

+54
-18
lines changed

routing/pathfind_test.go

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
538538

539539
aliasMap := make(map[string]route.Vertex)
540540
privKeyMap := make(map[string]*btcec.PrivateKey)
541+
channelIDs := make(map[route.Vertex]map[route.Vertex]uint64)
541542

542543
nodeIndex := byte(0)
543544
addNodeWithAlias := func(alias string, features *lnwire.FeatureVector) (
@@ -652,6 +653,16 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
652653
node1Vertex, node2Vertex = node2Vertex, node1Vertex
653654
}
654655

656+
if _, ok := channelIDs[node1Vertex]; !ok {
657+
channelIDs[node1Vertex] = map[route.Vertex]uint64{}
658+
}
659+
channelIDs[node1Vertex][node2Vertex] = channelID
660+
661+
if _, ok := channelIDs[node2Vertex]; !ok {
662+
channelIDs[node2Vertex] = map[route.Vertex]uint64{}
663+
}
664+
channelIDs[node2Vertex][node1Vertex] = channelID
665+
655666
// We first insert the existence of the edge between the two
656667
// nodes.
657668
edgeInfo := models.ChannelEdgeInfo{
@@ -765,6 +776,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
765776
mcBackend: graphBackend,
766777
aliasMap: aliasMap,
767778
privKeyMap: privKeyMap,
779+
channelIDs: channelIDs,
768780
links: links,
769781
}, nil
770782
}
@@ -3192,6 +3204,16 @@ func newPathFindingTestContext(t *testing.T, useCache bool,
31923204
return ctx
31933205
}
31943206

3207+
func (c *pathFindingTestContext) nodePairChannel(alias1, alias2 string) uint64 {
3208+
node1 := c.keyFromAlias(alias1)
3209+
node2 := c.keyFromAlias(alias2)
3210+
3211+
channel, ok := c.testGraphInstance.channelIDs[node1][node2]
3212+
require.True(c.t, ok)
3213+
3214+
return channel
3215+
}
3216+
31953217
func (c *pathFindingTestContext) keyFromAlias(alias string) route.Vertex {
31963218
return c.testGraphInstance.aliasMap[alias]
31973219
}
@@ -3914,9 +3936,11 @@ func TestFindBlindedPaths(t *testing.T) {
39143936
// with one hop other than the destination hop. Now with bob-dave as the
39153937
// incoming channel.
39163938
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
3917-
minNumHops: 1,
3918-
maxNumHops: 1,
3919-
incomingChainedChannels: []uint64{2},
3939+
minNumHops: 1,
3940+
maxNumHops: 1,
3941+
incomingChainedChannels: []uint64{
3942+
ctx.nodePairChannel("bob", "dave"),
3943+
},
39203944
})
39213945
require.NoError(t, err)
39223946

@@ -3928,9 +3952,11 @@ func TestFindBlindedPaths(t *testing.T) {
39283952
// 8) Extend the search to include 2 hops other than the destination,
39293953
// with bob-dave as the incoming channel.
39303954
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
3931-
minNumHops: 1,
3932-
maxNumHops: 2,
3933-
incomingChainedChannels: []uint64{2},
3955+
minNumHops: 1,
3956+
maxNumHops: 2,
3957+
incomingChainedChannels: []uint64{
3958+
ctx.nodePairChannel("bob", "dave"),
3959+
},
39343960
})
39353961
require.NoError(t, err)
39363962

@@ -3945,9 +3971,11 @@ func TestFindBlindedPaths(t *testing.T) {
39453971
// 9) Extend the search even further and also increase the minimum path
39463972
// length, but this time with charlie-dave as the incoming channel.
39473973
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
3948-
minNumHops: 2,
3949-
maxNumHops: 3,
3950-
incomingChainedChannels: []uint64{3},
3974+
minNumHops: 2,
3975+
maxNumHops: 3,
3976+
incomingChainedChannels: []uint64{
3977+
ctx.nodePairChannel("charlie", "dave"),
3978+
},
39513979
})
39523980
require.NoError(t, err)
39533981

@@ -3962,19 +3990,27 @@ func TestFindBlindedPaths(t *testing.T) {
39623990
// 10) Repeat the above test but instruct the function to never use
39633991
// charlie.
39643992
_, err = ctx.findBlindedPaths(&blindedPathRestrictions{
3965-
minNumHops: 2,
3966-
maxNumHops: 3,
3967-
nodeOmissionSet: fn.NewSet(ctx.keyFromAlias("charlie")),
3968-
incomingChainedChannels: []uint64{3},
3993+
minNumHops: 2,
3994+
maxNumHops: 3,
3995+
nodeOmissionSet: fn.NewSet(ctx.keyFromAlias("charlie")),
3996+
incomingChainedChannels: []uint64{
3997+
ctx.nodePairChannel("charlie", "dave"),
3998+
},
39693999
})
39704000
require.ErrorContains(t, err, "cannot simultaneously be included in "+
39714001
"the omission set and in the partially specified path")
39724002

3973-
// 11) Test the circular route error.
4003+
// 11) Assert that an error is returned if a user accidentally tries
4004+
// to force a circular path.
39744005
_, err = ctx.findBlindedPaths(&blindedPathRestrictions{
3975-
minNumHops: 2,
3976-
maxNumHops: 3,
3977-
incomingChainedChannels: []uint64{2, 7, 6, 3},
4006+
minNumHops: 2,
4007+
maxNumHops: 3,
4008+
incomingChainedChannels: []uint64{
4009+
ctx.nodePairChannel("dave", "alice"),
4010+
ctx.nodePairChannel("alice", "frank"),
4011+
ctx.nodePairChannel("frank", "bob"),
4012+
ctx.nodePairChannel("bob", "dave"),
4013+
},
39784014
})
3979-
require.ErrorContains(t, err, "a circular route cannot be specified")
4015+
require.ErrorContains(t, err, "circular route")
39804016
}

0 commit comments

Comments
 (0)