Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RickGriff committed Sep 19, 2024
1 parent f83569c commit 3ad1127
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions contracts/src/test/OracleMainnet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ contract OraclesMainnet is TestAccounts {
assertEq(contractsArray[1].troveManager.shutdownTime(), block.timestamp);
}

function testFetchPriceReturnsETHUSDxCanonicalWhenRETHETHOracleFails() public {
function testFetchPriceReturnsMinETHUSDxCanonicalAndLastGoodPriceWhenRETHETHOracleFails() public {
// Make the RETH-ETH oracle stale
vm.etch(address(rethOracle), address(mockOracle).code);
(,,, uint256 updatedAt,) = rethOracle.latestRoundData();
Expand All @@ -724,9 +724,10 @@ contract OraclesMainnet is TestAccounts {
uint256 exchangeRate = rethToken.getExchangeRate();
assertGt(ethUsdPrice, 0);
assertGt(exchangeRate, 0);
uint256 expectedPrice = ethUsdPrice * exchangeRate / 1e18;

assertEq(price, expectedPrice);
uint256 expectedPrice = LiquityMath._min(rethPriceFeed.lastGoodPrice(), ethUsdPrice * exchangeRate / 1e18);

assertEq(price, expectedPrice, "price not expected price");
}

function testRETHPriceSourceIsETHUSDxCanonicalWhenRETHETHFails() public {
Expand Down Expand Up @@ -1139,7 +1140,7 @@ contract OraclesMainnet is TestAccounts {
assertEq(contractsArray[2].troveManager.shutdownTime(), block.timestamp);
}

function testFetchPriceReturnsETHUSDxCanonicalWhenSTETHUSDOracleFails() public {
function testFetchPriceReturnsMinETHUSDxCanonicalAndLastGoodPriceWhenSTETHUSDOracleFails() public {
// Make the STETH-USD oracle stale
vm.etch(address(stethOracle), address(mockOracle).code);
(,,, uint256 updatedAt,) = stethOracle.latestRoundData();
Expand All @@ -1151,14 +1152,16 @@ contract OraclesMainnet is TestAccounts {
// Check that the primary calc oracle did fail
assertTrue(oracleFailedWhileBranchLive);


// Calc expected price i.e. ETH-USD x canonical
uint256 ethUsdPrice = _getLatestAnswerFromOracle(ethOracle);
uint256 exchangeRate = wstETH.stEthPerToken();
assertGt(ethUsdPrice, 0);
assertGt(exchangeRate, 0);
uint256 expectedPrice = ethUsdPrice * exchangeRate / 1e18;

assertEq(price, expectedPrice);
uint256 expectedPrice = LiquityMath._min(wstethPriceFeed.lastGoodPrice(), ethUsdPrice * exchangeRate / 1e18);

assertEq(price, expectedPrice, "price not expected price");
}

function testSTETHPriceSourceIsETHUSDxCanonicalWhenSTETHUSDOracleFails() public {
Expand Down

0 comments on commit 3ad1127

Please sign in to comment.