itest: use require in assertions

This commit is contained in:
yyforyongyu 2021-06-29 03:19:55 +08:00
parent 6f0da73ee1
commit 0612ced087
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868

@ -5,7 +5,6 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io" "io"
"strings"
"sync/atomic" "sync/atomic"
"testing" "testing"
"time" "time"
@ -52,9 +51,7 @@ func openChannelStream(ctx context.Context, t *harnessTest,
chanOpenUpdate, err = net.OpenChannel(ctx, alice, bob, p) chanOpenUpdate, err = net.OpenChannel(ctx, alice, bob, p)
return err return err
}, defaultTimeout) }, defaultTimeout)
if err != nil { require.NoError(t.t, err, "unable to open channel")
t.Fatalf("unable to open channel: %v", err)
}
return chanOpenUpdate return chanOpenUpdate
} }
@ -79,13 +76,11 @@ func openChannelAndAssert(ctx context.Context, t *harnessTest,
block := mineBlocks(t, net, 6, 1)[0] block := mineBlocks(t, net, 6, 1)[0]
fundingChanPoint, err := net.WaitForChannelOpen(ctx, chanOpenUpdate) fundingChanPoint, err := net.WaitForChannelOpen(ctx, chanOpenUpdate)
if err != nil { require.NoError(t.t, err, "error while waiting for channel open")
t.Fatalf("error while waiting for channel open: %v", err)
}
fundingTxID, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint) fundingTxID, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint)
if err != nil { require.NoError(t.t, err, "unable to get txid")
t.Fatalf("unable to get txid: %v", err)
}
assertTxInBlock(t, block, fundingTxID) assertTxInBlock(t, block, fundingTxID)
// The channel should be listed in the peer information returned by // The channel should be listed in the peer information returned by
@ -94,12 +89,14 @@ func openChannelAndAssert(ctx context.Context, t *harnessTest,
Hash: *fundingTxID, Hash: *fundingTxID,
Index: fundingChanPoint.OutputIndex, Index: fundingChanPoint.OutputIndex,
} }
if err := net.AssertChannelExists(ctx, alice, &chanPoint); err != nil { require.NoError(
t.Fatalf("unable to assert channel existence: %v", err) t.t, net.AssertChannelExists(ctx, alice, &chanPoint),
} "unable to assert channel existence",
if err := net.AssertChannelExists(ctx, bob, &chanPoint); err != nil { )
t.Fatalf("unable to assert channel existence: %v", err) require.NoError(
} t.t, net.AssertChannelExists(ctx, bob, &chanPoint),
"unable to assert channel existence",
)
return fundingChanPoint return fundingChanPoint
} }
@ -122,9 +119,7 @@ func subscribeGraphNotifications(ctxb context.Context, t *harnessTest,
req := &lnrpc.GraphTopologySubscription{} req := &lnrpc.GraphTopologySubscription{}
ctx, cancelFunc := context.WithCancel(ctxb) ctx, cancelFunc := context.WithCancel(ctxb)
topologyClient, err := node.SubscribeChannelGraph(ctx, req) topologyClient, err := node.SubscribeChannelGraph(ctx, req)
if err != nil { require.NoError(t.t, err, "unable to create topology client")
t.Fatalf("unable to create topology client: %v", err)
}
// We'll launch a goroutine that will be responsible for proxying all // We'll launch a goroutine that will be responsible for proxying all
// notifications recv'd from the client into the channel below. // notifications recv'd from the client into the channel below.
@ -192,7 +187,8 @@ func waitForGraphSync(t *harnessTest, node *lntest.HarnessNode) {
// via timeout from a base parent. Additionally, once the channel has been // via timeout from a base parent. Additionally, once the channel has been
// detected as closed, an assertion checks that the transaction is found within // detected as closed, an assertion checks that the transaction is found within
// a block. Finally, this assertion verifies that the node always sends out a // a block. Finally, this assertion verifies that the node always sends out a
// disable update when closing the channel if the channel was previously enabled. // disable update when closing the channel if the channel was previously
// enabled.
// //
// NOTE: This method assumes that the provided funding point is confirmed // NOTE: This method assumes that the provided funding point is confirmed
// on-chain AND that the edge exists in the node's channel graph. If the funding // on-chain AND that the edge exists in the node's channel graph. If the funding
@ -201,18 +197,23 @@ func closeChannelAndAssert(ctx context.Context, t *harnessTest,
net *lntest.NetworkHarness, node *lntest.HarnessNode, net *lntest.NetworkHarness, node *lntest.HarnessNode,
fundingChanPoint *lnrpc.ChannelPoint, force bool) *chainhash.Hash { fundingChanPoint *lnrpc.ChannelPoint, force bool) *chainhash.Hash {
return closeChannelAndAssertType(ctx, t, net, node, fundingChanPoint, false, force) return closeChannelAndAssertType(
ctx, t, net, node, fundingChanPoint, false, force,
)
} }
func closeChannelAndAssertType(ctx context.Context, t *harnessTest, func closeChannelAndAssertType(ctx context.Context, t *harnessTest,
net *lntest.NetworkHarness, node *lntest.HarnessNode, net *lntest.NetworkHarness, node *lntest.HarnessNode,
fundingChanPoint *lnrpc.ChannelPoint, anchors, force bool) *chainhash.Hash { fundingChanPoint *lnrpc.ChannelPoint,
anchors, force bool) *chainhash.Hash {
// Fetch the current channel policy. If the channel is currently // Fetch the current channel policy. If the channel is currently
// enabled, we will register for graph notifications before closing to // enabled, we will register for graph notifications before closing to
// assert that the node sends out a disabling update as a result of the // assert that the node sends out a disabling update as a result of the
// channel being closed. // channel being closed.
curPolicy := getChannelPolicies(t, node, node.PubKeyStr, fundingChanPoint)[0] curPolicy := getChannelPolicies(
t, node, node.PubKeyStr, fundingChanPoint,
)[0]
expectDisable := !curPolicy.Disabled expectDisable := !curPolicy.Disabled
// If the current channel policy is enabled, begin subscribing the graph // If the current channel policy is enabled, begin subscribing the graph
@ -224,10 +225,10 @@ func closeChannelAndAssertType(ctx context.Context, t *harnessTest,
defer close(graphSub.quit) defer close(graphSub.quit)
} }
closeUpdates, _, err := net.CloseChannel(ctx, node, fundingChanPoint, force) closeUpdates, _, err := net.CloseChannel(
if err != nil { ctx, node, fundingChanPoint, force,
t.Fatalf("unable to close channel: %v", err) )
} require.NoError(t.t, err, "unable to close channel")
// If the channel policy was enabled prior to the closure, wait until we // If the channel policy was enabled prior to the closure, wait until we
// received the disabled update. // received the disabled update.
@ -260,9 +261,7 @@ func closeReorgedChannelAndAssert(ctx context.Context, t *harnessTest,
fundingChanPoint *lnrpc.ChannelPoint, force bool) *chainhash.Hash { fundingChanPoint *lnrpc.ChannelPoint, force bool) *chainhash.Hash {
closeUpdates, _, err := net.CloseChannel(ctx, node, fundingChanPoint, force) closeUpdates, _, err := net.CloseChannel(ctx, node, fundingChanPoint, force)
if err != nil { require.NoError(t.t, err, "unable to close channel")
t.Fatalf("unable to close channel: %v", err)
}
return assertChannelClosed( return assertChannelClosed(
ctx, t, net, node, fundingChanPoint, false, closeUpdates, ctx, t, net, node, fundingChanPoint, false, closeUpdates,
@ -277,9 +276,7 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
closeUpdates lnrpc.Lightning_CloseChannelClient) *chainhash.Hash { closeUpdates lnrpc.Lightning_CloseChannelClient) *chainhash.Hash {
txid, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint) txid, err := lnrpc.GetChanPointFundingTxid(fundingChanPoint)
if err != nil { require.NoError(t.t, err, "unable to get txid")
t.Fatalf("unable to get txid: %v", err)
}
chanPointStr := fmt.Sprintf("%v:%v", txid, fundingChanPoint.OutputIndex) chanPointStr := fmt.Sprintf("%v:%v", txid, fundingChanPoint.OutputIndex)
// If the channel appears in list channels, ensure that its state // If the channel appears in list channels, ensure that its state
@ -287,9 +284,8 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
ctxt, _ := context.WithTimeout(ctx, defaultTimeout) ctxt, _ := context.WithTimeout(ctx, defaultTimeout)
listChansRequest := &lnrpc.ListChannelsRequest{} listChansRequest := &lnrpc.ListChannelsRequest{}
listChansResp, err := node.ListChannels(ctxt, listChansRequest) listChansResp, err := node.ListChannels(ctxt, listChansRequest)
if err != nil { require.NoError(t.t, err, "unable to query for list channels")
t.Fatalf("unable to query for list channels: %v", err)
}
for _, channel := range listChansResp.Channels { for _, channel := range listChansResp.Channels {
// Skip other channels. // Skip other channels.
if channel.ChannelPoint != chanPointStr { if channel.ChannelPoint != chanPointStr {
@ -297,11 +293,11 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
} }
// Assert that the channel is in coop broadcasted. // Assert that the channel is in coop broadcasted.
if !strings.Contains(channel.ChanStatusFlags, require.Contains(
channeldb.ChanStatusCoopBroadcasted.String()) { t.t, channel.ChanStatusFlags,
t.Fatalf("channel not coop broadcasted, "+ channeldb.ChanStatusCoopBroadcasted.String(),
"got: %v", channel.ChanStatusFlags) "channel not coop broadcasted",
} )
} }
// At this point, the channel should now be marked as being in the // At this point, the channel should now be marked as being in the
@ -309,9 +305,8 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
ctxt, _ = context.WithTimeout(ctx, defaultTimeout) ctxt, _ = context.WithTimeout(ctx, defaultTimeout)
pendingChansRequest := &lnrpc.PendingChannelsRequest{} pendingChansRequest := &lnrpc.PendingChannelsRequest{}
pendingChanResp, err := node.PendingChannels(ctxt, pendingChansRequest) pendingChanResp, err := node.PendingChannels(ctxt, pendingChansRequest)
if err != nil { require.NoError(t.t, err, "unable to query for pending channels")
t.Fatalf("unable to query for pending channels: %v", err)
}
var found bool var found bool
for _, pendingClose := range pendingChanResp.WaitingCloseChannels { for _, pendingClose := range pendingChanResp.WaitingCloseChannels {
if pendingClose.Channel.ChannelPoint == chanPointStr { if pendingClose.Channel.ChannelPoint == chanPointStr {
@ -319,9 +314,7 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
break break
} }
} }
if !found { require.True(t.t, found, "channel not marked as waiting close")
t.Fatalf("channel not marked as waiting close")
}
// We'll now, generate a single block, wait for the final close status // We'll now, generate a single block, wait for the final close status
// update, then ensure that the closing transaction was included in the // update, then ensure that the closing transaction was included in the
@ -334,9 +327,7 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
block := mineBlocks(t, net, 1, expectedTxes)[0] block := mineBlocks(t, net, 1, expectedTxes)[0]
closingTxid, err := net.WaitForChannelClose(ctx, closeUpdates) closingTxid, err := net.WaitForChannelClose(ctx, closeUpdates)
if err != nil { require.NoError(t.t, err, "error while waiting for channel close")
t.Fatalf("error while waiting for channel close: %v", err)
}
assertTxInBlock(t, block, closingTxid) assertTxInBlock(t, block, closingTxid)
@ -360,9 +351,9 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
return true return true
}, defaultTimeout) }, defaultTimeout)
if err != nil { require.NoError(
t.Fatalf("closing transaction not marked as fully closed") t.t, err, "closing transaction not marked as fully closed",
} )
return closingTxid return closingTxid
} }
@ -370,7 +361,8 @@ func assertChannelClosed(ctx context.Context, t *harnessTest,
// findForceClosedChannel searches a pending channel response for a particular // findForceClosedChannel searches a pending channel response for a particular
// channel, returning the force closed channel upon success. // channel, returning the force closed channel upon success.
func findForceClosedChannel(pendingChanResp *lnrpc.PendingChannelsResponse, func findForceClosedChannel(pendingChanResp *lnrpc.PendingChannelsResponse,
op *wire.OutPoint) (*lnrpc.PendingChannelsResponse_ForceClosedChannel, error) { op *wire.OutPoint) (*lnrpc.PendingChannelsResponse_ForceClosedChannel,
error) {
for _, forceClose := range pendingChanResp.PendingForceClosingChannels { for _, forceClose := range pendingChanResp.PendingForceClosingChannels {
if forceClose.Channel.ChannelPoint == op.String() { if forceClose.Channel.ChannelPoint == op.String() {
@ -384,7 +376,8 @@ func findForceClosedChannel(pendingChanResp *lnrpc.PendingChannelsResponse,
// findWaitingCloseChannel searches a pending channel response for a particular // findWaitingCloseChannel searches a pending channel response for a particular
// channel, returning the waiting close channel upon success. // channel, returning the waiting close channel upon success.
func findWaitingCloseChannel(pendingChanResp *lnrpc.PendingChannelsResponse, func findWaitingCloseChannel(pendingChanResp *lnrpc.PendingChannelsResponse,
op *wire.OutPoint) (*lnrpc.PendingChannelsResponse_WaitingCloseChannel, error) { op *wire.OutPoint) (*lnrpc.PendingChannelsResponse_WaitingCloseChannel,
error) {
for _, waitingClose := range pendingChanResp.WaitingCloseChannels { for _, waitingClose := range pendingChanResp.WaitingCloseChannels {
if waitingClose.Channel.ChannelPoint == op.String() { if waitingClose.Channel.ChannelPoint == op.String() {
@ -484,9 +477,7 @@ func cleanupForceClose(t *harnessTest, net *lntest.NetworkHarness,
// Wait for the channel to be marked pending force close. // Wait for the channel to be marked pending force close.
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
err := waitForChannelPendingForceClose(ctxt, node, chanPoint) err := waitForChannelPendingForceClose(ctxt, node, chanPoint)
if err != nil { require.NoError(t.t, err, "channel not pending force close")
t.Fatalf("channel not pending force close: %v", err)
}
// Mine enough blocks for the node to sweep its funds from the force // Mine enough blocks for the node to sweep its funds from the force
// closed channel. // closed channel.
@ -494,9 +485,7 @@ func cleanupForceClose(t *harnessTest, net *lntest.NetworkHarness,
// The commit sweep resolver is able to broadcast the sweep tx up to // The commit sweep resolver is able to broadcast the sweep tx up to
// one block before the CSV elapses, so wait until defaulCSV-1. // one block before the CSV elapses, so wait until defaulCSV-1.
_, err = net.Miner.Client.Generate(defaultCSV - 1) _, err = net.Miner.Client.Generate(defaultCSV - 1)
if err != nil { require.NoError(t.t, err, "unable to generate blocks")
t.Fatalf("unable to generate blocks: %v", err)
}
// The node should now sweep the funds, clean up by mining the sweeping // The node should now sweep the funds, clean up by mining the sweeping
// tx. // tx.
@ -506,7 +495,9 @@ func cleanupForceClose(t *harnessTest, net *lntest.NetworkHarness,
// numOpenChannelsPending sends an RPC request to a node to get a count of the // numOpenChannelsPending sends an RPC request to a node to get a count of the
// node's channels that are currently in a pending state (with a broadcast, but // node's channels that are currently in a pending state (with a broadcast, but
// not confirmed funding transaction). // not confirmed funding transaction).
func numOpenChannelsPending(ctxt context.Context, node *lntest.HarnessNode) (int, error) { func numOpenChannelsPending(ctxt context.Context,
node *lntest.HarnessNode) (int, error) {
pendingChansRequest := &lnrpc.PendingChannelsRequest{} pendingChansRequest := &lnrpc.PendingChannelsRequest{}
resp, err := node.PendingChannels(ctxt, pendingChansRequest) resp, err := node.PendingChannels(ctxt, pendingChansRequest)
if err != nil { if err != nil {
@ -548,12 +539,11 @@ func assertNumOpenChannelsPending(ctxt context.Context, t *harnessTest,
return nil return nil
}, defaultTimeout) }, defaultTimeout)
if err != nil { require.NoError(t.t, err)
t.Fatalf(err.Error())
}
} }
// assertNumConnections asserts number current connections between two peers. // assertNumConnections asserts number current connections between two peers.
// TODO(yy): refactor to use wait.
func assertNumConnections(t *harnessTest, alice, bob *lntest.HarnessNode, func assertNumConnections(t *harnessTest, alice, bob *lntest.HarnessNode,
expected int) { expected int) {
ctxb := context.Background() ctxb := context.Background()
@ -615,9 +605,7 @@ func shutdownAndAssert(net *lntest.NetworkHarness, t *harnessTest,
err := wait.NoError(func() error { err := wait.NoError(func() error {
return net.ShutdownNode(node) return net.ShutdownNode(node)
}, defaultTimeout) }, defaultTimeout)
if err != nil { require.NoErrorf(t.t, err, "unable to shutdown %v", node.Name())
t.Fatalf("unable to shutdown %v: %v", node.Name(), err)
}
} }
// assertChannelBalanceResp makes a ChannelBalance request and checks the // assertChannelBalanceResp makes a ChannelBalance request and checks the
@ -677,12 +665,13 @@ out:
select { select {
case graphUpdate := <-subscription.updateChan: case graphUpdate := <-subscription.updateChan:
for _, update := range graphUpdate.ChannelUpdates { for _, update := range graphUpdate.ChannelUpdates {
if len(expUpdates) == 0 { require.NotZerof(
t.Fatalf("received unexpected channel "+ t.t, len(expUpdates),
"received unexpected channel "+
"update from %v for channel %v", "update from %v for channel %v",
update.AdvertisingNode, update.AdvertisingNode,
update.ChanId) update.ChanId,
} )
// For each expected update, check if it matches // For each expected update, check if it matches
// the update we just received. // the update we just received.
@ -751,11 +740,10 @@ func assertNoChannelUpdates(t *harnessTest, subscription graphSubscription,
for { for {
select { select {
case graphUpdate := <-subscription.updateChan: case graphUpdate := <-subscription.updateChan:
if len(graphUpdate.ChannelUpdates) > 0 { require.Zero(
t.Fatalf("received %d channel updates when "+ t.t, len(graphUpdate.ChannelUpdates),
"none were expected", "no channel updates were expected",
len(graphUpdate.ChannelUpdates)) )
}
case err := <-subscription.errChan: case err := <-subscription.errChan:
t.Fatalf("graph subscription failure: %v", err) t.Fatalf("graph subscription failure: %v", err)
@ -1128,29 +1116,19 @@ func assertLastHTLCError(t *harnessTest, node *lntest.HarnessNode,
} }
ctxt, _ := context.WithTimeout(context.Background(), defaultTimeout) ctxt, _ := context.WithTimeout(context.Background(), defaultTimeout)
paymentsResp, err := node.ListPayments(ctxt, req) paymentsResp, err := node.ListPayments(ctxt, req)
if err != nil { require.NoError(t.t, err, "error when obtaining payments")
t.Fatalf("error when obtaining payments: %v", err)
}
payments := paymentsResp.Payments payments := paymentsResp.Payments
if len(payments) == 0 { require.NotZero(t.t, len(payments), "no payments found")
t.Fatalf("no payments found")
}
payment := payments[len(payments)-1] payment := payments[len(payments)-1]
htlcs := payment.Htlcs htlcs := payment.Htlcs
if len(htlcs) == 0 { require.NotZero(t.t, len(htlcs), "no htlcs")
t.Fatalf("no htlcs")
}
htlc := htlcs[len(htlcs)-1] htlc := htlcs[len(htlcs)-1]
if htlc.Failure == nil { require.NotNil(t.t, htlc.Failure, "expected failure")
t.Fatalf("expected failure")
}
if htlc.Failure.Code != code { require.Equal(t.t, code, htlc.Failure.Code, "unexpected failure code")
t.Fatalf("expected failure %v, got %v", code, htlc.Failure.Code)
}
} }
func assertChannelConstraintsEqual( func assertChannelConstraintsEqual(
@ -1158,41 +1136,27 @@ func assertChannelConstraintsEqual(
t.t.Helper() t.t.Helper()
if want.CsvDelay != got.CsvDelay { require.Equal(t.t, want.CsvDelay, got.CsvDelay, "CsvDelay mismatched")
t.Fatalf("CsvDelay mismatched, want: %v, got: %v", require.Equal(
want.CsvDelay, got.CsvDelay, t.t, want.ChanReserveSat, got.ChanReserveSat,
) "ChanReserveSat mismatched",
} )
require.Equal(
if want.ChanReserveSat != got.ChanReserveSat { t.t, want.DustLimitSat, got.DustLimitSat,
t.Fatalf("ChanReserveSat mismatched, want: %v, got: %v", "DustLimitSat mismatched",
want.ChanReserveSat, got.ChanReserveSat, )
) require.Equal(
} t.t, want.MaxPendingAmtMsat, got.MaxPendingAmtMsat,
"MaxPendingAmtMsat mismatched",
if want.DustLimitSat != got.DustLimitSat { )
t.Fatalf("DustLimitSat mismatched, want: %v, got: %v", require.Equal(
want.DustLimitSat, got.DustLimitSat, t.t, want.MinHtlcMsat, got.MinHtlcMsat,
) "MinHtlcMsat mismatched",
} )
require.Equal(
if want.MaxPendingAmtMsat != got.MaxPendingAmtMsat { t.t, want.MaxAcceptedHtlcs, got.MaxAcceptedHtlcs,
t.Fatalf("MaxPendingAmtMsat mismatched, want: %v, got: %v", "MaxAcceptedHtlcs mismatched",
want.MaxPendingAmtMsat, got.MaxPendingAmtMsat, )
)
}
if want.MinHtlcMsat != got.MinHtlcMsat {
t.Fatalf("MinHtlcMsat mismatched, want: %v, got: %v",
want.MinHtlcMsat, got.MinHtlcMsat,
)
}
if want.MaxAcceptedHtlcs != got.MaxAcceptedHtlcs {
t.Fatalf("MaxAcceptedHtlcs mismatched, want: %v, got: %v",
want.MaxAcceptedHtlcs, got.MaxAcceptedHtlcs,
)
}
} }
// assertAmountPaid checks that the ListChannels command of the provided // assertAmountPaid checks that the ListChannels command of the provided
@ -1251,9 +1215,10 @@ func assertAmountPaid(t *harnessTest, channelName string,
for { for {
isTimeover := atomic.LoadUint32(&timeover) == 1 isTimeover := atomic.LoadUint32(&timeover) == 1
if err := checkAmountPaid(); err != nil { if err := checkAmountPaid(); err != nil {
if isTimeover { require.Falsef(
t.Fatalf("Check amount Paid failed: %v", err) t.t, isTimeover,
} "Check amount Paid failed: %v", err,
)
} else { } else {
break break
} }
@ -1291,9 +1256,7 @@ func assertNumPendingChannels(t *harnessTest, node *lntest.HarnessNode,
} }
return true return true
}, defaultTimeout) }, defaultTimeout)
if err != nil { require.NoErrorf(t.t, err, "got err: %v", predErr)
t.Fatalf("%v", predErr)
}
} }
// assertDLPExecuted asserts that Dave is a node that has recovered their state // assertDLPExecuted asserts that Dave is a node that has recovered their state
@ -1325,10 +1288,10 @@ func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest,
_, err := waitForNTxsInMempool( _, err := waitForNTxsInMempool(
net.Miner.Client, expectedTxes, minerMempoolTimeout, net.Miner.Client, expectedTxes, minerMempoolTimeout,
) )
if err != nil { require.NoError(
t.Fatalf("unable to find Carol's force close tx in mempool: %v", t.t, err,
err) "unable to find Carol's force close tx in mempool",
} )
// Channel should be in the state "waiting close" for Carol since she // Channel should be in the state "waiting close" for Carol since she
// broadcasted the force close tx. // broadcasted the force close tx.
@ -1341,9 +1304,7 @@ func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest,
// Restart Dave to make sure he is able to sweep the funds after // Restart Dave to make sure he is able to sweep the funds after
// shutdown. // shutdown.
if err := net.RestartNode(dave, nil); err != nil { require.NoError(t.t, net.RestartNode(dave, nil), "Node restart failed")
t.Fatalf("Node restart failed: %v", err)
}
// Generate a single block, which should confirm the closing tx. // Generate a single block, which should confirm the closing tx.
_ = mineBlocks(t, net, 1, expectedTxes)[0] _ = mineBlocks(t, net, 1, expectedTxes)[0]
@ -1354,9 +1315,7 @@ func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest,
_, err = waitForNTxsInMempool( _, err = waitForNTxsInMempool(
net.Miner.Client, expectedTxes, minerMempoolTimeout, net.Miner.Client, expectedTxes, minerMempoolTimeout,
) )
if err != nil { require.NoError(t.t, err, "unable to find Dave's sweep tx in mempool")
t.Fatalf("unable to find Dave's sweep tx in mempool: %v", err)
}
// Dave should consider the channel pending force close (since he is // Dave should consider the channel pending force close (since he is
// waiting for his sweep to confirm). // waiting for his sweep to confirm).
@ -1378,15 +1337,12 @@ func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest,
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout) ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
balReq := &lnrpc.WalletBalanceRequest{} balReq := &lnrpc.WalletBalanceRequest{}
daveBalResp, err := dave.WalletBalance(ctxt, balReq) daveBalResp, err := dave.WalletBalance(ctxt, balReq)
if err != nil { require.NoError(t.t, err, "unable to get dave's balance")
t.Fatalf("unable to get dave's balance: %v", err)
}
daveBalance := daveBalResp.ConfirmedBalance daveBalance := daveBalResp.ConfirmedBalance
if daveBalance <= daveStartingBalance { require.Greater(
t.Fatalf("expected dave to have balance above %d, "+ t.t, daveBalance, daveStartingBalance, "balance not increased",
"instead had %v", daveStartingBalance, daveBalance) )
}
// After the Carol's output matures, she should also reclaim her funds. // After the Carol's output matures, she should also reclaim her funds.
// //
@ -1397,9 +1353,7 @@ func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest,
carolSweep, err := waitForTxInMempool( carolSweep, err := waitForTxInMempool(
net.Miner.Client, minerMempoolTimeout, net.Miner.Client, minerMempoolTimeout,
) )
if err != nil { require.NoError(t.t, err, "unable to find Carol's sweep tx in mempool")
t.Fatalf("unable to find Carol's sweep tx in mempool: %v", err)
}
block := mineBlocks(t, net, 1, 1)[0] block := mineBlocks(t, net, 1, 1)[0]
assertTxInBlock(t, block, carolSweep) assertTxInBlock(t, block, carolSweep)
@ -1423,9 +1377,7 @@ func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest,
return nil return nil
}, defaultTimeout) }, defaultTimeout)
if err != nil { require.NoError(t.t, err)
t.Fatalf(err.Error())
}
assertNodeNumChannels(t, dave, 0) assertNodeNumChannels(t, dave, 0)
assertNodeNumChannels(t, carol, 0) assertNodeNumChannels(t, carol, 0)
@ -1506,9 +1458,10 @@ func assertNodeNumChannels(t *harnessTest, node *lntest.HarnessNode,
return true return true
} }
if err := wait.Predicate(pred, defaultTimeout); err != nil { require.NoErrorf(
t.Fatalf("node has incorrect number of channels: %v", predErr) t.t, wait.Predicate(pred, defaultTimeout),
} "node has incorrect number of channels: %v", predErr,
)
} }
func assertSyncType(t *harnessTest, node *lntest.HarnessNode, func assertSyncType(t *harnessTest, node *lntest.HarnessNode,
@ -1651,9 +1604,7 @@ func getSpendingTxInMempool(t *harnessTest, miner *rpcclient.Client,
t.Fatalf("didn't find tx in mempool") t.Fatalf("didn't find tx in mempool")
case <-ticker.C: case <-ticker.C:
mempool, err := miner.GetRawMempool() mempool, err := miner.GetRawMempool()
if err != nil { require.NoError(t.t, err, "unable to get mempool")
t.Fatalf("unable to get mempool: %v", err)
}
if len(mempool) == 0 { if len(mempool) == 0 {
continue continue
@ -1661,9 +1612,7 @@ func getSpendingTxInMempool(t *harnessTest, miner *rpcclient.Client,
for _, txid := range mempool { for _, txid := range mempool {
tx, err := miner.GetRawTransaction(txid) tx, err := miner.GetRawTransaction(txid)
if err != nil { require.NoError(t.t, err, "unable to fetch tx")
t.Fatalf("unable to fetch tx: %v", err)
}
msgTx := tx.MsgTx() msgTx := tx.MsgTx()
for _, txIn := range msgTx.TxIn { for _, txIn := range msgTx.TxIn {
@ -1689,18 +1638,13 @@ func assertTxLabel(ctx context.Context, t *harnessTest,
txResp, err := node.GetTransactions( txResp, err := node.GetTransactions(
ctxt, &lnrpc.GetTransactionsRequest{}, ctxt, &lnrpc.GetTransactionsRequest{},
) )
if err != nil { require.NoError(t.t, err, "could not get transactions")
t.Fatalf("could not get transactions: %v", err)
}
// Find our transaction in the set of transactions returned and check // Find our transaction in the set of transactions returned and check
// its label. // its label.
for _, txn := range txResp.Transactions { for _, txn := range txResp.Transactions {
if txn.TxHash == targetTx { if txn.TxHash == targetTx {
if txn.Label != label { require.Equal(t.t, label, txn.Label, "labels not match")
t.Fatalf("expected label: %v, got: %v",
label, txn.Label)
}
} }
} }
} }
@ -1744,23 +1688,20 @@ func sendAndAssertFailure(t *harnessTest, node *lntest.HarnessNode,
defer cancel() defer cancel()
stream, err := node.RouterClient.SendPaymentV2(ctx, req) stream, err := node.RouterClient.SendPaymentV2(ctx, req)
if err != nil { require.NoError(t.t, err, "unable to send payment")
t.Fatalf("unable to send payment: %v", err)
}
result, err := getPaymentResult(stream) result, err := getPaymentResult(stream)
if err != nil { require.NoError(t.t, err, "unable to get payment result")
t.Fatalf("unable to get payment result: %v", err)
}
if result.Status != lnrpc.Payment_FAILED { require.Equal(
t.Fatalf("payment was expected to fail, but succeeded") t.t, lnrpc.Payment_FAILED, result.Status,
} "payment was expected to fail, but succeeded",
)
if result.FailureReason != failureReason { require.Equal(
t.Fatalf("payment should have been rejected due to "+ t.t, failureReason, result.FailureReason,
"%v, but got %v", failureReason, result.Status) "payment failureReason not matched",
} )
return result return result
} }