Skip to content

Commit c5f159f

Browse files
committed
graph/db: expand AddChannelEdge test
Expand the existing TestAddChannelEdgeShellNodes test so that we have coverage for error we expect when AddChannelEdge is called a second time if we already know of a channel.
1 parent 2a36e17 commit c5f159f

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

graph/db/graph_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,29 +3337,28 @@ func TestAddChannelEdgeShellNodes(t *testing.T) {
33373337
// To start, we'll create two nodes, and only add one of them to the
33383338
// channel graph.
33393339
node1 := createTestVertex(t)
3340-
if err := graph.AddLightningNode(node1); err != nil {
3341-
t.Fatalf("unable to add node: %v", err)
3342-
}
3340+
require.NoError(t, graph.SetSourceNode(node1))
33433341
node2 := createTestVertex(t)
33443342

33453343
// We'll now create an edge between the two nodes, as a result, node2
33463344
// should be inserted into the database as a shell node.
33473345
edgeInfo, _ := createEdge(100, 0, 0, 0, node1, node2)
3348-
if err := graph.AddChannelEdge(&edgeInfo); err != nil {
3349-
t.Fatalf("unable to add edge: %v", err)
3350-
}
3346+
require.NoError(t, graph.AddChannelEdge(&edgeInfo))
33513347

33523348
// Ensure that node1 was inserted as a full node, while node2 only has
33533349
// a shell node present.
33543350
node1, err := graph.FetchLightningNode(node1.PubKeyBytes)
33553351
require.NoError(t, err, "unable to fetch node1")
3356-
if !node1.HaveNodeAnnouncement {
3357-
t.Fatalf("have shell announcement for node1, shouldn't")
3358-
}
3352+
require.True(t, node1.HaveNodeAnnouncement)
33593353

33603354
node2, err = graph.FetchLightningNode(node2.PubKeyBytes)
33613355
require.NoError(t, err, "unable to fetch node2")
33623356
require.False(t, node2.HaveNodeAnnouncement)
3357+
3358+
// Show that attempting to add the channel again will result in an
3359+
// error.
3360+
err = graph.AddChannelEdge(&edgeInfo)
3361+
require.ErrorIs(t, err, ErrEdgeAlreadyExist)
33633362
}
33643363

33653364
// TestNodePruningUpdateIndexDeletion tests that once a node has been removed

0 commit comments

Comments
 (0)