@@ -694,140 +694,6 @@ func testPreimagePush(t *testing.T) {
694694 require .NoError (t , <- errChan )
695695}
696696
697- // TestExpiryBeforeReveal tests the case where the on-chain HTLC expires before
698- // we have revealed our preimage, demonstrating that we do not reveal our
699- // preimage once we've reached our expiry height.
700- func TestExpiryBeforeReveal (t * testing.T ) {
701- t .Run ("stable protocol" , func (t * testing.T ) {
702- testExpiryBeforeReveal (t )
703- })
704-
705- // Note that there's no point of testing this case with the new
706- // protocol where we use taproot htlc and attempt MuSig2 sweep. The
707- // reason is that the preimage is revealed to the server once the
708- // htlc is confirmed in order to facilitate the cooperative signing of
709- // the sweep transaction.
710- }
711-
712- func testExpiryBeforeReveal (t * testing.T ) {
713- defer test .Guard (t )()
714-
715- lnd := test .NewMockLnd ()
716- ctx := test .NewContext (t , lnd )
717- server := newServerMock (lnd )
718-
719- testReq := * testRequest
720-
721- // Set on-chain HTLC CLTV.
722- testReq .Expiry = ctx .Lnd .Height + testLoopOutMinOnChainCltvDelta
723-
724- // Set our fee estimate to higher than our max miner fee will allow.
725- lnd .SetFeeEstimate (testReq .SweepConfTarget , chainfee .SatPerKWeight (
726- testReq .MaxMinerFee * 2 ,
727- ))
728-
729- // Setup the cfg using mock server and init a loop out request.
730- cfg := newSwapConfig (
731- & lnd .LndServices , newStoreMock (t ), server ,
732- )
733- initResult , err := newLoopOutSwap (
734- context .Background (), cfg , ctx .Lnd .Height , & testReq ,
735- )
736- require .NoError (t , err )
737- swap := initResult .swap
738-
739- // Set up the required dependencies to execute the swap.
740- sweeper := & sweep.Sweeper {Lnd : & lnd .LndServices }
741- blockEpochChan := make (chan interface {})
742- statusChan := make (chan SwapInfo )
743- expiryChan := make (chan time.Time )
744- timerFactory := func (_ time.Duration ) <- chan time.Time {
745- return expiryChan
746- }
747-
748- errChan := make (chan error )
749- go func () {
750- err := swap .execute (context .Background (), & executeConfig {
751- statusChan : statusChan ,
752- blockEpochChan : blockEpochChan ,
753- timerFactory : timerFactory ,
754- sweeper : sweeper ,
755- verifySchnorrSig : mockVerifySchnorrSigFail ,
756- }, ctx .Lnd .Height )
757- if err != nil {
758- log .Error (err )
759- }
760- errChan <- err
761- }()
762-
763- // The swap should be found in its initial state.
764- cfg .store .(* storeMock ).assertLoopOutStored ()
765- state := <- statusChan
766- require .Equal (t , loopdb .StateInitiated , state .State )
767-
768- // We'll then pay both the swap and prepay invoice, which should trigger
769- // the server to publish the on-chain HTLC.
770- signalSwapPaymentResult := ctx .AssertPaid (swapInvoiceDesc )
771- signalPrepaymentResult := ctx .AssertPaid (prepayInvoiceDesc )
772-
773- signalSwapPaymentResult (nil )
774- signalPrepaymentResult (nil )
775-
776- // Notify the confirmation notification for the HTLC.
777- ctx .AssertRegisterConf (false , defaultConfirmations )
778-
779- // Advance the block height to get the HTLC confirmed.
780- height := ctx .Lnd .Height + 1
781- blockEpochChan <- height
782-
783- htlcTx := wire .NewMsgTx (2 )
784- htlcTx .AddTxOut (& wire.TxOut {
785- Value : int64 (swap .AmountRequested ),
786- PkScript : swap .htlc .PkScript ,
787- })
788- ctx .NotifyConf (htlcTx )
789-
790- // The client should then register for a spend of the HTLC and attempt
791- // to sweep it using the custom confirmation target.
792- ctx .AssertRegisterSpendNtfn (swap .htlc .PkScript )
793-
794- // Assert that we made a query to track our payment, as required for
795- // preimage push tracking.
796- ctx .AssertTrackPayment ()
797-
798- // Tick the expiry channel. Because our max miner fee is too high, we
799- // won't attempt a sweep at this point.
800- expiryChan <- testTime
801-
802- // Since we don't have a reliable mechanism to non-intrusively avoid
803- // races by setting the fee estimate too soon, let's sleep here a bit
804- // to ensure the first sweep fails.
805- time .Sleep (500 * time .Millisecond )
806-
807- // Now we decrease our conf target to less than our max miner fee.
808- lnd .SetFeeEstimate (testReq .SweepConfTarget , chainfee .SatPerKWeight (
809- testReq .MaxMinerFee / 2 ,
810- ))
811-
812- // Advance the block height to the point where we would do timeout
813- // instead of pushing the preimage.
814- blockEpochChan <- testReq .Expiry + height
815-
816- // Tick our expiry channel again to trigger another sweep attempt.
817- expiryChan <- testTime
818-
819- // We should see our swap marked as failed.
820- cfg .store .(* storeMock ).assertLoopOutState (
821- loopdb .StateFailTimeout ,
822- )
823- status := <- statusChan
824- require .Equal (
825- t , status .State , loopdb .StateFailTimeout ,
826- )
827-
828- require .Nil (t , <- errChan )
829- }
830-
831697// TestFailedOffChainCancelation tests sending of a cancelation message to
832698// the server when a swap fails due to off-chain routing.
833699func TestFailedOffChainCancelation (t * testing.T ) {
0 commit comments