invoices: run InvoiceStore and InvoiceRegistry tests on SQLite too

This commit is contained in:
Andras Banki-Horvath 2023-11-22 17:16:02 +01:00
parent 734d3a9d66
commit b10ce17cd4
No known key found for this signature in database
GPG Key ID: 80E5375C094198D8
2 changed files with 46 additions and 3 deletions

View File

@ -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)
})
}
}

View File

@ -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)