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.
This commit is contained in:
Elle Mouton
2025-05-27 08:24:28 +02:00
parent 2a36e17f6f
commit c5f159f485

View File

@@ -3337,29 +3337,28 @@ func TestAddChannelEdgeShellNodes(t *testing.T) {
// To start, we'll create two nodes, and only add one of them to the
// channel graph.
node1 := createTestVertex(t)
if err := graph.AddLightningNode(node1); err != nil {
t.Fatalf("unable to add node: %v", err)
}
require.NoError(t, graph.SetSourceNode(node1))
node2 := createTestVertex(t)
// We'll now create an edge between the two nodes, as a result, node2
// should be inserted into the database as a shell node.
edgeInfo, _ := createEdge(100, 0, 0, 0, node1, node2)
if err := graph.AddChannelEdge(&edgeInfo); err != nil {
t.Fatalf("unable to add edge: %v", err)
}
require.NoError(t, graph.AddChannelEdge(&edgeInfo))
// Ensure that node1 was inserted as a full node, while node2 only has
// a shell node present.
node1, err := graph.FetchLightningNode(node1.PubKeyBytes)
require.NoError(t, err, "unable to fetch node1")
if !node1.HaveNodeAnnouncement {
t.Fatalf("have shell announcement for node1, shouldn't")
}
require.True(t, node1.HaveNodeAnnouncement)
node2, err = graph.FetchLightningNode(node2.PubKeyBytes)
require.NoError(t, err, "unable to fetch node2")
require.False(t, node2.HaveNodeAnnouncement)
// Show that attempting to add the channel again will result in an
// error.
err = graph.AddChannelEdge(&edgeInfo)
require.ErrorIs(t, err, ErrEdgeAlreadyExist)
}
// TestNodePruningUpdateIndexDeletion tests that once a node has been removed