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
// not required and derived from the channel data. The goal is to keep
// 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
// our tests. This value isn't needed for path finding so it doesn't
// need to be unique.
@ -444,13 +446,13 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc
return dbNode, nil
}
var source *channeldb.LightningNode
if source, err = addNodeWithAlias("roasbeef"); err != nil {
// Add the source node.
dbNode, err := addNodeWithAlias(source)
if err != nil {
return nil, err
}
// Set the source node
if err := graph.SetSourceNode(source); err != nil {
if err = graph.SetSourceNode(dbNode); err != nil {
return nil, err
}
@ -464,7 +466,10 @@ func createTestGraphFromChannels(testChannels []*testChannel) (*testGraphInstanc
_, exists := aliasMap[alias]
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 {
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 {
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 {
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 {
t.Fatalf("unable to create graph: %v", err)
}
@ -2121,7 +2132,9 @@ func testProbabilityRouting(t *testing.T, p10, p11, p20, minProbability float64,
}, 20),
}
testGraphInstance, err := createTestGraphFromChannels(testChannels)
testGraphInstance, err := createTestGraphFromChannels(
testChannels, "roasbeef",
)
if err != nil {
t.Fatalf("unable to create graph: %v", err)
}

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