Skip to content

Commit

Permalink
test: configurable number of branches
Browse files Browse the repository at this point in the history
  • Loading branch information
danielattilasimon committed Sep 3, 2024
1 parent 20032d0 commit 9f93439
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions contracts/src/test/Invariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,24 @@ contract InvariantsTest is Logging, BaseInvariantTest, BaseMultiCollateralTest {
function setUp() public override {
super.setUp();

uint256 n;
try vm.envUint("NUM_BRANCHES") returns (uint256 value) {
n = value;
} catch {
n = 4;
}

// TODO: randomize params? How to do it with Foundry invariant testing?
TestDeployer.TroveManagerParams[] memory paramsList = new TestDeployer.TroveManagerParams[](4);
paramsList[0] = TestDeployer.TroveManagerParams(1.5 ether, 1.1 ether, 1.01 ether, 0.05 ether, 0.1 ether);
paramsList[1] = TestDeployer.TroveManagerParams(1.6 ether, 1.2 ether, 1.01 ether, 0.05 ether, 0.1 ether);
paramsList[2] = TestDeployer.TroveManagerParams(1.6 ether, 1.2 ether, 1.01 ether, 0.05 ether, 0.1 ether);
paramsList[3] = TestDeployer.TroveManagerParams(1.6 ether, 1.25 ether, 1.01 ether, 0.05 ether, 0.1 ether);
TestDeployer.TroveManagerParams[] memory p = new TestDeployer.TroveManagerParams[](n);
if (n > 0) p[0] = TestDeployer.TroveManagerParams(1.5 ether, 1.1 ether, 1.01 ether, 0.05 ether, 0.1 ether);
if (n > 1) p[1] = TestDeployer.TroveManagerParams(1.6 ether, 1.2 ether, 1.01 ether, 0.05 ether, 0.1 ether);
if (n > 2) p[2] = TestDeployer.TroveManagerParams(1.6 ether, 1.2 ether, 1.01 ether, 0.05 ether, 0.1 ether);
if (n > 3) p[3] = TestDeployer.TroveManagerParams(1.6 ether, 1.25 ether, 1.01 ether, 0.05 ether, 0.1 ether);

TestDeployer deployer = new TestDeployer();
Contracts memory contracts;
(contracts.branches, contracts.collateralRegistry, contracts.boldToken, contracts.hintHelpers,, contracts.weth,)
= deployer.deployAndConnectContractsMultiColl(paramsList);
= deployer.deployAndConnectContractsMultiColl(p);
setupContracts(contracts);

handler = new InvariantsTestHandler({contracts: contracts, assumeNoExpectedFailures: true});
Expand Down

0 comments on commit 9f93439

Please sign in to comment.