lntest/test: add check for sweeps in ListSweeps for force close test
This commit is contained in:
parent
f3212057dd
commit
18b0049e5e
@ -38,6 +38,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
|
||||
"github.com/lightningnetwork/lnd/lntest"
|
||||
@ -3586,6 +3587,13 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
||||
}
|
||||
}
|
||||
|
||||
// Check that we can find the commitment sweep in our set of known
|
||||
// sweeps.
|
||||
err = findSweep(ctxb, alice, sweepingTXID)
|
||||
if err != nil {
|
||||
t.Fatalf("csv sweep not found: %v", err)
|
||||
}
|
||||
|
||||
// Restart Alice to ensure that she resumes watching the finalized
|
||||
// commitment sweep txid.
|
||||
if err := net.RestartNode(alice, nil); err != nil {
|
||||
@ -3753,7 +3761,10 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
||||
|
||||
// Retrieve each htlc timeout txn from the mempool, and ensure it is
|
||||
// well-formed. This entails verifying that each only spends from
|
||||
// output, and that that output is from the commitment txn.
|
||||
// output, and that that output is from the commitment txn. We do not
|
||||
// the sweeper check for these timeout transactions because they are
|
||||
// not swept by the sweeper; the nursery broadcasts the pre-signed
|
||||
// transaction.
|
||||
for _, htlcTxID := range htlcTxIDs {
|
||||
// Fetch the sweep transaction, all input it's spending should
|
||||
// be from the commitment transaction which was broadcast
|
||||
@ -3904,6 +3915,12 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
||||
}
|
||||
}
|
||||
|
||||
// Check that we can find the htlc sweep in our set of sweeps.
|
||||
err = findSweep(ctxb, alice, htlcSweepTx.Hash())
|
||||
if err != nil {
|
||||
t.Fatalf("htlc sweep not found: %v", err)
|
||||
}
|
||||
|
||||
// The following restart checks to ensure that the nursery store is
|
||||
// storing the txid of the previously broadcast htlc sweep txn, and that
|
||||
// it begins watching that txid after restarting.
|
||||
@ -4010,6 +4027,35 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest,
|
||||
}
|
||||
}
|
||||
|
||||
// findSweep looks up a sweep in a nodes list of broadcast sweeps.
|
||||
func findSweep(ctx context.Context, node *lntest.HarnessNode,
|
||||
sweep *chainhash.Hash) error {
|
||||
|
||||
// List all sweeps that alice's node had broadcast.
|
||||
ctx, _ = context.WithTimeout(ctx, defaultTimeout)
|
||||
sweepResp, err := node.WalletKitClient.ListSweeps(
|
||||
ctx, &walletrpc.ListSweepsRequest{
|
||||
Verbose: false,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("list sweeps error: %v", err)
|
||||
}
|
||||
|
||||
sweepTxIDs, ok := sweepResp.Sweeps.(*walletrpc.ListSweepsResponse_TransactionIds)
|
||||
if !ok {
|
||||
return errors.New("expected sweep txids in response")
|
||||
}
|
||||
|
||||
// Check that the sweep tx we have just produced is present.
|
||||
for _, tx := range sweepTxIDs.TransactionIds.TransactionIds {
|
||||
if tx == sweep.String() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("sweep: %v not found", sweep.String())
|
||||
}
|
||||
|
||||
// assertAmountSent generates a closure which queries listchannels for sndr and
|
||||
// rcvr, and asserts that sndr sent amt satoshis, and that rcvr received amt
|
||||
// satoshis.
|
||||
|
Loading…
Reference in New Issue
Block a user