loopin: fail swap when htlc amount is incorrect

Previously the swap would get stuck in a state where it wouldn't ever
progress because the server rejected the htlc.
This commit is contained in:
Joost Jager 2020-06-25 13:55:27 +02:00
parent e33d2fb762
commit a3b7fa5977
No known key found for this signature in database
GPG key ID: A61B9D4C393C59C7
3 changed files with 29 additions and 0 deletions

View file

@ -209,6 +209,20 @@ func testLoopInTimeout(t *testing.T,
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)
err = <-errChan
if err != nil {
t.Fatal(err)
}
return
}
// Client starts listening for spend of htlc.
<-ctx.lnd.RegisterSpendChannel
@ -380,6 +394,7 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool) {
htlcTx.AddTxOut(&wire.TxOut{
PkScript: htlc.PkScript,
Value: int64(contract.AmountRequested),
})
}