Skip to content

Commit 855fa8d

Browse files
committed
unit: adjust for incorrect amount sweep
1 parent 3db4649 commit 855fa8d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

loopin_test.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,19 @@ func testLoopInTimeout(t *testing.T, externalValue int64) {
277277
Tx: &htlcTx,
278278
}
279279

280-
// Assert that the swap is failed in case of an invalid amount.
281-
invalidAmt := externalValue != 0 && externalValue != int64(req.Amount)
282-
if invalidAmt {
283-
ctx.assertState(loopdb.StateFailIncorrectHtlcAmt)
284-
ctx.store.AssertLoopInState(loopdb.StateFailIncorrectHtlcAmt)
280+
isInvalidAmt := externalValue != 0 && externalValue != int64(req.Amount)
281+
handleHtlcExpiry(
282+
t, ctx, inSwap, htlcTx, cost, errChan, isInvalidAmt,
283+
)
284+
}
285285

286-
require.NoError(t, <-errChan)
287-
return
286+
func handleHtlcExpiry(t *testing.T, ctx *loopInTestContext, inSwap *loopInSwap,
287+
htlcTx wire.MsgTx, cost loopdb.SwapCost, errChan chan error,
288+
isInvalidAmount bool) {
289+
290+
if isInvalidAmount {
291+
ctx.store.AssertLoopInState(loopdb.StateFailIncorrectHtlcAmt)
292+
ctx.assertState(loopdb.StateFailIncorrectHtlcAmt)
288293
}
289294

290295
// Client starts listening for spend of htlc.
@@ -329,8 +334,16 @@ func testLoopInTimeout(t *testing.T, externalValue int64) {
329334
// Signal that the invoice was canceled.
330335
ctx.updateInvoiceState(0, invpkg.ContractCanceled)
331336

332-
ctx.assertState(loopdb.StateFailTimeout)
333-
state := ctx.store.AssertLoopInState(loopdb.StateFailTimeout)
337+
var state loopdb.SwapStateData
338+
if isInvalidAmount {
339+
state = ctx.store.AssertLoopInState(
340+
loopdb.StateFailIncorrectHtlcAmtSwept,
341+
)
342+
ctx.assertState(loopdb.StateFailIncorrectHtlcAmtSwept)
343+
} else {
344+
ctx.assertState(loopdb.StateFailTimeout)
345+
state = ctx.store.AssertLoopInState(loopdb.StateFailTimeout)
346+
}
334347
require.Equal(t, cost, state.Cost)
335348

336349
require.NoError(t, <-errChan)

0 commit comments

Comments
 (0)