Skip to content

Commit

Permalink
invoices: run InvoiceStore and InvoiceRegistry tests on SQLite too
Browse files Browse the repository at this point in the history
  • Loading branch information
bhandras committed Mar 1, 2024
1 parent 734d3a9 commit b10ce17
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
22 changes: 21 additions & 1 deletion invoices/invoiceregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package invoices_test
import (
"context"
"crypto/rand"
"database/sql"
"fmt"
"math"
"testing"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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)
})
}
}

Expand Down
27 changes: 25 additions & 2 deletions invoices/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package invoices_test
import (
"context"
"crypto/rand"
"database/sql"
"fmt"
"math"
"testing"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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)
})
}
}

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit b10ce17

Please sign in to comment.