@@ -608,6 +608,69 @@ type LN() =
608608 return ()
609609 }
610610
611+ [<Test>]
612+ member __. ``can force - close channel with lnd`` () = Async.RunSynchronously <| async {
613+ let! channelId , clientWallet , bitcoind , electrumServer , lnd , _fundingAmount =
614+ try
615+ OpenChannelWithFundee None
616+ with
617+ | ex ->
618+ Assert.Fail (
619+ sprintf
620+ " Inconclusive: channel-closing inconclusive because Channel open failed, fix this first: %s "
621+ ( ex.ToString())
622+ )
623+ failwith " unreachable"
624+
625+ let! _forceCloseTxId = ( Lightning.Node.Client clientWallet.NodeClient). ForceCloseChannel channelId
626+
627+ let locallyForceClosedData =
628+ match ( clientWallet.ChannelStore.ChannelInfo channelId). Status with
629+ | ChannelStatus.LocallyForceClosed locallyForceClosedData ->
630+ locallyForceClosedData
631+ | status -> failwith ( SPrintF1 " unexpected channel status. Expected LocallyForceClosed, got %A " status)
632+
633+ // wait for force-close transaction to appear in mempool
634+ while bitcoind.GetTxIdsInMempool() .Length = 0 do
635+ do ! Async.Sleep 500
636+
637+ Infrastructure.LogDebug ( SPrintF1 " the time lock is %i blocks" locallyForceClosedData.ToSelfDelay)
638+
639+ let! balanceBeforeFundsReclaimed = clientWallet.GetBalance()
640+
641+ // Mine the force-close tx into a block
642+ bitcoind.GenerateBlocksToDummyAddress ( BlockHeightOffset32 1 u)
643+
644+ // Mine blocks to release time-lock
645+ bitcoind.GenerateBlocksToDummyAddress
646+ ( BlockHeightOffset32 ( uint32 locallyForceClosedData.ToSelfDelay))
647+
648+ let! spendingTxResult =
649+ let commitmentTx = clientWallet.ChannelStore.GetCommitmentTx channelId
650+ ( Lightning.Node.Client clientWallet.NodeClient). CreateRecoveryTxForForceClose
651+ channelId
652+ commitmentTx
653+
654+ let recoveryTx = UnwrapResult spendingTxResult " Local output is dust, recovery tx cannot be created"
655+
656+ let! _recoveryTxId =
657+ ChannelManager.BroadcastRecoveryTxAndCloseChannel recoveryTx clientWallet.ChannelStore
658+
659+ // wait for spending transaction to appear in mempool
660+ while bitcoind.GetTxIdsInMempool() .Length = 0 do
661+ do ! Async.Sleep 500
662+
663+ // Mine the spending tx into a block
664+ bitcoind.GenerateBlocksToDummyAddress ( BlockHeightOffset32 1 u)
665+
666+ Infrastructure.LogDebug " waiting for our wallet balance to increase"
667+ let! _balanceAfterFundsReclaimed =
668+ let amount = balanceBeforeFundsReclaimed + Money( 1.0 m, MoneyUnit.Satoshi)
669+ clientWallet.WaitForBalance amount
670+
671+ TearDown clientWallet bitcoind electrumServer lnd
672+ }
673+
611674 [<Category " G2G_ChannelLocalForceClosing_Funder" >]
612675 [<Test>]
613676 member __. ``can send monohop payments and handle local force - close of channel ( funder ) ``() = Async.RunSynchronously <| async {
0 commit comments