From 3e5d807773d247de264b287c439888bdbde15a30 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 5 Feb 2025 12:13:28 +0200 Subject: [PATCH] autopilot: add testDBGraph type Introduce a new type for testing code so the main databaseChannelGraph type does not need to make various write calls to the `graphdb.ChannelGraph` but the new testDBGraph type still can for tests. --- autopilot/prefattach_test.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/autopilot/prefattach_test.go b/autopilot/prefattach_test.go index 37fbdaa53..038fcbf35 100644 --- a/autopilot/prefattach_test.go +++ b/autopilot/prefattach_test.go @@ -30,6 +30,11 @@ type testGraph interface { addRandNode() (*btcec.PublicKey, error) } +type testDBGraph struct { + db *graphdb.ChannelGraph + databaseChannelGraph +} + func newDiskChanGraph(t *testing.T) (testGraph, error) { backend, err := kvdb.GetBoltBackend(&kvdb.BoltBackendConfig{ DBPath: t.TempDir(), @@ -44,12 +49,15 @@ func newDiskChanGraph(t *testing.T) (testGraph, error) { graphDB, err := graphdb.NewChannelGraph(backend) require.NoError(t, err) - return &databaseChannelGraph{ + return &testDBGraph{ db: graphDB, + databaseChannelGraph: databaseChannelGraph{ + db: graphDB, + }, }, nil } -var _ testGraph = (*databaseChannelGraph)(nil) +var _ testGraph = (*testDBGraph)(nil) func newMemChanGraph(_ *testing.T) (testGraph, error) { return newMemChannelGraph(), nil @@ -378,7 +386,7 @@ func TestPrefAttachmentSelectSkipNodes(t *testing.T) { // addRandChannel creates a new channel two target nodes. This function is // meant to aide in the generation of random graphs for use within test cases // the exercise the autopilot package. -func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey, +func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey, capacity btcutil.Amount) (*ChannelEdge, *ChannelEdge, error) { fetchNode := func(pub *btcec.PublicKey) (*models.LightningNode, error) { @@ -522,7 +530,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey, nil } -func (d *databaseChannelGraph) addRandNode() (*btcec.PublicKey, error) { +func (d *testDBGraph) addRandNode() (*btcec.PublicKey, error) { nodeKey, err := randKey() if err != nil { return nil, err