unit: adjust for incorrect amount sweep

pull/676/head
Slyghtning 4 months ago
parent 3db464955d
commit 855fa8dccf
No known key found for this signature in database
GPG Key ID: F82D456EA023C9BF

@ -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.
@ -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)

Loading…
Cancel
Save