Skip to content

Commit 976bb37

Browse files
committed
lntest+itest: add method AssertNumTxsInMempool and AssertTxInBlock
in harness Prepare to make `HarnessTest.Miner` a private instance to sync height.
1 parent e553895 commit 976bb37

20 files changed

+108
-93
lines changed

itest/lnd_channel_backup_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ func runChanRestoreScenarioForceClose(ht *lntest.HarnessTest, zeroConf bool) {
783783
)
784784

785785
// We now wait until both Dave's closing tx.
786-
ht.Miner.AssertNumTxsInMempool(1)
786+
ht.AssertNumTxsInMempool(1)
787787

788788
// Now that we're able to make our restored now, we'll shutdown the old
789789
// Dave node as we'll be storing it shortly below.
@@ -1272,7 +1272,7 @@ func testDataLossProtection(ht *lntest.HarnessTest) {
12721272
ht.MineBlocks(1)
12731273

12741274
// Dave should sweep his funds.
1275-
ht.Miner.AssertNumTxsInMempool(1)
1275+
ht.AssertNumTxsInMempool(1)
12761276

12771277
// Mine a block to confirm the sweep, and make sure Dave got his
12781278
// balance back.
@@ -1428,7 +1428,7 @@ func assertTimeLockSwept(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
14281428

14291429
// Mine a block to trigger the sweeps.
14301430
ht.MineBlocks(1)
1431-
ht.Miner.AssertNumTxsInMempool(expectedTxes)
1431+
ht.AssertNumTxsInMempool(expectedTxes)
14321432

14331433
// Carol should consider the channel pending force close (since she is
14341434
// waiting for her sweep to confirm).
@@ -1462,9 +1462,9 @@ func assertTimeLockSwept(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
14621462

14631463
// Mine a block to trigger the sweeps.
14641464
ht.MineEmptyBlocks(1)
1465-
daveSweep := ht.Miner.AssertNumTxsInMempool(1)[0]
1465+
daveSweep := ht.AssertNumTxsInMempool(1)[0]
14661466
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
1467-
ht.Miner.AssertTxInBlock(block, daveSweep)
1467+
ht.AssertTxInBlock(block, daveSweep)
14681468

14691469
// Now the channel should be fully closed also from Dave's POV.
14701470
ht.AssertNumPendingForceClose(dave, 0)
@@ -1510,7 +1510,7 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
15101510

15111511
// Upon reconnection, the nodes should detect that Dave is out of sync.
15121512
// Carol should force close the channel using her latest commitment.
1513-
ht.Miner.AssertNumTxsInMempool(1)
1513+
ht.AssertNumTxsInMempool(1)
15141514

15151515
// Channel should be in the state "waiting close" for Carol since she
15161516
// broadcasted the force close tx.

itest/lnd_channel_force_close_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
389389
// So we fetch the node's mempool to ensure it has been properly
390390
// broadcast.
391391
ht.MineEmptyBlocks(1)
392-
sweepingTXID := ht.Miner.AssertNumTxsInMempool(1)[0]
392+
sweepingTXID := ht.AssertNumTxsInMempool(1)[0]
393393

394394
// Fetch the sweep transaction, all input it's spending should be from
395395
// the commitment transaction which was broadcast on-chain.
@@ -547,7 +547,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
547547
// NOTE: after restart, all the htlc timeout txns will be offered to
548548
// the sweeper with `Immediate` set to true, so they won't be
549549
// aggregated.
550-
htlcTxIDs := ht.Miner.AssertNumTxsInMempool(numInvoices)
550+
htlcTxIDs := ht.AssertNumTxsInMempool(numInvoices)
551551

552552
// Retrieve each htlc timeout txn from the mempool, and ensure it is
553553
// well-formed. This entails verifying that each only spends from
@@ -733,7 +733,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
733733
}
734734

735735
// Wait for the single sweep txn to appear in the mempool.
736-
htlcSweepTxID := ht.Miner.AssertNumTxsInMempool(1)[0]
736+
htlcSweepTxID := ht.AssertNumTxsInMempool(1)[0]
737737

738738
// Fetch the htlc sweep transaction from the mempool.
739739
htlcSweepTx := ht.Miner.GetRawTransaction(htlcSweepTxID)
@@ -818,7 +818,7 @@ func channelForceClosureTest(ht *lntest.HarnessTest,
818818
// Generate the final block that sweeps all htlc funds into the user's
819819
// wallet, and make sure the sweep is in this block.
820820
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
821-
ht.Miner.AssertTxInBlock(block, htlcSweepTxID)
821+
ht.AssertTxInBlock(block, htlcSweepTxID)
822822

823823
// Now that the channel has been fully swept, it should no longer show
824824
// up within the pending channels RPC.
@@ -935,7 +935,7 @@ func testFailingChannel(ht *lntest.HarnessTest) {
935935
ht.MineEmptyBlocks(1)
936936

937937
// Carol should have broadcast her sweeping tx.
938-
ht.Miner.AssertNumTxsInMempool(1)
938+
ht.AssertNumTxsInMempool(1)
939939

940940
// Mine two blocks to confirm Carol's sweeping tx, which will by now
941941
// Alice's commit output should be offered to her sweeper.

itest/lnd_funding_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ func testChannelFundingPersistence(ht *lntest.HarnessTest) {
859859
// channel has been opened. The funding transaction should be found
860860
// within the newly mined block.
861861
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
862-
ht.Miner.AssertTxInBlock(block, fundingTxID)
862+
ht.AssertTxInBlock(block, fundingTxID)
863863

864864
// Get the height that our transaction confirmed at.
865865
_, height := ht.Miner.GetBestBlock()
@@ -1047,7 +1047,7 @@ func testBatchChanFunding(ht *lntest.HarnessTest) {
10471047

10481048
// Mine the batch transaction and check the network topology.
10491049
block := ht.MineBlocksAndAssertNumTxes(6, 1)[0]
1050-
ht.Miner.AssertTxInBlock(block, txHash)
1050+
ht.AssertTxInBlock(block, txHash)
10511051
ht.AssertTopologyChannelOpen(alice, chanPoint1)
10521052
ht.AssertTopologyChannelOpen(alice, chanPoint2)
10531053
ht.AssertTopologyChannelOpen(alice, chanPoint3)

itest/lnd_misc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func testMaxPendingChannels(ht *lntest.HarnessTest) {
416416

417417
// Ensure that the funding transaction enters a block, and is
418418
// properly advertised by Alice.
419-
ht.Miner.AssertTxInBlock(block, fundingTxID)
419+
ht.AssertTxInBlock(block, fundingTxID)
420420
ht.AssertTopologyChannelOpen(alice, fundingChanPoint)
421421

422422
// The channel should be listed in the peer information

itest/lnd_multi-hop_test.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest,
246246
ht.MineBlocks(int(numBlocks))
247247

248248
// Bob's force close transaction should now be found in the mempool.
249-
ht.Miner.AssertNumTxsInMempool(1)
249+
ht.AssertNumTxsInMempool(1)
250250
op := ht.OutPointFromChannelPoint(bobChanPoint)
251251
closeTx := ht.Miner.AssertOutpointInMempool(op)
252252

@@ -276,7 +276,7 @@ func runMultiHopHtlcLocalTimeout(ht *lntest.HarnessTest,
276276
// 1. Bob's sweeping tx anchor sweep should now be found in the mempool.
277277
// 2. Bob's HTLC timeout tx sweep should now be found in the mempool.
278278
// Carol's anchor sweep should be failed due to output being dust.
279-
ht.Miner.AssertNumTxsInMempool(2)
279+
ht.AssertNumTxsInMempool(2)
280280

281281
htlcOutpoint := wire.OutPoint{Hash: closeTx.TxHash(), Index: 2}
282282
commitOutpoint := wire.OutPoint{Hash: closeTx.TxHash(), Index: 3}
@@ -501,7 +501,7 @@ func runMultiHopReceiverChainClaim(ht *lntest.HarnessTest,
501501

502502
// At this point, Carol should broadcast her active commitment
503503
// transaction in order to go to the chain and sweep her HTLC.
504-
ht.Miner.AssertNumTxsInMempool(1)
504+
ht.AssertNumTxsInMempool(1)
505505

506506
closingTx := ht.Miner.AssertOutpointInMempool(
507507
ht.OutPointFromChannelPoint(bobChanPoint),
@@ -526,7 +526,7 @@ func runMultiHopReceiverChainClaim(ht *lntest.HarnessTest,
526526
// scenarios, as we are using a wallet utxo, which means any txns using
527527
// that wallet utxo must pay more fees. On the other hand, there's no
528528
// way to remove that anchor-CPFP tx from the mempool.
529-
ht.Miner.AssertNumTxsInMempool(1)
529+
ht.AssertNumTxsInMempool(1)
530530

531531
// After the force close transaction is mined, Carol should offer her
532532
// second level HTLC tx to the sweeper, which means we should see two
@@ -600,7 +600,7 @@ func runMultiHopReceiverChainClaim(ht *lntest.HarnessTest,
600600
ht.MineEmptyBlocks(1)
601601

602602
// We should have a new transaction in the mempool.
603-
ht.Miner.AssertNumTxsInMempool(1)
603+
ht.AssertNumTxsInMempool(1)
604604

605605
// Finally, if we mine an additional block to confirm Carol's second
606606
// level success transaction. Carol should not show a pending channel
@@ -761,7 +761,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
761761
)
762762
txid := commitSweepTx.TxHash()
763763
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
764-
ht.Miner.AssertTxInBlock(block, &txid)
764+
ht.AssertTxInBlock(block, &txid)
765765

766766
blocksMined++
767767
}
@@ -789,7 +789,7 @@ func runMultiHopLocalForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
789789
// Next, we'll mine an additional block. This should serve to confirm
790790
// the second layer timeout transaction.
791791
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
792-
ht.Miner.AssertTxInBlock(block, &timeoutTx)
792+
ht.AssertTxInBlock(block, &timeoutTx)
793793

794794
// With the second layer timeout transaction confirmed, Bob should have
795795
// canceled backwards the HTLC that carol sent.
@@ -1007,12 +1007,12 @@ func runMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
10071007

10081008
// Bob's sweeping transaction should now be found in the mempool at
10091009
// this point.
1010-
sweepTx := ht.Miner.AssertNumTxsInMempool(1)[0]
1010+
sweepTx := ht.AssertNumTxsInMempool(1)[0]
10111011

10121012
// If we mine an additional block, then this should confirm Bob's
10131013
// transaction which sweeps the direct HTLC output.
10141014
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
1015-
ht.Miner.AssertTxInBlock(block, sweepTx)
1015+
ht.AssertTxInBlock(block, sweepTx)
10161016

10171017
// Now that the sweeping transaction has been confirmed, Bob should
10181018
// cancel back that HTLC. As a result, Alice should not know of any
@@ -1047,7 +1047,7 @@ func runMultiHopRemoteForceCloseOnChainHtlcTimeout(ht *lntest.HarnessTest,
10471047
)
10481048
bobCommitSweepTxid := bobCommitSweep.TxHash()
10491049
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
1050-
ht.Miner.AssertTxInBlock(block, &bobCommitSweepTxid)
1050+
ht.AssertTxInBlock(block, &bobCommitSweepTxid)
10511051
}
10521052
ht.AssertNumPendingForceClose(bob, 0)
10531053

@@ -1191,7 +1191,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
11911191
blocksMined++
11921192

11931193
// Assert the expected num of txns are found in the mempool.
1194-
ht.Miner.AssertNumTxsInMempool(expectedTxes)
1194+
ht.AssertNumTxsInMempool(expectedTxes)
11951195

11961196
// Mine a block to clean up the mempool for the rest of the test.
11971197
ht.MineBlocksAndAssertNumTxes(1, expectedTxes)
@@ -1215,7 +1215,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
12151215
ht.MineEmptyBlocks(int(numBlocks - blocksMined))
12161216

12171217
// Carol's commitment transaction should now be in the mempool.
1218-
ht.Miner.AssertNumTxsInMempool(1)
1218+
ht.AssertNumTxsInMempool(1)
12191219

12201220
// Look up the closing transaction. It should be spending from the
12211221
// funding transaction,
@@ -1226,7 +1226,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
12261226

12271227
// Mine a block that should confirm the commit tx.
12281228
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
1229-
ht.Miner.AssertTxInBlock(block, &closingTxid)
1229+
ht.AssertTxInBlock(block, &closingTxid)
12301230

12311231
// After the force close transaction is mined, Carol should offer her
12321232
// second-level success HTLC tx and anchor to the sweeper.
@@ -1273,7 +1273,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
12731273
ht.MineEmptyBlocks(1)
12741274

12751275
// Assert transactions can be found in the mempool.
1276-
ht.Miner.AssertNumTxsInMempool(expectedTxes)
1276+
ht.AssertNumTxsInMempool(expectedTxes)
12771277

12781278
// At this point we suspend Alice to make sure she'll handle the
12791279
// on-chain settle after a restart.
@@ -1345,15 +1345,15 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
13451345
bobSecondLevelCSV--
13461346

13471347
// Carol's sweep tx should be broadcast.
1348-
carolSweep := ht.Miner.AssertNumTxsInMempool(1)[0]
1348+
carolSweep := ht.AssertNumTxsInMempool(1)[0]
13491349

13501350
// Bob should offer his second level tx to his sweeper.
13511351
ht.AssertNumPendingSweeps(bob, 1)
13521352

13531353
// Mining one additional block, Bob's second level tx is mature, and he
13541354
// can sweep the output.
13551355
block = ht.MineBlocksAndAssertNumTxes(bobSecondLevelCSV, 1)[0]
1356-
ht.Miner.AssertTxInBlock(block, carolSweep)
1356+
ht.AssertTxInBlock(block, carolSweep)
13571357

13581358
bobSweep := ht.Miner.GetNumTxsFromMempool(1)[0]
13591359
bobSweepTxid := bobSweep.TxHash()
@@ -1362,7 +1362,7 @@ func runMultiHopHtlcLocalChainClaim(ht *lntest.HarnessTest,
13621362
// Now Bob should have no pending channels anymore, as this just
13631363
// resolved it by the confirmation of the sweep transaction.
13641364
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
1365-
ht.Miner.AssertTxInBlock(block, &bobSweepTxid)
1365+
ht.AssertTxInBlock(block, &bobSweepTxid)
13661366

13671367
// With the script-enforced lease commitment type, Alice and Bob still
13681368
// haven't been able to sweep their respective commit outputs due to the
@@ -1558,7 +1558,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntest.HarnessTest,
15581558
ht.MineEmptyBlocks(int(numBlocks) - blocksMined)
15591559

15601560
// Carol's commitment transaction should now be in the mempool.
1561-
ht.Miner.AssertNumTxsInMempool(1)
1561+
ht.AssertNumTxsInMempool(1)
15621562

15631563
// The closing transaction should be spending from the funding
15641564
// transaction.
@@ -1574,7 +1574,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntest.HarnessTest,
15741574

15751575
// Mine a block, which should contain: the commitment.
15761576
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
1577-
ht.Miner.AssertTxInBlock(block, &closingTxid)
1577+
ht.AssertTxInBlock(block, &closingTxid)
15781578

15791579
// After the force close transaction is mined, Carol should offer her
15801580
// second level HTLC tx to the sweeper, along with her anchor output.
@@ -1612,7 +1612,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntest.HarnessTest,
16121612
// anchor sweeping.
16131613
ht.MineBlocksAndAssertNumTxes(1, 1)
16141614
carolSecondLevelCSV--
1615-
ht.Miner.AssertNumTxsInMempool(2)
1615+
ht.AssertNumTxsInMempool(2)
16161616

16171617
// Mine a block to confirm the expected transactions.
16181618
ht.MineBlocksAndAssertNumTxes(1, 2)
@@ -1633,7 +1633,7 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntest.HarnessTest,
16331633
// We'll now mine a block which should confirm Bob's HTLC sweep
16341634
// transaction.
16351635
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
1636-
ht.Miner.AssertTxInBlock(block, &bobHtlcSweepTxid)
1636+
ht.AssertTxInBlock(block, &bobHtlcSweepTxid)
16371637
carolSecondLevelCSV--
16381638

16391639
// Now that the sweeping transaction has been confirmed, Bob should now
@@ -1656,12 +1656,12 @@ func runMultiHopHtlcRemoteChainClaim(ht *lntest.HarnessTest,
16561656

16571657
// Mine a block to trigger the sweep of the second level tx.
16581658
ht.MineEmptyBlocks(1)
1659-
carolSweep := ht.Miner.AssertNumTxsInMempool(1)[0]
1659+
carolSweep := ht.AssertNumTxsInMempool(1)[0]
16601660

16611661
// When Carol's sweep gets confirmed, she should have no more pending
16621662
// channels.
16631663
block = ht.MineBlocksAndAssertNumTxes(1, 1)[0]
1664-
ht.Miner.AssertTxInBlock(block, carolSweep)
1664+
ht.AssertTxInBlock(block, carolSweep)
16651665
ht.AssertNumPendingForceClose(carol, 0)
16661666

16671667
// With the script-enforced lease commitment type, Alice and Bob still
@@ -1881,7 +1881,7 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
18811881

18821882
// Bob's force close transaction should now be found in the mempool. If
18831883
// there are anchors, we expect it to be offered to Bob's sweeper.
1884-
ht.Miner.AssertNumTxsInMempool(1)
1884+
ht.AssertNumTxsInMempool(1)
18851885

18861886
// Bob has two anchor sweep requests, one for remote (invalid) and the
18871887
// other for local.
@@ -1925,7 +1925,7 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
19251925
ht.MineBlocksAndAssertNumTxes(1, 1)
19261926

19271927
// The above mined block will trigger Bob to sweep his anchor output.
1928-
ht.Miner.AssertNumTxsInMempool(1)
1928+
ht.AssertNumTxsInMempool(1)
19291929

19301930
// Let Alice settle her invoices. When Bob now gets the preimages, he
19311931
// has no other option than to broadcast his second-level transactions
@@ -2162,7 +2162,7 @@ func runMultiHopHtlcAggregation(ht *lntest.HarnessTest,
21622162
// level sweep. Now Bob should have no pending channels anymore, as
21632163
// this just resolved it by the confirmation of the sweep transaction.
21642164
block := ht.MineBlocksAndAssertNumTxes(1, numExpected)[0]
2165-
ht.Miner.AssertTxInBlock(block, &bobSweep)
2165+
ht.AssertTxInBlock(block, &bobSweep)
21662166

21672167
// For leased channels, we need to mine one more block to confirm Bob's
21682168
// commit output sweep.
@@ -2441,7 +2441,7 @@ func runExtraPreimageFromRemoteCommit(ht *lntest.HarnessTest,
24412441
// Mine a block to trigger the sweep, and clean up the anchor sweeping
24422442
// tx.
24432443
ht.MineBlocksAndAssertNumTxes(1, 1)
2444-
ht.Miner.AssertNumTxsInMempool(1)
2444+
ht.AssertNumTxsInMempool(1)
24452445

24462446
// Restart Bob. Once he finishes syncing the channel state, he should
24472447
// notice the force close from Carol.
@@ -2457,7 +2457,7 @@ func runExtraPreimageFromRemoteCommit(ht *lntest.HarnessTest,
24572457

24582458
// We should now have Carol's htlc success tx in the mempool.
24592459
numTxesMempool := 1
2460-
ht.Miner.AssertNumTxsInMempool(numTxesMempool)
2460+
ht.AssertNumTxsInMempool(numTxesMempool)
24612461

24622462
// For neutrino backend, the timeout resolver needs to extract the
24632463
// preimage from the blocks.
@@ -2667,15 +2667,15 @@ func runExtraPreimageFromLocalCommit(ht *lntest.HarnessTest,
26672667
switch c {
26682668
case lnrpc.CommitmentType_LEGACY:
26692669
htlcOutpoint.Index = 0
2670-
ht.Miner.AssertNumTxsInMempool(2)
2670+
ht.AssertNumTxsInMempool(2)
26712671

26722672
case lnrpc.CommitmentType_ANCHORS, lnrpc.CommitmentType_SIMPLE_TAPROOT:
26732673
htlcOutpoint.Index = 2
2674-
ht.Miner.AssertNumTxsInMempool(2)
2674+
ht.AssertNumTxsInMempool(2)
26752675

26762676
case lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE:
26772677
htlcOutpoint.Index = 2
2678-
ht.Miner.AssertNumTxsInMempool(1)
2678+
ht.AssertNumTxsInMempool(1)
26792679
}
26802680

26812681
// Get the current height to compute number of blocks to mine to

itest/lnd_nonstd_sweep_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func testNonStdSweepInner(ht *lntest.HarnessTest, address string) {
9696
carol.RPC.SendCoins(sendReq)
9797

9898
// Fetch the txid so we can grab the raw transaction.
99-
txid := ht.Miner.AssertNumTxsInMempool(1)[0]
99+
txid := ht.AssertNumTxsInMempool(1)[0]
100100
tx := ht.Miner.GetRawTransaction(txid)
101101

102102
msgTx := tx.MsgTx()

0 commit comments

Comments
 (0)