Skip to content

Commit

Permalink
Merge pull request #695 from morpho-org/test/fix-precision-ci
Browse files Browse the repository at this point in the history
Tests: fix CI with precise computations
  • Loading branch information
MathisGD authored Sep 30, 2024
2 parents 3886a78 + 208c886 commit dee5cfc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 5 additions & 3 deletions test/forge/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ contract BaseTest is Test {
amountBorrowed.wDivDown(marketParams.lltv).mulDivDown(ORACLE_PRICE_SCALE, priceCollateral);
amountCollateral = bound(amountCollateral, 0, Math.min(maxCollateral, MAX_COLLATERAL_ASSETS));

vm.assume(amountCollateral > 0);
vm.assume(amountCollateral > 0 && amountCollateral < maxCollateral);
return (amountCollateral, amountBorrowed, priceCollateral);
}

Expand Down Expand Up @@ -330,13 +330,15 @@ contract BaseTest is Test {
{
Id _id = _marketParams.id();

uint256 collateral = morpho.collateral(_id, borrower);
uint256 collateralPrice = IOracle(_marketParams.oracle).price();
uint256 maxRepaidAssets = morpho.expectedBorrowAssets(_marketParams, borrower);
uint256 borrowShares = morpho.borrowShares(_id, borrower);
(,, uint256 totalBorrowAssets, uint256 totalBorrowShares) = morpho.expectedMarketBalances(_marketParams);
uint256 maxRepaidAssets = borrowShares.toAssetsDown(totalBorrowAssets, totalBorrowShares);
uint256 maxSeizedAssets = maxRepaidAssets.wMulDown(_liquidationIncentiveFactor(_marketParams.lltv)).mulDivDown(
ORACLE_PRICE_SCALE, collateralPrice
);

uint256 collateral = morpho.collateral(_id, borrower);
return bound(seizedAssets, 0, Math.min(collateral, maxSeizedAssets));
}

Expand Down
9 changes: 4 additions & 5 deletions test/forge/invariant/MorphoInvariantTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,11 @@ contract MorphoInvariantTest is InvariantTest {
{
uint256 collateralPrice = oracle.price();
uint256 liquidationIncentiveFactor = _liquidationIncentiveFactor(_marketParams.lltv);
Market memory _market = morpho.market(_marketParams.id());
(,, uint256 totalBorrowAssets, uint256 totalBorrowShares) = morpho.expectedMarketBalances(_marketParams);
uint256 seizedAssetsQuoted = seizedAssets.mulDivUp(collateralPrice, ORACLE_PRICE_SCALE);
uint256 repaidShares = seizedAssetsQuoted.wDivUp(liquidationIncentiveFactor).toSharesUp(
_market.totalBorrowAssets, _market.totalBorrowShares
);
uint256 repaidAssets = repaidShares.toAssetsUp(_market.totalBorrowAssets, _market.totalBorrowShares);
uint256 repaidShares =
seizedAssetsQuoted.wDivUp(liquidationIncentiveFactor).toSharesUp(totalBorrowAssets, totalBorrowShares);
uint256 repaidAssets = repaidShares.toAssetsUp(totalBorrowAssets, totalBorrowShares);

loanToken.setBalance(msg.sender, repaidAssets);

Expand Down

0 comments on commit dee5cfc

Please sign in to comment.