Skip to content

Commit

Permalink
unit: adjust for incorrect amount sweep
Browse files Browse the repository at this point in the history
  • Loading branch information
hieblmi committed Feb 13, 2024
1 parent 3db4649 commit 855fa8d
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions loopin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,19 @@ func testLoopInTimeout(t *testing.T, externalValue int64) {
Tx: &htlcTx,
}

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

require.NoError(t, <-errChan)
return
func handleHtlcExpiry(t *testing.T, ctx *loopInTestContext, inSwap *loopInSwap,
htlcTx wire.MsgTx, cost loopdb.SwapCost, errChan chan error,
isInvalidAmount bool) {

if isInvalidAmount {
ctx.store.AssertLoopInState(loopdb.StateFailIncorrectHtlcAmt)
ctx.assertState(loopdb.StateFailIncorrectHtlcAmt)
}

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

ctx.assertState(loopdb.StateFailTimeout)
state := ctx.store.AssertLoopInState(loopdb.StateFailTimeout)
var state loopdb.SwapStateData
if isInvalidAmount {
state = ctx.store.AssertLoopInState(
loopdb.StateFailIncorrectHtlcAmtSwept,
)
ctx.assertState(loopdb.StateFailIncorrectHtlcAmtSwept)
} else {
ctx.assertState(loopdb.StateFailTimeout)
state = ctx.store.AssertLoopInState(loopdb.StateFailTimeout)
}
require.Equal(t, cost, state.Cost)

require.NoError(t, <-errChan)
Expand Down

0 comments on commit 855fa8d

Please sign in to comment.