routing: add the test for incoming chained channels on blinded path

This commit is contained in:
MPins 2025-03-03 07:08:51 -03:00
parent 798f10b344
commit 26c5ba2e16

View file

@ -3766,8 +3766,34 @@ func TestFindBlindedPaths(t *testing.T) {
}
// 1) Restrict the min & max path length such that we only include paths
// with one hop other than the destination hop.
// with one being only the intro-node and the others with one hop other
// than the destination hop.
paths, err := ctx.findBlindedPaths(&blindedPathRestrictions{
minNumHops: 0,
maxNumHops: 1,
})
require.NoError(t, err)
// We expect only B->D path to be chosen.
assertPaths(paths, []string{
"dave",
"bob,dave",
"charlie,dave",
})
// 2) Now with bob-dave as the incoming channel, an error is expected as
// the minNumHops must be greater than or equal to the number of hops on
// the chained channels specified.
_, err = ctx.findBlindedPaths(&blindedPathRestrictions{
minNumHops: 0,
maxNumHops: 1,
incomingChainedChannels: []uint64{2},
})
require.Error(t, err)
// 3) Restrict the min & max path length such that we only include paths
// with one hop other than the destination hop.
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
minNumHops: 1,
maxNumHops: 1,
})
@ -3782,7 +3808,20 @@ func TestFindBlindedPaths(t *testing.T) {
"charlie,dave",
})
// 2) Extend the search to include 2 hops other than the destination.
// 4) Now with bob-dave as the incoming channel.
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
minNumHops: 1,
maxNumHops: 1,
incomingChainedChannels: []uint64{2},
})
require.NoError(t, err)
// We expect only B->D path to be chosen.
assertPaths(paths, []string{
"bob,dave",
})
// 5) Extend the search to include 2 hops other than the destination.
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
minNumHops: 1,
maxNumHops: 2,
@ -3803,7 +3842,25 @@ func TestFindBlindedPaths(t *testing.T) {
"eve,charlie,dave",
})
// 3) Extend the search even further and also increase the minimum path
// 6) Now with bob-dave as the incoming channel.
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
minNumHops: 1,
maxNumHops: 2,
incomingChainedChannels: []uint64{2},
})
require.NoError(t, err)
// We expect the following paths:
// - B, D
// - F, B, D
// - E, B, D
assertPaths(paths, []string{
"bob,dave",
"frank,bob,dave",
"eve,bob,dave",
})
// 7) Extend the search even further and also increase the minimum path
// length.
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
minNumHops: 2,
@ -3825,7 +3882,7 @@ func TestFindBlindedPaths(t *testing.T) {
"charlie,eve,bob,dave",
})
// 4) Repeat the above test but instruct the function to never use
// 8) Repeat the above test but instruct the function to never use
// charlie.
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
minNumHops: 2,
@ -3844,7 +3901,24 @@ func TestFindBlindedPaths(t *testing.T) {
"eve,bob,dave",
})
// 5) Finally, we will test the special case where the destination node
// 9) Repeat the test number 5, but now with charlie-dave as the
// incoming channel.
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
minNumHops: 2,
maxNumHops: 3,
incomingChainedChannels: []uint64{3},
})
require.NoError(t, err)
// We expect the following paths:
// - E, C, D
// - B, E, C, D
assertPaths(paths, []string{
"eve,charlie,dave",
"bob,eve,charlie,dave",
})
// 10) Finally, we will test the special case where the destination node
// is also the recipient.
paths, err = ctx.findBlindedPaths(&blindedPathRestrictions{
minNumHops: 0,