graph/db: use only exported KVStore ForEachNode method in tests

Replace all tests calls to the private `forEachNode` method on the
`KVStore` with the exported ForEachNode method. This is in preparation
for having the tests run against an abstract DB backend.
This commit is contained in:
Elle Mouton committed 2025-05-22 14:14:38 +02:00
1 parent b83b4015d9
commit 2f54a0a26a
1 file changed
+9 -14
+9 -14
View File
@@ -1103,13 +1103,11 @@ func TestGraphTraversalCacheable(t *testing.T) {
// Create a map of all nodes with the iteration we know works (because // Create a map of all nodes with the iteration we know works (because
// it is tested in another test). // it is tested in another test).
nodeMap := make(map[route.Vertex]struct{}) nodeMap := make(map[route.Vertex]struct{})
err = graph.forEachNode( err = graph.ForEachNode(func(tx NodeRTx) error {
func(tx kvdb.RTx, n *models.LightningNode) error { nodeMap[tx.Node().PubKeyBytes] = struct{}{}
nodeMap[n.PubKeyBytes] = struct{}{}
return nil return nil
}, })
)
require.NoError(t, err) require.NoError(t, err)
require.Len(t, nodeMap, numNodes) require.Len(t, nodeMap, numNodes)
@@ -1225,12 +1223,10 @@ func fillTestGraph(t testing.TB, graph *ChannelGraph, numNodes,
// Iterate over each node as returned by the graph, if all nodes are // Iterate over each node as returned by the graph, if all nodes are
// reached, then the map created above should be empty. // reached, then the map created above should be empty.
err := graph.forEachNode( err := graph.ForEachNode(func(tx NodeRTx) error {
func(_ kvdb.RTx, node *models.LightningNode) error { delete(nodeIndex, tx.Node().Alias)
delete(nodeIndex, node.Alias)
return nil return nil
}, })
)
require.NoError(t, err) require.NoError(t, err)
require.Len(t, nodeIndex, 0) require.Len(t, nodeIndex, 0)
@@ -1337,12 +1333,11 @@ func assertNumChans(t *testing.T, graph *ChannelGraph, n int) {
func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) { func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) {
numNodes := 0 numNodes := 0
err := graph.forEachNode( err := graph.ForEachNode(func(tx NodeRTx) error {
func(_ kvdb.RTx, _ *models.LightningNode) error {
numNodes++ numNodes++
return nil return nil
}, })
)
if err != nil { if err != nil {
_, _, line, _ := runtime.Caller(1) _, _, line, _ := runtime.Caller(1)
t.Fatalf("line %v: unable to scan nodes: %v", line, err) t.Fatalf("line %v: unable to scan nodes: %v", line, err)