mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-25 08:11:18 +02:00
graph: test cleanup
Remove the kvdb.Backend return type of the `makeTestGraph` helper. This is in preparation for the helper being used to create a test graph backed by a DB other than bbolt.
This commit is contained in:
parent
424f63b310
commit
4ab0699e10
@ -1352,10 +1352,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
|||||||
testAddrs = append(testAddrs, testAddr)
|
testAddrs = append(testAddrs, testAddr)
|
||||||
|
|
||||||
// Next, create a temporary graph database for usage within the test.
|
// Next, create a temporary graph database for usage within the test.
|
||||||
graph, graphBackend, err := makeTestGraph(t, useCache)
|
graph := makeTestGraph(t, useCache)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
aliasMap := make(map[string]route.Vertex)
|
aliasMap := make(map[string]route.Vertex)
|
||||||
privKeyMap := make(map[string]*btcec.PrivateKey)
|
privKeyMap := make(map[string]*btcec.PrivateKey)
|
||||||
@ -1563,7 +1560,6 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
|||||||
|
|
||||||
return &testGraphInstance{
|
return &testGraphInstance{
|
||||||
graph: graph,
|
graph: graph,
|
||||||
graphBackend: graphBackend,
|
|
||||||
aliasMap: aliasMap,
|
aliasMap: aliasMap,
|
||||||
privKeyMap: privKeyMap,
|
privKeyMap: privKeyMap,
|
||||||
channelIDs: channelIDs,
|
channelIDs: channelIDs,
|
||||||
@ -1730,10 +1726,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
testAddrs = append(testAddrs, testAddr)
|
testAddrs = append(testAddrs, testAddr)
|
||||||
|
|
||||||
// Next, create a temporary graph database for usage within the test.
|
// Next, create a temporary graph database for usage within the test.
|
||||||
graph, graphBackend, err := makeTestGraph(t, useCache)
|
graph := makeTestGraph(t, useCache)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
aliasMap := make(map[string]route.Vertex)
|
aliasMap := make(map[string]route.Vertex)
|
||||||
privKeyMap := make(map[string]*btcec.PrivateKey)
|
privKeyMap := make(map[string]*btcec.PrivateKey)
|
||||||
@ -1948,7 +1941,6 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
|
|
||||||
return &testGraphInstance{
|
return &testGraphInstance{
|
||||||
graph: graph,
|
graph: graph,
|
||||||
graphBackend: graphBackend,
|
|
||||||
aliasMap: aliasMap,
|
aliasMap: aliasMap,
|
||||||
privKeyMap: privKeyMap,
|
privKeyMap: privKeyMap,
|
||||||
links: links,
|
links: links,
|
||||||
|
@ -1034,8 +1034,7 @@ type testCtx struct {
|
|||||||
func createTestCtxSingleNode(t *testing.T,
|
func createTestCtxSingleNode(t *testing.T,
|
||||||
startingHeight uint32) *testCtx {
|
startingHeight uint32) *testCtx {
|
||||||
|
|
||||||
graph, graphBackend, err := makeTestGraph(t, true)
|
graph := makeTestGraph(t, true)
|
||||||
require.NoError(t, err, "failed to make test graph")
|
|
||||||
|
|
||||||
sourceNode := createTestNode(t)
|
sourceNode := createTestNode(t)
|
||||||
|
|
||||||
@ -1045,7 +1044,6 @@ func createTestCtxSingleNode(t *testing.T,
|
|||||||
|
|
||||||
graphInstance := &testGraphInstance{
|
graphInstance := &testGraphInstance{
|
||||||
graph: graph,
|
graph: graph,
|
||||||
graphBackend: graphBackend,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return createTestCtxFromGraphInstance(
|
return createTestCtxFromGraphInstance(
|
||||||
@ -1086,14 +1084,12 @@ func (c *testCtx) RestartBuilder(t *testing.T) {
|
|||||||
|
|
||||||
// makeTestGraph creates a new instance of a channeldb.ChannelGraph for testing
|
// makeTestGraph creates a new instance of a channeldb.ChannelGraph for testing
|
||||||
// purposes.
|
// purposes.
|
||||||
func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
|
func makeTestGraph(t *testing.T, useCache bool) *graphdb.ChannelGraph {
|
||||||
kvdb.Backend, error) {
|
t.Helper()
|
||||||
|
|
||||||
// Create channelgraph for the first time.
|
// Create channelgraph for the first time.
|
||||||
backend, backendCleanup, err := kvdb.GetTestBackend(t.TempDir(), "cgr")
|
backend, backendCleanup, err := kvdb.GetTestBackend(t.TempDir(), "cgr")
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Cleanup(backendCleanup)
|
t.Cleanup(backendCleanup)
|
||||||
|
|
||||||
@ -1101,20 +1097,17 @@ func makeTestGraph(t *testing.T, useCache bool) (*graphdb.ChannelGraph,
|
|||||||
&graphdb.Config{KVDB: backend},
|
&graphdb.Config{KVDB: backend},
|
||||||
graphdb.WithUseGraphCache(useCache),
|
graphdb.WithUseGraphCache(useCache),
|
||||||
)
|
)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
require.NoError(t, graph.Start())
|
require.NoError(t, graph.Start())
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
require.NoError(t, graph.Stop())
|
require.NoError(t, graph.Stop())
|
||||||
})
|
})
|
||||||
|
|
||||||
return graph, backend, nil
|
return graph
|
||||||
}
|
}
|
||||||
|
|
||||||
type testGraphInstance struct {
|
type testGraphInstance struct {
|
||||||
graph *graphdb.ChannelGraph
|
graph *graphdb.ChannelGraph
|
||||||
graphBackend kvdb.Backend
|
|
||||||
|
|
||||||
// aliasMap is a map from a node's alias to its public key. This type is
|
// aliasMap is a map from a node's alias to its public key. This type is
|
||||||
// provided in order to allow easily look up from the human memorable
|
// provided in order to allow easily look up from the human memorable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user