Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tests coverage #317

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/forge/integration/TestIntegrationAccrueInterests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ contract IntegrationAccrueInterestsTest is BaseTest {
using MathLib for uint256;
using SharesMathLib for uint256;

function testAccrueInterestsMarketNotCreated(Market memory marketFuzz) public {
vm.assume(neq(market, marketFuzz));

vm.expectRevert(bytes(ErrorsLib.MARKET_NOT_CREATED));
morpho.accrueInterests(marketFuzz);
}

function testAccrueInterestsNoTimeElapsed(uint256 amountSupplied, uint256 amountBorrowed) public {
amountSupplied = bound(amountSupplied, 2, MAX_TEST_AMOUNT);
amountBorrowed = bound(amountBorrowed, 1, amountSupplied);
Expand Down
33 changes: 20 additions & 13 deletions test/forge/integration/TestIntegrationCreateMarket.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ contract IntegrationCreateMarketTest is BaseTest {
marketFuzz.lltv = _boundValidLltv(marketFuzz.lltv);

vm.startPrank(OWNER);

vm.expectEmit(true, true, true, true, address(morpho));
emit EventsLib.EnableLltv(marketFuzz.lltv);
morpho.enableLltv(marketFuzz.lltv);
if (marketFuzz.lltv != LLTV) morpho.enableLltv(marketFuzz.lltv);
MathisGD marked this conversation as resolved.
Show resolved Hide resolved

vm.expectRevert(bytes(ErrorsLib.IRM_NOT_ENABLED));
morpho.createMarket(marketFuzz);
Expand All @@ -34,28 +31,25 @@ contract IntegrationCreateMarketTest is BaseTest {
vm.assume(marketFuzz.lltv != LLTV);

vm.startPrank(OWNER);

vm.expectEmit(true, true, true, true, address(morpho));
emit EventsLib.EnableIrm(marketFuzz.irm);
morpho.enableIrm(marketFuzz.irm);
if (marketFuzz.irm != market.irm) morpho.enableIrm(marketFuzz.irm);

vm.expectRevert(bytes(ErrorsLib.LLTV_NOT_ENABLED));
morpho.createMarket(marketFuzz);
vm.stopPrank();
}

function testCreateMarketWithEnabledIrmAndLltv(Market memory marketFuzz) public {
marketFuzz.lltv = LLTV;
marketFuzz.lltv = _boundValidLltv(marketFuzz.lltv);
Id marketFuzzId = marketFuzz.id();

vm.prank(OWNER);
vm.expectEmit(true, true, true, true, address(morpho));
emit EventsLib.EnableIrm(marketFuzz.irm);
morpho.enableIrm(marketFuzz.irm);
vm.startPrank(OWNER);
if (marketFuzz.irm != market.irm) morpho.enableIrm(marketFuzz.irm);
if (marketFuzz.lltv != LLTV) morpho.enableLltv(marketFuzz.lltv);

vm.expectEmit(true, true, true, true, address(morpho));
emit EventsLib.CreateMarket(marketFuzz.id(), marketFuzz);
morpho.createMarket(marketFuzz);
vm.stopPrank();

assertEq(morpho.lastUpdate(marketFuzzId), block.timestamp, "lastUpdate != block.timestamp");
assertEq(morpho.totalSupply(marketFuzzId), 0, "totalSupply != 0");
Expand All @@ -64,4 +58,17 @@ contract IntegrationCreateMarketTest is BaseTest {
assertEq(morpho.totalBorrowShares(marketFuzzId), 0, "totalBorrowShares != 0");
assertEq(morpho.fee(marketFuzzId), 0, "fee != 0");
}

function testCreateMarketAlreadyCreated(Market memory marketFuzz) public {
marketFuzz.lltv = _boundValidLltv(marketFuzz.lltv);

vm.startPrank(OWNER);
if (marketFuzz.irm != market.irm) morpho.enableIrm(marketFuzz.irm);
if (marketFuzz.lltv != LLTV) morpho.enableLltv(marketFuzz.lltv);
morpho.createMarket(marketFuzz);

vm.expectRevert(bytes(ErrorsLib.MARKET_CREATED));
morpho.createMarket(marketFuzz);
vm.stopPrank();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract IntegrationSupplyCollateralTest is BaseTest {

vm.prank(SUPPLIER);
vm.expectRevert(bytes(ErrorsLib.MARKET_NOT_CREATED));
morpho.supply(marketFuzz, amount, 0, SUPPLIER, hex"");
morpho.supplyCollateral(marketFuzz, amount, SUPPLIER, hex"");
}

function testSupplyCollateralZeroAmount(address SUPPLIER) public {
Expand Down