itest+lntest: fix itest re the new block driven behavior

This commit is contained in:
yyforyongyu
2024-03-14 20:39:22 +08:00
parent 558d9bd3ce
commit 521b1fc34a
10 changed files with 445 additions and 108 deletions

View File

@@ -1266,6 +1266,12 @@ func testDataLossProtection(ht *lntest.HarnessTest) {
// information Dave needs to sweep his funds.
require.NoError(ht, restartDave(), "unable to restart Eve")
// Dave should have a pending sweep.
ht.AssertNumPendingSweeps(dave, 1)
// Mine a block to trigger the sweep.
ht.MineBlocks(1)
// Dave should sweep his funds.
ht.Miner.AssertNumTxsInMempool(1)
@@ -1417,6 +1423,11 @@ func assertTimeLockSwept(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
// Carol should sweep her funds immediately, as they are not
// timelocked.
ht.AssertNumPendingSweeps(carol, 2)
ht.AssertNumPendingSweeps(dave, 1)
// Mine a block to trigger the sweeps.
ht.MineBlocks(1)
ht.Miner.AssertNumTxsInMempool(expectedTxes)
// Carol should consider the channel pending force close (since she is
@@ -1444,9 +1455,13 @@ func assertTimeLockSwept(ht *lntest.HarnessTest, carol, dave *node.HarnessNode,
// 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.
ht.MineBlocks(defaultCSV - 1 - 1)
// we already mined one block after the commitment was published, and
// one block to trigger Carol's sweeps, so take that into account.
ht.MineBlocks(1)
ht.AssertNumPendingSweeps(dave, 1)
// Mine a block to trigger the sweeps.
ht.MineBlocks(1)
daveSweep := ht.Miner.AssertNumTxsInMempool(1)[0]
block := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
ht.Miner.AssertTxInBlock(block, daveSweep)
@@ -1526,6 +1541,12 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
// Dave should sweep his anchor only, since he still has the
// lease CLTV constraint on his commitment output. We'd also
// see Carol's anchor sweep here.
ht.AssertNumPendingSweeps(dave, 1)
ht.AssertNumPendingSweeps(carol, 1)
// Mine a block to trigger the sweeps.
ht.MineBlocks(1)
blocksMined++
ht.Miner.AssertNumTxsInMempool(2)
// Mine anchor sweep txes for Carol and Dave.
@@ -1539,6 +1560,10 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
// defaultCSV-1 and we already mined one block after the
// commitmment was published, so take that into account.
ht.MineBlocks(defaultCSV - blocksMined)
ht.AssertNumPendingSweeps(carol, 1)
// Mine a block to trigger the sweep.
ht.MineBlocks(1)
ht.MineBlocksAndAssertNumTxes(1, 1)
// Now the channel should be fully closed also from Carol's POV.
@@ -1552,6 +1577,10 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
require.Positive(ht, blocksTilMaturity)
ht.MineBlocks(uint32(blocksTilMaturity))
ht.AssertNumPendingSweeps(dave, 1)
// Mine a block to trigger the sweep.
ht.MineBlocks(1)
ht.MineBlocksAndAssertNumTxes(1, 1)
// Now Dave should consider the channel fully closed.
@@ -1559,7 +1588,22 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
} else {
// Dave should sweep his funds immediately, as they are not
// timelocked. We also expect Carol and Dave sweep their
// anchors.
// anchors if it's an anchor channel.
if lntest.CommitTypeHasAnchors(commitType) {
ht.AssertNumPendingSweeps(carol, 1)
ht.AssertNumPendingSweeps(dave, 2)
} else {
ht.AssertNumPendingSweeps(dave, 1)
}
// Mine one block to trigger the sweeper to sweep.
ht.MineBlocks(1)
blocksMined++
// For anchor channels, we expect three txns,
// 1. the anchor sweeping tx from Dave.
// 2. the anchor sweeping tx from Carol.
// 3. the commitment sweep from Dave.
if lntest.CommitTypeHasAnchors(commitType) {
ht.MineBlocksAndAssertNumTxes(1, 3)
} else {
@@ -1578,6 +1622,12 @@ func assertDLPExecuted(ht *lntest.HarnessTest,
// defaultCSV-1 and we already have blocks mined after the
// commitmment was published, so take that into account.
ht.MineBlocks(defaultCSV - blocksMined)
// Mine one block to trigger the sweeper to sweep.
ht.MineBlocks(1)
ht.AssertNumPendingSweeps(carol, 1)
// Assert the sweeping tx is mined.
ht.MineBlocksAndAssertNumTxes(1, 1)
// Now the channel should be fully closed also from Carol's