graph/db: demonstrate SQL node addresses fetch bug

This commit demonstrates that currently the Addresses field of a
LightningNode is not populated correctly if the node has no addresses if
the SQL graph store is being used. This will be fixed in an upcoming
commit.
This commit is contained in:
Elle Mouton 2025-06-30 18:01:07 +02:00
parent 73eca1bf3d
commit 272a2db16c
No known key found for this signature in database
GPG key ID: D7D916376026F177

View file

@ -97,6 +97,7 @@ func createTestVertex(t testing.TB) *models.LightningNode {
return createLightningNode(priv)
}
// TestNodeInsertionAndDeletion tests the CRUD operations for a LightningNode.
func TestNodeInsertionAndDeletion(t *testing.T) {
t.Parallel()
ctx := context.Background()
@ -124,9 +125,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
// First, insert the node into the graph DB. This should succeed
// without any errors.
node := nodeWithAddrs(testAddrs)
if err := graph.AddLightningNode(ctx, node); err != nil {
t.Fatalf("unable to add node: %v", err)
}
require.NoError(t, graph.AddLightningNode(ctx, node))
assertNodeInCache(t, graph, node, testFeatures)
// Next, fetch the node from the database to ensure everything was
@ -135,11 +134,8 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
require.NoError(t, err, "unable to locate node")
_, exists, err := graph.HasLightningNode(ctx, dbNode.PubKeyBytes)
if err != nil {
t.Fatalf("unable to query for node: %v", err)
} else if !exists {
t.Fatalf("node should be found but wasn't")
}
require.NoError(t, err)
require.True(t, exists)
// The two nodes should match exactly!
compareNodes(t, node, dbNode)
@ -194,7 +190,17 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
// Fetch the node and assert the empty addresses.
dbNode, err = graph.FetchLightningNode(ctx, testPub)
require.NoError(t, err)
require.Empty(t, dbNode.Addresses)
// Temporarily have a special case for SQLStore, as currently, it does
// not correctly handle empty addresses. We assert this incorrect
// behaviour here in order to demonstrate the bug. This will be fixed in
// an upcoming commit.
if _, ok := graph.V1Store.(*SQLStore); ok {
require.Empty(t, dbNode.Addresses)
require.NotEqual(t, node.Addresses, dbNode.Addresses)
} else {
compareNodes(t, node, dbNode)
}
known, addrs, err = graph.AddrsForNode(ctx, pub)
require.NoError(t, err)