Skip to content

Commit

Permalink
test: add cases for missed coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Nov 28, 2024
1 parent 9d47a05 commit 77780f0
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/unit/ReservoirPriceOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
OracleAverageQuery,
ReservoirPriceOracle,
IERC20,
IERC4626,
IPriceOracle,
RoutesLib
} from "src/ReservoirPriceOracle.sol";
Expand All @@ -19,6 +20,7 @@ import { EnumerableSetLib } from "lib/solady/src/utils/EnumerableSetLib.sol";
import { Constants } from "src/libraries/Constants.sol";
import { MockFallbackOracle } from "test/mock/MockFallbackOracle.sol";
import { StubERC4626 } from "test/mock/StubERC4626.sol";
import {Errors} from "../../lib/amm-core/test/integration/AaveErrors.sol";

contract ReservoirPriceOracleTest is BaseTest {
using Utils for *;
Expand Down Expand Up @@ -95,6 +97,11 @@ contract ReservoirPriceOracleTest is BaseTest {
_oracle.setRoute(address(_tokenA), address(_tokenB), lRoute, lRewardThreshold);
}

function testName() external {
// act & assert
assertEq(_oracle.name(), "RESERVOIR PRICE ORACLE");
}

function testWritePriceCache(uint256 aPrice) external {
// arrange
uint256 lPrice = bound(aPrice, 1, 1e36);
Expand Down Expand Up @@ -976,6 +983,11 @@ contract ReservoirPriceOracleTest is BaseTest {
_oracle.updatePrice(address(_tokenB), address(_tokenC), address(0));
}

function testUpdatePrice_NoPath() external {
vm.expectRevert(OracleErrors.NoPath.selector);
_oracle.updatePrice(address(_tokenD), address(_tokenC), address(0));
}

function testSetRoute_SameToken() external {
// arrange
address lToken0 = address(0x1);
Expand Down Expand Up @@ -1108,4 +1120,28 @@ contract ReservoirPriceOracleTest is BaseTest {
vm.expectRevert(OracleErrors.AmountInTooLarge.selector);
_oracle.getQuote(lAmtIn, address(_tokenA), address(_tokenB));
}

function testGetQuote_ERC4626AssetFails() external {
// arrange
address lTargetContract = address(_tokenA); // just any address that doesn't impl the `asset()` function

// act & assert - the target should be called but should not fail despite not having the function. It should only fail when attempting to query the fallback
vm.expectCall(lTargetContract, abi.encodeCall(IERC4626.asset, ()));
vm.expectRevert(OracleErrors.NoPath.selector);
_oracle.getQuote(123, lTargetContract, address(_tokenD));
}

function testValidatePair_NoDesignatedPair() external {
// arrange
skip(1);
_pair.sync();
skip(_oracle.twapPeriod());
_pair.sync();

_oracle.undesignatePair(address(_tokenA), address(_tokenB));

// act & assert
vm.expectRevert(OracleErrors.NoDesignatedPair.selector);
_oracle.updatePrice(address(_tokenA), address(_tokenB), address(this));
}
}

0 comments on commit 77780f0

Please sign in to comment.