itest: refactor testChannelBackupRestore
This commit is contained in:
9 files changed
+453
-520
No files matched your search
@@ -306,3 +306,16 @@ func (h *HarnessRPC) RestoreChanBackups(
|
|||||||
|
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AcceptorClient lnrpc.Lightning_ChannelAcceptorClient
|
||||||
|
|
||||||
|
// ChannelAcceptor makes a RPC call to the node's ChannelAcceptor and asserts.
|
||||||
|
func (h *HarnessRPC) ChannelAcceptor() (AcceptorClient, context.CancelFunc) {
|
||||||
|
// Use runCtx here instead of a timeout context to keep the client
|
||||||
|
// alive for the entire test case.
|
||||||
|
ctxt, cancel := context.WithCancel(h.runCtx)
|
||||||
|
resp, err := h.LN.ChannelAcceptor(ctxt)
|
||||||
|
h.NoError(err, "ChannelAcceptor")
|
||||||
|
|
||||||
|
return resp, cancel
|
||||||
|
}
|
||||||
@@ -1106,7 +1106,7 @@ func assertNumPendingChannels(t *harnessTest, node *lntest.HarnessNode,
|
|||||||
// funds immediately, and Carol sweeping her fund after her CSV delay is up. If
|
// funds immediately, and Carol sweeping her fund after her CSV delay is up. If
|
||||||
// the blankSlate value is true, then this means that Dave won't need to sweep
|
// the blankSlate value is true, then this means that Dave won't need to sweep
|
||||||
// on chain as he has no funds in the channel.
|
// on chain as he has no funds in the channel.
|
||||||
func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest,
|
func assertDLPExecutedOld(net *lntest.NetworkHarness, t *harnessTest,
|
||||||
carol *lntest.HarnessNode, carolStartingBalance int64,
|
carol *lntest.HarnessNode, carolStartingBalance int64,
|
||||||
dave *lntest.HarnessNode, daveStartingBalance int64,
|
dave *lntest.HarnessNode, daveStartingBalance int64,
|
||||||
commitType lnrpc.CommitmentType) {
|
commitType lnrpc.CommitmentType) {
|
||||||
@@ -1293,91 +1293,6 @@ func assertDLPExecuted(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
assertNodeNumChannels(t, carol, 0)
|
assertNodeNumChannels(t, carol, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertTimeLockSwept(net *lntest.NetworkHarness, t *harnessTest,
|
|
||||||
carol *lntest.HarnessNode, carolStartingBalance int64,
|
|
||||||
dave *lntest.HarnessNode, daveStartingBalance int64,
|
|
||||||
anchors bool) {
|
|
||||||
|
|
||||||
ctxb := context.Background()
|
|
||||||
expectedTxes := 2
|
|
||||||
if anchors {
|
|
||||||
expectedTxes = 3
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carol should sweep her funds immediately, as they are not timelocked.
|
|
||||||
// We also expect Carol and Dave to sweep their anchor, if present.
|
|
||||||
_, err := waitForNTxsInMempool(
|
|
||||||
net.Miner.Client, expectedTxes, minerMempoolTimeout,
|
|
||||||
)
|
|
||||||
require.NoError(t.t, err, "unable to find Carol's sweep tx in mempool")
|
|
||||||
|
|
||||||
// Carol should consider the channel pending force close (since she is
|
|
||||||
// waiting for her sweep to confirm).
|
|
||||||
assertNumPendingChannels(t, carol, 0, 1)
|
|
||||||
|
|
||||||
// Dave is considering it "pending force close", as we must wait
|
|
||||||
// before he can sweep her outputs.
|
|
||||||
assertNumPendingChannels(t, dave, 0, 1)
|
|
||||||
|
|
||||||
// Mine the sweep (and anchor) tx(ns).
|
|
||||||
_ = mineBlocks(t, net, 1, expectedTxes)[0]
|
|
||||||
|
|
||||||
// Now Carol should consider the channel fully closed.
|
|
||||||
assertNumPendingChannels(t, carol, 0, 0)
|
|
||||||
|
|
||||||
// We query Carol's balance to make sure it increased after the channel
|
|
||||||
// closed. This checks that she was able to sweep the funds she had in
|
|
||||||
// the channel.
|
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
balReq := &lnrpc.WalletBalanceRequest{}
|
|
||||||
carolBalResp, err := carol.WalletBalance(ctxt, balReq)
|
|
||||||
require.NoError(t.t, err, "unable to get Carol's balance")
|
|
||||||
|
|
||||||
carolBalance := carolBalResp.ConfirmedBalance
|
|
||||||
require.Greater(
|
|
||||||
t.t, carolBalance, carolStartingBalance, "balance not increased",
|
|
||||||
)
|
|
||||||
|
|
||||||
// After the Dave's output matures, he should reclaim his funds.
|
|
||||||
//
|
|
||||||
// The commit sweep resolver publishes the sweep tx at defaultCSV-1 and
|
|
||||||
// we already mined one block after the commitment was published, so
|
|
||||||
// take that into account.
|
|
||||||
mineBlocks(t, net, defaultCSV-1-1, 0)
|
|
||||||
daveSweep, err := waitForTxInMempool(
|
|
||||||
net.Miner.Client, minerMempoolTimeout,
|
|
||||||
)
|
|
||||||
require.NoError(t.t, err, "unable to find Dave's sweep tx in mempool")
|
|
||||||
block := mineBlocks(t, net, 1, 1)[0]
|
|
||||||
assertTxInBlock(t, block, daveSweep)
|
|
||||||
|
|
||||||
// Now the channel should be fully closed also from Dave's POV.
|
|
||||||
assertNumPendingChannels(t, dave, 0, 0)
|
|
||||||
|
|
||||||
// Make sure Dave got his balance back.
|
|
||||||
err = wait.NoError(func() error {
|
|
||||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
|
||||||
daveBalResp, err := dave.WalletBalance(ctxt, balReq)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unable to get Dave's balance: %v",
|
|
||||||
err)
|
|
||||||
}
|
|
||||||
|
|
||||||
daveBalance := daveBalResp.ConfirmedBalance
|
|
||||||
if daveBalance <= daveStartingBalance {
|
|
||||||
return fmt.Errorf("expected dave to have balance "+
|
|
||||||
"above %d, instead had %v", daveStartingBalance,
|
|
||||||
daveBalance)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}, defaultTimeout)
|
|
||||||
require.NoError(t.t, err)
|
|
||||||
|
|
||||||
assertNodeNumChannels(t, dave, 0)
|
|
||||||
assertNodeNumChannels(t, carol, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// verifyCloseUpdate is used to verify that a closed channel update is of the
|
// verifyCloseUpdate is used to verify that a closed channel update is of the
|
||||||
// expected type.
|
// expected type.
|
||||||
func verifyCloseUpdate(chanUpdate *lnrpc.ChannelEventUpdate,
|
func verifyCloseUpdate(chanUpdate *lnrpc.ChannelEventUpdate,
|
||||||
|
|||||||
@@ -19,4 +19,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
|
|||||||
Name: "external channel funding",
|
Name: "external channel funding",
|
||||||
TestFunc: testExternalFundingChanPoint,
|
TestFunc: testExternalFundingChanPoint,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "channel backup restore",
|
||||||
|
TestFunc: testChannelBackupRestore,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1019,7 +1019,7 @@ func testDataLossProtection(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Assert that once Dave comes up, they reconnect, Carol force closes
|
// Assert that once Dave comes up, they reconnect, Carol force closes
|
||||||
// on chain, and both of them properly carry out the DLP protocol.
|
// on chain, and both of them properly carry out the DLP protocol.
|
||||||
assertDLPExecuted(
|
assertDLPExecutedOld(
|
||||||
net, t, carol, carolStartingBalance, dave, daveStartingBalance,
|
net, t, carol, carolStartingBalance, dave, daveStartingBalance,
|
||||||
lnrpc.CommitmentType_STATIC_REMOTE_KEY,
|
lnrpc.CommitmentType_STATIC_REMOTE_KEY,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
ctxc, cancel = context.WithCancel(ctxb)
|
ctxc, cancel = context.WithCancel(ctxb)
|
||||||
acceptStream, err := bob.ChannelAcceptor(ctxc)
|
acceptStream, err := bob.ChannelAcceptor(ctxc)
|
||||||
require.NoError(t.t, err)
|
require.NoError(t.t, err)
|
||||||
go acceptChannel(t, true, acceptStream)
|
go acceptChannel(t.t, true, acceptStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
aliceChanPoint := openChannelAndAssert(
|
aliceChanPoint := openChannelAndAssert(
|
||||||
@@ -349,7 +349,7 @@ func createThreeHopNetwork(t *harnessTest, net *lntest.NetworkHarness,
|
|||||||
ctxc, cancel = context.WithCancel(ctxb)
|
ctxc, cancel = context.WithCancel(ctxb)
|
||||||
acceptStream, err := carol.ChannelAcceptor(ctxc)
|
acceptStream, err := carol.ChannelAcceptor(ctxc)
|
||||||
require.NoError(t.t, err)
|
require.NoError(t.t, err)
|
||||||
go acceptChannel(t, true, acceptStream)
|
go acceptChannel(t.t, true, acceptStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
bobChanPoint := openChannelAndAssert(
|
bobChanPoint := openChannelAndAssert(
|
||||||
|
|||||||
@@ -247,10 +247,6 @@ var allTestCases = []*testCase{
|
|||||||
name: "export channel backup",
|
name: "export channel backup",
|
||||||
test: testExportChannelBackup,
|
test: testExportChannelBackup,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "channel backup restore",
|
|
||||||
test: testChannelBackupRestore,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "hold invoice sender persistence",
|
name: "hold invoice sender persistence",
|
||||||
test: testHoldInvoicePersistence,
|
test: testHoldInvoicePersistence,
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
ctxc, cancel := context.WithCancel(ctxb)
|
ctxc, cancel := context.WithCancel(ctxb)
|
||||||
acceptStream, err := dave.ChannelAcceptor(ctxc)
|
acceptStream, err := dave.ChannelAcceptor(ctxc)
|
||||||
require.NoError(t.t, err)
|
require.NoError(t.t, err)
|
||||||
go acceptChannel(t, true, acceptStream)
|
go acceptChannel(t.t, true, acceptStream)
|
||||||
|
|
||||||
// Open a private zero-conf anchors channel of 1M satoshis.
|
// Open a private zero-conf anchors channel of 1M satoshis.
|
||||||
params := lntest.OpenChannelParams{
|
params := lntest.OpenChannelParams{
|
||||||
@@ -167,7 +167,7 @@ func testZeroConfChannelOpen(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
ctxc, cancel = context.WithCancel(ctxb)
|
ctxc, cancel = context.WithCancel(ctxb)
|
||||||
acceptStream, err = carol.ChannelAcceptor(ctxc)
|
acceptStream, err = carol.ChannelAcceptor(ctxc)
|
||||||
require.NoError(t.t, err)
|
require.NoError(t.t, err)
|
||||||
go acceptChannel(t, true, acceptStream)
|
go acceptChannel(t.t, true, acceptStream)
|
||||||
|
|
||||||
// We'll open a public zero-conf anchors channel of 1M satoshis.
|
// We'll open a public zero-conf anchors channel of 1M satoshis.
|
||||||
params.Private = false
|
params.Private = false
|
||||||
@@ -604,7 +604,7 @@ func testPrivateUpdateAlias(net *lntest.NetworkHarness, t *harnessTest,
|
|||||||
ctxc, cancel := context.WithCancel(ctxb)
|
ctxc, cancel := context.WithCancel(ctxb)
|
||||||
acceptStream, err := dave.ChannelAcceptor(ctxc)
|
acceptStream, err := dave.ChannelAcceptor(ctxc)
|
||||||
require.NoError(t.t, err)
|
require.NoError(t.t, err)
|
||||||
go acceptChannel(t, zeroConf, acceptStream)
|
go acceptChannel(t.t, zeroConf, acceptStream)
|
||||||
|
|
||||||
// Open a private channel, optionally specifying a channel-type.
|
// Open a private channel, optionally specifying a channel-type.
|
||||||
params := lntest.OpenChannelParams{
|
params := lntest.OpenChannelParams{
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
@@ -19,6 +20,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||||
"github.com/lightningnetwork/lnd/lntemp"
|
"github.com/lightningnetwork/lnd/lntemp"
|
||||||
|
"github.com/lightningnetwork/lnd/lntemp/rpc"
|
||||||
"github.com/lightningnetwork/lnd/lntest"
|
"github.com/lightningnetwork/lnd/lntest"
|
||||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
@@ -538,11 +540,9 @@ func parseDerivationPath(path string) ([]uint32, error) {
|
|||||||
// acceptChannel is used to accept a single channel that comes across. This
|
// acceptChannel is used to accept a single channel that comes across. This
|
||||||
// should be run in a goroutine and is used to test nodes with the zero-conf
|
// should be run in a goroutine and is used to test nodes with the zero-conf
|
||||||
// feature bit.
|
// feature bit.
|
||||||
func acceptChannel(t *harnessTest, zeroConf bool,
|
func acceptChannel(t *testing.T, zeroConf bool, stream rpc.AcceptorClient) {
|
||||||
stream lnrpc.Lightning_ChannelAcceptorClient) {
|
|
||||||
|
|
||||||
req, err := stream.Recv()
|
req, err := stream.Recv()
|
||||||
require.NoError(t.t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
resp := &lnrpc.ChannelAcceptResponse{
|
resp := &lnrpc.ChannelAcceptResponse{
|
||||||
Accept: true,
|
Accept: true,
|
||||||
@@ -550,5 +550,5 @@ func acceptChannel(t *harnessTest, zeroConf bool,
|
|||||||
ZeroConf: zeroConf,
|
ZeroConf: zeroConf,
|
||||||
}
|
}
|
||||||
err = stream.Send(resp)
|
err = stream.Send(resp)
|
||||||
require.NoError(t.t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user