Skip to content

Commit 33fdde9

Browse files
committed
loop: fix loopout and client tests for sweeper integration
1 parent 0914074 commit 33fdde9

File tree

4 files changed

+173
-56
lines changed

4 files changed

+173
-56
lines changed

client_test.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/lightninglabs/loop/loopdb"
1414
"github.com/lightninglabs/loop/swap"
1515
"github.com/lightninglabs/loop/test"
16+
"github.com/lightninglabs/loop/utils"
1617
"github.com/lightningnetwork/lnd/lnrpc"
1718
"github.com/lightningnetwork/lnd/lntypes"
1819
"github.com/stretchr/testify/require"
@@ -146,8 +147,6 @@ func TestLoopOutFailWrongAmount(t *testing.T) {
146147
// TestLoopOutResume tests that swaps in various states are properly resumed
147148
// after a restart.
148149
func TestLoopOutResume(t *testing.T) {
149-
defer test.Guard(t)()
150-
151150
defaultConfs := loopdb.DefaultLoopOutHtlcConfirmations
152151

153152
storedVersion := []loopdb.ProtocolVersion{
@@ -279,7 +278,7 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
279278
preimageRevealed, int32(confs),
280279
)
281280

282-
htlc, err := GetHtlc(
281+
htlc, err := utils.GetHtlc(
283282
hash, &pendingSwap.Contract.SwapContract,
284283
&chaincfg.TestNet3Params,
285284
)
@@ -304,7 +303,7 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
304303
func(r error) {},
305304
func(r error) {},
306305
preimageRevealed,
307-
confIntent, GetHtlcScriptVersion(protocolVersion),
306+
confIntent, utils.GetHtlcScriptVersion(protocolVersion),
308307
)
309308
}
310309

@@ -317,15 +316,28 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
317316

318317
signalPrepaymentResult(nil)
319318

320-
ctx.AssertRegisterSpendNtfn(confIntent.PkScript)
321-
322319
// Assert that a call to track payment was sent, and respond with status
323320
// in flight so that our swap will push its preimage to the server.
324321
ctx.trackPayment(lnrpc.Payment_IN_FLIGHT)
325322

323+
// We need to notify the height, as the loopout is going to attempt a
324+
// sweep when a new block is received.
325+
err := ctx.Lnd.NotifyHeight(ctx.Lnd.Height + 1)
326+
require.NoError(ctx.Context.T, err)
327+
326328
// Publish tick.
327329
ctx.expiryChan <- testTime
328330

331+
// One spend notifier is registered by batch to watch primary sweep.
332+
ctx.AssertRegisterSpendNtfn(confIntent.PkScript)
333+
334+
ctx.AssertEpochListeners(2)
335+
336+
// Mock the blockheight again as that's when the batch will broadcast
337+
// the tx.
338+
err = ctx.Lnd.NotifyHeight(ctx.Lnd.Height + 1)
339+
require.NoError(ctx.Context.T, err)
340+
329341
// Expect a signing request in the non taproot case.
330342
if scriptVersion != swap.HtlcV3 {
331343
<-ctx.Context.Lnd.SignOutputRawChannel
@@ -341,13 +353,6 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
341353
// our MuSig2 signing attempts.
342354
if scriptVersion == swap.HtlcV3 {
343355
ctx.assertPreimagePush(ctx.store.LoopOutSwaps[hash].Preimage)
344-
345-
// Try MuSig2 signing first and fail it so that we go for a
346-
// normal sweep.
347-
for i := 0; i < maxMusigSweepRetries; i++ {
348-
ctx.expiryChan <- testTime
349-
ctx.assertPreimagePush(ctx.store.LoopOutSwaps[hash].Preimage)
350-
}
351356
<-ctx.Context.Lnd.SignOutputRawChannel
352357
}
353358

@@ -388,6 +393,8 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
388393

389394
ctx.NotifySpend(sweepTx, 0)
390395

396+
ctx.AssertRegisterConf(true, 3)
397+
391398
ctx.assertStatus(loopdb.StateSuccess)
392399

393400
ctx.assertStoreFinished(loopdb.StateSuccess)

loopin_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/btcsuite/btcd/wire"
1010
"github.com/lightninglabs/loop/loopdb"
1111
"github.com/lightninglabs/loop/test"
12+
"github.com/lightninglabs/loop/utils"
1213
"github.com/lightningnetwork/lnd/chainntnfs"
1314
invpkg "github.com/lightningnetwork/lnd/invoices"
1415
"github.com/lightningnetwork/lnd/routing/route"
@@ -449,7 +450,7 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool,
449450
pendSwap.Loop.Events[0].Cost = cost
450451
}
451452

452-
htlc, err := GetHtlc(
453+
htlc, err := utils.GetHtlc(
453454
testPreimage.Hash(), &contract.SwapContract,
454455
cfg.lnd.ChainParams,
455456
)

0 commit comments

Comments
 (0)