From b10ce17cd4531ca57c881a65242a4b488496df56 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Wed, 22 Nov 2023 17:16:02 +0100 Subject: [PATCH] invoices: run InvoiceStore and InvoiceRegistry tests on SQLite too --- invoices/invoiceregistry_test.go | 22 +++++++++++++++++++++- invoices/invoices_test.go | 27 +++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/invoices/invoiceregistry_test.go b/invoices/invoiceregistry_test.go index 04fe310b5..a1204573c 100644 --- a/invoices/invoiceregistry_test.go +++ b/invoices/invoiceregistry_test.go @@ -3,6 +3,7 @@ package invoices_test import ( "context" "crypto/rand" + "database/sql" "fmt" "math" "testing" @@ -18,6 +19,7 @@ import ( "github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/record" + "github.com/lightningnetwork/lnd/sqldb" "github.com/stretchr/testify/require" ) @@ -114,12 +116,30 @@ func TestInvoiceRegistry(t *testing.T) { return db, testClock } + makeSQLDB := func(t *testing.T) (invpkg.InvoiceDB, *clock.TestClock) { + db := sqldb.NewTestSqliteDB(t) + + executor := sqldb.NewTransactionExecutor( + db, func(tx *sql.Tx) sqldb.InvoiceQueries { + return db.BaseDB.WithTx(tx) + }, + ) + + testClock := clock.NewTestClock(testNow) + + return sqldb.NewInvoiceStore(executor, testClock), testClock + } + for _, test := range testList { test := test - t.Run(test.name, func(t *testing.T) { + t.Run(test.name+"_KV", func(t *testing.T) { test.test(t, makeKeyValueDB) }) + + t.Run(test.name+"_SQL", func(t *testing.T) { + test.test(t, makeSQLDB) + }) } } diff --git a/invoices/invoices_test.go b/invoices/invoices_test.go index 9e850fcbc..4296f0a54 100644 --- a/invoices/invoices_test.go +++ b/invoices/invoices_test.go @@ -3,6 +3,7 @@ package invoices_test import ( "context" "crypto/rand" + "database/sql" "fmt" "math" "testing" @@ -16,6 +17,7 @@ import ( "github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/record" + "github.com/lightningnetwork/lnd/sqldb" "github.com/stretchr/testify/require" ) @@ -198,12 +200,30 @@ func TestInvoices(t *testing.T) { return db } + makeSQLDB := func(t *testing.T) invpkg.InvoiceDB { + db := sqldb.NewTestSqliteDB(t) + + executor := sqldb.NewTransactionExecutor( + db, func(tx *sql.Tx) sqldb.InvoiceQueries { + return db.BaseDB.WithTx(tx) + }, + ) + + return sqldb.NewInvoiceStore( + executor, clock.NewTestClock(testNow), + ) + } + for _, test := range testList { test := test - t.Run(test.name, func(t *testing.T) { + t.Run(test.name+"_KV", func(t *testing.T) { test.test(t, makeKeyValueDB) }) + + t.Run(test.name+"_SQL", func(t *testing.T) { + test.test(t, makeSQLDB) + }) } } @@ -2113,7 +2133,10 @@ func testSetIDIndex(t *testing.T, makeDB func(t *testing.T) invpkg.InvoiceDB) { ) _, err = db.UpdateInvoice( ctxb, ref2, (*invpkg.SetID)(setID), - updateAcceptAMPHtlc(0, amt, setID, true), + // Note: we need a unique HTLC ID here otherwise the update will + // be rejected as a duplicate (due to SQL unique constraint + // violation). + updateAcceptAMPHtlc(55, amt, setID, true), ) require.Equal(t, invpkg.ErrDuplicateSetID{SetID: *setID}, err)