Skip to content

Commit 3e5d807

Browse files
committed
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.
1 parent 1184c9e commit 3e5d807

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

autopilot/prefattach_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ type testGraph interface {
3030
addRandNode() (*btcec.PublicKey, error)
3131
}
3232

33+
type testDBGraph struct {
34+
db *graphdb.ChannelGraph
35+
databaseChannelGraph
36+
}
37+
3338
func newDiskChanGraph(t *testing.T) (testGraph, error) {
3439
backend, err := kvdb.GetBoltBackend(&kvdb.BoltBackendConfig{
3540
DBPath: t.TempDir(),
@@ -44,12 +49,15 @@ func newDiskChanGraph(t *testing.T) (testGraph, error) {
4449
graphDB, err := graphdb.NewChannelGraph(backend)
4550
require.NoError(t, err)
4651

47-
return &databaseChannelGraph{
52+
return &testDBGraph{
4853
db: graphDB,
54+
databaseChannelGraph: databaseChannelGraph{
55+
db: graphDB,
56+
},
4957
}, nil
5058
}
5159

52-
var _ testGraph = (*databaseChannelGraph)(nil)
60+
var _ testGraph = (*testDBGraph)(nil)
5361

5462
func newMemChanGraph(_ *testing.T) (testGraph, error) {
5563
return newMemChannelGraph(), nil
@@ -378,7 +386,7 @@ func TestPrefAttachmentSelectSkipNodes(t *testing.T) {
378386
// addRandChannel creates a new channel two target nodes. This function is
379387
// meant to aide in the generation of random graphs for use within test cases
380388
// the exercise the autopilot package.
381-
func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
389+
func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
382390
capacity btcutil.Amount) (*ChannelEdge, *ChannelEdge, error) {
383391

384392
fetchNode := func(pub *btcec.PublicKey) (*models.LightningNode, error) {
@@ -522,7 +530,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
522530
nil
523531
}
524532

525-
func (d *databaseChannelGraph) addRandNode() (*btcec.PublicKey, error) {
533+
func (d *testDBGraph) addRandNode() (*btcec.PublicKey, error) {
526534
nodeKey, err := randKey()
527535
if err != nil {
528536
return nil, err

0 commit comments

Comments
 (0)