routing/pathfind_test: use ctx in recent tests
Modifies TestMissingFeatureDep and TestDestPaymentAddr to use the test ctx directly instead of generating a closure and using local state to modify restrictions.
This commit is contained in:
parent
6c8c99dae9
commit
32284ef1f1
@ -1591,33 +1591,14 @@ func TestMissingFeatureDep(t *testing.T) {
|
|||||||
ctx := newPathFindingTestContext(t, testChannels, "roasbeef")
|
ctx := newPathFindingTestContext(t, testChannels, "roasbeef")
|
||||||
defer ctx.cleanup()
|
defer ctx.cleanup()
|
||||||
|
|
||||||
sourceNode, err := ctx.graphParams.graph.SourceNode()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to fetch source node: %v", err)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
find := func(r *RestrictParams,
|
|
||||||
target route.Vertex) ([]*channeldb.ChannelEdgePolicy, error) {
|
|
||||||
|
|
||||||
return findPath(
|
|
||||||
&graphParams{
|
|
||||||
graph: ctx.graphParams.graph,
|
|
||||||
},
|
|
||||||
r, testPathFindingConfig,
|
|
||||||
sourceNode.PubKeyBytes, target, 100, 0,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Conner's node in the graph has a broken feature vector, since it
|
// Conner's node in the graph has a broken feature vector, since it
|
||||||
// signals payment addresses without signaling tlv onions. Pathfinding
|
// signals payment addresses without signaling tlv onions. Pathfinding
|
||||||
// should fail since we validate transitive feature dependencies for the
|
// should fail since we validate transitive feature dependencies for the
|
||||||
// final node.
|
// final node.
|
||||||
conner := ctx.testGraphInstance.aliasMap["conner"]
|
conner := ctx.keyFromAlias("conner")
|
||||||
|
joost := ctx.keyFromAlias("joost")
|
||||||
|
|
||||||
restrictions := *noRestrictions
|
_, err := ctx.findPath(conner, 100)
|
||||||
|
|
||||||
_, err = find(&restrictions, conner)
|
|
||||||
if err != feature.NewErrMissingFeatureDep(
|
if err != feature.NewErrMissingFeatureDep(
|
||||||
lnwire.TLVOnionPayloadOptional,
|
lnwire.TLVOnionPayloadOptional,
|
||||||
) {
|
) {
|
||||||
@ -1627,9 +1608,9 @@ func TestMissingFeatureDep(t *testing.T) {
|
|||||||
// Now, set the TLV and payment addresses features to override the
|
// Now, set the TLV and payment addresses features to override the
|
||||||
// broken features found in the graph. We should succeed in finding a
|
// broken features found in the graph. We should succeed in finding a
|
||||||
// path to conner.
|
// path to conner.
|
||||||
restrictions.DestFeatures = tlvPayAddrFeatures
|
ctx.restrictParams.DestFeatures = tlvPayAddrFeatures
|
||||||
|
|
||||||
path, err := find(&restrictions, conner)
|
path, err := ctx.findPath(conner, 100)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("path should have been found: %v", err)
|
t.Fatalf("path should have been found: %v", err)
|
||||||
}
|
}
|
||||||
@ -1641,9 +1622,7 @@ func TestMissingFeatureDep(t *testing.T) {
|
|||||||
// errNoPathFound and not the missing feature dep err above since
|
// errNoPathFound and not the missing feature dep err above since
|
||||||
// intermediate hops are simply skipped if they have invalid feature
|
// intermediate hops are simply skipped if they have invalid feature
|
||||||
// vectors, leaving no possible route to joost.
|
// vectors, leaving no possible route to joost.
|
||||||
joost := ctx.testGraphInstance.aliasMap["joost"]
|
_, err = ctx.findPath(joost, 100)
|
||||||
|
|
||||||
_, err = find(&restrictions, joost)
|
|
||||||
if err != errNoPathFound {
|
if err != errNoPathFound {
|
||||||
t.Fatalf("path shouldn't have been found: %v", err)
|
t.Fatalf("path shouldn't have been found: %v", err)
|
||||||
}
|
}
|
||||||
@ -1736,45 +1715,25 @@ func TestDestPaymentAddr(t *testing.T) {
|
|||||||
ctx := newPathFindingTestContext(t, testChannels, "roasbeef")
|
ctx := newPathFindingTestContext(t, testChannels, "roasbeef")
|
||||||
defer ctx.cleanup()
|
defer ctx.cleanup()
|
||||||
|
|
||||||
sourceNode, err := ctx.graphParams.graph.SourceNode()
|
luoji := ctx.keyFromAlias("luoji")
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("unable to fetch source node: %v", err)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
find := func(r *RestrictParams,
|
|
||||||
target route.Vertex) ([]*channeldb.ChannelEdgePolicy, error) {
|
|
||||||
|
|
||||||
return findPath(
|
|
||||||
&graphParams{
|
|
||||||
graph: ctx.graphParams.graph,
|
|
||||||
},
|
|
||||||
r, testPathFindingConfig,
|
|
||||||
sourceNode.PubKeyBytes, target, 100, 0,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
luoji := ctx.testGraphInstance.aliasMap["luoji"]
|
|
||||||
|
|
||||||
restrictions := *noRestrictions
|
|
||||||
|
|
||||||
// Add payment address w/o any invoice features.
|
// Add payment address w/o any invoice features.
|
||||||
restrictions.PaymentAddr = &[32]byte{1}
|
ctx.restrictParams.PaymentAddr = &[32]byte{1}
|
||||||
|
|
||||||
// Add empty destination features. This should cause us to fail, since
|
// Add empty destination features. This should cause us to fail, since
|
||||||
// this overrides anything in the graph.
|
// this overrides anything in the graph.
|
||||||
restrictions.DestFeatures = lnwire.EmptyFeatureVector()
|
ctx.restrictParams.DestFeatures = lnwire.EmptyFeatureVector()
|
||||||
|
|
||||||
_, err = find(&restrictions, luoji)
|
_, err := ctx.findPath(luoji, 100)
|
||||||
if err != errNoPaymentAddr {
|
if err != errNoPaymentAddr {
|
||||||
t.Fatalf("path shouldn't have been found: %v", err)
|
t.Fatalf("path shouldn't have been found: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, set the TLV and payment address features for the destination. We
|
// Now, set the TLV and payment address features for the destination. We
|
||||||
// should succeed in finding a path to luoji.
|
// should succeed in finding a path to luoji.
|
||||||
restrictions.DestFeatures = tlvPayAddrFeatures
|
ctx.restrictParams.DestFeatures = tlvPayAddrFeatures
|
||||||
|
|
||||||
path, err := find(&restrictions, luoji)
|
path, err := ctx.findPath(luoji, 100)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("path should have been found: %v", err)
|
t.Fatalf("path should have been found: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user