@@ -277,14 +277,19 @@ func testLoopInTimeout(t *testing.T, externalValue int64) {
277
277
Tx : & htlcTx ,
278
278
}
279
279
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
+ }
285
285
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 )
288
293
}
289
294
290
295
// Client starts listening for spend of htlc.
@@ -329,8 +334,16 @@ func testLoopInTimeout(t *testing.T, externalValue int64) {
329
334
// Signal that the invoice was canceled.
330
335
ctx .updateInvoiceState (0 , invpkg .ContractCanceled )
331
336
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
+ }
334
347
require .Equal (t , cost , state .Cost )
335
348
336
349
require .NoError (t , <- errChan )
0 commit comments