From 8240a87c2be6c4a3e86ef22eab2dccb2d06771f5 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Mon, 20 May 2024 23:06:20 +0800 Subject: [PATCH] itest: fix misuse of `MineBlocks` and replace it with `MineBlocksAndAssertNumTxes` --- itest/lnd_channel_backup_test.go | 2 +- itest/lnd_estimate_route_fee_test.go | 2 ++ itest/lnd_mpp_test.go | 5 +++-- itest/lnd_multi-hop_test.go | 12 +++++++++--- itest/lnd_onchain_test.go | 2 +- itest/lnd_recovery_test.go | 3 +-- itest/lnd_res_handoff_test.go | 2 +- lntest/harness_miner.go | 2 +- 8 files changed, 19 insertions(+), 11 deletions(-) diff --git a/itest/lnd_channel_backup_test.go b/itest/lnd_channel_backup_test.go index 8da67a71a..36b38f8b5 100644 --- a/itest/lnd_channel_backup_test.go +++ b/itest/lnd_channel_backup_test.go @@ -94,7 +94,7 @@ func newChanRestoreScenario(ht *lntest.HarnessTest, ct lnrpc.CommitmentType, ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, dave) // Mine a block to confirm the funds. - ht.MineBlocks(1) + ht.MineBlocksAndAssertNumTxes(1, 2) // For the anchor output case we need two UTXOs for Carol so she can // sweep both the local and remote anchor. diff --git a/itest/lnd_estimate_route_fee_test.go b/itest/lnd_estimate_route_fee_test.go index 352dfe5ce..8ed0be272 100644 --- a/itest/lnd_estimate_route_fee_test.go +++ b/itest/lnd_estimate_route_fee_test.go @@ -359,6 +359,8 @@ func testEstimateRouteFee(ht *lntest.HarnessTest) { mts.ht.CloseChannelAssertPending(mts.bob, channelPointBobPaula, false) mts.ht.CloseChannelAssertPending(mts.eve, channelPointEvePaula, false) + ht.MineBlocksAndAssertNumTxes(1, 2) + mts.closeChannels() } diff --git a/itest/lnd_mpp_test.go b/itest/lnd_mpp_test.go index bf2679846..b5cd147dd 100644 --- a/itest/lnd_mpp_test.go +++ b/itest/lnd_mpp_test.go @@ -208,7 +208,8 @@ func newMppTestScenario(ht *lntest.HarnessTest) *mppTestScenario { ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, carol) ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, dave) ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, eve) - ht.MineBlocks(1) + + ht.MineBlocksAndAssertNumTxes(1, 3) } mts := &mppTestScenario{ @@ -318,7 +319,7 @@ func (m *mppTestScenario) closeChannels() { m.ht.CloseChannelAssertPending(m.eve, m.channelPoints[5], false) // Now mine a block to include all the closing transactions. - m.ht.MineBlocks(1) + m.ht.MineBlocksAndAssertNumTxes(1, 6) // Assert that the channels are closed. for _, hn := range m.nodes { diff --git a/itest/lnd_multi-hop_test.go b/itest/lnd_multi-hop_test.go index 47df4c38f..d09593619 100644 --- a/itest/lnd_multi-hop_test.go +++ b/itest/lnd_multi-hop_test.go @@ -2223,7 +2223,7 @@ func createThreeHopNetwork(ht *lntest.HarnessTest, ht.FundCoinsUnconfirmed(btcutil.SatoshiPerBitcoin, carol) // Mine 1 block to get the above coins confirmed. - ht.MineBlocks(1) + ht.MineBlocksAndAssertNumTxes(1, 3) } // We'll start the test by creating a channel between Alice and Bob, @@ -2703,8 +2703,14 @@ func runExtraPreimageFromLocalCommit(ht *lntest.HarnessTest, // Make sure the direct spend tx is still in the mempool. ht.AssertOutpointInMempool(htlcOutpoint) - // Mine a block to confirm Carol's direct spend tx. - ht.MineBlocks(1) + // Mine a block to confirm two txns, + // - Carol's direct spend tx. + // - Bob's to_local output sweep tx. + if c != lnrpc.CommitmentType_SCRIPT_ENFORCED_LEASE { + ht.MineBlocksAndAssertNumTxes(1, 2) + } else { + ht.MineBlocksAndAssertNumTxes(1, 1) + } } // Finally, check that the Alice's payment is marked as succeeded as diff --git a/itest/lnd_onchain_test.go b/itest/lnd_onchain_test.go index 9ddf194b3..a34b9a2e4 100644 --- a/itest/lnd_onchain_test.go +++ b/itest/lnd_onchain_test.go @@ -601,7 +601,7 @@ func testAnchorThirdPartySpend(ht *lntest.HarnessTest) { Index: 1, } ht.AssertOutpointInMempool(commitSweepOp) - ht.MineBlocks(1) + ht.MineBlocksAndAssertNumTxes(1, 1) ht.AssertNumWaitingClose(alice, 0) } diff --git a/itest/lnd_recovery_test.go b/itest/lnd_recovery_test.go index ccc5f90af..ea93f373e 100644 --- a/itest/lnd_recovery_test.go +++ b/itest/lnd_recovery_test.go @@ -428,8 +428,7 @@ func testRescanAddressDetection(ht *lntest.HarnessTest) { }) // Wait until the spending tx is found and mine a block to confirm it. - ht.AssertNumTxsInMempool(1) - ht.MineBlocks(1) + ht.MineBlocksAndAssertNumTxes(1, 1) // The wallet should still just see a single UTXO of the change output // created earlier. diff --git a/itest/lnd_res_handoff_test.go b/itest/lnd_res_handoff_test.go index 8fc2f1043..941cc5283 100644 --- a/itest/lnd_res_handoff_test.go +++ b/itest/lnd_res_handoff_test.go @@ -66,7 +66,7 @@ func testResHandoff(ht *lntest.HarnessTest) { ht.AssertNumWaitingClose(bob, 1) // Mine a block to confirm the closing tx. - ht.MineBlocks(1) + ht.MineBlocksAndAssertNumTxes(1, 1) // We sleep here so we can be sure that the hand-off has occurred from // Bob's contractcourt to Bob's htlcswitch. This sleep could be removed diff --git a/lntest/harness_miner.go b/lntest/harness_miner.go index 964965f32..65994d254 100644 --- a/lntest/harness_miner.go +++ b/lntest/harness_miner.go @@ -104,7 +104,7 @@ func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32, txids := h.AssertNumTxsInMempool(numTxs) // Mine blocks. - blocks := h.miner.MineBlocksSlow(num) + blocks := h.miner.MineBlocks(num) // Assert that all the transactions were included in the first block. for _, txid := range txids {