Skip to content

Commit

Permalink
Fix fuzz test
Browse files Browse the repository at this point in the history
Otherwise we may run into the following issue:
lightning/bolts#728
  • Loading branch information
t-bast committed Jan 27, 2020
1 parent 5831f12 commit 1628192
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,20 +404,21 @@ class CommitmentsSpec extends TestkitBaseClass with StateTestsHelperMethods {
}

test("should always be able to send availableForSend", Tag("fuzzy")) { f =>
val maxPendingHtlcAmount = 1000000.msat
case class FuzzTest(isFunder: Boolean, pendingHtlcs: Int, feeRatePerKw: Long, dustLimit: Satoshi, toLocal: MilliSatoshi, toRemote: MilliSatoshi)
for (_ <- 1 to 100) {
val t = FuzzTest(
isFunder = Random.nextInt(2) == 0,
pendingHtlcs = Random.nextInt(10),
feeRatePerKw = Random.nextInt(10000),
dustLimit = Random.nextInt(1000).sat,
// We make sure there's always enough to add the initial pending HTLCs.
toLocal = 20000000.msat + Random.nextInt(1000000000).msat,
toRemote = Random.nextInt(1000000000).msat)
// We make sure both sides have enough to send/receive at least the initial pending HTLCs.
toLocal = maxPendingHtlcAmount * 2 * 10 + Random.nextInt(1000000000).msat,
toRemote = maxPendingHtlcAmount * 2 * 10 + Random.nextInt(1000000000).msat)
var c = CommitmentsSpec.makeCommitments(t.toLocal, t.toRemote, t.feeRatePerKw, t.dustLimit, t.isFunder)
// Add some initial HTLCs to the pending list (bigger commit tx).
for (_ <- 0 to t.pendingHtlcs) {
val amount = Random.nextInt(1000000).msat
val amount = Random.nextInt(maxPendingHtlcAmount.toLong.toInt).msat
val (_, cmdAdd) = makeCmdAdd(amount, randomKey.publicKey, f.currentBlockHeight)
sendAdd(c, cmdAdd, Local(UUID.randomUUID, None), f.currentBlockHeight) match {
case Right((cc, _)) => c = cc
Expand All @@ -431,20 +432,21 @@ class CommitmentsSpec extends TestkitBaseClass with StateTestsHelperMethods {
}

test("should always be able to receive availableForReceive", Tag("fuzzy")) { f =>
val maxPendingHtlcAmount = 1000000.msat
case class FuzzTest(isFunder: Boolean, pendingHtlcs: Int, feeRatePerKw: Long, dustLimit: Satoshi, toLocal: MilliSatoshi, toRemote: MilliSatoshi)
for (_ <- 1 to 100) {
val t = FuzzTest(
isFunder = Random.nextInt(2) == 0,
pendingHtlcs = Random.nextInt(10),
feeRatePerKw = Random.nextInt(10000),
dustLimit = Random.nextInt(1000).sat,
toLocal = Random.nextInt(1000000000).msat,
// We make sure there's always enough to add the potential pending HTLCs
toRemote = 20000000.msat + Random.nextInt(1000000000).msat)
// We make sure both sides have enough to send/receive at least the initial pending HTLCs.
toLocal = maxPendingHtlcAmount * 2 * 10 + Random.nextInt(1000000000).msat,
toRemote = maxPendingHtlcAmount * 2 * 10 + Random.nextInt(1000000000).msat)
var c = CommitmentsSpec.makeCommitments(t.toLocal, t.toRemote, t.feeRatePerKw, t.dustLimit, t.isFunder)
// Add some initial HTLCs to the pending list (bigger commit tx).
for (_ <- 0 to t.pendingHtlcs) {
val amount = Random.nextInt(1000000).msat
val amount = Random.nextInt(maxPendingHtlcAmount.toLong.toInt).msat
val add = UpdateAddHtlc(randomBytes32, c.remoteNextHtlcId, amount, randomBytes32, CltvExpiry(f.currentBlockHeight), TestConstants.emptyOnionPacket)
Try(receiveAdd(c, add)) match {
case Success(cc) => c = cc
Expand Down

0 comments on commit 1628192

Please sign in to comment.