From 23c81949cc261335b4ee85a2aba183d4386cccf0 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 4 Mar 2020 13:21:29 +0100 Subject: [PATCH] itest: enable anchor type for force close test Co-authored-by: Johan T. Halseth --- lntest/itest/lnd_test.go | 51 +++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index 790eff5f5..c36e8a139 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -3081,6 +3081,7 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) { // outputs can be swept. commitTypes := []commitType{ commitTypeLegacy, + commitTypeAnchors, } for _, channelType := range commitTypes { @@ -3120,7 +3121,19 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) { err) } - channelForceClosureTest(net, ht, alice, carol) + // Also give Carol some coins to allow her to sweep her + // anchor. + err = net.SendCoins( + ctxt, btcutil.SatoshiPerBitcoin, carol, + ) + if err != nil { + t.Fatalf("unable to send coins to Alice: %v", + err) + } + + channelForceClosureTest( + net, ht, alice, carol, channelType, + ) }) if !success { return @@ -3129,7 +3142,7 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) { } func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest, - alice, carol *lntest.HarnessNode) { + alice, carol *lntest.HarnessNode, channelType commitType) { ctxb := context.Background() @@ -3305,8 +3318,16 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest, } // Mine a block which should confirm the commitment transaction - // broadcast as a result of the force closure. - _, err = waitForTxInMempool(net.Miner.Node, minerMempoolTimeout) + // broadcast as a result of the force closure. If there are anchors, we + // also expect the anchor sweep tx to be in the mempool. + expectedTxes := 1 + if channelType == commitTypeAnchors { + expectedTxes = 2 + } + + _, err = waitForNTxsInMempool( + net.Miner.Node, expectedTxes, minerMempoolTimeout, + ) if err != nil { t.Fatalf("failed to find commitment in miner mempool: %v", err) } @@ -3347,12 +3368,17 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest, } // None of our outputs have been swept, so they should all be in - // limbo. + // limbo. For anchors, we expect the anchor amount to be + // recovered. if forceClose.LimboBalance == 0 { return errors.New("all funds should still be in " + "limbo") } - if forceClose.RecoveredBalance != 0 { + expectedRecoveredBalance := int64(0) + if channelType == commitTypeAnchors { + expectedRecoveredBalance = anchorSize + } + if forceClose.RecoveredBalance != expectedRecoveredBalance { return errors.New("no funds should yet be shown " + "as recovered") } @@ -3372,8 +3398,11 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest, } // Carol's sweep tx should be in the mempool already, as her output is - // not timelocked. - _, err = waitForTxInMempool(net.Miner.Node, minerMempoolTimeout) + // not timelocked. If there are anchors, we also expect Carol's anchor + // sweep now. + _, err = waitForNTxsInMempool( + net.Miner.Node, expectedTxes, minerMempoolTimeout, + ) if err != nil { t.Fatalf("failed to find Carol's sweep in miner mempool: %v", err) @@ -3435,7 +3464,11 @@ func channelForceClosureTest(net *lntest.NetworkHarness, t *harnessTest, return errors.New("all funds should still be in " + "limbo") } - if forceClose.RecoveredBalance != 0 { + expectedRecoveredBalance := int64(0) + if channelType == commitTypeAnchors { + expectedRecoveredBalance = anchorSize + } + if forceClose.RecoveredBalance != expectedRecoveredBalance { return errors.New("no funds should yet be shown " + "as recovered") }