channeldb: modify TestPruneGraphNodes to test nodes w/ single edge
In this commit, we extend the TestPruneGraphNodes test to also test the case of when a node is involved in a channel, but only a single edge for that channel has been advertised. In order to test this, we add an additional node to the graph, and also a new channel. However, this channel will only have a single edge advertised. As result, when we prune the set of edges, the only node remaining should be the node that didn't have any edges at all.
This commit is contained in:
parent
f8cbe34e93
commit
131eea4960
@ -2080,9 +2080,9 @@ func TestPruneGraphNodes(t *testing.T) {
|
|||||||
t.Fatalf("unable to set source node: %v", err)
|
t.Fatalf("unable to set source node: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// With the source node inserted, we'll now add two nodes into the
|
// With the source node inserted, we'll now add three nodes to the
|
||||||
// channel graph, as they don't have any channels they should be
|
// channel graph, at the end of the scenario, only two of these nodes
|
||||||
// removed from the graph at the end.
|
// should still be in the graph.
|
||||||
node1, err := createTestVertex(db)
|
node1, err := createTestVertex(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create test node: %v", err)
|
t.Fatalf("unable to create test node: %v", err)
|
||||||
@ -2097,14 +2097,51 @@ func TestPruneGraphNodes(t *testing.T) {
|
|||||||
if err := graph.AddLightningNode(node2); err != nil {
|
if err := graph.AddLightningNode(node2); err != nil {
|
||||||
t.Fatalf("unable to add node: %v", err)
|
t.Fatalf("unable to add node: %v", err)
|
||||||
}
|
}
|
||||||
|
node3, err := createTestVertex(db)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to create test node: %v", err)
|
||||||
|
}
|
||||||
|
if err := graph.AddLightningNode(node3); err != nil {
|
||||||
|
t.Fatalf("unable to add node: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We'll now add a new edge to the graph, but only actually advertise
|
||||||
|
// the edge of *one* of the nodes.
|
||||||
|
edgeInfo, chanID := createEdge(100, 0, 0, 0, node1, node2)
|
||||||
|
if err := graph.AddChannelEdge(&edgeInfo); err != nil {
|
||||||
|
t.Fatalf("unable to add edge: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We'll now insert an advertised edge, but it'll only be the edge that
|
||||||
|
// points from the first to the second node.
|
||||||
|
edge1 := randEdgePolicy(chanID.ToUint64(), edgeInfo.ChannelPoint, db)
|
||||||
|
edge1.Flags = 0
|
||||||
|
edge1.Node = node1
|
||||||
|
edge1.SigBytes = testSig.Serialize()
|
||||||
|
if err := graph.UpdateEdgePolicy(edge1); err != nil {
|
||||||
|
t.Fatalf("unable to update edge: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We'll now initiate a around of graph pruning.
|
||||||
if err := graph.PruneGraphNodes(); err != nil {
|
if err := graph.PruneGraphNodes(); err != nil {
|
||||||
t.Fatalf("unable to prune graph nodes: %v", err)
|
t.Fatalf("unable to prune graph nodes: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// There should only be a single node left at this point, the source
|
// At this point, there should be 3 nodes left in the graph still: the
|
||||||
// node.
|
// source node (which can't be pruned), and node 1+2. Nodes 1 and two
|
||||||
assertNumNodes(t, graph, 1)
|
// should still be left in the graph as there's half of an advertised
|
||||||
|
// edge between them.
|
||||||
|
assertNumNodes(t, graph, 3)
|
||||||
|
|
||||||
|
// Finally, we'll ensure that node3, the only fully unconnected node as
|
||||||
|
// properly deleted from the graph and not another node in its place.
|
||||||
|
node3Pub, err := node3.PubKey()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to fetch the pubkey of node3: %v", err)
|
||||||
|
}
|
||||||
|
if _, err := graph.FetchLightningNode(node3Pub); err == nil {
|
||||||
|
t.Fatalf("node 3 should have been deleted!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// compareNodes is used to compare two LightningNodes while excluding the
|
// compareNodes is used to compare two LightningNodes while excluding the
|
||||||
|
Loading…
Reference in New Issue
Block a user