mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
unit: adjust for incorrect amount sweep
This commit is contained in:
parent
3db464955d
commit
855fa8dccf
1 changed files with 22 additions and 9 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue