From 74bffda39bdab139c33f67dfc6cc77f24da47841 Mon Sep 17 00:00:00 2001 From: Rubilmax Date: Wed, 20 Sep 2023 14:17:02 +0200 Subject: [PATCH] refactor(test): move debt initialization to fee test --- test/forge/FeeTest.sol | 19 ++++++++++++ test/forge/helpers/BaseTest.sol | 55 ++++++++++++--------------------- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/test/forge/FeeTest.sol b/test/forge/FeeTest.sol index fe5cf7d0..9b9dbdc2 100644 --- a/test/forge/FeeTest.sol +++ b/test/forge/FeeTest.sol @@ -11,6 +11,25 @@ contract FeeTest is BaseTest { function setUp() public override { super.setUp(); + for (uint256 i; i < NB_MARKETS; ++i) { + MarketParams memory marketParams = allMarkets[i]; + + // Create some debt on the market to accrue interest. + + borrowableToken.setBalance(SUPPLIER, 1); + + vm.prank(SUPPLIER); + morpho.supply(marketParams, 1, 0, ONBEHALF, hex""); + + uint256 borrowed = uint256(1).wDivUp(marketParams.lltv); + collateralToken.setBalance(BORROWER, borrowed); + + vm.startPrank(BORROWER); + morpho.supplyCollateral(marketParams, borrowed, BORROWER, hex""); + morpho.borrow(marketParams, 1, 0, BORROWER, BORROWER); + vm.stopPrank(); + } + _setCap(allMarkets[0], CAP); } diff --git a/test/forge/helpers/BaseTest.sol b/test/forge/helpers/BaseTest.sol index 080e90de..07ff6887 100644 --- a/test/forge/helpers/BaseTest.sol +++ b/test/forge/helpers/BaseTest.sol @@ -95,6 +95,9 @@ contract BaseTest is Test { morpho.setFeeRecipient(MORPHO_FEE_RECIPIENT); vm.stopPrank(); + // block.timestamp defaults to 1 which is an unrealistic state: block.timestamp < TIMELOCK. + vm.warp(block.timestamp + TIMELOCK); + vm.startPrank(OWNER); vault = new MetaMorpho(address(morpho), TIMELOCK, address(borrowableToken), "MetaMorpho Vault", "MMV"); @@ -106,30 +109,6 @@ contract BaseTest is Test { _setFee(FEE); - borrowableToken.approve(address(vault), type(uint256).max); - collateralToken.approve(address(vault), type(uint256).max); - - vm.startPrank(SUPPLIER); - borrowableToken.approve(address(vault), type(uint256).max); - collateralToken.approve(address(vault), type(uint256).max); - borrowableToken.approve(address(morpho), type(uint256).max); - collateralToken.approve(address(morpho), type(uint256).max); - vm.stopPrank(); - - vm.prank(BORROWER); - collateralToken.approve(address(morpho), type(uint256).max); - - vm.prank(REPAYER); - borrowableToken.approve(address(morpho), type(uint256).max); - - vm.startPrank(ONBEHALF); - borrowableToken.approve(address(vault), type(uint256).max); - collateralToken.approve(address(vault), type(uint256).max); - vm.stopPrank(); - - // block.timestamp defaults to 1 which is an unrealistic state. - vm.warp(block.timestamp + TIMELOCK); - for (uint256 i; i < NB_MARKETS; ++i) { uint256 lltv = 0.8 ether / (i + 1); @@ -147,22 +126,28 @@ contract BaseTest is Test { vm.stopPrank(); allMarkets.push(marketParams); + } - // Create some debt on the market to accrue interest. + borrowableToken.approve(address(vault), type(uint256).max); + collateralToken.approve(address(vault), type(uint256).max); - borrowableToken.setBalance(SUPPLIER, 1); + vm.startPrank(SUPPLIER); + borrowableToken.approve(address(vault), type(uint256).max); + collateralToken.approve(address(vault), type(uint256).max); + borrowableToken.approve(address(morpho), type(uint256).max); + collateralToken.approve(address(morpho), type(uint256).max); + vm.stopPrank(); - vm.prank(SUPPLIER); - morpho.supply(marketParams, 1, 0, ONBEHALF, hex""); + vm.prank(BORROWER); + collateralToken.approve(address(morpho), type(uint256).max); - uint256 borrowed = uint256(1).wDivUp(lltv); - collateralToken.setBalance(BORROWER, borrowed); + vm.prank(REPAYER); + borrowableToken.approve(address(morpho), type(uint256).max); - vm.startPrank(BORROWER); - morpho.supplyCollateral(marketParams, borrowed, BORROWER, hex""); - morpho.borrow(marketParams, 1, 0, BORROWER, BORROWER); - vm.stopPrank(); - } + vm.startPrank(ONBEHALF); + borrowableToken.approve(address(vault), type(uint256).max); + collateralToken.approve(address(vault), type(uint256).max); + vm.stopPrank(); } function _addrFromHashedString(string memory name) internal returns (address addr) {