mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
multi: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
5c5997935d
commit
c70e39cd21
@ -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()
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
||||
|
@ -956,18 +956,18 @@ restartCheck:
|
||||
|
||||
func initBreachedState(t *testing.T) (*BreachArbiter,
|
||||
*lnwallet.LightningChannel, *lnwallet.LightningChannel,
|
||||
*lnwallet.LocalForceCloseSummary, chan *ContractBreachEvent,
|
||||
func(), func()) {
|
||||
*lnwallet.LocalForceCloseSummary, chan *ContractBreachEvent) {
|
||||
|
||||
// Create a pair of channels using a notifier that allows us to signal
|
||||
// a spend of the funding transaction. Alice's channel will be the on
|
||||
// observing a breach.
|
||||
alice, bob, cleanUpChans, err := createInitChannels(t, 1)
|
||||
alice, bob, err := createInitChannels(t, 1)
|
||||
require.NoError(t, err, "unable to create test channels")
|
||||
|
||||
// Instantiate a breach arbiter to handle the breach of alice's channel.
|
||||
contractBreaches := make(chan *ContractBreachEvent)
|
||||
|
||||
brar, cleanUpArb, err := createTestArbiter(
|
||||
brar, err := createTestArbiter(
|
||||
t, contractBreaches, alice.State().Db.GetParentDB(),
|
||||
)
|
||||
require.NoError(t, err, "unable to initialize test breach arbiter")
|
||||
@ -1003,8 +1003,7 @@ func initBreachedState(t *testing.T) (*BreachArbiter,
|
||||
t.Fatalf("Can't update the channel state: %v", err)
|
||||
}
|
||||
|
||||
return brar, alice, bob, bobClose, contractBreaches, cleanUpChans,
|
||||
cleanUpArb
|
||||
return brar, alice, bob, bobClose, contractBreaches
|
||||
}
|
||||
|
||||
// TestBreachHandoffSuccess tests that a channel's close observer properly
|
||||
@ -1012,10 +1011,7 @@ func initBreachedState(t *testing.T) (*BreachArbiter,
|
||||
// breach close. This test verifies correctness in the event that the handoff
|
||||
// experiences no interruptions.
|
||||
func TestBreachHandoffSuccess(t *testing.T) {
|
||||
brar, alice, _, bobClose, contractBreaches,
|
||||
cleanUpChans, cleanUpArb := initBreachedState(t)
|
||||
defer cleanUpChans()
|
||||
defer cleanUpArb()
|
||||
brar, alice, _, bobClose, contractBreaches := initBreachedState(t)
|
||||
|
||||
chanPoint := alice.ChanPoint
|
||||
|
||||
@ -1093,10 +1089,7 @@ func TestBreachHandoffSuccess(t *testing.T) {
|
||||
// arbiter fails to write the information to disk, and that a subsequent attempt
|
||||
// at the handoff succeeds.
|
||||
func TestBreachHandoffFail(t *testing.T) {
|
||||
brar, alice, _, bobClose, contractBreaches,
|
||||
cleanUpChans, cleanUpArb := initBreachedState(t)
|
||||
defer cleanUpChans()
|
||||
defer cleanUpArb()
|
||||
brar, alice, _, bobClose, contractBreaches := initBreachedState(t)
|
||||
|
||||
// Before alerting Alice of the breach, instruct our failing retribution
|
||||
// store to fail the next database operation, which we expect to write
|
||||
@ -1140,11 +1133,10 @@ func TestBreachHandoffFail(t *testing.T) {
|
||||
assertNoArbiterBreach(t, brar, chanPoint)
|
||||
assertNotPendingClosed(t, alice)
|
||||
|
||||
brar, cleanUpArb, err := createTestArbiter(
|
||||
brar, err := createTestArbiter(
|
||||
t, contractBreaches, alice.State().Db.GetParentDB(),
|
||||
)
|
||||
require.NoError(t, err, "unable to initialize test breach arbiter")
|
||||
defer cleanUpArb()
|
||||
|
||||
// Signal a spend of the funding transaction and wait for the close
|
||||
// observer to exit. This time we are allowing the handoff to succeed.
|
||||
@ -1183,9 +1175,7 @@ func TestBreachHandoffFail(t *testing.T) {
|
||||
// TestBreachCreateJusticeTx tests that we create three different variants of
|
||||
// the justice tx.
|
||||
func TestBreachCreateJusticeTx(t *testing.T) {
|
||||
brar, _, _, _, _, cleanUpChans, cleanUpArb := initBreachedState(t)
|
||||
defer cleanUpChans()
|
||||
defer cleanUpArb()
|
||||
brar, _, _, _, _ := initBreachedState(t)
|
||||
|
||||
// In this test we just want to check that the correct inputs are added
|
||||
// to the justice tx, not that we create a valid spend, so we just set
|
||||
@ -1564,10 +1554,7 @@ func TestBreachSpends(t *testing.T) {
|
||||
}
|
||||
|
||||
func testBreachSpends(t *testing.T, test breachTest) {
|
||||
brar, alice, _, bobClose, contractBreaches,
|
||||
cleanUpChans, cleanUpArb := initBreachedState(t)
|
||||
defer cleanUpChans()
|
||||
defer cleanUpArb()
|
||||
brar, alice, _, bobClose, contractBreaches := initBreachedState(t)
|
||||
|
||||
var (
|
||||
height = bobClose.ChanSnapshot.CommitHeight
|
||||
@ -1783,10 +1770,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
|
||||
// "split" the justice tx in case the first justice tx doesn't confirm within
|
||||
// a reasonable time.
|
||||
func TestBreachDelayedJusticeConfirmation(t *testing.T) {
|
||||
brar, alice, _, bobClose, contractBreaches,
|
||||
cleanUpChans, cleanUpArb := initBreachedState(t)
|
||||
defer cleanUpChans()
|
||||
defer cleanUpArb()
|
||||
brar, alice, _, bobClose, contractBreaches := initBreachedState(t)
|
||||
|
||||
var (
|
||||
height = bobClose.ChanSnapshot.CommitHeight
|
||||
@ -2123,7 +2107,7 @@ func assertNotPendingClosed(t *testing.T, c *lnwallet.LightningChannel) {
|
||||
// createTestArbiter instantiates a breach arbiter with a failing retribution
|
||||
// store, so that controlled failures can be tested.
|
||||
func createTestArbiter(t *testing.T, contractBreaches chan *ContractBreachEvent,
|
||||
db *channeldb.DB) (*BreachArbiter, func(), error) {
|
||||
db *channeldb.DB) (*BreachArbiter, error) {
|
||||
|
||||
// Create a failing retribution store, that wraps a normal one.
|
||||
store := newFailingRetributionStore(func() RetributionStorer {
|
||||
@ -2148,21 +2132,21 @@ func createTestArbiter(t *testing.T, contractBreaches chan *ContractBreachEvent,
|
||||
})
|
||||
|
||||
if err := ba.Start(); err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, ba.Stop())
|
||||
})
|
||||
|
||||
// The caller is responsible for closing the database.
|
||||
cleanUp := func() {
|
||||
ba.Stop()
|
||||
}
|
||||
|
||||
return ba, cleanUp, nil
|
||||
return ba, nil
|
||||
}
|
||||
|
||||
// createInitChannels creates two initialized test channels funded with 10 BTC,
|
||||
// with 5 BTC allocated to each side. Within the channel, Alice is the
|
||||
// initiator.
|
||||
func createInitChannels(t *testing.T, revocationWindow int) (*lnwallet.LightningChannel, *lnwallet.LightningChannel, func(), error) {
|
||||
func createInitChannels(t *testing.T, revocationWindow int) (
|
||||
*lnwallet.LightningChannel, *lnwallet.LightningChannel, error) {
|
||||
|
||||
aliceKeyPriv, aliceKeyPub := btcec.PrivKeyFromBytes(
|
||||
channels.AlicesPrivKey,
|
||||
)
|
||||
@ -2172,7 +2156,7 @@ func createInitChannels(t *testing.T, revocationWindow int) (*lnwallet.Lightning
|
||||
|
||||
channelCapacity, err := btcutil.NewAmount(10)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
channelBal := channelCapacity / 2
|
||||
@ -2240,23 +2224,23 @@ func createInitChannels(t *testing.T, revocationWindow int) (*lnwallet.Lightning
|
||||
|
||||
bobRoot, err := chainhash.NewHash(bobKeyPriv.Serialize())
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
bobPreimageProducer := shachain.NewRevocationProducer(*bobRoot)
|
||||
bobFirstRevoke, err := bobPreimageProducer.AtIndex(0)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
bobCommitPoint := input.ComputeCommitmentPoint(bobFirstRevoke[:])
|
||||
|
||||
aliceRoot, err := chainhash.NewHash(aliceKeyPriv.Serialize())
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
alicePreimageProducer := shachain.NewRevocationProducer(*aliceRoot)
|
||||
aliceFirstRevoke, err := alicePreimageProducer.AtIndex(0)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
aliceCommitPoint := input.ComputeCommitmentPoint(aliceFirstRevoke[:])
|
||||
|
||||
@ -2266,23 +2250,29 @@ func createInitChannels(t *testing.T, revocationWindow int) (*lnwallet.Lightning
|
||||
false, 0,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
dbAlice, err := channeldb.Open(t.TempDir())
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, dbAlice.Close())
|
||||
})
|
||||
|
||||
dbBob, err := channeldb.Open(t.TempDir())
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, dbBob.Close())
|
||||
})
|
||||
|
||||
estimator := chainfee.NewStaticEstimator(12500, 0)
|
||||
feePerKw, err := estimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
commitFee := feePerKw.FeeForWeight(input.CommitWeight)
|
||||
@ -2309,7 +2299,7 @@ func createInitChannels(t *testing.T, revocationWindow int) (*lnwallet.Lightning
|
||||
|
||||
var chanIDBytes [8]byte
|
||||
if _, err := io.ReadFull(crand.Reader, chanIDBytes[:]); err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
shortChanID := lnwire.NewShortChanIDFromInt(
|
||||
@ -2360,25 +2350,31 @@ func createInitChannels(t *testing.T, revocationWindow int) (*lnwallet.Lightning
|
||||
aliceSigner, aliceChannelState, alicePool,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
alicePool.Start()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, alicePool.Stop())
|
||||
})
|
||||
|
||||
bobPool := lnwallet.NewSigPool(1, bobSigner)
|
||||
channelBob, err := lnwallet.NewLightningChannel(
|
||||
bobSigner, bobChannelState, bobPool,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
bobPool.Start()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, bobPool.Stop())
|
||||
})
|
||||
|
||||
addr := &net.TCPAddr{
|
||||
IP: net.ParseIP("127.0.0.1"),
|
||||
Port: 18556,
|
||||
}
|
||||
if err := channelAlice.State().SyncPending(addr, 101); err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
addr = &net.TCPAddr{
|
||||
@ -2386,22 +2382,17 @@ func createInitChannels(t *testing.T, revocationWindow int) (*lnwallet.Lightning
|
||||
Port: 18555,
|
||||
}
|
||||
if err := channelBob.State().SyncPending(addr, 101); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
cleanUpFunc := func() {
|
||||
dbBob.Close()
|
||||
dbAlice.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Now that the channel are open, simulate the start of a session by
|
||||
// having Alice and Bob extend their revocation windows to each other.
|
||||
err = initRevocationWindows(channelAlice, channelBob, revocationWindow)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return channelAlice, channelBob, cleanUpFunc, nil
|
||||
return channelAlice, channelBob, nil
|
||||
}
|
||||
|
||||
// initRevocationWindows simulates a new channel being opened within the p2p
|
||||
|
@ -24,19 +24,20 @@ func TestChainArbitratorRepublishCloses(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, db.Close())
|
||||
})
|
||||
|
||||
// Create 10 test channels and sync them to the database.
|
||||
const numChans = 10
|
||||
var channels []*channeldb.OpenChannel
|
||||
for i := 0; i < numChans; i++ {
|
||||
lChannel, _, cleanup, err := lnwallet.CreateTestChannels(
|
||||
channeldb.SingleFunderTweaklessBit,
|
||||
lChannel, _, err := lnwallet.CreateTestChannels(
|
||||
t, channeldb.SingleFunderTweaklessBit,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
channel := lChannel.State()
|
||||
|
||||
@ -94,11 +95,9 @@ func TestChainArbitratorRepublishCloses(t *testing.T) {
|
||||
if err := chainArb.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
if err := chainArb.Stop(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, chainArb.Stop())
|
||||
})
|
||||
|
||||
// Half of the channels should have had their closing tx re-published.
|
||||
if len(published) != numChans/2 {
|
||||
@ -137,15 +136,16 @@ func TestResolveContract(t *testing.T) {
|
||||
|
||||
db, err := channeldb.Open(t.TempDir())
|
||||
require.NoError(t, err, "unable to open db")
|
||||
defer db.Close()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, db.Close())
|
||||
})
|
||||
|
||||
// With the DB created, we'll make a new channel, and mark it as
|
||||
// pending open within the database.
|
||||
newChannel, _, cleanup, err := lnwallet.CreateTestChannels(
|
||||
channeldb.SingleFunderTweaklessBit,
|
||||
newChannel, _, err := lnwallet.CreateTestChannels(
|
||||
t, channeldb.SingleFunderTweaklessBit,
|
||||
)
|
||||
require.NoError(t, err, "unable to make new test channel")
|
||||
defer cleanup()
|
||||
channel := newChannel.State()
|
||||
channel.Db = db.ChannelStateDB()
|
||||
addr := &net.TCPAddr{
|
||||
@ -177,11 +177,9 @@ func TestResolveContract(t *testing.T) {
|
||||
if err := chainArb.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
if err := chainArb.Stop(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, chainArb.Stop())
|
||||
})
|
||||
|
||||
channelArb := chainArb.activeChannels[channel.FundingOutpoint]
|
||||
|
||||
|
@ -25,11 +25,10 @@ func TestChainWatcherRemoteUnilateralClose(t *testing.T) {
|
||||
|
||||
// First, we'll create two channels which already have established a
|
||||
// commitment contract between themselves.
|
||||
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(
|
||||
channeldb.SingleFunderTweaklessBit,
|
||||
aliceChannel, bobChannel, err := lnwallet.CreateTestChannels(
|
||||
t, channeldb.SingleFunderTweaklessBit,
|
||||
)
|
||||
require.NoError(t, err, "unable to create test channels")
|
||||
defer cleanUp()
|
||||
|
||||
// With the channels created, we'll now create a chain watcher instance
|
||||
// which will be watching for any closes of Alice's channel.
|
||||
@ -110,11 +109,10 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
|
||||
|
||||
// First, we'll create two channels which already have established a
|
||||
// commitment contract between themselves.
|
||||
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(
|
||||
channeldb.SingleFunderTweaklessBit,
|
||||
aliceChannel, bobChannel, err := lnwallet.CreateTestChannels(
|
||||
t, channeldb.SingleFunderTweaklessBit,
|
||||
)
|
||||
require.NoError(t, err, "unable to create test channels")
|
||||
defer cleanUp()
|
||||
|
||||
// With the channels created, we'll now create a chain watcher instance
|
||||
// which will be watching for any closes of Alice's channel.
|
||||
@ -255,13 +253,12 @@ func TestChainWatcherDataLossProtect(t *testing.T) {
|
||||
dlpScenario := func(t *testing.T, testCase dlpTestCase) bool {
|
||||
// First, we'll create two channels which already have
|
||||
// established a commitment contract between themselves.
|
||||
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(
|
||||
channeldb.SingleFunderBit,
|
||||
aliceChannel, bobChannel, err := lnwallet.CreateTestChannels(
|
||||
t, channeldb.SingleFunderBit,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test channels: %v", err)
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
// Based on the number of random updates for this state, make a
|
||||
// new HTLC to add to the commitment, and then lock in a state
|
||||
@ -430,13 +427,12 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
|
||||
|
||||
// First, we'll create two channels which already have
|
||||
// established a commitment contract between themselves.
|
||||
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(
|
||||
channeldb.SingleFunderBit,
|
||||
aliceChannel, bobChannel, err := lnwallet.CreateTestChannels(
|
||||
t, channeldb.SingleFunderBit,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test channels: %v", err)
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
// We'll execute a number of state transitions based on the
|
||||
// randomly selected number from testing/quick. We do this to
|
||||
|
@ -460,11 +460,9 @@ func TestChannelArbitratorCooperativeClose(t *testing.T) {
|
||||
if err := chanArbCtx.chanArb.Start(nil); err != nil {
|
||||
t.Fatalf("unable to start ChannelArbitrator: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := chanArbCtx.chanArb.Stop(); err != nil {
|
||||
t.Fatalf("unable to stop chan arb: %v", err)
|
||||
}
|
||||
}()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, chanArbCtx.chanArb.Stop())
|
||||
})
|
||||
|
||||
// It should start out in the default state.
|
||||
chanArbCtx.AssertState(StateDefault)
|
||||
@ -681,11 +679,9 @@ func TestChannelArbitratorBreachClose(t *testing.T) {
|
||||
if err := chanArb.Start(nil); err != nil {
|
||||
t.Fatalf("unable to start ChannelArbitrator: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := chanArb.Stop(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, chanArb.Stop())
|
||||
})
|
||||
|
||||
// It should start out in the default state.
|
||||
chanArbCtx.AssertState(StateDefault)
|
||||
@ -1990,11 +1986,9 @@ func TestChannelArbitratorPendingExpiredHTLC(t *testing.T) {
|
||||
if err := chanArb.Start(nil); err != nil {
|
||||
t.Fatalf("unable to start ChannelArbitrator: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := chanArb.Stop(); err != nil {
|
||||
t.Fatalf("unable to stop chan arb: %v", err)
|
||||
}
|
||||
}()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, chanArb.Stop())
|
||||
})
|
||||
|
||||
// Now that our channel arb has started, we'll set up
|
||||
// its contract signals channel so we can send it
|
||||
@ -2098,14 +2092,13 @@ func TestRemoteCloseInitiator(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// First, create alice's channel.
|
||||
alice, _, cleanUp, err := lnwallet.CreateTestChannels(
|
||||
channeldb.SingleFunderTweaklessBit,
|
||||
alice, _, err := lnwallet.CreateTestChannels(
|
||||
t, channeldb.SingleFunderTweaklessBit,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create test channels: %v",
|
||||
err)
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
// Create a mock log which will not block the test's
|
||||
// expected number of transitions transitions, and has
|
||||
@ -2148,11 +2141,9 @@ func TestRemoteCloseInitiator(t *testing.T) {
|
||||
t.Fatalf("unable to start "+
|
||||
"ChannelArbitrator: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := chanArb.Stop(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, chanArb.Stop())
|
||||
})
|
||||
|
||||
// It should start out in the default state.
|
||||
chanArbCtx.AssertState(StateDefault)
|
||||
@ -2501,11 +2492,9 @@ func TestChannelArbitratorAnchors(t *testing.T) {
|
||||
if err := chanArb.Start(nil); err != nil {
|
||||
t.Fatalf("unable to start ChannelArbitrator: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := chanArb.Stop(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, chanArb.Stop())
|
||||
})
|
||||
|
||||
signals := &ContractSignals{
|
||||
ShortChanID: lnwire.ShortChannelID{},
|
||||
|
@ -170,7 +170,7 @@ var _ UtxoSweeper = &mockSweeper{}
|
||||
// unencumbered by a time lock.
|
||||
func TestCommitSweepResolverNoDelay(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
res := lnwallet.CommitOutputResolution{
|
||||
SelfOutputSignDesc: input.SignDescriptor{
|
||||
@ -227,7 +227,7 @@ func TestCommitSweepResolverNoDelay(t *testing.T) {
|
||||
// that is encumbered by a time lock. sweepErr indicates whether the local node
|
||||
// fails to sweep the output.
|
||||
func testCommitSweepResolverDelay(t *testing.T, sweepErr error) {
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
const sweepProcessInterval = 100 * time.Millisecond
|
||||
amt := int64(100)
|
||||
|
@ -36,7 +36,7 @@ var (
|
||||
// for which the preimage is already known initially.
|
||||
func TestHtlcIncomingResolverFwdPreimageKnown(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
ctx := newIncomingResolverTestContext(t, false)
|
||||
ctx.witnessBeacon.lookupPreimage[testResHash] = testResPreimage
|
||||
@ -49,7 +49,7 @@ func TestHtlcIncomingResolverFwdPreimageKnown(t *testing.T) {
|
||||
// started.
|
||||
func TestHtlcIncomingResolverFwdContestedSuccess(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
ctx := newIncomingResolverTestContext(t, false)
|
||||
ctx.resolve()
|
||||
@ -65,7 +65,7 @@ func TestHtlcIncomingResolverFwdContestedSuccess(t *testing.T) {
|
||||
// htlc that times out after the resolver has been started.
|
||||
func TestHtlcIncomingResolverFwdContestedTimeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
ctx := newIncomingResolverTestContext(t, false)
|
||||
|
||||
@ -104,7 +104,7 @@ func TestHtlcIncomingResolverFwdContestedTimeout(t *testing.T) {
|
||||
// has already expired when the resolver starts.
|
||||
func TestHtlcIncomingResolverFwdTimeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
ctx := newIncomingResolverTestContext(t, true)
|
||||
ctx.witnessBeacon.lookupPreimage[testResHash] = testResPreimage
|
||||
@ -117,7 +117,7 @@ func TestHtlcIncomingResolverFwdTimeout(t *testing.T) {
|
||||
// which the invoice has already been settled when the resolver starts.
|
||||
func TestHtlcIncomingResolverExitSettle(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
ctx := newIncomingResolverTestContext(t, true)
|
||||
ctx.registry.notifyResolution = invoices.NewSettleResolution(
|
||||
@ -149,7 +149,7 @@ func TestHtlcIncomingResolverExitSettle(t *testing.T) {
|
||||
// an invoice that is already canceled when the resolver starts.
|
||||
func TestHtlcIncomingResolverExitCancel(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
ctx := newIncomingResolverTestContext(t, true)
|
||||
ctx.registry.notifyResolution = invoices.NewFailResolution(
|
||||
@ -165,7 +165,7 @@ func TestHtlcIncomingResolverExitCancel(t *testing.T) {
|
||||
// for a hodl invoice that is settled after the resolver has started.
|
||||
func TestHtlcIncomingResolverExitSettleHodl(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
ctx := newIncomingResolverTestContext(t, true)
|
||||
ctx.resolve()
|
||||
@ -183,7 +183,7 @@ func TestHtlcIncomingResolverExitSettleHodl(t *testing.T) {
|
||||
// for a hodl invoice that times out.
|
||||
func TestHtlcIncomingResolverExitTimeoutHodl(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
ctx := newIncomingResolverTestContext(t, true)
|
||||
|
||||
@ -220,7 +220,7 @@ func TestHtlcIncomingResolverExitTimeoutHodl(t *testing.T) {
|
||||
// for a hodl invoice that is canceled after the resolver has started.
|
||||
func TestHtlcIncomingResolverExitCancelHodl(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
ctx := newIncomingResolverTestContext(t, true)
|
||||
|
||||
|
@ -23,7 +23,7 @@ const (
|
||||
// timed out.
|
||||
func TestHtlcOutgoingResolverTimeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
// Setup the resolver with our test resolution.
|
||||
ctx := newOutgoingResolverTestContext(t)
|
||||
@ -44,7 +44,7 @@ func TestHtlcOutgoingResolverTimeout(t *testing.T) {
|
||||
// is claimed by the remote party.
|
||||
func TestHtlcOutgoingResolverRemoteClaim(t *testing.T) {
|
||||
t.Parallel()
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
// Setup the resolver with our test resolution and start the resolution
|
||||
// process.
|
||||
|
@ -477,7 +477,7 @@ type checkpoint struct {
|
||||
func testHtlcSuccess(t *testing.T, resolution lnwallet.IncomingHtlcResolution,
|
||||
checkpoints []checkpoint) {
|
||||
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
// We first run the resolver from start to finish, ensuring it gets
|
||||
// checkpointed at every expected stage. We store the checkpointed data
|
||||
@ -521,7 +521,7 @@ func testHtlcSuccess(t *testing.T, resolution lnwallet.IncomingHtlcResolution,
|
||||
func runFromCheckpoint(t *testing.T, ctx *htlcResolverTestContext,
|
||||
expectedCheckpoints []checkpoint) [][]byte {
|
||||
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
var checkpointedState [][]byte
|
||||
|
||||
|
@ -1286,7 +1286,7 @@ func TestHtlcTimeoutSecondStageSweeperRemoteSpend(t *testing.T) {
|
||||
func testHtlcTimeout(t *testing.T, resolution lnwallet.OutgoingHtlcResolution,
|
||||
checkpoints []checkpoint) {
|
||||
|
||||
defer timeout(t)()
|
||||
defer timeout()()
|
||||
|
||||
// We first run the resolver from start to finish, ensuring it gets
|
||||
// checkpointed at every expected stage. We store the checkpointed data
|
||||
|
@ -53,9 +53,8 @@ func initIncubateTests() {
|
||||
// TestNurseryStoreInit verifies basic properties of the nursery store before
|
||||
// any modifying calls are made.
|
||||
func TestNurseryStoreInit(t *testing.T) {
|
||||
cdb, cleanUp, err := channeldb.MakeTestDB()
|
||||
cdb, err := channeldb.MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to open channel db")
|
||||
defer cleanUp()
|
||||
|
||||
ns, err := NewNurseryStore(&chainHash, cdb)
|
||||
require.NoError(t, err, "unable to open nursery store")
|
||||
@ -69,9 +68,8 @@ func TestNurseryStoreInit(t *testing.T) {
|
||||
// outputs through the nursery store, verifying the properties of the
|
||||
// intermediate states.
|
||||
func TestNurseryStoreIncubate(t *testing.T) {
|
||||
cdb, cleanUp, err := channeldb.MakeTestDB()
|
||||
cdb, err := channeldb.MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to open channel db")
|
||||
defer cleanUp()
|
||||
|
||||
ns, err := NewNurseryStore(&chainHash, cdb)
|
||||
require.NoError(t, err, "unable to open nursery store")
|
||||
@ -306,9 +304,8 @@ func TestNurseryStoreIncubate(t *testing.T) {
|
||||
// populated entries from the height index as it is purged, and that the last
|
||||
// purged height is set appropriately.
|
||||
func TestNurseryStoreGraduate(t *testing.T) {
|
||||
cdb, cleanUp, err := channeldb.MakeTestDB()
|
||||
cdb, err := channeldb.MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to open channel db")
|
||||
defer cleanUp()
|
||||
|
||||
ns, err := NewNurseryStore(&chainHash, cdb)
|
||||
require.NoError(t, err, "unable to open nursery store")
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
// timeout implements a test level timeout.
|
||||
func timeout(t *testing.T) func() {
|
||||
func timeout() func() {
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
select {
|
||||
|
@ -409,7 +409,6 @@ type nurseryTestContext struct {
|
||||
sweeper *mockSweeperFull
|
||||
timeoutChan chan chan time.Time
|
||||
t *testing.T
|
||||
dbCleanup func()
|
||||
}
|
||||
|
||||
func createNurseryTestContext(t *testing.T,
|
||||
@ -419,7 +418,7 @@ func createNurseryTestContext(t *testing.T,
|
||||
// alternative, mocking nurseryStore, is not chosen because there is
|
||||
// still considerable logic in the store.
|
||||
|
||||
cdb, cleanup, err := channeldb.MakeTestDB()
|
||||
cdb, err := channeldb.MakeTestDB(t)
|
||||
require.NoError(t, err, "unable to open channeldb")
|
||||
|
||||
store, err := NewNurseryStore(&chainhash.Hash{}, cdb)
|
||||
@ -480,7 +479,6 @@ func createNurseryTestContext(t *testing.T,
|
||||
sweeper: sweeper,
|
||||
timeoutChan: timeoutChan,
|
||||
t: t,
|
||||
dbCleanup: cleanup,
|
||||
}
|
||||
|
||||
ctx.receiveTx = func() wire.MsgTx {
|
||||
@ -528,8 +526,6 @@ func (ctx *nurseryTestContext) notifyEpoch(height int32) {
|
||||
}
|
||||
|
||||
func (ctx *nurseryTestContext) finish() {
|
||||
defer ctx.dbCleanup()
|
||||
|
||||
// Add a final restart point in this state
|
||||
ctx.restart()
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,10 +5,9 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
prand "math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
@ -20,6 +19,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/shachain"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -103,17 +103,15 @@ var (
|
||||
// CreateTestChannels creates to fully populated channels to be used within
|
||||
// testing fixtures. The channels will be returned as if the funding process
|
||||
// has just completed. The channel itself is funded with 10 BTC, with 5 BTC
|
||||
// allocated to each side. Within the channel, Alice is the initiator. The
|
||||
// function also returns a "cleanup" function that is meant to be called once
|
||||
// the test has been finalized. The clean up function will remote all temporary
|
||||
// files created. If tweaklessCommits is true, then the commits within the
|
||||
// channels will use the new format, otherwise the legacy format.
|
||||
func CreateTestChannels(chanType channeldb.ChannelType) (
|
||||
*LightningChannel, *LightningChannel, func(), error) {
|
||||
// allocated to each side. Within the channel, Alice is the initiator. If
|
||||
// tweaklessCommits is true, then the commits within the channels will use the
|
||||
// new format, otherwise the legacy format.
|
||||
func CreateTestChannels(t *testing.T, chanType channeldb.ChannelType) (
|
||||
*LightningChannel, *LightningChannel, error) {
|
||||
|
||||
channelCapacity, err := btcutil.NewAmount(testChannelCapacity)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
channelBal := channelCapacity / 2
|
||||
@ -202,23 +200,23 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
|
||||
|
||||
bobRoot, err := chainhash.NewHash(bobKeys[0].Serialize())
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
bobPreimageProducer := shachain.NewRevocationProducer(*bobRoot)
|
||||
bobFirstRevoke, err := bobPreimageProducer.AtIndex(0)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
bobCommitPoint := input.ComputeCommitmentPoint(bobFirstRevoke[:])
|
||||
|
||||
aliceRoot, err := chainhash.NewHash(aliceKeys[0].Serialize())
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
alicePreimageProducer := shachain.NewRevocationProducer(*aliceRoot)
|
||||
aliceFirstRevoke, err := alicePreimageProducer.AtIndex(0)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
aliceCommitPoint := input.ComputeCommitmentPoint(aliceFirstRevoke[:])
|
||||
|
||||
@ -227,33 +225,29 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
|
||||
bobCommitPoint, *fundingTxIn, chanType, isAliceInitiator, 0,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
alicePath, err := ioutil.TempDir("", "alicedb")
|
||||
dbAlice, err := channeldb.Open(t.TempDir())
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, dbAlice.Close())
|
||||
})
|
||||
|
||||
dbAlice, err := channeldb.Open(alicePath)
|
||||
dbBob, err := channeldb.Open(t.TempDir())
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
bobPath, err := ioutil.TempDir("", "bobdb")
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
dbBob, err := channeldb.Open(bobPath)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, dbBob.Close())
|
||||
})
|
||||
|
||||
estimator := chainfee.NewStaticEstimator(6000, 0)
|
||||
feePerKw, err := estimator.EstimateFeePerKW(1)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
commitFee := calcStaticFee(chanType, 0)
|
||||
var anchorAmt btcutil.Amount
|
||||
@ -305,7 +299,7 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
|
||||
|
||||
var chanIDBytes [8]byte
|
||||
if _, err := io.ReadFull(rand.Reader, chanIDBytes[:]); err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
shortChanID := lnwire.NewShortChanIDFromInt(
|
||||
@ -358,9 +352,12 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
|
||||
aliceSigner, aliceChannelState, alicePool,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
alicePool.Start()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, alicePool.Stop())
|
||||
})
|
||||
|
||||
obfuscator := createStateHintObfuscator(aliceChannelState)
|
||||
|
||||
@ -369,21 +366,24 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
|
||||
bobSigner, bobChannelState, bobPool,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
bobPool.Start()
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, bobPool.Stop())
|
||||
})
|
||||
|
||||
err = SetStateNumHint(
|
||||
aliceCommitTx, 0, obfuscator,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
err = SetStateNumHint(
|
||||
bobCommitTx, 0, obfuscator,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
addr := &net.TCPAddr{
|
||||
@ -391,7 +391,7 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
|
||||
Port: 18556,
|
||||
}
|
||||
if err := channelAlice.channelState.SyncPending(addr, 101); err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
addr = &net.TCPAddr{
|
||||
@ -400,25 +400,17 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
|
||||
}
|
||||
|
||||
if err := channelBob.channelState.SyncPending(addr, 101); err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
cleanUpFunc := func() {
|
||||
os.RemoveAll(bobPath)
|
||||
os.RemoveAll(alicePath)
|
||||
|
||||
alicePool.Stop()
|
||||
bobPool.Stop()
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Now that the channel are open, simulate the start of a session by
|
||||
// having Alice and Bob extend their revocation windows to each other.
|
||||
err = initRevocationWindows(channelAlice, channelBob)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return channelAlice, channelBob, cleanUpFunc, nil
|
||||
return channelAlice, channelBob, nil
|
||||
}
|
||||
|
||||
// initRevocationWindows simulates a new channel being opened within the p2p
|
||||
|
@ -15,15 +15,10 @@ func TestStore(t *testing.T) {
|
||||
t.Run("bolt", func(t *testing.T) {
|
||||
|
||||
// Create new store.
|
||||
cdb, cleanUp, err := channeldb.MakeTestDB()
|
||||
cdb, err := channeldb.MakeTestDB(t)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to open channel db: %v", err)
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testStore(t, func() (SweeperStore, error) {
|
||||
var chain chainhash.Hash
|
||||
|
Loading…
Reference in New Issue
Block a user