|
|
|
@ -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)
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
state = ctx.store.AssertLoopInState(loopdb.StateFailTimeout)
|
|
|
|
|
}
|
|
|
|
|
require.Equal(t, cost, state.Cost)
|
|
|
|
|
|
|
|
|
|
require.NoError(t, <-errChan)
|
|
|
|
|