Skip to content

Commit fa8a8bf

Browse files
committed
itest: update itests to use new *WithSweep helper assertions
This change is due to the fact that blockbeat handling is now more async in the cnct.
1 parent d179903 commit fa8a8bf

8 files changed

+36
-31
lines changed

itest/lnd_channel_backup_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
16301630
// Expect one tx - the commitment sweep from Dave. For anchor
16311631
// channels, we expect the two anchor sweeping txns to be
16321632
// failed due they are uneconomical.
1633-
ht.MineBlocksAndAssertNumTxes(1, 1)
1633+
ht.MineBlocksAndAssertNumTxesWithSweep(1, 1, dave)
16341634
blocksMined++
16351635

16361636
// Now Dave should consider the channel fully closed.

itest/lnd_channel_force_close_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func runChannelForceClosureTest(ht *lntest.HarnessTest,
184184
)
185185

186186
// We expect to see Alice's force close tx in the mempool.
187-
ht.AssertNumTxsInMempool(1)
187+
ht.AssertNumTxsInMempoolWithSweepTrigger(1, alice)
188188

189189
// Mine a block which should confirm the commitment transaction
190190
// broadcast as a result of the force closure. Once mined, we also
@@ -233,7 +233,7 @@ func runChannelForceClosureTest(ht *lntest.HarnessTest,
233233
// Carol's sweep tx should be in the mempool already, as her output is
234234
// not timelocked. This sweep tx should spend her to_local output as
235235
// the anchor output is not economical to spend.
236-
carolTx := ht.GetNumTxsFromMempool(1)[0]
236+
carolTx := ht.GetNumTxsFromMempoolWithSweep(1, carol)[0]
237237

238238
// Carol's sweeping tx should have 1-input-1-output shape.
239239
require.Len(ht, carolTx.TxIn, 1)
@@ -792,7 +792,7 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
792792
ht.RestartNode(alice)
793793

794794
// We expect to see Alice's force close tx in the mempool.
795-
ht.AssertNumTxsInMempool(1)
795+
ht.AssertNumTxsInMempoolWithSweepTrigger(1, alice)
796796

797797
// Mine a block which should confirm the commitment transaction
798798
// broadcast as a result of the force closure. Once mined, we also
@@ -847,7 +847,7 @@ func runChannelForceClosureTestRestart(ht *lntest.HarnessTest,
847847
// Carol's sweep tx should be in the mempool already, as her output is
848848
// not timelocked. This sweep tx should spend her to_local output as
849849
// the anchor output is not economical to spend.
850-
carolTx := ht.GetNumTxsFromMempool(1)[0]
850+
carolTx := ht.GetNumTxsFromMempoolWithSweep(1, carol)[0]
851851

852852
// Carol's sweeping tx should have 1-input-1-output shape.
853853
require.Len(ht, carolTx.TxIn, 1)

itest/lnd_funding_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,11 +1272,10 @@ func testChannelFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
12721272
// Make sure Carol sees her to_remote output from the force close tx.
12731273
ht.AssertNumPendingSweeps(carol, 1)
12741274

1275-
// Wait for Carol's sweep transaction to appear in the mempool. Due to
1276-
// async confirmation notifications, there's a race between when the
1277-
// sweep is registered and when the sweeper processes the next block.
1278-
// The sweeper uses immediate=false, so it broadcasts on the next block
1279-
// after registration. Mine an empty block to trigger the broadcast.
1275+
// Mine an empty block to trigger the sweep. Due to async confirmation
1276+
// notifications, the sweep registration might happen after the force
1277+
// close block is processed by the sweeper. Mining another block gives
1278+
// time for registration and triggers the broadcast.
12801279
ht.MineEmptyBlocks(1)
12811280

12821281
// Now the sweep should be in the mempool.
@@ -1338,9 +1337,10 @@ func testChannelFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
13381337
// Make sure Carol sees her to_remote output from the force close tx.
13391338
ht.AssertNumPendingSweeps(carol, 1)
13401339

1341-
// Mine an empty block to trigger the sweep broadcast (same fix as
1342-
// above).
1340+
// Mine an empty block to trigger the sweep (same as above).
13431341
ht.MineEmptyBlocks(1)
1342+
1343+
// Sweep should be in mempool.
13441344
ht.AssertNumTxsInMempool(1)
13451345

13461346
// Wait for the to_remote sweep tx to show up in carol's wallet.

itest/lnd_htlc_timeout_resolver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func testHtlcTimeoutResolverExtractPreimageLocal(ht *lntest.HarnessTest) {
348348
// Check the current mempool state and we should see,
349349
// - Carol's direct spend tx, which contains the preimage.
350350
// - Carol's anchor sweep tx cannot be broadcast as it's uneconomical.
351-
ht.AssertNumTxsInMempool(1)
351+
ht.AssertNumTxsInMempoolWithSweepTrigger(1, carol)
352352

353353
// We'll now mine enough blocks to trigger Bob's htlc timeout resolver
354354
// to act. Once his timeout resolver starts, it will extract the

itest/lnd_multi-hop_force_close_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ func runLocalClaimOutgoingHTLC(ht *lntest.HarnessTest,
428428
// We expect to see tow txns in the mempool,
429429
// 1. Bob's force close tx.
430430
// 2. Bob's anchor sweep tx.
431-
ht.AssertNumTxsInMempool(2)
431+
ht.AssertNumTxsInMempoolWithSweepTrigger(2, bob)
432432

433433
// Mine a block to confirm the closing tx and the anchor sweeping tx.
434434
ht.MineBlocksAndAssertNumTxes(1, 2)
@@ -447,7 +447,7 @@ func runLocalClaimOutgoingHTLC(ht *lntest.HarnessTest,
447447
// Bob's sweeper should sweep his outgoing HTLC immediately since it's
448448
// expired. His to_local output cannot be swept due to the CSV lock.
449449
// Carol's anchor sweep should be failed due to output being dust.
450-
ht.AssertNumTxsInMempool(1)
450+
ht.AssertNumTxsInMempoolWithSweepTrigger(1, bob)
451451

452452
// Mine a block to confirm Bob's outgoing HTLC sweeping tx.
453453
ht.MineBlocksAndAssertNumTxes(1, 1)
@@ -788,7 +788,7 @@ func runMultiHopReceiverPreimageClaim(ht *lntest.HarnessTest,
788788
// We expect to see tow txns in the mempool,
789789
// 1. Carol's force close tx.
790790
// 2. Carol's anchor sweep tx.
791-
ht.AssertNumTxsInMempool(2)
791+
ht.AssertNumTxsInMempoolWithSweepTrigger(2, carol)
792792

793793
// Mine a block to confirm the closing tx and the anchor sweeping tx.
794794
ht.MineBlocksAndAssertNumTxes(1, 2)
@@ -1133,7 +1133,7 @@ func runLocalForceCloseBeforeHtlcTimeout(ht *lntest.HarnessTest,
11331133
ht.MineBlocks(int(defaultCSV - 1))
11341134

11351135
// Mine a block to confirm Bob's to_local sweep.
1136-
ht.MineBlocksAndAssertNumTxes(1, 1)
1136+
ht.MineBlocksAndAssertNumTxesWithSweep(1, 1, bob)
11371137
}
11381138

11391139
// We'll now mine enough blocks for the HTLC to expire. After this, Bob
@@ -1457,7 +1457,7 @@ func runRemoteForceCloseBeforeHtlcTimeout(ht *lntest.HarnessTest,
14571457
// won't be swept due it being uneconomical. For Carol, since
14581458
// her anchor is not used for CPFP, it'd be also uneconomical
14591459
// to sweep so it will fail.
1460-
ht.MineBlocksAndAssertNumTxes(1, 1)
1460+
ht.MineBlocksAndAssertNumTxesWithSweep(1, 1, bob)
14611461
}
14621462

14631463
// Next, we'll mine enough blocks for the HTLC to expire. At this
@@ -1711,7 +1711,7 @@ func runLocalClaimIncomingHTLC(ht *lntest.HarnessTest,
17111711
// commit tx). Her anchor output won't be swept as it's uneconomical.
17121712
// For Bob, since his anchor is not used for CPFP, it'd be uneconomical
17131713
// to sweep so it will fail.
1714-
ht.AssertNumTxsInMempool(1)
1714+
ht.AssertNumTxsInMempoolWithSweepTrigger(1, alice)
17151715

17161716
// Mine a block to confirm Alice's sweeping tx.
17171717
ht.MineBlocksAndAssertNumTxes(1, 1)
@@ -1771,7 +1771,7 @@ func runLocalClaimIncomingHTLC(ht *lntest.HarnessTest,
17711771
// commitment anchor output, we'd expect to see two txns,
17721772
// - Carol's second level HTLC tx.
17731773
// - Bob's commitment output sweeping tx.
1774-
ht.AssertNumTxsInMempool(2)
1774+
ht.AssertNumTxsInMempoolWithSweepTrigger(2, bob)
17751775

17761776
// At this point we suspend Alice to make sure she'll handle the
17771777
// on-chain settle after a restart.
@@ -2045,7 +2045,7 @@ func runLocalClaimIncomingHTLCLeased(ht *lntest.HarnessTest,
20452045
//
20462046
// Carol will broadcast her second-level HTLC sweeping txns. Bob canoot
20472047
// sweep his commitment anchor output yet due to it being CLTV locked.
2048-
ht.AssertNumTxsInMempool(1)
2048+
ht.AssertNumTxsInMempoolWithSweepTrigger(1, carol)
20492049

20502050
// At this point we suspend Alice to make sure she'll handle the
20512051
// on-chain settle after a restart.
@@ -2401,7 +2401,7 @@ func runLocalPreimageClaim(ht *lntest.HarnessTest,
24012401
// We mine one block to confirm,
24022402
// - Carol's sweeping tx of the incoming HTLC.
24032403
// - Bob's sweeping tx of his commit output.
2404-
ht.MineBlocksAndAssertNumTxes(1, 2)
2404+
ht.MineBlocksAndAssertNumTxesWithSweep(1, 2, carol)
24052405

24062406
// When Bob notices Carol's second level tx in the block, he will
24072407
// extract the preimage and offer the HTLC to his sweeper. So he has,
@@ -2641,7 +2641,7 @@ func runLocalPreimageClaimLeased(ht *lntest.HarnessTest,
26412641

26422642
// We mine one block to confirm,
26432643
// - Carol's sweeping tx of the incoming HTLC.
2644-
ht.MineBlocksAndAssertNumTxes(1, 1)
2644+
ht.MineBlocksAndAssertNumTxesWithSweep(1, 1, carol)
26452645

26462646
// When Bob notices Carol's second level tx in the block, he will
26472647
// extract the preimage and offer the HTLC to his sweeper. So he has,
@@ -3030,7 +3030,7 @@ func runHtlcAggregation(ht *lntest.HarnessTest,
30303030

30313031
// Bob's force close tx and anchor sweeping tx should now be found in
30323032
// the mempool.
3033-
ht.AssertNumTxsInMempool(2)
3033+
ht.AssertNumTxsInMempoolWithSweepTrigger(2, bob)
30343034

30353035
// Mine a block to confirm Bob's force close tx and anchor sweeping tx.
30363036
ht.MineBlocksAndAssertNumTxes(1, 2)
@@ -3062,7 +3062,7 @@ func runHtlcAggregation(ht *lntest.HarnessTest,
30623062
// 2. Bob's sweeping tx for all success HTLCs.
30633063
// 3. Carol's sweeping tx for her commit output.
30643064
// Mine a block to confirm them.
3065-
ht.MineBlocksAndAssertNumTxes(1, 3)
3065+
ht.MineBlocksAndAssertNumTxesWithSweep(1, 3, carol)
30663066

30673067
// For this channel, we also check the number of HTLCs and the stage
30683068
// are correct.

itest/lnd_psbt_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/lightningnetwork/lnd/input"
2020
"github.com/lightningnetwork/lnd/keychain"
2121
"github.com/lightningnetwork/lnd/lnrpc"
22+
"github.com/lightningnetwork/lnd/lnrpc/devrpc"
2223
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
2324
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
2425
"github.com/lightningnetwork/lnd/lntest"
@@ -1677,7 +1678,9 @@ func testPsbtChanFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
16771678
// Make sure Carol sees her to_remote output from the force close tx.
16781679
ht.AssertNumPendingSweeps(carol, 1)
16791680

1680-
// We wait for the to_remote sweep tx.
1681+
// We wait for the to_remote sweep tx. Trigger sweep to handle async
1682+
// blockbeat notification races.
1683+
carol.RPC.TriggerSweeper(&devrpc.TriggerSweeperRequest{})
16811684
ht.AssertNumUTXOsUnconfirmed(carol, 1)
16821685

16831686
// We need the maximum funding amount to ensure we are opening the next
@@ -1799,7 +1802,9 @@ func testPsbtChanFundingWithUnstableUtxos(ht *lntest.HarnessTest) {
17991802
// Make sure Carol sees her to_remote output from the force close tx.
18001803
ht.AssertNumPendingSweeps(carol, 1)
18011804

1802-
// We wait for the to_remote sweep tx of channelPoint2.
1805+
// We wait for the to_remote sweep tx of channelPoint2. Trigger sweep
1806+
// to handle async blockbeat notification races.
1807+
carol.RPC.TriggerSweeper(&devrpc.TriggerSweeperRequest{})
18031808
utxos := ht.AssertNumUTXOsUnconfirmed(carol, 1)
18041809

18051810
// We need the maximum funding amount to ensure we are opening the next

itest/lnd_sweep_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
916916
ht.AssertNumPendingSweeps(bob, 2)
917917

918918
// Bob should have one sweeping tx in the mempool.
919-
outgoingSweep := ht.GetNumTxsFromMempool(1)[0]
919+
outgoingSweep := ht.GetNumTxsFromMempoolWithSweep(1, bob)[0]
920920

921921
// Check the shape of the sweeping tx - we expect it to be
922922
// 2-input-2-output as a wallet utxo is used and a required output is
@@ -1057,7 +1057,7 @@ func testSweepHTLCs(ht *lntest.HarnessTest) {
10571057
// 1. the outgoing HTLC sweeping tx.
10581058
// 2. the incoming HTLC sweeping tx.
10591059
// 3. the anchor sweeping tx.
1060-
txns = ht.GetNumTxsFromMempool(3)
1060+
txns = ht.GetNumTxsFromMempoolWithSweep(3, bob)
10611061

10621062
abCloseTxid := closeTx.TxHash()
10631063

@@ -1389,7 +1389,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
13891389
// requests will be sent to the sweeper. Finally, when the sweeper
13901390
// receives this blockbeat, it will create the sweeping tx and publish
13911391
// it.
1392-
ht.AssertNumTxsInMempool(1)
1392+
ht.AssertNumTxsInMempoolWithSweepTrigger(1, bob)
13931393

13941394
// Mine one more empty block should trigger Bob's sweeping. Since we
13951395
// use a CSV of 2, this means Alice's to_local output is now mature.

itest/lnd_wipe_fwdpkgs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,5 @@ func testWipeForwardingPackages(ht *lntest.HarnessTest) {
9797
ht.AssertNumPendingSweeps(alice, 1)
9898

9999
// Mine 1 block to get Alice's sweeping tx confirmed.
100-
ht.MineBlocksAndAssertNumTxes(1, 1)
100+
ht.MineBlocksAndAssertNumTxesWithSweep(1, 1, alice)
101101
}

0 commit comments

Comments
 (0)