Skip to content

Commit

Permalink
ci: attempting with optimizer enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Nov 29, 2024
1 parent 2289ec4 commit 470c615
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ skip = ["test/large/*.sol"]
[profile.default.fuzz]
seed = "0xe9cdc8fb2a2c0d1c046034d74d6498826ae3f1d9877353cf40d8a6a7aedfe875"

[profile.coverage]
optimizer = true
optimizer_runs = 1_000_000

[profile.large-test]
via_ir = true
match_path = "test/large/*.sol"
Expand Down
12 changes: 12 additions & 0 deletions test/__fixtures/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ contract BaseTest is Test {

GenericFactory internal _factory = new GenericFactory();
ReservoirPair internal _pair;
ReservoirPair internal _pairBC;
ReservoirPair internal _pairCD;

ReservoirPriceOracle internal _oracle =
new ReservoirPriceOracle(DEFAULT_TWAP_PERIOD, DEFAULT_REWARD_GAS_AMOUNT, PriceType.CLAMPED_PRICE);
Expand Down Expand Up @@ -54,6 +56,16 @@ contract BaseTest is Test {
_tokenA.mint(address(_pair), 103e6);
_tokenB.mint(address(_pair), 10_189e18);
_pair.mint(address(this));

_pairBC = ReservoirPair(_createPair(address(_tokenB), address(_tokenC), 0));
_tokenB.mint(address(_pairBC), 102_303e18);
_tokenC.mint(address(_pairBC), 292e10);
_pairBC.mint(address(this));

_pairCD = ReservoirPair(_createPair(address(_tokenC), address(_tokenD), 0));
_tokenC.mint(address(_pairCD), 991_102_221e10);
_tokenD.mint(address(_pairCD), 937_991_222e6);
_pairCD.mint(address(this));
}

function _createPair(address aTokenA, address aTokenB, uint256 aCurveId) internal returns (address rPair) {
Expand Down
34 changes: 34 additions & 0 deletions test/unit/ReservoirPriceOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ contract ReservoirPriceOracleTest is BaseTest {
lRewardThreshold[0] = 200; // 2%

_oracle.designatePair(address(_tokenB), address(_tokenA), _pair);
_oracle.designatePair(address(_tokenB), address(_tokenC), _pairBC);
_oracle.designatePair(address(_tokenD), address(_tokenC), _pairCD);
_oracle.setRoute(address(_tokenA), address(_tokenB), lRoute, lRewardThreshold);
}

Expand Down Expand Up @@ -983,6 +985,38 @@ contract ReservoirPriceOracleTest is BaseTest {
_oracle.updatePrice(address(_tokenB), address(_tokenC), address(0));
}

function testUpdatePrice_WriteToNonSimpleRoute() external {
// arrange
uint16[] memory lRewardThresholds = new uint16[](2);
lRewardThresholds[0] = lRewardThresholds[1] = 1;
address[] memory lRoute = new address[](3);
lRoute[0] = address(_tokenA);
lRoute[1] = address(_tokenB);
lRoute[2] = address(_tokenC);

_oracle.setRoute(address(_tokenA), address(_tokenC), lRoute, lRewardThresholds);

// then we change the original B->C route with B->D->C
address[] memory lModifiedRoute = new address[](3);
lModifiedRoute[0] = address(_tokenB);
lModifiedRoute[1] = address(_tokenD);
lModifiedRoute[2] = address(_tokenC);
_oracle.setRoute(address(_tokenB), address(_tokenC), lModifiedRoute, lRewardThresholds);

skip(10);
_pair.sync();
_pairBC.sync();
_pairCD.sync();
skip(_oracle.twapPeriod());
_pair.sync();
_pairBC.sync();
_pairCD.sync();

// act & assert
vm.expectRevert(OracleErrors.WriteToNonSimpleRoute.selector);
_oracle.updatePrice(address(_tokenA), address(_tokenC), address(0));
}

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

0 comments on commit 470c615

Please sign in to comment.