Skip to content

Commit 8f4c620

Browse files
authored
Merge pull request #681 from morpho-org/test/bound-improve
Improve bounds in tests
2 parents d36719d + 6660947 commit 8f4c620

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

test/forge/BaseTest.sol

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,6 @@ contract BaseTest is Test {
139139
return bound(blocks, 1, type(uint32).max);
140140
}
141141

142-
/// @dev Bounds the fuzzing input to a non-zero address.
143-
/// @dev This function should be used in place of `vm.assume` in invariant test handler functions:
144-
/// https://github.com/foundry-rs/foundry/issues/4190.
145-
function _boundAddressNotZero(address input) internal view virtual returns (address) {
146-
return address(uint160(bound(uint256(uint160(input)), 1, type(uint160).max)));
147-
}
148-
149142
function _supply(uint256 amount) internal {
150143
loanToken.setBalance(address(this), amount);
151144
morpho.supply(marketParams, amount, 0, address(this), hex"");
@@ -194,7 +187,7 @@ contract BaseTest is Test {
194187

195188
uint256 maxCollateral =
196189
amountBorrowed.wDivDown(marketParams.lltv).mulDivDown(ORACLE_PRICE_SCALE, priceCollateral);
197-
amountCollateral = bound(amountBorrowed, 0, Math.min(maxCollateral, MAX_COLLATERAL_ASSETS));
190+
amountCollateral = bound(amountCollateral, 0, Math.min(maxCollateral, MAX_COLLATERAL_ASSETS));
198191

199192
vm.assume(amountCollateral > 0);
200193
return (amountCollateral, amountBorrowed, priceCollateral);

test/forge/invariant/MorphoInvariantTest.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ contract MorphoInvariantTest is InvariantTest {
235235
function withdrawAssetsOnBehalfNoRevert(uint256 marketSeed, uint256 assets, uint256 onBehalfSeed, address receiver)
236236
external
237237
{
238-
receiver = _boundAddressNotZero(receiver);
238+
vm.assume(receiver != address(0));
239239

240240
MarketParams memory _marketParams = _randomMarket(marketSeed);
241241

@@ -251,7 +251,7 @@ contract MorphoInvariantTest is InvariantTest {
251251
function borrowAssetsOnBehalfNoRevert(uint256 marketSeed, uint256 assets, uint256 onBehalfSeed, address receiver)
252252
external
253253
{
254-
receiver = _boundAddressNotZero(receiver);
254+
vm.assume(receiver != address(0));
255255

256256
MarketParams memory _marketParams = _randomMarket(marketSeed);
257257

@@ -305,7 +305,7 @@ contract MorphoInvariantTest is InvariantTest {
305305
uint256 onBehalfSeed,
306306
address receiver
307307
) external {
308-
receiver = _boundAddressNotZero(receiver);
308+
vm.assume(receiver != address(0));
309309

310310
MarketParams memory _marketParams = _randomMarket(marketSeed);
311311

0 commit comments

Comments
 (0)