multi: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
29 files changed
+393
-606
No files matched your search
@@ -346,9 +346,8 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
|
||||
func TestOpenChannelPutGetDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -487,11 +486,10 @@ func TestOptionalShutdown(t *testing.T) {
|
||||
test := test
|
||||
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to make test database: %v", err)
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -572,9 +570,8 @@ func assertRevocationLogEntryEqual(t *testing.T, c *ChannelCommitment,
|
||||
func TestChannelStateTransition(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -889,9 +886,8 @@ func TestChannelStateTransition(t *testing.T) {
|
||||
func TestFetchPendingChannels(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -960,9 +956,8 @@ func TestFetchPendingChannels(t *testing.T) {
|
||||
func TestFetchClosedChannels(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -1041,9 +1036,8 @@ func TestFetchWaitingCloseChannels(t *testing.T) {
|
||||
// We'll start by creating two channels within our test database. One of
|
||||
// them will have their funding transaction confirmed on-chain, while
|
||||
// the other one will remain unconfirmed.
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -1154,9 +1148,8 @@ func TestFetchWaitingCloseChannels(t *testing.T) {
|
||||
func TestRefresh(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -1298,12 +1291,11 @@ func TestCloseInitiator(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to make test database: %v",
|
||||
err)
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -1345,12 +1337,11 @@ func TestCloseInitiator(t *testing.T) {
|
||||
// TestCloseChannelStatus tests setting of a channel status on the historical
|
||||
// channel on channel close.
|
||||
func TestCloseChannelStatus(t *testing.T) {
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to make test database: %v",
|
||||
err)
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
|
||||
+8
-13
@@ -4,9 +4,9 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
@@ -1655,33 +1655,28 @@ func (c *ChannelStateDB) FetchHistoricalChannel(outPoint *wire.OutPoint) (
|
||||
// MakeTestDB creates a new instance of the ChannelDB for testing purposes.
|
||||
// A callback which cleans up the created temporary directories is also
|
||||
// returned and intended to be executed after the test completes.
|
||||
func MakeTestDB(modifiers ...OptionModifier) (*DB, func(), error) {
|
||||
func MakeTestDB(t *testing.T, modifiers ...OptionModifier) (*DB, error) {
|
||||
// First, create a temporary directory to be used for the duration of
|
||||
// this test.
|
||||
tempDirName, err := ioutil.TempDir("", "channeldb")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
tempDirName := t.TempDir()
|
||||
|
||||
// Next, create channeldb for the first time.
|
||||
backend, backendCleanup, err := kvdb.GetTestBackend(tempDirName, "cdb")
|
||||
if err != nil {
|
||||
backendCleanup()
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cdb, err := CreateWithBackend(backend, modifiers...)
|
||||
if err != nil {
|
||||
backendCleanup()
|
||||
os.RemoveAll(tempDirName)
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cleanUp := func() {
|
||||
t.Cleanup(func() {
|
||||
cdb.Close()
|
||||
backendCleanup()
|
||||
os.RemoveAll(tempDirName)
|
||||
}
|
||||
})
|
||||
|
||||
return cdb, cleanUp, nil
|
||||
return cdb, nil
|
||||
}
|
||||
+9
-16
@@ -36,7 +36,7 @@ func TestOpenWithCreate(t *testing.T) {
|
||||
dbPath := filepath.Join(tempDirName, "cdb")
|
||||
backend, cleanup, err := kvdb.GetTestBackend(dbPath, "cdb")
|
||||
require.NoError(t, err, "unable to get test db backend")
|
||||
defer cleanup()
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
cdb, err := CreateWithBackend(backend)
|
||||
require.NoError(t, err, "unable to create channeldb")
|
||||
@@ -72,7 +72,7 @@ func TestWipe(t *testing.T) {
|
||||
dbPath := filepath.Join(tempDirName, "cdb")
|
||||
backend, cleanup, err := kvdb.GetTestBackend(dbPath, "cdb")
|
||||
require.NoError(t, err, "unable to get test db backend")
|
||||
defer cleanup()
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
fullDB, err := CreateWithBackend(backend)
|
||||
require.NoError(t, err, "unable to create channeldb")
|
||||
@@ -101,9 +101,8 @@ func TestFetchClosedChannelForID(t *testing.T) {
|
||||
|
||||
const numChans = 101
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -172,9 +171,8 @@ func TestFetchClosedChannelForID(t *testing.T) {
|
||||
func TestAddrsForNode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
graph := fullDB.ChannelGraph()
|
||||
|
||||
@@ -226,9 +224,8 @@ func TestAddrsForNode(t *testing.T) {
|
||||
func TestFetchChannel(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -324,9 +321,8 @@ func genRandomChannelShell() (*ChannelShell, error) {
|
||||
func TestRestoreChannelShells(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -414,9 +410,8 @@ func TestRestoreChannelShells(t *testing.T) {
|
||||
func TestAbandonChannel(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -581,12 +576,11 @@ func TestFetchChannels(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to make test "+
|
||||
"database: %v", err)
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -652,9 +646,8 @@ func TestFetchChannels(t *testing.T) {
|
||||
|
||||
// TestFetchHistoricalChannel tests lookup of historical channels.
|
||||
func TestFetchHistoricalChannel(t *testing.T) {
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
|
||||
@@ -20,9 +20,8 @@ func TestForwardingLogBasicStorageAndQuery(t *testing.T) {
|
||||
// First, we'll set up a test database, and use that to instantiate the
|
||||
// forwarding event log that we'll be using for the duration of the
|
||||
// test.
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
defer cleanUp()
|
||||
|
||||
log := ForwardingLog{
|
||||
db: db,
|
||||
@@ -89,9 +88,8 @@ func TestForwardingLogQueryOptions(t *testing.T) {
|
||||
// First, we'll set up a test database, and use that to instantiate the
|
||||
// forwarding event log that we'll be using for the duration of the
|
||||
// test.
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
defer cleanUp()
|
||||
|
||||
log := ForwardingLog{
|
||||
db: db,
|
||||
@@ -189,9 +187,8 @@ func TestForwardingLogQueryLimit(t *testing.T) {
|
||||
// First, we'll set up a test database, and use that to instantiate the
|
||||
// forwarding event log that we'll be using for the duration of the
|
||||
// test.
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
defer cleanUp()
|
||||
|
||||
log := ForwardingLog{
|
||||
db: db,
|
||||
@@ -301,9 +298,8 @@ func TestForwardingLogStoreEvent(t *testing.T) {
|
||||
// First, we'll set up a test database, and use that to instantiate the
|
||||
// forwarding event log that we'll be using for the duration of the
|
||||
// test.
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
defer cleanUp()
|
||||
|
||||
log := ForwardingLog{
|
||||
db: db,
|
||||
|
||||
+20
-40
@@ -149,8 +149,7 @@ func TestInvoiceWorkflow(t *testing.T) {
|
||||
}
|
||||
|
||||
func testInvoiceWorkflow(t *testing.T, test invWorkflowTest) {
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
|
||||
// Create a fake invoice which we'll use several times in the tests
|
||||
@@ -293,8 +292,7 @@ func testInvoiceWorkflow(t *testing.T, test invWorkflowTest) {
|
||||
// TestAddDuplicatePayAddr asserts that the payment addresses of inserted
|
||||
// invoices are unique.
|
||||
func TestAddDuplicatePayAddr(t *testing.T) {
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create two invoices with the same payment addr.
|
||||
@@ -320,8 +318,7 @@ func TestAddDuplicatePayAddr(t *testing.T) {
|
||||
// addresses to be inserted if they are blank to support JIT legacy keysend
|
||||
// invoices.
|
||||
func TestAddDuplicateKeysendPayAddr(t *testing.T) {
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create two invoices with the same _blank_ payment addr.
|
||||
@@ -363,8 +360,7 @@ func TestAddDuplicateKeysendPayAddr(t *testing.T) {
|
||||
// ensures that the HTLC's payment hash always matches the payment hash in the
|
||||
// returned invoice.
|
||||
func TestFailInvoiceLookupMPPPayAddrOnly(t *testing.T) {
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create and insert a random invoice.
|
||||
@@ -391,8 +387,7 @@ func TestFailInvoiceLookupMPPPayAddrOnly(t *testing.T) {
|
||||
// TestInvRefEquivocation asserts that retrieving or updating an invoice using
|
||||
// an equivocating InvoiceRef results in ErrInvRefEquivocation.
|
||||
func TestInvRefEquivocation(t *testing.T) {
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Add two random invoices.
|
||||
@@ -431,8 +426,7 @@ func TestInvRefEquivocation(t *testing.T) {
|
||||
func TestInvoiceCancelSingleHtlc(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
|
||||
preimage := lntypes.Preimage{1}
|
||||
@@ -499,8 +493,7 @@ func TestInvoiceCancelSingleHtlc(t *testing.T) {
|
||||
func TestInvoiceCancelSingleHtlcAMP(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := MakeTestDB(OptionClock(testClock))
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t, OptionClock(testClock))
|
||||
require.NoError(t, err, "unable to make test db: %v", err)
|
||||
|
||||
// We'll start out by creating an invoice and writing it to the DB.
|
||||
@@ -656,8 +649,7 @@ func TestInvoiceCancelSingleHtlcAMP(t *testing.T) {
|
||||
func TestInvoiceAddTimeSeries(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := MakeTestDB(OptionClock(testClock))
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t, OptionClock(testClock))
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
|
||||
_, err = db.InvoicesAddedSince(0)
|
||||
@@ -812,8 +804,7 @@ func TestSettleIndexAmpPayments(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testClock := clock.NewTestClock(testNow)
|
||||
db, cleanUp, err := MakeTestDB(OptionClock(testClock))
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t, OptionClock(testClock))
|
||||
require.Nil(t, err)
|
||||
|
||||
// First, we'll make a sample invoice that'll be paid to several times
|
||||
@@ -969,8 +960,7 @@ func TestSettleIndexAmpPayments(t *testing.T) {
|
||||
func TestScanInvoices(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
|
||||
var invoices map[lntypes.Hash]*Invoice
|
||||
@@ -1028,8 +1018,7 @@ func TestScanInvoices(t *testing.T) {
|
||||
func TestDuplicateSettleInvoice(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := MakeTestDB(OptionClock(testClock))
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t, OptionClock(testClock))
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
|
||||
// We'll start out by creating an invoice and writing it to the DB.
|
||||
@@ -1087,8 +1076,7 @@ func TestDuplicateSettleInvoice(t *testing.T) {
|
||||
func TestQueryInvoices(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := MakeTestDB(OptionClock(testClock))
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t, OptionClock(testClock))
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
|
||||
// To begin the test, we'll add 50 invoices to the database. We'll
|
||||
@@ -1400,8 +1388,7 @@ func getUpdateInvoice(amt lnwire.MilliSatoshi) InvoiceUpdateCallback {
|
||||
func TestCustomRecords(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
|
||||
preimage := lntypes.Preimage{1}
|
||||
@@ -1470,8 +1457,7 @@ func TestInvoiceHtlcAMPFields(t *testing.T) {
|
||||
}
|
||||
|
||||
func testInvoiceHtlcAMPFields(t *testing.T, isAMP bool) {
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.Nil(t, err)
|
||||
|
||||
testInvoice, err := randInvoice(1000)
|
||||
@@ -1652,8 +1638,7 @@ func TestHTLCSet(t *testing.T) {
|
||||
// TestAddInvoiceWithHTLCs asserts that you can't insert an invoice that already
|
||||
// has HTLCs.
|
||||
func TestAddInvoiceWithHTLCs(t *testing.T) {
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.Nil(t, err)
|
||||
|
||||
testInvoice, err := randInvoice(1000)
|
||||
@@ -1672,8 +1657,7 @@ func TestAddInvoiceWithHTLCs(t *testing.T) {
|
||||
// that invoices with duplicate set ids are disallowed.
|
||||
func TestSetIDIndex(t *testing.T) {
|
||||
testClock := clock.NewTestClock(testNow)
|
||||
db, cleanUp, err := MakeTestDB(OptionClock(testClock))
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t, OptionClock(testClock))
|
||||
require.Nil(t, err)
|
||||
|
||||
// We'll start out by creating an invoice and writing it to the DB.
|
||||
@@ -1983,8 +1967,7 @@ func getUpdateInvoiceAMPSettle(setID *[32]byte,
|
||||
func TestUnexpectedInvoicePreimage(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
|
||||
invoice, err := randInvoice(lnwire.MilliSatoshi(100))
|
||||
@@ -2040,8 +2023,7 @@ func TestUpdateHTLCPreimages(t *testing.T) {
|
||||
}
|
||||
|
||||
func testUpdateHTLCPreimages(t *testing.T, test updateHTLCPreimageTestCase) {
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
|
||||
// We'll start out by creating an invoice and writing it to the DB.
|
||||
@@ -2772,8 +2754,7 @@ func testUpdateHTLC(t *testing.T, test updateHTLCTest) {
|
||||
func TestDeleteInvoices(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
|
||||
// Add some invoices to the test db.
|
||||
@@ -2856,9 +2837,8 @@ func TestDeleteInvoices(t *testing.T) {
|
||||
func TestAddInvoiceInvalidFeatureDeps(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test db")
|
||||
defer cleanup()
|
||||
|
||||
invoice, err := randInvoice(500)
|
||||
require.NoError(t, err)
|
||||
|
||||
+7
-13
@@ -15,8 +15,7 @@ import (
|
||||
func applyMigration(t *testing.T, beforeMigration, afterMigration func(d *DB),
|
||||
migrationFunc migration, shouldFail bool, dryRun bool) {
|
||||
|
||||
cdb, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
cdb, err := MakeTestDB(t)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -86,8 +85,7 @@ func applyMigration(t *testing.T, beforeMigration, afterMigration func(d *DB),
|
||||
func TestVersionFetchPut(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -450,7 +448,7 @@ func TestMigrationReversion(t *testing.T) {
|
||||
|
||||
backend, cleanup, err = kvdb.GetTestBackend(tempDirName, "cdb")
|
||||
require.NoError(t, err, "unable to get test db backend")
|
||||
defer cleanup()
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
_, err = CreateWithBackend(backend)
|
||||
if err != ErrDBReversion {
|
||||
@@ -498,8 +496,7 @@ func TestMigrationDryRun(t *testing.T) {
|
||||
func TestOptionalMeta(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test read an empty optional meta.
|
||||
@@ -527,8 +524,7 @@ func TestOptionalMeta(t *testing.T) {
|
||||
func TestApplyOptionalVersions(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Overwrite the migration function so we can count how many times the
|
||||
@@ -581,8 +577,7 @@ func TestApplyOptionalVersions(t *testing.T) {
|
||||
func TestFetchMeta(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
|
||||
meta := &Meta{}
|
||||
@@ -601,8 +596,7 @@ func TestFetchMeta(t *testing.T) {
|
||||
func TestMarkerAndTombstone(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := MakeTestDB()
|
||||
defer cleanUp()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test that a generic marker is not present in a fresh DB.
|
||||
|
||||
@@ -14,9 +14,8 @@ import (
|
||||
func TestLinkNodeEncodeDecode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
@@ -103,9 +102,8 @@ func TestLinkNodeEncodeDecode(t *testing.T) {
|
||||
func TestDeleteLinkNode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
cdb := fullDB.ChannelStateDB()
|
||||
|
||||
|
||||
@@ -54,8 +54,7 @@ func genInfo() (*PaymentCreationInfo, *HTLCAttemptInfo,
|
||||
func TestPaymentControlSwitchFail(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to init db")
|
||||
|
||||
pControl := NewPaymentControl(db)
|
||||
@@ -185,9 +184,7 @@ func TestPaymentControlSwitchFail(t *testing.T) {
|
||||
func TestPaymentControlSwitchDoubleSend(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to init db")
|
||||
|
||||
pControl := NewPaymentControl(db)
|
||||
@@ -258,9 +255,7 @@ func TestPaymentControlSwitchDoubleSend(t *testing.T) {
|
||||
func TestPaymentControlSuccessesWithoutInFlight(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to init db")
|
||||
|
||||
pControl := NewPaymentControl(db)
|
||||
@@ -287,9 +282,7 @@ func TestPaymentControlSuccessesWithoutInFlight(t *testing.T) {
|
||||
func TestPaymentControlFailsWithoutInFlight(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to init db")
|
||||
|
||||
pControl := NewPaymentControl(db)
|
||||
@@ -311,9 +304,7 @@ func TestPaymentControlFailsWithoutInFlight(t *testing.T) {
|
||||
func TestPaymentControlDeleteNonInFlight(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to init db")
|
||||
|
||||
// Create a sequence number for duplicate payments that will not collide
|
||||
@@ -520,8 +511,7 @@ func TestPaymentControlDeleteNonInFlight(t *testing.T) {
|
||||
func TestPaymentControlDeletePayments(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to init db")
|
||||
|
||||
pControl := NewPaymentControl(db)
|
||||
@@ -574,8 +564,7 @@ func TestPaymentControlDeletePayments(t *testing.T) {
|
||||
func TestPaymentControlDeleteSinglePayment(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to init db")
|
||||
|
||||
pControl := NewPaymentControl(db)
|
||||
@@ -678,9 +667,7 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
}
|
||||
|
||||
runSubTest := func(t *testing.T, test testCase) {
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
|
||||
db, err := MakeTestDB(t)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init db: %v", err)
|
||||
}
|
||||
@@ -924,9 +911,7 @@ func TestPaymentControlMultiShard(t *testing.T) {
|
||||
func TestPaymentControlMPPRecordValidation(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to init db")
|
||||
|
||||
pControl := NewPaymentControl(db)
|
||||
@@ -1017,8 +1002,7 @@ func TestDeleteFailedAttempts(t *testing.T) {
|
||||
}
|
||||
|
||||
func testDeleteFailedAttempts(t *testing.T, keepFailedPaymentAttempts bool) {
|
||||
db, cleanup, err := MakeTestDB()
|
||||
defer cleanup()
|
||||
db, err := MakeTestDB(t)
|
||||
|
||||
require.NoError(t, err, "unable to init db")
|
||||
db.keepFailedPaymentAttempts = keepFailedPaymentAttempts
|
||||
|
||||
@@ -398,11 +398,10 @@ func TestQueryPayments(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to init db: %v", err)
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
// Make a preliminary query to make sure it's ok to
|
||||
// query when we have no payments.
|
||||
@@ -514,11 +513,9 @@ func TestQueryPayments(t *testing.T) {
|
||||
// case where a specific duplicate is not found and the duplicates bucket is not
|
||||
// present when we expect it to be.
|
||||
func TestFetchPaymentWithSequenceNumber(t *testing.T) {
|
||||
db, cleanup, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
|
||||
defer cleanup()
|
||||
|
||||
pControl := NewPaymentControl(db)
|
||||
|
||||
// Generate a test payment which does not have duplicates.
|
||||
|
||||
@@ -10,9 +10,8 @@ import (
|
||||
|
||||
// TestFlapCount tests lookup and writing of flap count to disk.
|
||||
func TestFlapCount(t *testing.T) {
|
||||
db, cleanup, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
defer cleanup()
|
||||
|
||||
// Try to read flap count for a peer that we have no records for.
|
||||
_, err = db.ReadFlapCount(testPub)
|
||||
|
||||
@@ -48,9 +48,8 @@ func TestPersistReport(t *testing.T) {
|
||||
test := test
|
||||
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
db, cleanup, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
defer cleanup()
|
||||
|
||||
channelOutpoint := testChanPoint1
|
||||
|
||||
@@ -85,9 +84,8 @@ func TestPersistReport(t *testing.T) {
|
||||
// channel, testing that the appropriate error is returned based on the state
|
||||
// of the existing bucket.
|
||||
func TestFetchChannelReadBucket(t *testing.T) {
|
||||
db, cleanup, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
defer cleanup()
|
||||
|
||||
channelOutpoint := testChanPoint1
|
||||
|
||||
@@ -197,9 +195,8 @@ func TestFetchChannelWriteBucket(t *testing.T) {
|
||||
test := test
|
||||
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
db, cleanup, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
defer cleanup()
|
||||
|
||||
// Update our db to the starting state we expect.
|
||||
err = kvdb.Update(db, test.setup, func() {})
|
||||
|
||||
@@ -291,9 +291,8 @@ func TestDerializeRevocationLog(t *testing.T) {
|
||||
func TestFetchLogBucket(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
defer cleanUp()
|
||||
|
||||
backend := fullDB.ChannelStateDB().backend
|
||||
|
||||
@@ -326,9 +325,8 @@ func TestFetchLogBucket(t *testing.T) {
|
||||
func TestDeleteLogBucket(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
defer cleanUp()
|
||||
|
||||
backend := fullDB.ChannelStateDB().backend
|
||||
|
||||
@@ -423,9 +421,8 @@ func TestPutRevocationLog(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
defer cleanUp()
|
||||
|
||||
backend := fullDB.ChannelStateDB().backend
|
||||
|
||||
@@ -523,9 +520,8 @@ func TestFetchRevocationLogCompatible(t *testing.T) {
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
|
||||
fullDB, cleanUp, err := MakeTestDB()
|
||||
fullDB, err := MakeTestDB(t)
|
||||
require.NoError(t, err)
|
||||
defer cleanUp()
|
||||
|
||||
backend := fullDB.ChannelStateDB().backend
|
||||
|
||||
|
||||
@@ -15,9 +15,8 @@ import (
|
||||
func TestWaitingProofStore(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanup, err := MakeTestDB()
|
||||
db, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "failed to make test database")
|
||||
defer cleanup()
|
||||
|
||||
proof1 := NewWaitingProof(true, &lnwire.AnnounceSignatures{
|
||||
NodeSignature: wireSig,
|
||||
|
||||
@@ -13,9 +13,8 @@ import (
|
||||
func TestWitnessCacheSha256Retrieval(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cdb, cleanUp, err := MakeTestDB()
|
||||
cdb, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
wCache := cdb.NewWitnessCache()
|
||||
|
||||
@@ -54,9 +53,8 @@ func TestWitnessCacheSha256Retrieval(t *testing.T) {
|
||||
func TestWitnessCacheSha256Deletion(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cdb, cleanUp, err := MakeTestDB()
|
||||
cdb, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
wCache := cdb.NewWitnessCache()
|
||||
|
||||
@@ -101,9 +99,8 @@ func TestWitnessCacheSha256Deletion(t *testing.T) {
|
||||
func TestWitnessCacheUnknownWitness(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cdb, cleanUp, err := MakeTestDB()
|
||||
cdb, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
wCache := cdb.NewWitnessCache()
|
||||
|
||||
@@ -118,9 +115,8 @@ func TestWitnessCacheUnknownWitness(t *testing.T) {
|
||||
// TestAddSha256Witnesses tests that insertion using AddSha256Witnesses behaves
|
||||
// identically to the insertion via the generalized interface.
|
||||
func TestAddSha256Witnesses(t *testing.T) {
|
||||
cdb, cleanUp, err := MakeTestDB()
|
||||
cdb, err := MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to make test database")
|
||||
defer cleanUp()
|
||||
|
||||
wCache := cdb.NewWitnessCache()
|
||||
|
||||
|
||||
Reference in new issue
Block a user