From 666094791e952cd2d0657321c839c8b07c4c7487 Mon Sep 17 00:00:00 2001 From: Quentin Garchery Date: Mon, 13 May 2024 10:49:03 +0200 Subject: [PATCH] test: improve bound --- test/forge/BaseTest.sol | 9 +-------- test/forge/invariant/MorphoInvariantTest.sol | 6 +++--- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/test/forge/BaseTest.sol b/test/forge/BaseTest.sol index f00917261..29020d1af 100644 --- a/test/forge/BaseTest.sol +++ b/test/forge/BaseTest.sol @@ -139,13 +139,6 @@ contract BaseTest is Test { return bound(blocks, 1, type(uint32).max); } - /// @dev Bounds the fuzzing input to a non-zero address. - /// @dev This function should be used in place of `vm.assume` in invariant test handler functions: - /// https://github.com/foundry-rs/foundry/issues/4190. - function _boundAddressNotZero(address input) internal view virtual returns (address) { - return address(uint160(bound(uint256(uint160(input)), 1, type(uint160).max))); - } - function _supply(uint256 amount) internal { loanToken.setBalance(address(this), amount); morpho.supply(marketParams, amount, 0, address(this), hex""); @@ -194,7 +187,7 @@ contract BaseTest is Test { uint256 maxCollateral = amountBorrowed.wDivDown(marketParams.lltv).mulDivDown(ORACLE_PRICE_SCALE, priceCollateral); - amountCollateral = bound(amountBorrowed, 0, Math.min(maxCollateral, MAX_COLLATERAL_ASSETS)); + amountCollateral = bound(amountCollateral, 0, Math.min(maxCollateral, MAX_COLLATERAL_ASSETS)); vm.assume(amountCollateral > 0); return (amountCollateral, amountBorrowed, priceCollateral); diff --git a/test/forge/invariant/MorphoInvariantTest.sol b/test/forge/invariant/MorphoInvariantTest.sol index 122d5f515..a0202391b 100644 --- a/test/forge/invariant/MorphoInvariantTest.sol +++ b/test/forge/invariant/MorphoInvariantTest.sol @@ -235,7 +235,7 @@ contract MorphoInvariantTest is InvariantTest { function withdrawAssetsOnBehalfNoRevert(uint256 marketSeed, uint256 assets, uint256 onBehalfSeed, address receiver) external { - receiver = _boundAddressNotZero(receiver); + vm.assume(receiver != address(0)); MarketParams memory _marketParams = _randomMarket(marketSeed); @@ -251,7 +251,7 @@ contract MorphoInvariantTest is InvariantTest { function borrowAssetsOnBehalfNoRevert(uint256 marketSeed, uint256 assets, uint256 onBehalfSeed, address receiver) external { - receiver = _boundAddressNotZero(receiver); + vm.assume(receiver != address(0)); MarketParams memory _marketParams = _randomMarket(marketSeed); @@ -305,7 +305,7 @@ contract MorphoInvariantTest is InvariantTest { uint256 onBehalfSeed, address receiver ) external { - receiver = _boundAddressNotZero(receiver); + vm.assume(receiver != address(0)); MarketParams memory _marketParams = _randomMarket(marketSeed);