mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 22:21:18 +02:00
itest: make invoice mig helpers re-usable
Refactor to make some of the invoice migration helpers re-usable so that we can use them for the graph migration itests.
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func openChannelDB(ht *lntest.HarnessTest, hn *node.HarnessNode) *channeldb.DB {
|
||||
func openKVBackend(ht *lntest.HarnessTest, hn *node.HarnessNode) kvdb.Backend {
|
||||
sqlbase.Init(0)
|
||||
var (
|
||||
backend kvdb.Backend
|
||||
@@ -53,15 +53,28 @@ func openChannelDB(ht *lntest.HarnessTest, hn *node.HarnessNode) *channeldb.DB {
|
||||
require.NoError(ht, err)
|
||||
}
|
||||
|
||||
db, err := channeldb.CreateWithBackend(backend)
|
||||
require.NoError(ht, err)
|
||||
|
||||
return db
|
||||
return backend
|
||||
}
|
||||
|
||||
func openNativeSQLInvoiceDB(ht *lntest.HarnessTest,
|
||||
hn *node.HarnessNode) invoices.InvoiceDB {
|
||||
|
||||
db := openNativeSQLDB(ht, hn)
|
||||
|
||||
executor := sqldb.NewTransactionExecutor(
|
||||
db, func(tx *sql.Tx) invoices.SQLInvoiceQueries {
|
||||
return db.WithTx(tx)
|
||||
},
|
||||
)
|
||||
|
||||
return invoices.NewSQLStore(
|
||||
executor, clock.NewDefaultClock(),
|
||||
)
|
||||
}
|
||||
|
||||
func openNativeSQLDB(ht *lntest.HarnessTest,
|
||||
hn *node.HarnessNode) *sqldb.BaseDB {
|
||||
|
||||
var db *sqldb.BaseDB
|
||||
|
||||
switch hn.Cfg.DBBackend {
|
||||
@@ -90,15 +103,7 @@ func openNativeSQLInvoiceDB(ht *lntest.HarnessTest,
|
||||
db = postgresStore.BaseDB
|
||||
}
|
||||
|
||||
executor := sqldb.NewTransactionExecutor(
|
||||
db, func(tx *sql.Tx) invoices.SQLInvoiceQueries {
|
||||
return db.WithTx(tx)
|
||||
},
|
||||
)
|
||||
|
||||
return invoices.NewSQLStore(
|
||||
executor, clock.NewDefaultClock(),
|
||||
)
|
||||
return db
|
||||
}
|
||||
|
||||
// clampTime truncates the time of the passed invoice to the microsecond level.
|
||||
@@ -238,7 +243,8 @@ func testInvoiceMigration(ht *lntest.HarnessTest) {
|
||||
require.NoError(ht, bob.Stop())
|
||||
|
||||
// Open the KV channel DB.
|
||||
db := openChannelDB(ht, bob)
|
||||
db, err := channeldb.CreateWithBackend(openKVBackend(ht, bob))
|
||||
require.NoError(ht, err)
|
||||
|
||||
query := invoices.InvoiceQuery{
|
||||
IndexOffset: 0,
|
||||
|
Reference in New Issue
Block a user