mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loop: fix loopout and client tests for sweeper integration
This commit is contained in:
parent
0914074b10
commit
33fdde949f
4 changed files with 173 additions and 56 deletions
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/lightninglabs/loop/loopdb"
|
||||
"github.com/lightninglabs/loop/swap"
|
||||
"github.com/lightninglabs/loop/test"
|
||||
"github.com/lightninglabs/loop/utils"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -146,8 +147,6 @@ func TestLoopOutFailWrongAmount(t *testing.T) {
|
|||
// TestLoopOutResume tests that swaps in various states are properly resumed
|
||||
// after a restart.
|
||||
func TestLoopOutResume(t *testing.T) {
|
||||
defer test.Guard(t)()
|
||||
|
||||
defaultConfs := loopdb.DefaultLoopOutHtlcConfirmations
|
||||
|
||||
storedVersion := []loopdb.ProtocolVersion{
|
||||
|
|
@ -279,7 +278,7 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
|
|||
preimageRevealed, int32(confs),
|
||||
)
|
||||
|
||||
htlc, err := GetHtlc(
|
||||
htlc, err := utils.GetHtlc(
|
||||
hash, &pendingSwap.Contract.SwapContract,
|
||||
&chaincfg.TestNet3Params,
|
||||
)
|
||||
|
|
@ -304,7 +303,7 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
|
|||
func(r error) {},
|
||||
func(r error) {},
|
||||
preimageRevealed,
|
||||
confIntent, GetHtlcScriptVersion(protocolVersion),
|
||||
confIntent, utils.GetHtlcScriptVersion(protocolVersion),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -317,15 +316,28 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
|
|||
|
||||
signalPrepaymentResult(nil)
|
||||
|
||||
ctx.AssertRegisterSpendNtfn(confIntent.PkScript)
|
||||
|
||||
// Assert that a call to track payment was sent, and respond with status
|
||||
// in flight so that our swap will push its preimage to the server.
|
||||
ctx.trackPayment(lnrpc.Payment_IN_FLIGHT)
|
||||
|
||||
// We need to notify the height, as the loopout is going to attempt a
|
||||
// sweep when a new block is received.
|
||||
err := ctx.Lnd.NotifyHeight(ctx.Lnd.Height + 1)
|
||||
require.NoError(ctx.Context.T, err)
|
||||
|
||||
// Publish tick.
|
||||
ctx.expiryChan <- testTime
|
||||
|
||||
// One spend notifier is registered by batch to watch primary sweep.
|
||||
ctx.AssertRegisterSpendNtfn(confIntent.PkScript)
|
||||
|
||||
ctx.AssertEpochListeners(2)
|
||||
|
||||
// Mock the blockheight again as that's when the batch will broadcast
|
||||
// the tx.
|
||||
err = ctx.Lnd.NotifyHeight(ctx.Lnd.Height + 1)
|
||||
require.NoError(ctx.Context.T, err)
|
||||
|
||||
// Expect a signing request in the non taproot case.
|
||||
if scriptVersion != swap.HtlcV3 {
|
||||
<-ctx.Context.Lnd.SignOutputRawChannel
|
||||
|
|
@ -341,13 +353,6 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
|
|||
// our MuSig2 signing attempts.
|
||||
if scriptVersion == swap.HtlcV3 {
|
||||
ctx.assertPreimagePush(ctx.store.LoopOutSwaps[hash].Preimage)
|
||||
|
||||
// Try MuSig2 signing first and fail it so that we go for a
|
||||
// normal sweep.
|
||||
for i := 0; i < maxMusigSweepRetries; i++ {
|
||||
ctx.expiryChan <- testTime
|
||||
ctx.assertPreimagePush(ctx.store.LoopOutSwaps[hash].Preimage)
|
||||
}
|
||||
<-ctx.Context.Lnd.SignOutputRawChannel
|
||||
}
|
||||
|
||||
|
|
@ -388,6 +393,8 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
|
|||
|
||||
ctx.NotifySpend(sweepTx, 0)
|
||||
|
||||
ctx.AssertRegisterConf(true, 3)
|
||||
|
||||
ctx.assertStatus(loopdb.StateSuccess)
|
||||
|
||||
ctx.assertStoreFinished(loopdb.StateSuccess)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue