Lesson 12 testMustImproveHealthFactorOnLiquidation Revert Error #1934
-
When I try and run the testMustImproveHealthFactorOnLiquidation test I get an error and it says that it reverts with DSCEngine__BreaksHealthFactor instead of DSCEngine__HealthFactorNotImproved. Below I will show the error, DSCEngineTest.t.sol, and DSCEngine. I made sure the MockMoreDebtDSC.sol file is correct. I found something that fixes this error, but I don't know if it is necessarily a good thing because there might be an issue in my code somewhere else. Here is the error(just the end):
Here is my code. I cut out some to make it shorter.
DSCEngineTest.t.sol:
Like I said at the beginning I found some solutions to make the test pass but I don't know if this means that this area of my code is actually safe or if I am just jumping around the error to get it to pass. If this was in production and someone needed 10 times more Amount_Minted to be liquidated as I stated worked in my first solution I don't think that would be a good thing since they should be liquidated as soon as possible. Maybe I am wrong but I am just not sure. If anyone can help me with this that would be great. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Hello @LanceAddison, I will say don't manipulate values to make the test pass. That might not be an appropriate solution, but instead, take time to look into the function _calculateHealthFactor(uint256 totalDscMinted, uint256 collateralValueInUsd)
internal
pure
returns (uint256)
{
if (totalDscMinted == 0) {
return type(uint256).max;
}
uint256 collateralAdjustedForThreshold = (collateralValueInUsd * LIQUIDATION_THRESHOLD) / LIQUIDATION_PRECISION;
return (collateralAdjustedForThreshold * PRECISION) / totalDscMinted;
} |
Beta Was this translation helpful? Give feedback.
Well, I figure out the issue. The MockMoreDebtDSC.sol contract was the issue. I just copy pasted my DecentralizedStableCoin.sol contract to the MockMoreDebtDSC contract and updated the constructor to not be empty and to instead have the
mockAggregator = _mockAggregator
line. What I didn't do was addMockV3Aggregator(mockAggregator).updateAnswer(0)
to the burn function which caused the price to be incorrect in my test. Now looking back on it it was a stupid mistake on my end since obviously just adding themockAggregator = _mockAggregator
part to the constructor won't do anything because I didn't actually use it anywhere. Thanks for trying to help anyway even though what I supplied would h…