Skip to content

Commit

Permalink
Remove warnings from tests and mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
RickGriff committed Nov 6, 2024
1 parent bdb6492 commit 1bb9c46
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 35 deletions.
54 changes: 26 additions & 28 deletions contracts/src/test/OracleMainnet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ contract OraclesMainnet is TestAccounts {
assertEq(updatedAt, block.timestamp - 7 days);

// Fetch price again
(uint256 price, bool oracleFailedWhileBranchLive) = rethPriceFeed.fetchPrice();
(, bool oracleFailedWhileBranchLive) = rethPriceFeed.fetchPrice();

assertTrue(oracleFailedWhileBranchLive);

Expand Down Expand Up @@ -795,7 +795,7 @@ contract OraclesMainnet is TestAccounts {
assertEq(updatedAt, block.timestamp - 7 days);

// Fetch price again
(uint256 price, bool oracleFailedWhileBranchLive) = rethPriceFeed.fetchPrice();
(, bool oracleFailedWhileBranchLive) = rethPriceFeed.fetchPrice();

assertTrue(oracleFailedWhileBranchLive);

Expand Down Expand Up @@ -881,7 +881,6 @@ contract OraclesMainnet is TestAccounts {
uint256 exchangeRate = rethToken.getExchangeRate();
assertGt(ethUsdPrice, 0);
assertGt(exchangeRate, 0);
uint256 priceIfDidntFail = ethUsdPrice * exchangeRate / 1e18;

// Make the exchange rate return 0
vm.etch(address(rethToken), address(mockRethToken).code);
Expand Down Expand Up @@ -1039,7 +1038,7 @@ contract OraclesMainnet is TestAccounts {
assertEq(updatedAt, block.timestamp - 7 days);

// Fetch price again
(uint256 price, bool oracleFailedWhileBranchLive) = rethPriceFeed.fetchPrice();
rethPriceFeed.fetchPrice();

// Check using lastGoodPrice
assertEq(uint8(rethPriceFeed.priceSource()), uint8(IMainnetPriceFeed.PriceSource.lastGoodPrice));
Expand Down Expand Up @@ -1112,7 +1111,7 @@ contract OraclesMainnet is TestAccounts {
assertGt(mockPrice, 0, "mockPrice 0");

// Fetch price again
(uint256 price2, bool oracleFailedWhileBranchLive) = wstethPriceFeed.fetchPrice();
(, bool oracleFailedWhileBranchLive) = wstethPriceFeed.fetchPrice();

// Check ncall failed
assertTrue(oracleFailedWhileBranchLive);
Expand Down Expand Up @@ -1230,7 +1229,7 @@ contract OraclesMainnet is TestAccounts {
assertEq(updatedAt, block.timestamp - 7 days);

// Fetch price
(uint256 price, bool oracleFailedWhileBranchLive) = wstethPriceFeed.fetchPrice();
(, bool oracleFailedWhileBranchLive) = wstethPriceFeed.fetchPrice();

// Check that the primary calc oracle did fail
assertTrue(oracleFailedWhileBranchLive);
Expand Down Expand Up @@ -1310,13 +1309,6 @@ contract OraclesMainnet is TestAccounts {
);

uint256 lastGoodPrice = wstethPriceFeed.lastGoodPrice();

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

// Make the exchange rate return 0
vm.etch(address(wstETH), address(mockWstethToken).code);
Expand Down Expand Up @@ -1512,7 +1504,7 @@ contract OraclesMainnet is TestAccounts {
assertEq(updatedAt, block.timestamp - 7 days);

// Fetch price again
(uint256 price, bool oracleFailedWhileBranchLive) = wstethPriceFeed.fetchPrice();
wstethPriceFeed.fetchPrice();

// Check using lastGoodPrice
assertEq(uint8(wstethPriceFeed.priceSource()), uint8(IMainnetPriceFeed.PriceSource.lastGoodPrice));
Expand All @@ -1533,7 +1525,7 @@ contract OraclesMainnet is TestAccounts {
uint256 debtRequest = 3000e18;

vm.startPrank(A);
uint256 troveId = contractsArray[0].borrowerOperations.openTrove(
contractsArray[0].borrowerOperations.openTrove(
A, 0, coll, debtRequest, 0, 0, 5e16, debtRequest, address(0), address(0), address(0)
);

Expand All @@ -1543,7 +1535,7 @@ contract OraclesMainnet is TestAccounts {
assertEq(updatedAt, block.timestamp - 7 days);

// Fetch price again
(uint256 price, bool oracleFailedWhileBranchLive) = wethPriceFeed.fetchPrice();
(, bool oracleFailedWhileBranchLive) = wethPriceFeed.fetchPrice();
assertTrue(oracleFailedWhileBranchLive);
// Confirm branch shutdown
assertEq(contractsArray[0].troveManager.shutdownTime(), block.timestamp);
Expand Down Expand Up @@ -1577,7 +1569,7 @@ contract OraclesMainnet is TestAccounts {
uint256 debtRequest = 3000e18;

vm.startPrank(A);
uint256 troveId = contractsArray[1].borrowerOperations.openTrove(
contractsArray[1].borrowerOperations.openTrove(
A, 0, coll, debtRequest, 0, 0, 5e16, debtRequest, address(0), address(0), address(0)
);

Expand All @@ -1587,7 +1579,7 @@ contract OraclesMainnet is TestAccounts {
assertEq(updatedAt, block.timestamp - 7 days);

// Fetch price again
(uint256 price, bool oracleFailedWhileBranchLive) = rethPriceFeed.fetchPrice();
(, bool oracleFailedWhileBranchLive) = rethPriceFeed.fetchPrice();
assertTrue(oracleFailedWhileBranchLive);
// Confirm RETH branch shutdown
assertEq(contractsArray[1].troveManager.shutdownTime(), block.timestamp);
Expand Down Expand Up @@ -1621,7 +1613,7 @@ contract OraclesMainnet is TestAccounts {
uint256 debtRequest = 3000e18;

vm.startPrank(A);
uint256 troveId = contractsArray[2].borrowerOperations.openTrove(
contractsArray[2].borrowerOperations.openTrove(
A, 0, coll, debtRequest, 0, 0, 5e16, debtRequest, address(0), address(0), address(0)
);

Expand All @@ -1631,7 +1623,7 @@ contract OraclesMainnet is TestAccounts {
assertEq(updatedAt, block.timestamp - 7 days);

// Fetch price again
(uint256 price, bool oracleFailedWhileBranchLive) = wstethPriceFeed.fetchPrice();
(, bool oracleFailedWhileBranchLive) = wstethPriceFeed.fetchPrice();
assertTrue(oracleFailedWhileBranchLive);
// Confirm RETH branch shutdown
assertEq(contractsArray[2].troveManager.shutdownTime(), block.timestamp);
Expand Down Expand Up @@ -1665,7 +1657,7 @@ contract OraclesMainnet is TestAccounts {
uint256 debtRequest = 3000e18;

vm.startPrank(A);
uint256 troveId = contractsArray[0].borrowerOperations.openTrove(
contractsArray[0].borrowerOperations.openTrove(
A, 0, coll, debtRequest, 0, 0, 5e16, debtRequest, address(0), address(0), address(0)
);

Expand Down Expand Up @@ -1714,7 +1706,7 @@ contract OraclesMainnet is TestAccounts {
uint256 debtRequest = 3000e18;

vm.startPrank(A);
uint256 troveId = contractsArray[2].borrowerOperations.openTrove(
contractsArray[2].borrowerOperations.openTrove(
A, 0, coll, debtRequest, 0, 0, 5e16, debtRequest, address(0), address(0), address(0)
);

Expand Down Expand Up @@ -1775,7 +1767,7 @@ contract OraclesMainnet is TestAccounts {
uint256 debtRequest = 3000e18;

vm.startPrank(A);
uint256 troveId = contractsArray[2].borrowerOperations.openTrove(
contractsArray[2].borrowerOperations.openTrove(
A, 0, coll, debtRequest, 0, 0, 5e16, debtRequest, address(0), address(0), address(0)
);

Expand Down Expand Up @@ -1853,7 +1845,7 @@ contract OraclesMainnet is TestAccounts {
uint256 debtRequest = 3000e18;

vm.startPrank(A);
uint256 troveId = contractsArray[1].borrowerOperations.openTrove(
contractsArray[1].borrowerOperations.openTrove(
A, 0, coll, debtRequest, 0, 0, 5e16, debtRequest, address(0), address(0), address(0)
);

Expand Down Expand Up @@ -1915,7 +1907,7 @@ contract OraclesMainnet is TestAccounts {
uint256 debtRequest = 3000e18;

vm.startPrank(A);
uint256 troveId = contractsArray[1].borrowerOperations.openTrove(
contractsArray[1].borrowerOperations.openTrove(
A, 0, coll, debtRequest, 0, 0, 5e16, debtRequest, address(0), address(0), address(0)
);
vm.stopPrank();
Expand Down Expand Up @@ -1982,17 +1974,23 @@ contract OraclesMainnet is TestAccounts {
// --- Call these functions with 10k gas - i.e. enough to run out of gas in the Chainlink calls ---
function testRevertLowGasWSTETH() public {
vm.expectRevert(MainnetPriceFeedBase.InsufficientGasForExternalCall.selector);
address(wstethPriceFeed).call{gas: 10000}(abi.encodeWithSignature("fetchPrice()"));
// just catch return val to suppress warning
(bool success, ) = address(wstethPriceFeed).call{gas: 10000}(abi.encodeWithSignature("fetchPrice()"));
assertFalse(success);
}

function testRevertLowGasRETH() public {
vm.expectRevert(MainnetPriceFeedBase.InsufficientGasForExternalCall.selector);
address(rethPriceFeed).call{gas: 10000}(abi.encodeWithSignature("fetchPrice()"));
// just catch return val to suppress warning
(bool success, ) = address(rethPriceFeed).call{gas: 10000}(abi.encodeWithSignature("fetchPrice()"));
assertFalse(success);
}

function testRevertLowGasWETH() public {
vm.expectRevert(MainnetPriceFeedBase.InsufficientGasForExternalCall.selector);
address(wethPriceFeed).call{gas: 10000}(abi.encodeWithSignature("fetchPrice()"));
// just catch return val to suppress warning
(bool success, ) = address(wethPriceFeed).call{gas: 10000}(abi.encodeWithSignature("fetchPrice()"));
assertFalse(success);
}

// - More basic actions tests (adjust, close, etc)
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/test/TestContracts/RETHTokenMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "../../Interfaces/IRETHToken.sol";

contract RETHTokenMock is IRETHToken {

function getExchangeRate() external view returns (uint256) {
function getExchangeRate() external pure returns (uint256) {
return 0;
}
}
12 changes: 6 additions & 6 deletions contracts/src/test/TestContracts/WSTETHTokenMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import "../../Interfaces/IWSTETH.sol";

contract WSTETHTokenMock is IWSTETH{

function stEthPerToken() external view returns (uint256) {return 0;}
function wrap(uint256 _stETHAmount) external returns (uint256) {return 0;}
function unwrap(uint256 _wstETHAmount) external returns (uint256) {return 0;}
function getWstETHByStETH(uint256 _stETHAmount) external view returns (uint256) {return 0;}
function getStETHByWstETH(uint256 _wstETHAmount) external view returns (uint256) {return 0;}
function tokensPerStEth() external view returns (uint256) {return 0;}
function stEthPerToken() external pure returns (uint256) {return 0;}
function wrap(uint256 _stETHAmount) external pure returns (uint256) {return _stETHAmount;}
function unwrap(uint256 _wstETHAmount) external pure returns (uint256) {return _wstETHAmount;}
function getWstETHByStETH(uint256 _stETHAmount) external pure returns (uint256) {return _stETHAmount;}
function getStETHByWstETH(uint256 _wstETHAmount) external pure returns (uint256) {return _wstETHAmount;}
function tokensPerStEth() external pure returns (uint256) {return 0;}
}

0 comments on commit 1bb9c46

Please sign in to comment.