Skip to content

Commit

Permalink
Merge pull request #870 from morpho-org/fix/ci-2
Browse files Browse the repository at this point in the history
refactor(test): revert renaming
  • Loading branch information
MerlinEgalite committed Jun 22, 2023
2 parents 3dbb8b9 + 24efe27 commit 852ad38
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 190 deletions.
240 changes: 79 additions & 161 deletions test/extensions/TestIntegrationBulkerGateway.sol

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/helpers/BaseTest.sol
Expand Up @@ -74,7 +74,7 @@ contract BaseTest is Test {
}

/// @dev Bounds the fuzzing input to a non-zero address.
function _boundAddressNotInvalid(address input) internal view virtual returns (address) {
function _boundAddressNotZero(address input) internal view virtual returns (address) {
return address(uint160(bound(uint256(uint160(input)), 1, type(uint160).max)));
}

Expand Down
8 changes: 4 additions & 4 deletions test/helpers/IntegrationTest.sol
Expand Up @@ -463,8 +463,8 @@ contract IntegrationTest is ForkTest {
return amount;
}

function _boundAddressNotInvalid(address input) internal view virtual override returns (address) {
input = super._boundAddressNotInvalid(input);
function _boundAddressValid(address input) internal view virtual returns (address) {
input = _boundAddressNotZero(input);

vm.assume(input != address(proxyAdmin)); // TransparentUpgradeableProxy: admin cannot fallback to proxy target.
vm.assume(input != 0x807a96288A1A408dBC13DE2b1d087d10356395d2); // Proxy admin for USDC.
Expand All @@ -473,13 +473,13 @@ contract IntegrationTest is ForkTest {
}

function _boundOnBehalf(address onBehalf) internal view returns (address) {
onBehalf = _boundAddressNotInvalid(onBehalf);
onBehalf = _boundAddressValid(onBehalf);

return onBehalf;
}

function _boundReceiver(address input) internal view returns (address output) {
output = _boundAddressNotInvalid(input);
output = _boundAddressValid(input);

vm.assume(output != address(this));

Expand Down
1 change: 1 addition & 0 deletions test/integration/TestIntegrationAssetAsCollateral.sol
Expand Up @@ -43,6 +43,7 @@ contract TestIntegrationAssetAsCollateral is IntegrationTest {
}

function testSetAssetIsCollateralShouldRevertWhenMarketNotCreated(address underlying) public {
_assumeNotUnderlying(underlying);
vm.expectRevert(Errors.MarketNotCreated.selector);
morpho.setAssetIsCollateral(underlying, true);
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/TestIntegrationClaimToTreasury.sol
Expand Up @@ -22,7 +22,7 @@ contract TestIntegrationClaimToTreasury is IntegrationTest {
}

function testShouldNotClaimToTreasuryIfMarketNotCreated(address treasuryVault, uint8 nbUnderlyings) public {
treasuryVault = _boundAddressNotInvalid(treasuryVault);
treasuryVault = _boundAddressValid(treasuryVault);
vm.assume(treasuryVault != address(morpho));

address[] memory claimedUnderlyings = new address[](nbUnderlyings);
Expand Down
2 changes: 1 addition & 1 deletion test/integration/TestIntegrationPermit2.sol
Expand Up @@ -291,7 +291,7 @@ contract TestIntegrationPermit2 is IntegrationTest {
deadline = bound(deadline, block.timestamp, type(uint32).max);
privateKey = bound(privateKey, 1, type(uint160).max);
address delegator = vm.addr(privateKey);
pranker = _boundAddressNotInvalid(pranker);
pranker = _boundAddressValid(pranker);
vm.assume(pranker != delegator && pranker.code.length == 0);

TestMarket storage market = testMarkets[_randomUnderlying(seed)];
Expand Down
2 changes: 1 addition & 1 deletion test/integration/TestIntegrationSupplyCollateral.sol
Expand Up @@ -59,7 +59,7 @@ contract TestIntegrationSupplyCollateral is IntegrationTest {
assertEq(test.borrows.length, 0, "borrows.length");

assertEq(morpho.supplyBalance(market.underlying, onBehalf), 0, "supply != 0");
assertApproxLeAbs(morpho.collateralBalance(market.underlying, onBehalf), amount, 1, "collateral != amount");
assertApproxLeAbs(morpho.collateralBalance(market.underlying, onBehalf), amount, 2, "collateral != amount");

// Assert Morpho's position on pool.
assertApproxEqAbs(
Expand Down
8 changes: 4 additions & 4 deletions test/integration/TestIntegrationWETHGateway.sol
Expand Up @@ -52,15 +52,15 @@ contract TestIntegrationWETHGateway is IntegrationTest {
}

function testCannotSupplyETHWhenAmountIsZero(address onBehalf) public {
onBehalf = _boundAddressNotInvalid(onBehalf);
onBehalf = _boundAddressValid(onBehalf);
assertEq(morpho.supplyBalance(weth, onBehalf), 0);

vm.expectRevert(Errors.AmountIsZero.selector);
_supplyETH(onBehalf, 0);
}

function testSupplyETH(uint256 amount, address onBehalf) public {
onBehalf = _boundAddressNotInvalid(onBehalf);
onBehalf = _boundAddressValid(onBehalf);
assertEq(morpho.supplyBalance(weth, onBehalf), 0);

amount = bound(amount, MIN_AMOUNT, type(uint96).max);
Expand All @@ -76,15 +76,15 @@ contract TestIntegrationWETHGateway is IntegrationTest {
}

function testCannotSupplyCollateralETHWhenAmountIsZero(address onBehalf) public {
onBehalf = _boundAddressNotInvalid(onBehalf);
onBehalf = _boundAddressValid(onBehalf);
assertEq(morpho.collateralBalance(weth, onBehalf), 0);

vm.expectRevert(Errors.AmountIsZero.selector);
_supplyCollateralETH(onBehalf, 0);
}

function testSupplyCollateralETH(uint256 amount, address onBehalf) public {
onBehalf = _boundAddressNotInvalid(onBehalf);
onBehalf = _boundAddressValid(onBehalf);
assertEq(morpho.collateralBalance(weth, onBehalf), 0);

amount = bound(amount, MIN_AMOUNT, type(uint96).max);
Expand Down
8 changes: 4 additions & 4 deletions test/internal/TestInternalEMode.sol
Expand Up @@ -149,7 +149,7 @@ contract TestInternalEMode is InternalTest, PositionsManagerInternal {
uint8 eModeCategoryId
) public {
eModeCategoryId = uint8(bound(eModeCategoryId, 1, type(uint8).max));
priceSourceEMode = _boundAddressNotInvalid(priceSourceEMode);
priceSourceEMode = _boundAddressNotZero(priceSourceEMode);
vm.assume(underlying != priceSourceEMode);
underlyingPriceEMode = bound(underlyingPriceEMode, 1, type(uint256).max);
underlyingPrice = bound(underlyingPrice, 0, type(uint256).max);
Expand Down Expand Up @@ -177,7 +177,7 @@ contract TestInternalEMode is InternalTest, PositionsManagerInternal {
uint8 eModeCategoryId
) public {
eModeCategoryId = uint8(bound(eModeCategoryId, 1, type(uint8).max));
underlying = _boundAddressNotInvalid(underlying);
underlying = _boundAddressNotZero(underlying);
underlyingPriceEMode = bound(underlyingPriceEMode, 1, type(uint256).max);
underlyingPrice = bound(underlyingPrice, 0, type(uint256).max);

Expand All @@ -203,7 +203,7 @@ contract TestInternalEMode is InternalTest, PositionsManagerInternal {
uint256 underlyingPrice,
uint8 eModeCategoryId
) public {
priceSourceEMode = _boundAddressNotInvalid(priceSourceEMode);
priceSourceEMode = _boundAddressNotZero(priceSourceEMode);
vm.assume(underlying != priceSourceEMode);
underlyingPriceEMode = bound(underlyingPriceEMode, 1, type(uint256).max);
underlyingPrice = bound(underlyingPrice, 0, type(uint256).max);
Expand All @@ -229,7 +229,7 @@ contract TestInternalEMode is InternalTest, PositionsManagerInternal {
uint8 eModeCategoryId
) public {
eModeCategoryId = uint8(bound(eModeCategoryId, 1, type(uint8).max));
priceSourceEMode = _boundAddressNotInvalid(priceSourceEMode);
priceSourceEMode = _boundAddressNotZero(priceSourceEMode);
vm.assume(underlying != priceSourceEMode);
underlyingPrice = bound(underlyingPrice, 0, type(uint256).max);

Expand Down
18 changes: 9 additions & 9 deletions test/internal/TestInternalMorphoInternal.sol
Expand Up @@ -228,7 +228,7 @@ contract TestInternalMorphoInternal is InternalTest {
}

function testUpdateInDSWithSuppliers(address user, uint256 onPool, uint256 inP2P, bool head) public {
user = _boundAddressNotInvalid(user);
user = _boundAddressNotZero(user);
onPool = bound(onPool, Constants.DUST_THRESHOLD + 1, type(uint96).max);
inP2P = bound(inP2P, Constants.DUST_THRESHOLD + 1, type(uint96).max);

Expand All @@ -242,7 +242,7 @@ contract TestInternalMorphoInternal is InternalTest {
}

function testUpdateInDSWithBorrowers(address user, uint256 onPool, uint256 inP2P, bool head) public {
user = _boundAddressNotInvalid(user);
user = _boundAddressNotZero(user);
onPool = bound(onPool, Constants.DUST_THRESHOLD + 1, type(uint96).max);
inP2P = bound(inP2P, Constants.DUST_THRESHOLD + 1, type(uint96).max);

Expand All @@ -256,7 +256,7 @@ contract TestInternalMorphoInternal is InternalTest {
}

function testUpdateInDSWithDust(address user, uint256 onPool, uint256 inP2P, bool head) public {
user = _boundAddressNotInvalid(user);
user = _boundAddressNotZero(user);
onPool = bound(onPool, 0, Constants.DUST_THRESHOLD);
inP2P = bound(inP2P, 0, Constants.DUST_THRESHOLD);

Expand All @@ -277,7 +277,7 @@ contract TestInternalMorphoInternal is InternalTest {
}

function testUpdateSupplierInDS(address user, uint256 onPool, uint256 inP2P, bool head) public {
user = _boundAddressNotInvalid(user);
user = _boundAddressNotZero(user);
onPool = bound(onPool, Constants.DUST_THRESHOLD + 1, type(uint96).max);
inP2P = bound(inP2P, Constants.DUST_THRESHOLD + 1, type(uint96).max);

Expand All @@ -289,7 +289,7 @@ contract TestInternalMorphoInternal is InternalTest {
}

function testUpdateSupplierInDSWithDust(address user, uint256 onPool, uint256 inP2P, bool head) public {
user = _boundAddressNotInvalid(user);
user = _boundAddressNotZero(user);
onPool = bound(onPool, 0, Constants.DUST_THRESHOLD);
inP2P = bound(inP2P, 0, Constants.DUST_THRESHOLD);

Expand All @@ -301,7 +301,7 @@ contract TestInternalMorphoInternal is InternalTest {
}

function testUpdateBorrowerInDS(address user, uint256 onPool, uint256 inP2P, bool head) public {
user = _boundAddressNotInvalid(user);
user = _boundAddressNotZero(user);
onPool = bound(onPool, Constants.DUST_THRESHOLD + 1, type(uint96).max);
inP2P = bound(inP2P, Constants.DUST_THRESHOLD + 1, type(uint96).max);

Expand All @@ -314,7 +314,7 @@ contract TestInternalMorphoInternal is InternalTest {
}

function testUpdateBorrowerInDSWithDust(address user, uint256 onPool, uint256 inP2P, bool head) public {
user = _boundAddressNotInvalid(user);
user = _boundAddressNotZero(user);
onPool = bound(onPool, 0, Constants.DUST_THRESHOLD);
inP2P = bound(inP2P, 0, Constants.DUST_THRESHOLD);

Expand All @@ -334,7 +334,7 @@ contract TestInternalMorphoInternal is InternalTest {
uint256 p2pSupplyIndex,
bool head
) public {
user = _boundAddressNotInvalid(user);
user = _boundAddressNotZero(user);
onPool = bound(onPool, Constants.DUST_THRESHOLD + 1, type(uint96).max);
inP2P = bound(inP2P, Constants.DUST_THRESHOLD + 1, type(uint96).max);
poolSupplyIndex = bound(poolSupplyIndex, MIN_INDEX, MAX_INDEX);
Expand All @@ -360,7 +360,7 @@ contract TestInternalMorphoInternal is InternalTest {
uint256 p2pBorrowIndex,
bool head
) public {
user = _boundAddressNotInvalid(user);
user = _boundAddressNotZero(user);
onPool = bound(onPool, Constants.DUST_THRESHOLD + 1, type(uint96).max);
inP2P = bound(inP2P, Constants.DUST_THRESHOLD + 1, type(uint96).max);
poolBorrowIndex = bound(poolBorrowIndex, MIN_INDEX, MAX_INDEX);
Expand Down
8 changes: 4 additions & 4 deletions test/internal/TestInternalPositionsManagerInternal.sol
Expand Up @@ -251,7 +251,7 @@ contract TestInternalPositionsManagerInternal is InternalTest, PositionsManagerI

function testAuthorizeLiquidateShouldRevertIfSentinelDisallows(address borrower, uint256 healthFactor) public {
_market[dai].isCollateral = true;
borrower = _boundAddressNotInvalid(borrower);
borrower = _boundAddressNotZero(borrower);
healthFactor = bound(
healthFactor,
Constants.DEFAULT_LIQUIDATION_MIN_HF.percentAdd(1),
Expand All @@ -268,7 +268,7 @@ contract TestInternalPositionsManagerInternal is InternalTest, PositionsManagerI

function testAuthorizeLiquidateShouldRevertIfBorrowerHealthy(address borrower, uint256 healthFactor) public {
_market[dai].isCollateral = true;
borrower = _boundAddressNotInvalid(borrower);
borrower = _boundAddressNotZero(borrower);
healthFactor = bound(healthFactor, Constants.DEFAULT_LIQUIDATION_MAX_HF.percentAdd(1), type(uint128).max);

_setHealthFactor(borrower, dai, healthFactor);
Expand All @@ -281,7 +281,7 @@ contract TestInternalPositionsManagerInternal is InternalTest, PositionsManagerI
public
{
_market[dai].isCollateral = true;
borrower = _boundAddressNotInvalid(borrower);
borrower = _boundAddressNotZero(borrower);
healthFactor = bound(healthFactor, 0, Constants.DEFAULT_LIQUIDATION_MIN_HF.percentSub(1));

_setHealthFactor(borrower, dai, healthFactor);
Expand All @@ -295,7 +295,7 @@ contract TestInternalPositionsManagerInternal is InternalTest, PositionsManagerI
uint256 healthFactor
) public {
_market[dai].isCollateral = true;
borrower = _boundAddressNotInvalid(borrower);
borrower = _boundAddressNotZero(borrower);
healthFactor = bound(
healthFactor,
Constants.DEFAULT_LIQUIDATION_MIN_HF.percentAdd(1),
Expand Down

0 comments on commit 852ad38

Please sign in to comment.