Skip to content

Commit

Permalink
test(irm): revert invariants
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Nov 13, 2023
1 parent ead8b28 commit f9a1bf7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ out = "out"
test = "test"
libs = ["lib"]

[profile.default.fuzz]
runs = 4096

[profile.default.invariant]
fail_on_revert = true

Expand All @@ -21,7 +24,7 @@ script = "/dev/null"
via-ir = false

[profile.test.fuzz]
runs = 8192
runs = 16384

[profile.test.invariant]
runs = 32
Expand Down
13 changes: 8 additions & 5 deletions test/SpeedJumpIrmTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,13 @@ contract AdaptativeCurveIrmTest is Test {

/* HANDLERS */

function handleBorrowRate(uint256 totalSupplyAssets, uint256 totalBorrowAssets) external {
function handleBorrowRate(uint256 totalSupplyAssets, uint256 totalBorrowAssets, uint256 elapsed) external {
elapsed = bound(elapsed, 0, type(uint48).max);
totalSupplyAssets = bound(totalSupplyAssets, 0, type(uint128).max);
totalBorrowAssets = bound(totalBorrowAssets, 0, totalSupplyAssets);

vm.warp(block.timestamp + elapsed);

Market memory market;
market.totalBorrowAssets = uint128(totalSupplyAssets);
market.totalSupplyAssets = uint128(totalBorrowAssets);
Expand All @@ -203,17 +206,17 @@ contract AdaptativeCurveIrmTest is Test {
market.totalBorrowAssets = 9 ether;
market.totalSupplyAssets = 10 ether;

assertGe(irm.borrowRateView(marketParams, market), irm.MIN_RATE_AT_TARGET());
assertGe(irm.borrowRate(marketParams, market), irm.MIN_RATE_AT_TARGET());
assertGe(irm.borrowRateView(marketParams, market), irm.MIN_RATE_AT_TARGET().wDivDown(CURVE_STEEPNESS));
assertGe(irm.borrowRate(marketParams, market), irm.MIN_RATE_AT_TARGET().wDivDown(CURVE_STEEPNESS));
}

function invariantLeMaxRateAtTarget() public {
Market memory market;
market.totalBorrowAssets = 9 ether;
market.totalSupplyAssets = 10 ether;

assertLe(irm.borrowRateView(marketParams, market), irm.MAX_RATE_AT_TARGET());
assertLe(irm.borrowRate(marketParams, market), irm.MAX_RATE_AT_TARGET());
assertLe(irm.borrowRateView(marketParams, market), irm.MAX_RATE_AT_TARGET().wMulDown(CURVE_STEEPNESS));
assertLe(irm.borrowRate(marketParams, market), irm.MAX_RATE_AT_TARGET().wMulDown(CURVE_STEEPNESS));
}

function _expectedRateAtTarget(Id id, Market memory market) internal view returns (uint256) {
Expand Down

0 comments on commit f9a1bf7

Please sign in to comment.