-
Notifications
You must be signed in to change notification settings - Fork 1k
Need Help With Liquidation Tests... #2014
Replies: 2 comments · 4 replies
-
Hello @AllenOps08, import |
Beta Was this translation helpful? Give feedback.
All reactions
-
Yo bro @EngrPips here's it...Looks like the collateralValue is 0 here....
|
Beta Was this translation helpful? Give feedback.
All reactions
-
Also Here's my DSCEngine
|
Beta Was this translation helpful? Give feedback.
All reactions
-
You pranked modifier depositedCollateral() {
vm.startPrank(USER);
ERC20Mock(weth).approve(address(dsce), AMOUNT_COLLATERAL);
dsce.depositCollateral(weth, AMOUNT_COLLATERAL);
vm.stopPrank();
_;
} And then you come inside here and didnt prank function testIfLiquidatesCorrectly() public depositedCollateral {
//Setup , done
//Provide collateral and mint dsc for the user , done
dsce.mintDsc(DEBT_AMOUNT/20);
//Check health factor
uint256 userHealthFactor = dsce.getHealthFactor(USER);
assertLt(userHealthFactor, dsce.MIN_HEALTH_FACTOR());
//Prepare the liquidator
vm.startPrank(liquidator);
uint256 debtToCover = DEBT_AMOUNT/4;
uint256 liquidatorCollateral = 10 ether;
ERC20Mock(weth).mint(liquidator, debtToCover);
ERC20Mock(weth).approve(address(dsce), debtToCover);
// Deposit more collateral than the debt to ensure a good health factor
dsce.depositCollateralAndMintDSC(weth, liquidatorCollateral, debtToCover);
dsc.approve(address(dsce), debtToCover);
//Record balances after liquidation
uint256 liquidatorWethBefore = ERC20Mock(weth).balanceOf(liquidator);
uint256 liquidatorDscBefore = dsc.balanceOf(liquidator);
uint256 userWethBefore = ERC20Mock(weth).balanceOf(USER);
uint256 userDscBefore = dsc.balanceOf(USER);
//Perform liquidation
dsce.liquidate(liquidator, USER, debtToCover);
vm.stopPrank();
//Check balances after liquidation
uint256 liquidatorWethAfter = ERC20Mock(weth).balanceOf(liquidator);
uint256 liquidatorDscAfter = dsc.balanceOf(liquidator);
uint256 userWethAfter = ERC20Mock(weth).balanceOf(USER);
uint256 userDscAfter = dsc.balanceOf(USER);
assertLt(liquidatorWethAfter, liquidatorWethBefore, "Liquidator WETH should decrease");
assertGt(liquidatorDscAfter, liquidatorDscBefore, "Liquidator DSC amount should increase");
assertLt(userWethAfter, userWethBefore, "User WETH should decrease");
assertEq(userDscAfter, userDscBefore - debtToCover, "User DSC should decrease by debtToCover");
//Check health factor improvement
uint256 userHealthFactorAfter = dsce.getHealthFactor(USER);
assertGt(userHealthFactorAfter, userHealthFactor, "User health factor should improve");
} If anything is confusing please ask questions @AllenOps08. |
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes...Got another error..
Tried to refractor the code a bit....
|
Beta Was this translation helpful? Give feedback.
All reactions
-
A different error means you are making progress. Now, you need to go through your test step by step to discover why your assert reverted. |
Beta Was this translation helpful? Give feedback.
-
Hey so i was writing some tests for liquidation function ...
And got this error
The problem is that the health factor is breaking and I don't know how to fix it.
This is my DSCTEST file
and this is my health factor function , tried to refractor it by adding a error
Beta Was this translation helpful? Give feedback.
All reactions