Skip to content

Commit dee5cfc

Browse files
authored
Merge pull request #695 from morpho-org/test/fix-precision-ci
Tests: fix CI with precise computations
2 parents 3886a78 + 208c886 commit dee5cfc

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

test/forge/BaseTest.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ contract BaseTest is Test {
189189
amountBorrowed.wDivDown(marketParams.lltv).mulDivDown(ORACLE_PRICE_SCALE, priceCollateral);
190190
amountCollateral = bound(amountCollateral, 0, Math.min(maxCollateral, MAX_COLLATERAL_ASSETS));
191191

192-
vm.assume(amountCollateral > 0);
192+
vm.assume(amountCollateral > 0 && amountCollateral < maxCollateral);
193193
return (amountCollateral, amountBorrowed, priceCollateral);
194194
}
195195

@@ -330,13 +330,15 @@ contract BaseTest is Test {
330330
{
331331
Id _id = _marketParams.id();
332332

333-
uint256 collateral = morpho.collateral(_id, borrower);
334333
uint256 collateralPrice = IOracle(_marketParams.oracle).price();
335-
uint256 maxRepaidAssets = morpho.expectedBorrowAssets(_marketParams, borrower);
334+
uint256 borrowShares = morpho.borrowShares(_id, borrower);
335+
(,, uint256 totalBorrowAssets, uint256 totalBorrowShares) = morpho.expectedMarketBalances(_marketParams);
336+
uint256 maxRepaidAssets = borrowShares.toAssetsDown(totalBorrowAssets, totalBorrowShares);
336337
uint256 maxSeizedAssets = maxRepaidAssets.wMulDown(_liquidationIncentiveFactor(_marketParams.lltv)).mulDivDown(
337338
ORACLE_PRICE_SCALE, collateralPrice
338339
);
339340

341+
uint256 collateral = morpho.collateral(_id, borrower);
340342
return bound(seizedAssets, 0, Math.min(collateral, maxSeizedAssets));
341343
}
342344

test/forge/invariant/MorphoInvariantTest.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,11 @@ contract MorphoInvariantTest is InvariantTest {
170170
{
171171
uint256 collateralPrice = oracle.price();
172172
uint256 liquidationIncentiveFactor = _liquidationIncentiveFactor(_marketParams.lltv);
173-
Market memory _market = morpho.market(_marketParams.id());
173+
(,, uint256 totalBorrowAssets, uint256 totalBorrowShares) = morpho.expectedMarketBalances(_marketParams);
174174
uint256 seizedAssetsQuoted = seizedAssets.mulDivUp(collateralPrice, ORACLE_PRICE_SCALE);
175-
uint256 repaidShares = seizedAssetsQuoted.wDivUp(liquidationIncentiveFactor).toSharesUp(
176-
_market.totalBorrowAssets, _market.totalBorrowShares
177-
);
178-
uint256 repaidAssets = repaidShares.toAssetsUp(_market.totalBorrowAssets, _market.totalBorrowShares);
175+
uint256 repaidShares =
176+
seizedAssetsQuoted.wDivUp(liquidationIncentiveFactor).toSharesUp(totalBorrowAssets, totalBorrowShares);
177+
uint256 repaidAssets = repaidShares.toAssetsUp(totalBorrowAssets, totalBorrowShares);
179178

180179
loanToken.setBalance(msg.sender, repaidAssets);
181180

0 commit comments

Comments
 (0)