graph/db: make TestPartialNode version-aware

Convert TestPartialNode to a versioned test that runs for both v1 and
v2 gossip versions, ensuring shell node creation works correctly for
both channel types.
This commit is contained in:
Elle Mouton committed 2026-02-13 07:21:23 +02:00
1 parent 99d622ca03
commit dcd0b9dac7
1 file changed
+13 -11
+13 -11
View File
@@ -142,6 +142,10 @@ var versionedTests = []versionedTest{
name: "add edge proof", name: "add edge proof",
test: testAddEdgeProof, test: testAddEdgeProof,
}, },
{
name: "partial node",
test: testPartialNode,
},
} }
// TestVersionedDBs runs various tests against both v1 and v2 versioned // TestVersionedDBs runs various tests against both v1 and v2 versioned
@@ -367,24 +371,22 @@ func testNodeInsertionAndDeletion(t *testing.T, v lnwire.GossipVersion) {
require.NoError(t, err) require.NoError(t, err)
} }
// TestPartialNode checks that we can add and retrieve a Node where // testPartialNode tests that partial/shell nodes are correctly created when
// only the pubkey is known to the database. // a channel edge is added referencing nodes we are not yet aware of.
func TestPartialNode(t *testing.T) { func testPartialNode(t *testing.T, v lnwire.GossipVersion) {
t.Parallel() t.Parallel()
ctx := t.Context() ctx := t.Context()
graph := NewVersionedGraph(MakeTestGraph(t), lnwire.GossipVersion1) graph := NewVersionedGraph(MakeTestGraph(t), v)
// To insert a partial node, we need to add a channel edge that has // To insert a partial node, we need to add a channel edge that has
// node keys for nodes we are not yet aware // node keys for nodes we are not yet aware of.
var node1, node2 models.Node var node1, node2 models.Node
copy(node1.PubKeyBytes[:], pubKey1Bytes) copy(node1.PubKeyBytes[:], pubKey1Bytes)
copy(node2.PubKeyBytes[:], pubKey2Bytes) copy(node2.PubKeyBytes[:], pubKey2Bytes)
// Create an edge attached to these nodes and add it to the graph. // Create an edge attached to these nodes and add it to the graph.
edgeInfo, _ := createEdge( edgeInfo, _ := createEdge(v, 140, 0, 0, 0, &node1, &node2)
lnwire.GossipVersion1, 140, 0, 0, 0, &node1, &node2,
)
require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo)) require.NoError(t, graph.AddChannelEdge(ctx, edgeInfo))
// Both of the nodes should now be in both the graph (as partial/shell) // Both of the nodes should now be in both the graph (as partial/shell)
@@ -392,7 +394,7 @@ func TestPartialNode(t *testing.T) {
assertNodeInCache(t, graph.ChannelGraph, &node1, nil) assertNodeInCache(t, graph.ChannelGraph, &node1, nil)
assertNodeInCache(t, graph.ChannelGraph, &node2, nil) assertNodeInCache(t, graph.ChannelGraph, &node2, nil)
// Next, fetch the node2 from the database to ensure everything was // Next, fetch the nodes from the database to ensure everything was
// serialized properly. // serialized properly.
dbNode1, err := graph.FetchNode(ctx, pubKey1) dbNode1, err := graph.FetchNode(ctx, pubKey1)
require.NoError(t, err) require.NoError(t, err)
@@ -405,7 +407,7 @@ func TestPartialNode(t *testing.T) {
// The two nodes should match exactly! (with default values for // The two nodes should match exactly! (with default values for
// LastUpdate and db set to satisfy compareNodes()) // LastUpdate and db set to satisfy compareNodes())
expectedNode1 := models.NewV1ShellNode(pubKey1) expectedNode1 := models.NewShellNode(v, pubKey1)
compareNodes(t, expectedNode1, dbNode1) compareNodes(t, expectedNode1, dbNode1)
exists, err = graph.HasNode(ctx, dbNode2.PubKeyBytes) exists, err = graph.HasNode(ctx, dbNode2.PubKeyBytes)
@@ -414,7 +416,7 @@ func TestPartialNode(t *testing.T) {
// The two nodes should match exactly! (with default values for // The two nodes should match exactly! (with default values for
// LastUpdate and db set to satisfy compareNodes()) // LastUpdate and db set to satisfy compareNodes())
expectedNode2 := models.NewV1ShellNode(pubKey2) expectedNode2 := models.NewShellNode(v, pubKey2)
compareNodes(t, expectedNode2, dbNode2) compareNodes(t, expectedNode2, dbNode2)
// Next, delete the node from the graph, this should purge all data // Next, delete the node from the graph, this should purge all data