mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-31 17:51:33 +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"
|
"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)
|
sqlbase.Init(0)
|
||||||
var (
|
var (
|
||||||
backend kvdb.Backend
|
backend kvdb.Backend
|
||||||
@@ -53,15 +53,28 @@ func openChannelDB(ht *lntest.HarnessTest, hn *node.HarnessNode) *channeldb.DB {
|
|||||||
require.NoError(ht, err)
|
require.NoError(ht, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := channeldb.CreateWithBackend(backend)
|
return backend
|
||||||
require.NoError(ht, err)
|
|
||||||
|
|
||||||
return db
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func openNativeSQLInvoiceDB(ht *lntest.HarnessTest,
|
func openNativeSQLInvoiceDB(ht *lntest.HarnessTest,
|
||||||
hn *node.HarnessNode) invoices.InvoiceDB {
|
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
|
var db *sqldb.BaseDB
|
||||||
|
|
||||||
switch hn.Cfg.DBBackend {
|
switch hn.Cfg.DBBackend {
|
||||||
@@ -90,15 +103,7 @@ func openNativeSQLInvoiceDB(ht *lntest.HarnessTest,
|
|||||||
db = postgresStore.BaseDB
|
db = postgresStore.BaseDB
|
||||||
}
|
}
|
||||||
|
|
||||||
executor := sqldb.NewTransactionExecutor(
|
return db
|
||||||
db, func(tx *sql.Tx) invoices.SQLInvoiceQueries {
|
|
||||||
return db.WithTx(tx)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return invoices.NewSQLStore(
|
|
||||||
executor, clock.NewDefaultClock(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clampTime truncates the time of the passed invoice to the microsecond level.
|
// 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())
|
require.NoError(ht, bob.Stop())
|
||||||
|
|
||||||
// Open the KV channel DB.
|
// Open the KV channel DB.
|
||||||
db := openChannelDB(ht, bob)
|
db, err := channeldb.CreateWithBackend(openKVBackend(ht, bob))
|
||||||
|
require.NoError(ht, err)
|
||||||
|
|
||||||
query := invoices.InvoiceQuery{
|
query := invoices.InvoiceQuery{
|
||||||
IndexOffset: 0,
|
IndexOffset: 0,
|
||||||
|
Reference in New Issue
Block a user