How to limit the range of the random values of the Solidity Fuzz test parameters? – vm.assume` cheatcode rejected too many inputs (65536 allowed)]

Context

After having written the Solidity fuzz test below, it says the vm.assume( throws too many reverts. The easy solution would be to increase the number of permitted reverts, however, I would like to limit the random parameter values to specific ranges to remove the vm.assume( statements instead. That would lower the number of thrown reverts.

Code

// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.25 <0.9.0;

import "forge-std/src/Vm.sol" as vm;
import { PRBTest } from "@prb/test/src/PRBTest.sol";
import { StdCheats } from "forge-std/src/StdCheats.sol";

import { DecentralisedInvestmentManager } from "../../../../src/DecentralisedInvestmentManager.sol";
import { TestHelper } from "../../../TestHelper.sol";
import { InitialiseDim } from "test/InitialiseDim.sol";
import { console2 } from "forge-std/src/console2.sol";

interface IFuzzTriggerReturnAll {
  function setUp() external;

  function testFuzzAfterRaisePeriodReturnSingleInvestment(
    uint256 projectLeadFracNumerator,
    uint256 projectLeadFracDenominator,
    uint256 firstInvestmentAmount,
    uint256 investmentTarget,
    uint256 firstCeiling,
    uint256 secondCeiling,
    uint256 thirdCeiling,
    uint32 raisePeriod,
    uint32 additionalWaitPeriod,
    uint8 firstMultiple,
    uint8 secondMultiple,
    uint8 thirdMultiple
  ) external;
}

/**
Tests whether the dim.triggerReturnAll() function ensures the investments are:
- returned if the investment target is not reached, after the raisePeriod has passed.
- not returned if the investment target is reached, after the raisePeriod has passed.
TODO: test whether the investments are:
- not returned if the investment target is not reached, before the raisePeriod has passed.
- not returned if the investment target is reached, before the raisePeriod has passed.
*/
contract FuzzTriggerReturnAll is PRBTest, StdCheats, IFuzzTriggerReturnAll {
  address internal _projectLead;
  TestHelper private _testHelper;

  function setUp() public virtual override {
    _testHelper = new TestHelper();
  }

  function _initialiseRandomDim(
    uint256 projectLeadFracNumerator,
    uint256 projectLeadFracDenominator,
    uint256 investmentTarget,
    uint256 firstCeiling,
    uint256 secondCeiling,
    uint256 thirdCeiling,
    uint32 raisePeriod,
    uint8 firstMultiple,
    uint8 secondMultiple,
    uint8 thirdMultiple
  ) internal virtual returns (DecentralisedInvestmentManager dim) {
    // Instantiate the attribute for the contract-under-test.
    _projectLead = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;
    uint256[] memory ceilings = new uint256[](3);
    ceilings[0] = firstCeiling;
    ceilings[1] = secondCeiling;
    ceilings[2] = thirdCeiling;
    uint8[] memory multiples = new uint8[](3);
    multiples[0] = firstMultiple;
    multiples[1] = secondMultiple;
    multiples[2] = thirdMultiple;
    InitialiseDim initDim = new InitialiseDim({
      ceilings: ceilings,
      multiples: multiples,
      investmentTarget: investmentTarget,
      projectLeadFracNumerator: projectLeadFracNumerator,
      projectLeadFracDenominator: projectLeadFracDenominator,
      projectLead: _projectLead,
      raisePeriod: raisePeriod
    });
    dim = initDim.getDim();
    return dim;
  }

  function _performInvestmentInRandomDim(
    DecentralisedInvestmentManager dim,
    uint256 someInvestmentAmount,
    address payable someInvestorWallet
  ) internal virtual {
    deal(someInvestorWallet, someInvestmentAmount);

    // Set the msg.sender address to that of the _firstInvestorWallet for the next call.
    vm.prank(address(someInvestorWallet));
    // Send investment directly from the investor wallet into the receiveInvestment function.
    dim.receiveInvestment{ value: someInvestmentAmount }();
    // assertEq(dim.getTierInvestmentLength(), 1, "Error, the _tierInvestments.length was not as expected.");
  }

  /**
  @dev The investor has invested 0.5 eth, and the investment target is 0.6 eth after 12 weeks.
  So the investment target is not reached, so all the funds should be returned.
   */
  function testFuzzAfterRaisePeriodReturnSingleInvestment(
    uint256 projectLeadFracNumerator,
    uint256 projectLeadFracDenominator,
    uint256 investmentTarget,
    uint256 firstInvestmentAmount,
    uint256 firstCeiling,
    uint256 secondCeiling,
    uint256 thirdCeiling,
    uint32 additionalWaitPeriod,
    uint32 raisePeriod,
    uint8 firstMultiple,
    uint8 secondMultiple,
    uint8 thirdMultiple
  ) public virtual override {
    // Assume requirements on contract initialisation by project lead are valid.
    vm.assume(projectLeadFracDenominator > 0);

    vm.assume(firstCeiling > 0);
    vm.assume(additionalWaitPeriod > 0);
    vm.assume(raisePeriod > 0);
    vm.assume(investmentTarget > 0);
    vm.assume(firstCeiling < secondCeiling);
    vm.assume(secondCeiling < thirdCeiling);
    vm.assume(investmentTarget <= thirdCeiling);
    vm.assume(projectLeadFracNumerator <= projectLeadFracDenominator);
    vm.assume(firstMultiple > 1);
    vm.assume(secondMultiple > 1);
    vm.assume(thirdMultiple > 1);

    // Assume an investor tries to invest at least 1 wei.
    vm.assume(firstInvestmentAmount > 0);

    // Store multiples in an array to assert they do not lead to an overflow when computing the investor return.
    uint256[] memory multiples = new uint256[](3);
    multiples[0] = firstMultiple;
    multiples[1] = secondMultiple;
    multiples[2] = thirdMultiple;
    vm.assume(!_testHelper.sumOfNrsThrowsOverFlow({ numbers: multiples }));
    vm.assume(
      !_testHelper.yieldsOverflowMultiply({
        a: firstMultiple + secondMultiple + thirdMultiple,
        b: firstInvestmentAmount
      })
    );

    // Initialise the contract that is being fuzz tested.
    DecentralisedInvestmentManager dim = _initialiseRandomDim({
      projectLeadFracNumerator: projectLeadFracNumerator,
      projectLeadFracDenominator: projectLeadFracDenominator,
      raisePeriod: raisePeriod,
      investmentTarget: investmentTarget,
      firstCeiling: firstCeiling,
      secondCeiling: secondCeiling,
      thirdCeiling: thirdCeiling,
      firstMultiple: firstMultiple,
      secondMultiple: secondMultiple,
      thirdMultiple: thirdMultiple
    });

    // Generate a non-random investor wallet address and make an investment.
    address payable firstInvestorWallet = payable(address(uint160(uint256(keccak256(bytes("1"))))));
    _performInvestmentInRandomDim({
      dim: dim,
      someInvestmentAmount: firstInvestmentAmount,
      someInvestorWallet: firstInvestorWallet
    });

    // Perform test logic.
    if (firstInvestmentAmount >= investmentTarget) {
      vm.prank(_projectLead);
      // solhint-disable-next-line not-rely-on-time
      vm.warp(block.timestamp + raisePeriod + additionalWaitPeriod);
      vm.expectRevert(bytes("Investment target reached!"));
      dim.triggerReturnAll();
    } else {
      vm.prank(_projectLead);
      // solhint-disable-next-line not-rely-on-time
      vm.warp(block.timestamp + raisePeriod + additionalWaitPeriod);
      dim.triggerReturnAll();
      assertEq(address(dim).balance, 0 ether, "The dim did not contain 0 ether after returning all investments.");
    }
  }
}

Output

When I run that test above with:

clear && forge test -vvvvvv --match-test testFuzzAfterRaisePeriodReturnSingleInvestment --via-ir

It gives output:

Ran 1 test for test/functional/DecentralisedInvestmentManager/triggerReturnAll/FuzzTriggerReturnAll.t.sol:FuzzTriggerReturnAll
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] testFuzzAfterRaisePeriodReturnSingleInvestment(uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint32,uint32,uint8,uint8,uint8) (runs: 0, μ: 0, ~: 0)
Traces:
  [334958] FuzzTriggerReturnAll::setUp()
    ├─ [280325] → new TestHelper@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
    │   └─ ← [Return] 1400 bytes of code
    └─ ← [Return] 

Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 1.02s (1.02s CPU time)

Ran 1 test suite in 1.57s (1.02s CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)

Failing tests:
Encountered 1 failing test in test/functional/DecentralisedInvestmentManager/triggerReturnAll/FuzzTriggerReturnAll.t.sol:FuzzTriggerReturnAll
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] testFuzzAfterRaisePeriodReturnSingleInvestment(uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint32,uint32,uint8,uint8,uint8) (runs: 0, μ: 0, ~: 0)

Encountered a total of 1 failing tests, 0 tests succeeded

Documentation

This documentation describes one can use the fixture to set the random parameters to a hardcoded random range, like:

uint32[] public fixtureAmount = [1, 5, 555];

However, I do not want to hardcode the random values, as I may not be as random as I expect, and I expect the randomness from Forge to be perhaps a bit better tailored to edge cases than pure randomness.

So instead I would like to set a fixture like:

uint256 fixtureFirstCeiling > 0

However, that is invalid Solidity syntax.

Note

I initially had a nested for loop of 15 steps deep, however, that is not desirable from a code-readability perspective.

Question

How can I constrain the range of random parameters (on one side of the range) in a Forge fuzz test?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật