Skip to content

Commit

Permalink
refactor(test): move debt initialization to fee test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Sep 20, 2023
1 parent 3650c46 commit 74bffda
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
19 changes: 19 additions & 0 deletions test/forge/FeeTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
55 changes: 20 additions & 35 deletions test/forge/helpers/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit 74bffda

Please sign in to comment.