routing/test: allow arbitrary graph source nodes

This commit is contained in:
Joost Jager 2019-01-31 16:07:30 +01:00
parent 93aad89f4c
commit 569f821142
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 40 additions and 17 deletions

@ -386,7 +386,9 @@ type testGraphInstance struct {
// a deterministical way and added to the channel graph. A list of nodes is // a deterministical way and added to the channel graph. A list of nodes is
// not required and derived from the channel data. The goal is to keep // not required and derived from the channel data. The goal is to keep
// instantiating a test channel graph as light weight as possible. // instantiating a test channel graph as light weight as possible.
func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstance, error) { func createTestGraphFromChannels(testChannels []*testChannel, source string) (
*testGraphInstance, error) {
// We'll use this fake address for the IP address of all the nodes in // We'll use this fake address for the IP address of all the nodes in
// our tests. This value isn't needed for path finding so it doesn't // our tests. This value isn't needed for path finding so it doesn't
// need to be unique. // need to be unique.
@ -444,13 +446,13 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc
return dbNode, nil return dbNode, nil
} }
var source *channeldb.LightningNode // Add the source node.
if source, err = addNodeWithAlias("roasbeef"); err != nil { dbNode, err := addNodeWithAlias(source)
if err != nil {
return nil, err return nil, err
} }
// Set the source node if err = graph.SetSourceNode(dbNode); err != nil {
if err := graph.SetSourceNode(source); err != nil {
return nil, err return nil, err
} }
@ -464,7 +466,10 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc
_, exists := aliasMap[alias] _, exists := aliasMap[alias]
if !exists { if !exists {
addNodeWithAlias(alias) _, err := addNodeWithAlias(alias)
if err != nil {
return nil, err
}
} }
} }
@ -619,7 +624,9 @@ func TestFindLowestFeePath(t *testing.T) {
}), }),
} }
testGraphInstance, err := createTestGraphFromChannels(testChannels) testGraphInstance, err := createTestGraphFromChannels(
testChannels, "roasbeef",
)
if err != nil { if err != nil {
t.Fatalf("unable to create graph: %v", err) t.Fatalf("unable to create graph: %v", err)
} }
@ -1367,7 +1374,7 @@ func TestRouteFailMaxHTLC(t *testing.T) {
}), }),
} }
graph, err := createTestGraphFromChannels(testChannels) graph, err := createTestGraphFromChannels(testChannels, "roasbeef")
if err != nil { if err != nil {
t.Fatalf("unable to create graph: %v", err) t.Fatalf("unable to create graph: %v", err)
} }
@ -1862,7 +1869,9 @@ func TestRestrictOutgoingChannel(t *testing.T) {
}), }),
} }
testGraphInstance, err := createTestGraphFromChannels(testChannels) testGraphInstance, err := createTestGraphFromChannels(
testChannels, "roasbeef",
)
if err != nil { if err != nil {
t.Fatalf("unable to create graph: %v", err) t.Fatalf("unable to create graph: %v", err)
} }
@ -1957,7 +1966,9 @@ func testCltvLimit(t *testing.T, limit uint32, expectedChannel uint64) {
}), }),
} }
testGraphInstance, err := createTestGraphFromChannels(testChannels) testGraphInstance, err := createTestGraphFromChannels(
testChannels, "roasbeef",
)
if err != nil { if err != nil {
t.Fatalf("unable to create graph: %v", err) t.Fatalf("unable to create graph: %v", err)
} }
@ -2121,7 +2132,9 @@ func testProbabilityRouting(t *testing.T, p10, p11, p20, minProbability float64,
}, 20), }, 20),
} }
testGraphInstance, err := createTestGraphFromChannels(testChannels) testGraphInstance, err := createTestGraphFromChannels(
testChannels, "roasbeef",
)
if err != nil { if err != nil {
t.Fatalf("unable to create graph: %v", err) t.Fatalf("unable to create graph: %v", err)
} }

@ -342,7 +342,7 @@ func TestChannelUpdateValidation(t *testing.T) {
}, 2), }, 2),
} }
testGraph, err := createTestGraphFromChannels(testChannels) testGraph, err := createTestGraphFromChannels(testChannels, "a")
defer testGraph.cleanUp() defer testGraph.cleanUp()
if err != nil { if err != nil {
t.Fatalf("unable to create graph: %v", err) t.Fatalf("unable to create graph: %v", err)
@ -1039,7 +1039,9 @@ func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) {
// Setup an initially empty network. // Setup an initially empty network.
testChannels := []*testChannel{} testChannels := []*testChannel{}
testGraph, err := createTestGraphFromChannels(testChannels) testGraph, err := createTestGraphFromChannels(
testChannels, "roasbeef",
)
if err != nil { if err != nil {
t.Fatalf("unable to create graph: %v", err) t.Fatalf("unable to create graph: %v", err)
} }
@ -2027,7 +2029,7 @@ func TestPruneChannelGraphStaleEdges(t *testing.T) {
// We'll create our test graph and router backed with these test // We'll create our test graph and router backed with these test
// channels we've created. // channels we've created.
testGraph, err := createTestGraphFromChannels(testChannels) testGraph, err := createTestGraphFromChannels(testChannels, "a")
if err != nil { if err != nil {
t.Fatalf("unable to create test graph: %v", err) t.Fatalf("unable to create test graph: %v", err)
} }
@ -2064,6 +2066,14 @@ func TestPruneChannelGraphDoubleDisabled(t *testing.T) {
// according to that heuristic. // according to that heuristic.
timestamp := time.Now() timestamp := time.Now()
testChannels := []*testChannel{ testChannels := []*testChannel{
// Channel from self shouldn't be pruned.
symmetricTestChannel(
"self", "a", 100000, &testChannelPolicy{
LastUpdate: timestamp,
Disabled: true,
}, 99,
),
// No edges. // No edges.
{ {
Node1: &testChannelEnd{Alias: "a"}, Node1: &testChannelEnd{Alias: "a"},
@ -2135,7 +2145,7 @@ func TestPruneChannelGraphDoubleDisabled(t *testing.T) {
// We'll create our test graph and router backed with these test // We'll create our test graph and router backed with these test
// channels we've created. // channels we've created.
testGraph, err := createTestGraphFromChannels(testChannels) testGraph, err := createTestGraphFromChannels(testChannels, "self")
if err != nil { if err != nil {
t.Fatalf("unable to create test graph: %v", err) t.Fatalf("unable to create test graph: %v", err)
} }
@ -2543,7 +2553,7 @@ func TestRouterPaymentStateMachine(t *testing.T) {
}, 2), }, 2),
} }
testGraph, err := createTestGraphFromChannels(testChannels) testGraph, err := createTestGraphFromChannels(testChannels, "a")
if err != nil { if err != nil {
t.Fatalf("unable to create graph: %v", err) t.Fatalf("unable to create graph: %v", err)
} }
@ -3164,7 +3174,7 @@ func TestSendToRouteStructuredError(t *testing.T) {
}, 2), }, 2),
} }
testGraph, err := createTestGraphFromChannels(testChannels) testGraph, err := createTestGraphFromChannels(testChannels, "a")
if err != nil { if err != nil {
t.Fatalf("unable to create graph: %v", err) t.Fatalf("unable to create graph: %v", err)
} }