From f5b50afb92c7036398fac6a05095f410fdb47c17 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 14 Jul 2025 09:07:00 +0200 Subject: [PATCH] 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. --- itest/lnd_invoice_migration_test.go | 36 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/itest/lnd_invoice_migration_test.go b/itest/lnd_invoice_migration_test.go index 637ec5992..07028bc65 100644 --- a/itest/lnd_invoice_migration_test.go +++ b/itest/lnd_invoice_migration_test.go @@ -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,