Skip to content

Commit a0433aa

Browse files
Fix flaky CommitmentsSpec test (#2458)
In case feeRatePerKw is high and liquidity is low on the initiator side, the initiator can't send anything and the test would fail because we try to create a HTLC for an amount of 0.
1 parent 3b12475 commit a0433aa

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

eclair-core/src/test/scala/fr/acinq/eclair/channel/CommitmentsSpec.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,19 @@ class CommitmentsSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
427427
toRemote = maxPendingHtlcAmount * 2 * 10 + Random.nextInt(1000000000).msat)
428428
var c = CommitmentsSpec.makeCommitments(t.toLocal, t.toRemote, t.feeRatePerKw, t.dustLimit, t.isInitiator)
429429
// Add some initial HTLCs to the pending list (bigger commit tx).
430-
for (_ <- 0 to t.pendingHtlcs) {
430+
for (_ <- 1 to t.pendingHtlcs) {
431431
val amount = Random.nextInt(maxPendingHtlcAmount.toLong.toInt).msat.max(1 msat)
432432
val (_, cmdAdd) = makeCmdAdd(amount, randomKey().publicKey, f.currentBlockHeight)
433433
sendAdd(c, cmdAdd, f.currentBlockHeight, feeConfNoMismatch) match {
434434
case Right((cc, _)) => c = cc
435435
case Left(e) => ignore(s"$t -> could not setup initial htlcs: $e")
436436
}
437437
}
438-
val (_, cmdAdd) = makeCmdAdd(c.availableBalanceForSend, randomKey().publicKey, f.currentBlockHeight)
439-
val result = sendAdd(c, cmdAdd, f.currentBlockHeight, feeConfNoMismatch)
440-
assert(result.isRight, s"$t -> $result")
438+
if (c.availableBalanceForSend > 0.msat) {
439+
val (_, cmdAdd) = makeCmdAdd(c.availableBalanceForSend, randomKey().publicKey, f.currentBlockHeight)
440+
val result = sendAdd(c, cmdAdd, f.currentBlockHeight, feeConfNoMismatch)
441+
assert(result.isRight, s"$t -> $result")
442+
}
441443
}
442444
}
443445

@@ -455,18 +457,20 @@ class CommitmentsSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with
455457
toRemote = maxPendingHtlcAmount * 2 * 10 + Random.nextInt(1000000000).msat)
456458
var c = CommitmentsSpec.makeCommitments(t.toLocal, t.toRemote, t.feeRatePerKw, t.dustLimit, t.isInitiator)
457459
// Add some initial HTLCs to the pending list (bigger commit tx).
458-
for (_ <- 0 to t.pendingHtlcs) {
460+
for (_ <- 1 to t.pendingHtlcs) {
459461
val amount = Random.nextInt(maxPendingHtlcAmount.toLong.toInt).msat.max(1 msat)
460462
val add = UpdateAddHtlc(randomBytes32(), c.remoteNextHtlcId, amount, randomBytes32(), CltvExpiry(f.currentBlockHeight), TestConstants.emptyOnionPacket, None)
461463
receiveAdd(c, add, feeConfNoMismatch) match {
462464
case Right(cc) => c = cc
463465
case Left(e) => ignore(s"$t -> could not setup initial htlcs: $e")
464466
}
465467
}
466-
val add = UpdateAddHtlc(randomBytes32(), c.remoteNextHtlcId, c.availableBalanceForReceive, randomBytes32(), CltvExpiry(f.currentBlockHeight), TestConstants.emptyOnionPacket, None)
467-
receiveAdd(c, add, feeConfNoMismatch) match {
468-
case Right(_) => ()
469-
case Left(e) => fail(s"$t -> $e")
468+
if (c.availableBalanceForReceive > 0.msat) {
469+
val add = UpdateAddHtlc(randomBytes32(), c.remoteNextHtlcId, c.availableBalanceForReceive, randomBytes32(), CltvExpiry(f.currentBlockHeight), TestConstants.emptyOnionPacket, None)
470+
receiveAdd(c, add, feeConfNoMismatch) match {
471+
case Right(_) => ()
472+
case Left(e) => fail(s"$t -> $e")
473+
}
470474
}
471475
}
472476
}

0 commit comments

Comments
 (0)