multi: use MakeTestGraphNew for all remaining unit tests

And delete the old MakeTestGraph function.

Here we need to update some of our unit tests to ensure that any updates
to existing nodes or channel policies have newer timestamps. This is so
that we don't violate our SQL DB constraints that prevent updates to a
node or channel policy record if the new update is not newer (has a
newer LastUpdate time) than the currently presisted record).
This commit is contained in:
Elle Mouton committed 2025-06-26 10:12:27 +02:00
1 parent e0801f5a5d
commit c06036d2b4
6 files changed
+50 -65

No files matched your search

+2 -2
View File
@@ -3147,7 +3147,7 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) {
t.Parallel()
ctx := context.Background()
graph := MakeTestGraph(t)
graph := MakeTestGraphNew(t)
// The update index only applies to the bbolt graph.
boltStore, ok := graph.V1Store.(*KVStore)
@@ -3681,7 +3681,7 @@ func TestEdgePolicyMissingMaxHtcl(t *testing.T) {
t.Parallel()
ctx := context.Background()
graph := MakeTestGraph(t)
graph := MakeTestGraphNew(t)
// This test currently directly edits the bytes stored in the bbolt DB.
boltStore, ok := graph.V1Store.(*KVStore)
-31
View File
@@ -12,7 +12,6 @@ import (
"net"
"sort"
"sync"
"testing"
"time"
"github.com/btcsuite/btcd/btcec/v2"
@@ -28,7 +27,6 @@ import (
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/stretchr/testify/require"
)
var (
@@ -4869,32 +4867,3 @@ func (c *chanGraphNodeTx) ForEachChannel(f func(*models.ChannelEdgeInfo,
},
)
}
// MakeTestGraph creates a new instance of the ChannelGraph for testing
// purposes.
//
// NOTE: this helper currently creates a ChannelGraph that is only ever backed
// by the `KVStore` of the `V1Store` interface.
func MakeTestGraph(t testing.TB, opts ...ChanGraphOption) *ChannelGraph {
t.Helper()
// Next, create KVStore for the first time.
backend, backendCleanup, err := kvdb.GetTestBackend(t.TempDir(), "cgr")
t.Cleanup(backendCleanup)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, backend.Close())
})
graphStore, err := NewKVStore(backend)
require.NoError(t, err)
graph, err := NewChannelGraph(graphStore, opts...)
require.NoError(t, err)
require.NoError(t, graph.Start())
t.Cleanup(func() {
require.NoError(t, graph.Stop())
})
return graph
}