multi: move many t.Fatalf calls to require.NoError

This commit is contained in:
Tommy Volk committed 2022-06-17 04:26:55 +00:00
1 parent 9e6f0ef46b
commit 9a10c80bcb
92 files changed
+1905 -5565

No files matched your search

+11 -33
View File
@@ -711,9 +711,7 @@ func countRetributions(t *testing.T, rs RetributionStorer) int {
}, func() {
count = 0
})
if err != nil {
t.Fatalf("unable to list retributions in db: %v", err)
}
require.NoError(t, err, "unable to list retributions in db")
return count
}
@@ -979,9 +977,7 @@ func initBreachedState(t *testing.T) (*BreachArbiter,
// a spend of the funding transaction. Alice's channel will be the on
// observing a breach.
alice, bob, cleanUpChans, err := createInitChannels(1)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
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)
@@ -989,9 +985,7 @@ func initBreachedState(t *testing.T) (*BreachArbiter,
brar, cleanUpArb, err := createTestArbiter(
t, contractBreaches, alice.State().Db.GetParentDB(),
)
if err != nil {
t.Fatalf("unable to initialize test breach arbiter: %v", err)
}
require.NoError(t, err, "unable to initialize test breach arbiter")
// Send one HTLC to Bob and perform a state transition to lock it in.
htlcAmount := lnwire.NewMSatFromSatoshis(20000)
@@ -1009,9 +1003,7 @@ func initBreachedState(t *testing.T) (*BreachArbiter,
// Generate the force close summary at this point in time, this will
// serve as the old state bob will broadcast.
bobClose, err := bob.ForceClose()
if err != nil {
t.Fatalf("unable to force close bob's channel: %v", err)
}
require.NoError(t, err, "unable to force close bob's channel")
// Now send another HTLC and perform a state transition, this ensures
// Alice is ahead of the state Bob will broadcast.
@@ -1166,9 +1158,7 @@ func TestBreachHandoffFail(t *testing.T) {
brar, cleanUpArb, err := createTestArbiter(
t, contractBreaches, alice.State().Db.GetParentDB(),
)
if err != nil {
t.Fatalf("unable to initialize test breach arbiter: %v", err)
}
require.NoError(t, err, "unable to initialize test breach arbiter")
defer cleanUpArb()
// Signal a spend of the funding transaction and wait for the close
@@ -1623,9 +1613,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
retribution, err := lnwallet.NewBreachRetribution(
alice.State(), height, 1, forceCloseTx,
)
if err != nil {
t.Fatalf("unable to create breach retribution: %v", err)
}
require.NoError(t, err, "unable to create breach retribution")
processACK := make(chan error)
breach := &ContractBreachEvent{
@@ -1664,9 +1652,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
RemoteNextRevocation: state.RemoteNextRevocation,
LocalChanConfig: state.LocalChanCfg,
})
if err != nil {
t.Fatalf("unable to close channel: %v", err)
}
require.NoError(t, err, "unable to close channel")
// After exiting, the breach arbiter should have persisted the
// retribution information and the channel should be shown as pending
@@ -1839,9 +1825,7 @@ func TestBreachDelayedJusticeConfirmation(t *testing.T) {
retribution, err := lnwallet.NewBreachRetribution(
alice.State(), height, uint32(blockHeight), forceCloseTx,
)
if err != nil {
t.Fatalf("unable to create breach retribution: %v", err)
}
require.NoError(t, err, "unable to create breach retribution")
processACK := make(chan error, 1)
breach := &ContractBreachEvent{
@@ -1881,9 +1865,7 @@ func TestBreachDelayedJusticeConfirmation(t *testing.T) {
RemoteNextRevocation: state.RemoteNextRevocation,
LocalChanConfig: state.LocalChanCfg,
})
if err != nil {
t.Fatalf("unable to close channel: %v", err)
}
require.NoError(t, err, "unable to close channel")
// After exiting, the breach arbiter should have persisted the
// retribution information and the channel should be shown as pending
@@ -2126,9 +2108,7 @@ func assertPendingClosed(t *testing.T, c *lnwallet.LightningChannel) {
t.Helper()
closedChans, err := c.State().Db.FetchClosedChannels(true)
if err != nil {
t.Fatalf("unable to load pending closed channels: %v", err)
}
require.NoError(t, err, "unable to load pending closed channels")
for _, chanSummary := range closedChans {
if chanSummary.ChanPoint == *c.ChanPoint {
@@ -2145,9 +2125,7 @@ func assertNotPendingClosed(t *testing.T, c *lnwallet.LightningChannel) {
t.Helper()
closedChans, err := c.State().Db.FetchClosedChannels(true)
if err != nil {
t.Fatalf("unable to load pending closed channels: %v", err)
}
require.NoError(t, err, "unable to load pending closed channels")
for _, chanSummary := range closedChans {
if chanSummary.ChanPoint == *c.ChanPoint {
+25 -72
View File
@@ -20,6 +20,7 @@ import (
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lntest/channels"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/stretchr/testify/require"
)
var (
@@ -306,9 +307,7 @@ func TestContractInsertionRetrieval(t *testing.T) {
testLog, cleanUp, err := newTestBoltArbLog(
testChainHash, testChanPoint1,
)
if err != nil {
t.Fatalf("unable to create test log: %v", err)
}
require.NoError(t, err, "unable to create test log")
defer cleanUp()
// The log created, we'll create a series of resolvers, each properly
@@ -386,17 +385,13 @@ func TestContractInsertionRetrieval(t *testing.T) {
// Now, we'll insert the resolver into the log, we do not need to apply
// any closures, so we will pass in nil.
err = testLog.InsertUnresolvedContracts(nil, resolvers...)
if err != nil {
t.Fatalf("unable to insert resolvers: %v", err)
}
require.NoError(t, err, "unable to insert resolvers")
// With the resolvers inserted, we'll now attempt to retrieve them from
// the database, so we can compare them to the versions we created
// above.
diskResolvers, err := testLog.FetchUnresolvedContracts()
if err != nil {
t.Fatalf("unable to retrieve resolvers: %v", err)
}
require.NoError(t, err, "unable to retrieve resolvers")
if len(diskResolvers) != len(resolvers) {
t.Fatalf("expected %v got resolvers, instead got %v: %#v",
@@ -423,9 +418,7 @@ func TestContractInsertionRetrieval(t *testing.T) {
t.Fatalf("unable to wipe log: %v", err)
}
diskResolvers, err = testLog.FetchUnresolvedContracts()
if err != nil {
t.Fatalf("unable to fetch unresolved contracts: %v", err)
}
require.NoError(t, err, "unable to fetch unresolved contracts")
if len(diskResolvers) != 0 {
t.Fatalf("no resolvers should be found, instead %v were",
len(diskResolvers))
@@ -442,9 +435,7 @@ func TestContractResolution(t *testing.T) {
testLog, cleanUp, err := newTestBoltArbLog(
testChainHash, testChanPoint1,
)
if err != nil {
t.Fatalf("unable to create test log: %v", err)
}
require.NoError(t, err, "unable to create test log")
defer cleanUp()
// We'll now create a timeout resolver that we'll be using for the
@@ -469,13 +460,9 @@ func TestContractResolution(t *testing.T) {
// we get the same resolver out the other side. We do not need to apply
// any closures.
err = testLog.InsertUnresolvedContracts(nil, timeoutResolver)
if err != nil {
t.Fatalf("unable to insert contract into db: %v", err)
}
require.NoError(t, err, "unable to insert contract into db")
dbContracts, err := testLog.FetchUnresolvedContracts()
if err != nil {
t.Fatalf("unable to fetch contracts from db: %v", err)
}
require.NoError(t, err, "unable to fetch contracts from db")
assertResolversEqual(t, timeoutResolver, dbContracts[0])
// Now, we'll mark the contract as resolved within the database.
@@ -485,9 +472,7 @@ func TestContractResolution(t *testing.T) {
// At this point, no contracts should exist within the log.
dbContracts, err = testLog.FetchUnresolvedContracts()
if err != nil {
t.Fatalf("unable to fetch contracts from db: %v", err)
}
require.NoError(t, err, "unable to fetch contracts from db")
if len(dbContracts) != 0 {
t.Fatalf("no contract should be from in the db, instead %v "+
"were", len(dbContracts))
@@ -504,9 +489,7 @@ func TestContractSwapping(t *testing.T) {
testLog, cleanUp, err := newTestBoltArbLog(
testChainHash, testChanPoint1,
)
if err != nil {
t.Fatalf("unable to create test log: %v", err)
}
require.NoError(t, err, "unable to create test log")
defer cleanUp()
// We'll create two resolvers, a regular timeout resolver, and the
@@ -533,23 +516,17 @@ func TestContractSwapping(t *testing.T) {
// We'll first insert the contest resolver into the log with no
// additional updates.
err = testLog.InsertUnresolvedContracts(nil, contestResolver)
if err != nil {
t.Fatalf("unable to insert contract into db: %v", err)
}
require.NoError(t, err, "unable to insert contract into db")
// With the resolver inserted, we'll now attempt to atomically swap it
// for its underlying timeout resolver.
err = testLog.SwapContract(contestResolver, timeoutResolver)
if err != nil {
t.Fatalf("unable to swap contracts: %v", err)
}
require.NoError(t, err, "unable to swap contracts")
// At this point, there should now only be a single contract in the
// database.
dbContracts, err := testLog.FetchUnresolvedContracts()
if err != nil {
t.Fatalf("unable to fetch contracts from db: %v", err)
}
require.NoError(t, err, "unable to fetch contracts from db")
if len(dbContracts) != 1 {
t.Fatalf("one contract should be from in the db, instead %v "+
"were", len(dbContracts))
@@ -569,9 +546,7 @@ func TestContractResolutionsStorage(t *testing.T) {
testLog, cleanUp, err := newTestBoltArbLog(
testChainHash, testChanPoint1,
)
if err != nil {
t.Fatalf("unable to create test log: %v", err)
}
require.NoError(t, err, "unable to create test log")
defer cleanUp()
// With the test log created, we'll now craft a contact resolution that
@@ -661,9 +636,7 @@ func TestContractResolutionsStorage(t *testing.T) {
t.Fatalf("unable to insert resolutions into db: %v", err)
}
diskRes, err := testLog.FetchContractResolutions()
if err != nil {
t.Fatalf("unable to read resolution from db: %v", err)
}
require.NoError(t, err, "unable to read resolution from db")
if !reflect.DeepEqual(&res, diskRes) {
t.Fatalf("resolution mismatch: expected %v\n, got %v",
@@ -689,16 +662,12 @@ func TestStateMutation(t *testing.T) {
testLog, cleanUp, err := newTestBoltArbLog(
testChainHash, testChanPoint1,
)
if err != nil {
t.Fatalf("unable to create test log: %v", err)
}
require.NoError(t, err, "unable to create test log")
defer cleanUp()
// The default state of an arbitrator should be StateDefault.
arbState, err := testLog.CurrentState(nil)
if err != nil {
t.Fatalf("unable to read arb state: %v", err)
}
require.NoError(t, err, "unable to read arb state")
if arbState != StateDefault {
t.Fatalf("state mismatch: expected %v, got %v", StateDefault,
arbState)
@@ -710,9 +679,7 @@ func TestStateMutation(t *testing.T) {
t.Fatalf("unable to write state: %v", err)
}
arbState, err = testLog.CurrentState(nil)
if err != nil {
t.Fatalf("unable to read arb state: %v", err)
}
require.NoError(t, err, "unable to read arb state")
if arbState != StateFullyResolved {
t.Fatalf("state mismatch: expected %v, got %v", StateFullyResolved,
arbState)
@@ -721,16 +688,12 @@ func TestStateMutation(t *testing.T) {
// Next, we'll wipe our state and ensure that if we try to query for
// the current state, we get the proper error.
err = testLog.WipeHistory()
if err != nil {
t.Fatalf("unable to wipe history: %v", err)
}
require.NoError(t, err, "unable to wipe history")
// If we try to query for the state again, we should get the default
// state again.
arbState, err = testLog.CurrentState(nil)
if err != nil {
t.Fatalf("unable to query current state: %v", err)
}
require.NoError(t, err, "unable to query current state")
if arbState != StateDefault {
t.Fatalf("state mismatch: expected %v, got %v", StateDefault,
arbState)
@@ -747,17 +710,13 @@ func TestScopeIsolation(t *testing.T) {
testLog1, cleanUp1, err := newTestBoltArbLog(
testChainHash, testChanPoint1,
)
if err != nil {
t.Fatalf("unable to create test log: %v", err)
}
require.NoError(t, err, "unable to create test log")
defer cleanUp1()
testLog2, cleanUp2, err := newTestBoltArbLog(
testChainHash, testChanPoint2,
)
if err != nil {
t.Fatalf("unable to create test log: %v", err)
}
require.NoError(t, err, "unable to create test log")
defer cleanUp2()
// We'll now update the current state of both the logs to a unique
@@ -772,13 +731,9 @@ func TestScopeIsolation(t *testing.T) {
// Querying each log, the states should be the prior one we set, and be
// disjoint.
log1State, err := testLog1.CurrentState(nil)
if err != nil {
t.Fatalf("unable to read arb state: %v", err)
}
require.NoError(t, err, "unable to read arb state")
log2State, err := testLog2.CurrentState(nil)
if err != nil {
t.Fatalf("unable to read arb state: %v", err)
}
require.NoError(t, err, "unable to read arb state")
if log1State == log2State {
t.Fatalf("log states are the same: %v", log1State)
@@ -802,9 +757,7 @@ func TestCommitSetStorage(t *testing.T) {
testLog, cleanUp, err := newTestBoltArbLog(
testChainHash, testChanPoint1,
)
if err != nil {
t.Fatalf("unable to create test log: %v", err)
}
require.NoError(t, err, "unable to create test log")
defer cleanUp()
activeHTLCs := []channeldb.HTLC{
+7 -18
View File
@@ -13,6 +13,7 @@ import (
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/stretchr/testify/require"
)
// TestChainArbitratorRepulishCloses tests that the chain arbitrator will
@@ -145,14 +146,10 @@ func TestResolveContract(t *testing.T) {
// To start with, we'll create a new temp DB for the duration of this
// test.
tempPath, err := ioutil.TempDir("", "testdb")
if err != nil {
t.Fatalf("unable to make temp dir: %v", err)
}
require.NoError(t, err, "unable to make temp dir")
defer os.RemoveAll(tempPath)
db, err := channeldb.Open(tempPath)
if err != nil {
t.Fatalf("unable to open db: %v", err)
}
require.NoError(t, err, "unable to open db")
defer db.Close()
// With the DB created, we'll make a new channel, and mark it as
@@ -160,9 +157,7 @@ func TestResolveContract(t *testing.T) {
newChannel, _, cleanup, err := lnwallet.CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to make new test channel: %v", err)
}
require.NoError(t, err, "unable to make new test channel")
defer cleanup()
channel := newChannel.State()
channel.Db = db.ChannelStateDB()
@@ -206,17 +201,13 @@ func TestResolveContract(t *testing.T) {
// While the resolver are active, we'll now remove the channel from the
// database (mark is as closed).
err = db.ChannelStateDB().AbandonChannel(&channel.FundingOutpoint, 4)
if err != nil {
t.Fatalf("unable to remove channel: %v", err)
}
require.NoError(t, err, "unable to remove channel")
// With the channel removed, we'll now manually call ResolveContract.
// This stimulates needing to remove a channel from the chain arb due
// to any possible external consistency issues.
err = chainArb.ResolveContract(channel.FundingOutpoint)
if err != nil {
t.Fatalf("unable to resolve contract: %v", err)
}
require.NoError(t, err, "unable to resolve contract")
// The shouldn't be an active chain watcher or channel arb for this
// channel.
@@ -240,7 +231,5 @@ func TestResolveContract(t *testing.T) {
// If we attempt to call this method again, then we should get a nil
// error, as there is no more state to be cleaned up.
err = chainArb.ResolveContract(channel.FundingOutpoint)
if err != nil {
t.Fatalf("second resolve call shouldn't fail: %v", err)
}
require.NoError(t, err, "second resolve call shouldn't fail")
}
+6 -15
View File
@@ -14,6 +14,7 @@ import (
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/require"
)
// TestChainWatcherRemoteUnilateralClose tests that the chain watcher is able
@@ -27,9 +28,7 @@ func TestChainWatcherRemoteUnilateralClose(t *testing.T) {
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
require.NoError(t, err, "unable to create test channels")
defer cleanUp()
// With the channels created, we'll now create a chain watcher instance
@@ -45,13 +44,9 @@ func TestChainWatcherRemoteUnilateralClose(t *testing.T) {
signer: aliceChannel.Signer,
extractStateNumHint: lnwallet.GetStateNumHint,
})
if err != nil {
t.Fatalf("unable to create chain watcher: %v", err)
}
require.NoError(t, err, "unable to create chain watcher")
err = aliceChainWatcher.Start()
if err != nil {
t.Fatalf("unable to start chain watcher: %v", err)
}
require.NoError(t, err, "unable to start chain watcher")
defer aliceChainWatcher.Stop()
// We'll request a new channel event subscription from Alice's chain
@@ -118,9 +113,7 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
aliceChannel, bobChannel, cleanUp, err := lnwallet.CreateTestChannels(
channeldb.SingleFunderTweaklessBit,
)
if err != nil {
t.Fatalf("unable to create test channels: %v", err)
}
require.NoError(t, err, "unable to create test channels")
defer cleanUp()
// With the channels created, we'll now create a chain watcher instance
@@ -136,9 +129,7 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
signer: aliceChannel.Signer,
extractStateNumHint: lnwallet.GetStateNumHint,
})
if err != nil {
t.Fatalf("unable to create chain watcher: %v", err)
}
require.NoError(t, err, "unable to create chain watcher")
if err := aliceChainWatcher.Start(); err != nil {
t.Fatalf("unable to start chain watcher: %v", err)
}
+18 -54
View File
@@ -462,9 +462,7 @@ func TestChannelArbitratorCooperativeClose(t *testing.T) {
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
if err := chanArbCtx.chanArb.Start(nil); err != nil {
t.Fatalf("unable to start ChannelArbitrator: %v", err)
@@ -523,9 +521,7 @@ func TestChannelArbitratorRemoteForceClose(t *testing.T) {
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb := chanArbCtx.chanArb
if err := chanArb.Start(nil); err != nil {
@@ -578,9 +574,7 @@ func TestChannelArbitratorLocalForceClose(t *testing.T) {
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb := chanArbCtx.chanArb
if err := chanArb.Start(nil); err != nil {
@@ -686,9 +680,7 @@ func TestChannelArbitratorBreachClose(t *testing.T) {
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb := chanArbCtx.chanArb
chanArb.cfg.PreimageDB = newMockWitnessBeacon()
chanArb.cfg.Registry = &mockRegistry{}
@@ -817,9 +809,7 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) {
// a real DB will be created. We need this for our test as we want to
// test proper restart recovery and resolver population.
chanArbCtx, err := createTestChannelArbitrator(t, nil)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb := chanArbCtx.chanArb
chanArb.cfg.PreimageDB = newMockWitnessBeacon()
chanArb.cfg.Registry = &mockRegistry{}
@@ -990,9 +980,7 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) {
// We'll no re-create the resolver, notice that we use the existing
// arbLog so it carries over the same on-disk state.
chanArbCtxNew, err := chanArbCtx.Restart(nil)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb = chanArbCtxNew.chanArb
defer chanArbCtxNew.CleanUp()
@@ -1088,9 +1076,7 @@ func TestChannelArbitratorLocalForceCloseRemoteConfirmed(t *testing.T) {
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb := chanArbCtx.chanArb
if err := chanArb.Start(nil); err != nil {
@@ -1197,9 +1183,7 @@ func TestChannelArbitratorLocalForceDoubleSpend(t *testing.T) {
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb := chanArbCtx.chanArb
if err := chanArb.Start(nil); err != nil {
@@ -1305,9 +1289,7 @@ func TestChannelArbitratorPersistence(t *testing.T) {
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb := chanArbCtx.chanArb
if err := chanArb.Start(nil); err != nil {
@@ -1340,9 +1322,7 @@ func TestChannelArbitratorPersistence(t *testing.T) {
// Restart the channel arb, this'll use the same long and prior
// context.
chanArbCtx, err = chanArbCtx.Restart(nil)
if err != nil {
t.Fatalf("unable to restart channel arb: %v", err)
}
require.NoError(t, err, "unable to restart channel arb")
chanArb = chanArbCtx.chanArb
// Again, it should start up in the default state.
@@ -1371,9 +1351,7 @@ func TestChannelArbitratorPersistence(t *testing.T) {
// Restart once again to simulate yet another restart.
chanArbCtx, err = chanArbCtx.Restart(nil)
if err != nil {
t.Fatalf("unable to restart channel arb: %v", err)
}
require.NoError(t, err, "unable to restart channel arb")
chanArb = chanArbCtx.chanArb
// Starts out in StateDefault.
@@ -1400,9 +1378,7 @@ func TestChannelArbitratorPersistence(t *testing.T) {
// Create a new arbitrator, and now make fetching resolutions succeed.
log.failFetch = nil
chanArbCtx, err = chanArbCtx.Restart(nil)
if err != nil {
t.Fatalf("unable to restart channel arb: %v", err)
}
require.NoError(t, err, "unable to restart channel arb")
defer chanArbCtx.CleanUp()
// Finally it should advance to StateFullyResolved.
@@ -1431,9 +1407,7 @@ func TestChannelArbitratorForceCloseBreachedChannel(t *testing.T) {
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb := chanArbCtx.chanArb
if err := chanArb.Start(nil); err != nil {
@@ -1515,9 +1489,7 @@ func TestChannelArbitratorForceCloseBreachedChannel(t *testing.T) {
c.chanArb.cfg.ClosingHeight = 100
c.chanArb.cfg.CloseType = channeldb.BreachClose
})
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
defer chanArbCtx.CleanUp()
// We should transition to StateContractClosed.
@@ -1699,9 +1671,7 @@ func TestChannelArbitratorEmptyResolutions(t *testing.T) {
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb := chanArbCtx.chanArb
chanArb.cfg.IsPendingClose = true
@@ -1736,9 +1706,7 @@ func TestChannelArbitratorAlreadyForceClosed(t *testing.T) {
state: StateCommitmentBroadcasted,
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb := chanArbCtx.chanArb
if err := chanArb.Start(nil); err != nil {
t.Fatalf("unable to start ChannelArbitrator: %v", err)
@@ -2009,9 +1977,7 @@ func TestChannelArbitratorPendingExpiredHTLC(t *testing.T) {
resolvers: make(map[ContractResolver]struct{}),
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
chanArb := chanArbCtx.chanArb
// We'll inject a test clock implementation so we can control the uptime.
@@ -2504,9 +2470,7 @@ func TestChannelArbitratorAnchors(t *testing.T) {
}
chanArbCtx, err := createTestChannelArbitrator(t, log)
if err != nil {
t.Fatalf("unable to create ChannelArbitrator: %v", err)
}
require.NoError(t, err, "unable to create ChannelArbitrator")
// Replace our mocked put report function with one which will push
// reports into a channel for us to consume. We update this function
+11 -30
View File
@@ -10,6 +10,7 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/stretchr/testify/require"
)
type incubateTest struct {
@@ -53,15 +54,11 @@ func initIncubateTests() {
// any modifying calls are made.
func TestNurseryStoreInit(t *testing.T) {
cdb, cleanUp, err := channeldb.MakeTestDB()
if err != nil {
t.Fatalf("unable to open channel db: %v", err)
}
require.NoError(t, err, "unable to open channel db")
defer cleanUp()
ns, err := NewNurseryStore(&chainHash, cdb)
if err != nil {
t.Fatalf("unable to open nursery store: %v", err)
}
require.NoError(t, err, "unable to open nursery store")
assertNumChannels(t, ns, 0)
assertNumPreschools(t, ns, 0)
@@ -73,15 +70,11 @@ func TestNurseryStoreInit(t *testing.T) {
// intermediate states.
func TestNurseryStoreIncubate(t *testing.T) {
cdb, cleanUp, err := channeldb.MakeTestDB()
if err != nil {
t.Fatalf("unable to open channel db: %v", err)
}
require.NoError(t, err, "unable to open channel db")
defer cleanUp()
ns, err := NewNurseryStore(&chainHash, cdb)
if err != nil {
t.Fatalf("unable to open nursery store: %v", err)
}
require.NoError(t, err, "unable to open nursery store")
for i, test := range incubateTests {
// At the beginning of each test, we do not expect to the
@@ -314,15 +307,11 @@ func TestNurseryStoreIncubate(t *testing.T) {
// purged height is set appropriately.
func TestNurseryStoreGraduate(t *testing.T) {
cdb, cleanUp, err := channeldb.MakeTestDB()
if err != nil {
t.Fatalf("unable to open channel db: %v", err)
}
require.NoError(t, err, "unable to open channel db")
defer cleanUp()
ns, err := NewNurseryStore(&chainHash, cdb)
if err != nil {
t.Fatalf("unable to open nursery store: %v", err)
}
require.NoError(t, err, "unable to open nursery store")
kid := &kidOutputs[3]
@@ -333,16 +322,12 @@ func TestNurseryStoreGraduate(t *testing.T) {
// First, add a commitment output to the nursery store, which is
// initially inserted in the preschool bucket.
err = ns.Incubate([]kidOutput{*kid}, nil)
if err != nil {
t.Fatalf("unable to incubate commitment output: %v", err)
}
require.NoError(t, err, "unable to incubate commitment output")
// Then, move the commitment output to the kindergarten bucket, such
// that it resides in the height index at its maturity height.
err = ns.PreschoolToKinder(kid, 0)
if err != nil {
t.Fatalf("unable to move pscl output to kndr: %v", err)
}
require.NoError(t, err, "unable to move pscl output to kndr")
// Now, iteratively purge all height below the target maturity height,
// checking that each class is now empty, and that the last purged
@@ -394,9 +379,7 @@ func assertNumChanOutputs(t *testing.T, ns NurseryStorer,
// matches the expected number.
func assertNumPreschools(t *testing.T, ns NurseryStorer, expected int) {
psclOutputs, err := ns.FetchPreschools()
if err != nil {
t.Fatalf("unable to retrieve preschool outputs: %v", err)
}
require.NoError(t, err, "unable to retrieve preschool outputs")
if len(psclOutputs) != expected {
t.Fatalf("expected number of pscl outputs to be %d, got %v",
@@ -534,9 +517,7 @@ func assertChannelMaturity(t *testing.T, ns NurseryStorer,
chanPoint *wire.OutPoint, expectedMaturity bool) {
isMature, err := ns.IsMatureChannel(chanPoint)
if err != nil {
t.Fatalf("unable to fetch channel maturity: %v", err)
}
require.NoError(t, err, "unable to fetch channel maturity")
if isMature != expectedMaturity {
t.Fatalf("expected channel maturity: %v, actual: %v",
+2 -3
View File
@@ -24,6 +24,7 @@ import (
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/sweep"
"github.com/stretchr/testify/require"
)
var (
@@ -419,9 +420,7 @@ func createNurseryTestContext(t *testing.T,
// still considerable logic in the store.
cdb, cleanup, err := channeldb.MakeTestDB()
if err != nil {
t.Fatalf("unable to open channeldb: %v", err)
}
require.NoError(t, err, "unable to open channeldb")
store, err := NewNurseryStore(&chainhash.Hash{}, cdb)
if err != nil {