From 9f3f8505d011d6772db662ac89160fd44033ea3d Mon Sep 17 00:00:00 2001 From: Patrick Kim Date: Sun, 27 Aug 2023 06:03:17 -0400 Subject: [PATCH] test: implement naming change suggestion --- test/forge/BaseTest.sol | 29 +++++++++---------- .../CreateMarketIntegrationTest.sol | 12 ++++---- .../integration/OnlyOwnerIntegrationTest.sol | 6 ++-- .../invariant/TwoMarketsInvariantTest.sol | 4 +-- .../periphery/MorphoBalancesLibTest.sol | 4 +-- .../libraries/periphery/MorphoLibTest.sol | 4 +-- .../periphery/MorphoStorageLibTest.sol | 8 ++--- 7 files changed, 33 insertions(+), 34 deletions(-) diff --git a/test/forge/BaseTest.sol b/test/forge/BaseTest.sol index 7429fafeb..1d83a08de 100644 --- a/test/forge/BaseTest.sol +++ b/test/forge/BaseTest.sol @@ -38,8 +38,6 @@ contract BaseTest is Test { address internal LIQUIDATOR = _addrFromHashedString("Morpho Liquidator"); address internal OWNER = _addrFromHashedString("Morpho Owner"); - uint256 internal LLTV = 0.8 ether; - Morpho internal morpho; ERC20 internal borrowableToken; ERC20 internal collateralToken; @@ -47,6 +45,7 @@ contract BaseTest is Test { Irm internal irm; MarketParams internal marketParams; Id internal id; + uint256 internal lltv; function setUp() public virtual { vm.label(OWNER, "Owner"); @@ -104,17 +103,17 @@ contract BaseTest is Test { morpho.setAuthorization(BORROWER, true); vm.stopPrank(); - _setLltv(LLTV); + _setLltv(0.8 ether); } - function _setLltv(uint256 lltv) internal { - LLTV = lltv; + function _setLltv(uint256 _lltv) internal { + lltv = _lltv; marketParams = - MarketParams(address(borrowableToken), address(collateralToken), address(oracle), address(irm), lltv); + MarketParams(address(borrowableToken), address(collateralToken), address(oracle), address(irm), _lltv); id = marketParams.id(); vm.startPrank(OWNER); - if (!morpho.isLltvEnabled(lltv)) morpho.enableLltv(lltv); + if (!morpho.isLltvEnabled(_lltv)) morpho.enableLltv(_lltv); if (morpho.lastUpdate(marketParams.id()) == 0) morpho.createMarket(marketParams); vm.stopPrank(); @@ -180,21 +179,21 @@ contract BaseTest is Test { return (amountCollateral, amountBorrowed, priceCollateral); } - function _boundTestLltv(uint256 lltv) internal view returns (uint256) { - return bound(lltv, MIN_TEST_LLTV, MAX_TEST_LLTV); + function _boundTestLltv(uint256 _lltv) internal view returns (uint256) { + return bound(_lltv, MIN_TEST_LLTV, MAX_TEST_LLTV); } - function _boundValidLltv(uint256 lltv) internal view returns (uint256) { - return bound(lltv, 0, WAD - 1); + function _boundValidLltv(uint256 _lltv) internal view returns (uint256) { + return bound(_lltv, 0, WAD - 1); } - function _boundInvalidLltv(uint256 lltv) internal view returns (uint256) { - return bound(lltv, WAD, type(uint256).max); + function _boundInvalidLltv(uint256 _lltv) internal view returns (uint256) { + return bound(_lltv, WAD, type(uint256).max); } - function _liquidationIncentive(uint256 lltv) internal pure returns (uint256) { + function _liquidationIncentive(uint256 _lltv) internal pure returns (uint256) { return - UtilsLib.min(MAX_LIQUIDATION_INCENTIVE_FACTOR, WAD.wDivDown(WAD - LIQUIDATION_CURSOR.wMulDown(WAD - lltv))); + UtilsLib.min(MAX_LIQUIDATION_INCENTIVE_FACTOR, WAD.wDivDown(WAD - LIQUIDATION_CURSOR.wMulDown(WAD - _lltv))); } function _accrueInterest(MarketParams memory market) internal { diff --git a/test/forge/integration/CreateMarketIntegrationTest.sol b/test/forge/integration/CreateMarketIntegrationTest.sol index 3c4d62fcf..f393c6550 100644 --- a/test/forge/integration/CreateMarketIntegrationTest.sol +++ b/test/forge/integration/CreateMarketIntegrationTest.sol @@ -9,7 +9,7 @@ contract CreateMarketIntegrationTest is BaseTest { using MarketParamsLib for MarketParams; function testCreateMarketWithNotEnabledIrmAndNotEnabledLltv(MarketParams memory marketParamsFuzz) public { - vm.assume(marketParamsFuzz.irm != address(irm) && marketParamsFuzz.lltv != LLTV); + vm.assume(marketParamsFuzz.irm != address(irm) && marketParamsFuzz.lltv != lltv); vm.prank(OWNER); vm.expectRevert(bytes(ErrorsLib.IRM_NOT_ENABLED)); @@ -21,7 +21,7 @@ contract CreateMarketIntegrationTest is BaseTest { marketParamsFuzz.lltv = _boundValidLltv(marketParamsFuzz.lltv); vm.startPrank(OWNER); - if (marketParamsFuzz.lltv != LLTV) morpho.enableLltv(marketParamsFuzz.lltv); + if (marketParamsFuzz.lltv != lltv) morpho.enableLltv(marketParamsFuzz.lltv); vm.expectRevert(bytes(ErrorsLib.IRM_NOT_ENABLED)); morpho.createMarket(marketParamsFuzz); @@ -29,7 +29,7 @@ contract CreateMarketIntegrationTest is BaseTest { } function testCreateMarketWithEnabledIrmAndNotEnabledLltv(MarketParams memory marketParamsFuzz) public { - vm.assume(marketParamsFuzz.lltv != LLTV); + vm.assume(marketParamsFuzz.lltv != lltv); vm.startPrank(OWNER); if (marketParamsFuzz.irm != marketParams.irm) morpho.enableIrm(marketParamsFuzz.irm); @@ -45,7 +45,7 @@ contract CreateMarketIntegrationTest is BaseTest { vm.startPrank(OWNER); if (marketParamsFuzz.irm != marketParams.irm) morpho.enableIrm(marketParamsFuzz.irm); - if (marketParamsFuzz.lltv != LLTV) morpho.enableLltv(marketParamsFuzz.lltv); + if (marketParamsFuzz.lltv != lltv) morpho.enableLltv(marketParamsFuzz.lltv); vm.expectEmit(true, true, true, true, address(morpho)); emit EventsLib.CreateMarket(marketParamsFuzz.id(), marketParamsFuzz); @@ -65,7 +65,7 @@ contract CreateMarketIntegrationTest is BaseTest { vm.startPrank(OWNER); if (marketParamsFuzz.irm != marketParams.irm) morpho.enableIrm(marketParamsFuzz.irm); - if (marketParamsFuzz.lltv != LLTV) morpho.enableLltv(marketParamsFuzz.lltv); + if (marketParamsFuzz.lltv != lltv) morpho.enableLltv(marketParamsFuzz.lltv); morpho.createMarket(marketParamsFuzz); vm.expectRevert(bytes(ErrorsLib.MARKET_ALREADY_CREATED)); @@ -79,7 +79,7 @@ contract CreateMarketIntegrationTest is BaseTest { vm.startPrank(OWNER); if (marketParamsFuzz.irm != marketParams.irm) morpho.enableIrm(marketParamsFuzz.irm); - if (marketParamsFuzz.lltv != LLTV) morpho.enableLltv(marketParamsFuzz.lltv); + if (marketParamsFuzz.lltv != lltv) morpho.enableLltv(marketParamsFuzz.lltv); morpho.createMarket(marketParamsFuzz); vm.stopPrank(); diff --git a/test/forge/integration/OnlyOwnerIntegrationTest.sol b/test/forge/integration/OnlyOwnerIntegrationTest.sol index 6ffe4f396..45f0be8de 100644 --- a/test/forge/integration/OnlyOwnerIntegrationTest.sol +++ b/test/forge/integration/OnlyOwnerIntegrationTest.sol @@ -65,7 +65,7 @@ contract OnlyOwnerIntegrationTest is BaseTest { function testEnableLltvWhenNotOwner(address addressFuzz, uint256 lltvFuzz) public { vm.assume(addressFuzz != OWNER); - vm.assume(lltvFuzz != LLTV); + vm.assume(lltvFuzz != lltv); vm.prank(addressFuzz); vm.expectRevert(bytes(ErrorsLib.NOT_OWNER)); @@ -75,7 +75,7 @@ contract OnlyOwnerIntegrationTest is BaseTest { function testEnableLltvAlreadySet() public { vm.prank(OWNER); vm.expectRevert(bytes(ErrorsLib.ALREADY_SET)); - morpho.enableLltv(LLTV); + morpho.enableLltv(lltv); } function testEnableTooHighLltv(uint256 lltvFuzz) public { @@ -88,7 +88,7 @@ contract OnlyOwnerIntegrationTest is BaseTest { function testEnableLltv(uint256 lltvFuzz) public { lltvFuzz = _boundValidLltv(lltvFuzz); - vm.assume(lltvFuzz != LLTV); + vm.assume(lltvFuzz != lltv); vm.prank(OWNER); vm.expectEmit(true, true, true, true, address(morpho)); diff --git a/test/forge/invariant/TwoMarketsInvariantTest.sol b/test/forge/invariant/TwoMarketsInvariantTest.sol index d0742273e..d37eac98c 100644 --- a/test/forge/invariant/TwoMarketsInvariantTest.sol +++ b/test/forge/invariant/TwoMarketsInvariantTest.sol @@ -20,12 +20,12 @@ contract TwoMarketsInvariantTest is InvariantTest { vm.label(address(irm2), "IRM2"); marketParams2 = - MarketParams(address(borrowableToken), address(collateralToken), address(oracle), address(irm2), LLTV + 1); + MarketParams(address(borrowableToken), address(collateralToken), address(oracle), address(irm2), lltv + 1); id2 = marketParams2.id(); vm.startPrank(OWNER); morpho.enableIrm(address(irm2)); - morpho.enableLltv(LLTV + 1); + morpho.enableLltv(lltv + 1); morpho.createMarket(marketParams2); vm.stopPrank(); diff --git a/test/forge/libraries/periphery/MorphoBalancesLibTest.sol b/test/forge/libraries/periphery/MorphoBalancesLibTest.sol index db813c80d..ea50c4064 100644 --- a/test/forge/libraries/periphery/MorphoBalancesLibTest.sol +++ b/test/forge/libraries/periphery/MorphoBalancesLibTest.sol @@ -121,13 +121,13 @@ contract MorphoBalancesLibTest is BaseTest { if (amountBorrowed > 0) { uint256 collateralPrice = IOracle(marketParams.oracle).price(); collateralToken.setBalance( - BORROWER, amountBorrowed.wDivUp(LLTV).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice) + BORROWER, amountBorrowed.wDivUp(lltv).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice) ); vm.startPrank(BORROWER); morpho.supplyCollateral( marketParams, - amountBorrowed.wDivUp(LLTV).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice), + amountBorrowed.wDivUp(lltv).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice), BORROWER, hex"" ); diff --git a/test/forge/libraries/periphery/MorphoLibTest.sol b/test/forge/libraries/periphery/MorphoLibTest.sol index af9b2f362..c763352c3 100644 --- a/test/forge/libraries/periphery/MorphoLibTest.sol +++ b/test/forge/libraries/periphery/MorphoLibTest.sol @@ -32,11 +32,11 @@ contract MorphoLibTest is BaseTest { morpho.supply(marketParams, amountSupplied, 0, address(this), hex""); uint256 collateralPrice = IOracle(marketParams.oracle).price(); - collateralToken.setBalance(BORROWER, amountBorrowed.wDivUp(LLTV).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice)); + collateralToken.setBalance(BORROWER, amountBorrowed.wDivUp(lltv).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice)); vm.startPrank(BORROWER); morpho.supplyCollateral( - marketParams, amountBorrowed.wDivUp(LLTV).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice), BORROWER, hex"" + marketParams, amountBorrowed.wDivUp(lltv).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice), BORROWER, hex"" ); morpho.borrow(marketParams, amountBorrowed, 0, BORROWER, BORROWER); vm.stopPrank(); diff --git a/test/forge/libraries/periphery/MorphoStorageLibTest.sol b/test/forge/libraries/periphery/MorphoStorageLibTest.sol index 56cfbc07f..3856b70d6 100644 --- a/test/forge/libraries/periphery/MorphoStorageLibTest.sol +++ b/test/forge/libraries/periphery/MorphoStorageLibTest.sol @@ -29,11 +29,11 @@ contract MorphoStorageLibTest is BaseTest { morpho.supply(marketParams, amountSupplied, 0, address(this), hex""); uint256 collateralPrice = IOracle(marketParams.oracle).price(); - collateralToken.setBalance(BORROWER, amountBorrowed.wDivUp(LLTV).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice)); + collateralToken.setBalance(BORROWER, amountBorrowed.wDivUp(lltv).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice)); vm.startPrank(BORROWER); morpho.supplyCollateral( - marketParams, amountBorrowed.wDivUp(LLTV).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice), BORROWER, hex"" + marketParams, amountBorrowed.wDivUp(lltv).mulDivUp(ORACLE_PRICE_SCALE, collateralPrice), BORROWER, hex"" ); morpho.borrow(marketParams, amountBorrowed, 0, BORROWER, BORROWER); vm.stopPrank(); @@ -63,7 +63,7 @@ contract MorphoStorageLibTest is BaseTest { slots[5] = MorphoStorageLib.marketTotalBorrowAssetsAndSharesSlot(id); slots[6] = MorphoStorageLib.marketLastUpdateAndFeeSlot(id); slots[7] = MorphoStorageLib.isIrmEnabledSlot(address(irm)); - slots[8] = MorphoStorageLib.isLltvEnabledSlot(LLTV); + slots[8] = MorphoStorageLib.isLltvEnabledSlot(lltv); slots[9] = MorphoStorageLib.isAuthorizedSlot(authorizer, BORROWER); slots[10] = MorphoStorageLib.nonceSlot(authorizer); slots[11] = MorphoStorageLib.idToBorrowableTokenSlot(id); @@ -86,7 +86,7 @@ contract MorphoStorageLibTest is BaseTest { assertEq(uint128(uint256(values[6])), morpho.lastUpdate(id)); assertEq(uint256(values[6] >> 128), morpho.fee(id)); assertEq(abi.decode(abi.encode(values[7]), (bool)), morpho.isIrmEnabled(address(irm))); - assertEq(abi.decode(abi.encode(values[8]), (bool)), morpho.isLltvEnabled(LLTV)); + assertEq(abi.decode(abi.encode(values[8]), (bool)), morpho.isLltvEnabled(lltv)); assertEq(abi.decode(abi.encode(values[9]), (bool)), morpho.isAuthorized(authorizer, BORROWER)); assertEq(uint256(values[10]), morpho.nonce(authorizer));