From dc9a694410793dd5a0cb5a04c0cc6e3417a0401e Mon Sep 17 00:00:00 2001 From: "A.L." Date: Tue, 3 Dec 2024 16:11:01 +0800 Subject: [PATCH] feat: enable via-ir --- .gas-snapshot | 158 +++++++++++------------ foundry.toml | 1 + test/__fixtures/BaseTest.t.sol | 5 + test/unit/ReservoirPriceOracle.t.sol | 48 +++---- test/unit/libraries/QueryProcessor.t.sol | 20 +-- 5 files changed, 119 insertions(+), 113 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 712c3c7..377a00f 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,79 +1,79 @@ -QueryProcessorTest:testFindNearestSample_CanFindExactValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 69293044, ~: 77954902) -QueryProcessorTest:testFindNearestSample_CanFindIntermediateValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 68012389, ~: 77774179) -QueryProcessorTest:testFindNearestSample_NotInitialized() (gas: 1056944146) -QueryProcessorTest:testFindNearestSample_OneSample(uint256) (runs: 256, μ: 80623, ~: 80652) -QueryProcessorTest:testGetInstantValue() (gas: 124418) -QueryProcessorTest:testGetInstantValue_NotInitialized(uint256) (runs: 256, μ: 19400, ~: 19400) -QueryProcessorTest:testGetInstantValue_NotInitialized_BeyondBufferSize(uint8,uint16) (runs: 256, μ: 69204583, ~: 69204518) -QueryProcessorTest:testGetPastAccumulator_BufferEmpty(uint8) (runs: 256, μ: 26911, ~: 26984) -QueryProcessorTest:testGetPastAccumulator_ExactMatch(uint32,uint256,uint256,uint16) (runs: 256, μ: 72113529, ~: 81319251) -QueryProcessorTest:testGetPastAccumulator_ExactMatch_LatestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 69463960, ~: 78425849) -QueryProcessorTest:testGetPastAccumulator_ExactMatch_OldestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 69493894, ~: 78457616) -QueryProcessorTest:testGetPastAccumulator_ExtrapolatesBeyondLatest(uint32,uint256,uint256,uint256) (runs: 256, μ: 67986036, ~: 77745180) -QueryProcessorTest:testGetPastAccumulator_InterpolatesBetweenPastAccumulators(uint32,uint256,uint256,uint256) (runs: 256, μ: 68020346, ~: 77780471) -QueryProcessorTest:testGetPastAccumulator_InvalidAgo(uint32,uint256,uint256,uint256) (runs: 256, μ: 67977605, ~: 77737553) -QueryProcessorTest:testGetPastAccumulator_QueryTooOld(uint32,uint256,uint256,uint256) (runs: 256, μ: 67989141, ~: 77747128) -QueryProcessorTest:testGetTimeWeightedAverage(uint32,uint256,uint256,uint256,uint256) (runs: 256, μ: 103407330, ~: 109858182) -QueryProcessorTest:testGetTimeWeightedAverage_BadSecs() (gas: 10981) -ReservoirPriceOracleTest:testClearRoute() (gas: 52209) -ReservoirPriceOracleTest:testClearRoute_AllWordsCleared() (gas: 159642) -ReservoirPriceOracleTest:testDesignatePair() (gas: 29089) -ReservoirPriceOracleTest:testDesignatePair_IncorrectPair() (gas: 21129) -ReservoirPriceOracleTest:testDesignatePair_NotOwner() (gas: 17515) -ReservoirPriceOracleTest:testDesignatePair_TokenOrderReversed() (gas: 30670) -ReservoirPriceOracleTest:testGetQuote(uint256,uint256) (runs: 256, μ: 33680, ~: 33783) -ReservoirPriceOracleTest:testGetQuote_AmountInTooLarge() (gas: 13019) -ReservoirPriceOracleTest:testGetQuote_BaseIsVault(uint256) (runs: 256, μ: 401362, ~: 401124) -ReservoirPriceOracleTest:testGetQuote_ComplicatedDecimals() (gas: 10361941) -ReservoirPriceOracleTest:testGetQuote_ERC4626AssetFails() (gas: 21434) -ReservoirPriceOracleTest:testGetQuote_Inverse(uint256,uint256) (runs: 256, μ: 35858, ~: 36022) -ReservoirPriceOracleTest:testGetQuote_MultipleHops() (gas: 111597) -ReservoirPriceOracleTest:testGetQuote_MultipleHops_Inverse() (gas: 111891) -ReservoirPriceOracleTest:testGetQuote_MultipleHops_PriceZero() (gas: 122213) -ReservoirPriceOracleTest:testGetQuote_NoFallbackOracle() (gas: 20830) -ReservoirPriceOracleTest:testGetQuote_PriceZero() (gas: 15942) -ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_1HopRoute(uint256,uint256,address,address,uint8,uint8) (runs: 256, μ: 5316105, ~: 5316096) -ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_2HopRoute(uint256,uint256,uint256,address,address,address,uint8,uint8,uint8) (runs: 256, μ: 10503666, ~: 10503746) -ReservoirPriceOracleTest:testGetQuote_SameBaseQuote(uint256,address) (runs: 256, μ: 8972, ~: 8972) -ReservoirPriceOracleTest:testGetQuote_UseFallback() (gas: 38232) -ReservoirPriceOracleTest:testGetQuote_ZeroIn() (gas: 36638) -ReservoirPriceOracleTest:testGetQuotes(uint256,uint256) (runs: 256, μ: 26236, ~: 26339) -ReservoirPriceOracleTest:testName() (gas: 9355) -ReservoirPriceOracleTest:testPriceCache_Inverted() (gas: 22028) -ReservoirPriceOracleTest:testSetFallbackOracle_NotOwner() (gas: 10993) -ReservoirPriceOracleTest:testSetRoute() (gas: 60992) -ReservoirPriceOracleTest:testSetRoute_InvalidDecimals() (gas: 761313) -ReservoirPriceOracleTest:testSetRoute_InvalidRewardThreshold() (gas: 37234) -ReservoirPriceOracleTest:testSetRoute_InvalidRewardThresholdLength() (gas: 18050) -ReservoirPriceOracleTest:testSetRoute_InvalidRoute() (gas: 20151) -ReservoirPriceOracleTest:testSetRoute_InvalidRouteLength() (gas: 19209) -ReservoirPriceOracleTest:testSetRoute_MultipleHops() (gas: 201150) -ReservoirPriceOracleTest:testSetRoute_NotSorted() (gas: 13029) -ReservoirPriceOracleTest:testSetRoute_OverwriteExisting() (gas: 169526) -ReservoirPriceOracleTest:testSetRoute_SameToken() (gas: 12975) -ReservoirPriceOracleTest:testUndesignatePair() (gas: 30263) -ReservoirPriceOracleTest:testUndesignatePair_NotOwner() (gas: 15315) -ReservoirPriceOracleTest:testUpdatePrice_AboveThresholdBelowMaxReward(uint256) (runs: 256, μ: 164770, ~: 164790) -ReservoirPriceOracleTest:testUpdatePrice_BelowThreshold(uint256) (runs: 256, μ: 149645, ~: 149316) -ReservoirPriceOracleTest:testUpdatePrice_BeyondMaxReward(uint256) (runs: 256, μ: 162201, ~: 162226) -ReservoirPriceOracleTest:testUpdatePrice_FirstUpdate() (gas: 153384) -ReservoirPriceOracleTest:testUpdatePrice_IntermediateRoutes() (gas: 11080585) -ReservoirPriceOracleTest:testUpdatePrice_NoPath() (gas: 15986) -ReservoirPriceOracleTest:testUpdatePrice_PriceOutOfRange() (gas: 5374104) -ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_ContractNoReceive() (gas: 152500) -ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_InsufficientReward(uint256) (runs: 256, μ: 210828, ~: 211040) -ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_ZeroRecipient() (gas: 146179) -ReservoirPriceOracleTest:testUpdatePrice_WriteToNonSimpleRoute() (gas: 498183) -ReservoirPriceOracleTest:testUpdateRewardGasAmount() (gas: 19038) -ReservoirPriceOracleTest:testUpdateRewardGasAmount_NotOwner() (gas: 10953) -ReservoirPriceOracleTest:testUpdateTwapPeriod(uint256) (runs: 256, μ: 21613, ~: 21687) -ReservoirPriceOracleTest:testUpdateTwapPeriod_InvalidTwapPeriod(uint256) (runs: 256, μ: 17688, ~: 17994) -ReservoirPriceOracleTest:testValidatePair_NoDesignatedPair() (gas: 119204) -ReservoirPriceOracleTest:testWritePriceCache(uint256) (runs: 256, μ: 30001, ~: 29763) -RoutesLibTest:testGetDecimalDifference() (gas: 3966) -RoutesLibTest:testIsCompositeRoute() (gas: 4332) -RoutesLibTest:testPackSimplePrice(int8,uint256) (runs: 256, μ: 8083, ~: 7862) -SamplesTest:testAccumulator() (gas: 3930) -SamplesTest:testAccumulator_BadVariableRequest() (gas: 3355) -SamplesTest:testInstant() (gas: 3880) -SamplesTest:testInstant_BadVariableRequest() (gas: 3376) \ No newline at end of file +QueryProcessorTest:testFindNearestSample_CanFindExactValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 71380209, ~: 79623432) +QueryProcessorTest:testFindNearestSample_CanFindIntermediateValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 70331197, ~: 78843929) +QueryProcessorTest:testFindNearestSample_NotInitialized() (gas: 1056943859) +QueryProcessorTest:testFindNearestSample_OneSample(uint256) (runs: 256, μ: 82306, ~: 82327) +QueryProcessorTest:testGetInstantValue() (gas: 125107) +QueryProcessorTest:testGetInstantValue_NotInitialized(uint256) (runs: 256, μ: 19451, ~: 19451) +QueryProcessorTest:testGetInstantValue_NotInitialized_BeyondBufferSize(uint8,uint16) (runs: 256, μ: 72066010, ~: 72065951) +QueryProcessorTest:testGetPastAccumulator_BufferEmpty(uint8) (runs: 256, μ: 27254, ~: 27295) +QueryProcessorTest:testGetPastAccumulator_ExactMatch(uint32,uint256,uint256,uint16) (runs: 256, μ: 78170252, ~: 86282081) +QueryProcessorTest:testGetPastAccumulator_ExactMatch_LatestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 73969954, ~: 82761267) +QueryProcessorTest:testGetPastAccumulator_ExactMatch_OldestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 74005646, ~: 82798985) +QueryProcessorTest:testGetPastAccumulator_ExtrapolatesBeyondLatest(uint32,uint256,uint256,uint256) (runs: 256, μ: 70301293, ~: 78811761) +QueryProcessorTest:testGetPastAccumulator_InterpolatesBetweenPastAccumulators(uint32,uint256,uint256,uint256) (runs: 256, μ: 70339437, ~: 78850387) +QueryProcessorTest:testGetPastAccumulator_InvalidAgo(uint32,uint256,uint256,uint256) (runs: 256, μ: 70291146, ~: 78801336) +QueryProcessorTest:testGetPastAccumulator_QueryTooOld(uint32,uint256,uint256,uint256) (runs: 256, μ: 70304007, ~: 78812373) +QueryProcessorTest:testGetTimeWeightedAverage(uint32,uint256,uint256,uint256,uint256) (runs: 256, μ: 111087875, ~: 118169976) +QueryProcessorTest:testGetTimeWeightedAverage_BadSecs() (gas: 10647) +ReservoirPriceOracleTest:testClearRoute() (gas: 52904) +ReservoirPriceOracleTest:testClearRoute_AllWordsCleared() (gas: 160332) +ReservoirPriceOracleTest:testDesignatePair() (gas: 30840) +ReservoirPriceOracleTest:testDesignatePair_IncorrectPair() (gas: 22078) +ReservoirPriceOracleTest:testDesignatePair_NotOwner() (gas: 18140) +ReservoirPriceOracleTest:testDesignatePair_TokenOrderReversed() (gas: 32501) +ReservoirPriceOracleTest:testGetQuote(uint256,uint256) (runs: 256, μ: 32685, ~: 32752) +ReservoirPriceOracleTest:testGetQuote_AmountInTooLarge() (gas: 13348) +ReservoirPriceOracleTest:testGetQuote_BaseIsVault(uint256) (runs: 256, μ: 458795, ~: 458644) +ReservoirPriceOracleTest:testGetQuote_ComplicatedDecimals() (gas: 10150724) +ReservoirPriceOracleTest:testGetQuote_ERC4626AssetFails() (gas: 21838) +ReservoirPriceOracleTest:testGetQuote_Inverse(uint256,uint256) (runs: 256, μ: 34631, ~: 34737) +ReservoirPriceOracleTest:testGetQuote_MultipleHops() (gas: 111636) +ReservoirPriceOracleTest:testGetQuote_MultipleHops_Inverse() (gas: 111295) +ReservoirPriceOracleTest:testGetQuote_MultipleHops_PriceZero() (gas: 120875) +ReservoirPriceOracleTest:testGetQuote_NoFallbackOracle() (gas: 21727) +ReservoirPriceOracleTest:testGetQuote_PriceZero() (gas: 16162) +ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_1HopRoute(uint256,uint256,address,address,uint8,uint8) (runs: 256, μ: 5211594, ~: 5211503) +ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_2HopRoute(uint256,uint256,uint256,address,address,address,uint8,uint8,uint8) (runs: 256, μ: 10293413, ~: 10293405) +ReservoirPriceOracleTest:testGetQuote_SameBaseQuote(uint256,address) (runs: 256, μ: 9331, ~: 9331) +ReservoirPriceOracleTest:testGetQuote_UseFallback() (gas: 38587) +ReservoirPriceOracleTest:testGetQuote_ZeroIn() (gas: 35209) +ReservoirPriceOracleTest:testGetQuotes(uint256,uint256) (runs: 256, μ: 26480, ~: 26547) +ReservoirPriceOracleTest:testName() (gas: 10385) +ReservoirPriceOracleTest:testPriceCache_Inverted() (gas: 22122) +ReservoirPriceOracleTest:testSetFallbackOracle_NotOwner() (gas: 11370) +ReservoirPriceOracleTest:testSetRoute() (gas: 61530) +ReservoirPriceOracleTest:testSetRoute_InvalidDecimals() (gas: 807577) +ReservoirPriceOracleTest:testSetRoute_InvalidRewardThreshold() (gas: 38394) +ReservoirPriceOracleTest:testSetRoute_InvalidRewardThresholdLength() (gas: 18718) +ReservoirPriceOracleTest:testSetRoute_InvalidRoute() (gas: 20660) +ReservoirPriceOracleTest:testSetRoute_InvalidRouteLength() (gas: 19628) +ReservoirPriceOracleTest:testSetRoute_MultipleHops() (gas: 202199) +ReservoirPriceOracleTest:testSetRoute_NotSorted() (gas: 14317) +ReservoirPriceOracleTest:testSetRoute_OverwriteExisting() (gas: 170616) +ReservoirPriceOracleTest:testSetRoute_SameToken() (gas: 13459) +ReservoirPriceOracleTest:testUndesignatePair() (gas: 32010) +ReservoirPriceOracleTest:testUndesignatePair_NotOwner() (gas: 16361) +ReservoirPriceOracleTest:testUpdatePrice_AboveThresholdBelowMaxReward(uint256) (runs: 256, μ: 168624, ~: 168617) +ReservoirPriceOracleTest:testUpdatePrice_BelowThreshold(uint256) (runs: 256, μ: 154056, ~: 153856) +ReservoirPriceOracleTest:testUpdatePrice_BeyondMaxReward(uint256) (runs: 256, μ: 166423, ~: 166419) +ReservoirPriceOracleTest:testUpdatePrice_FirstUpdate() (gas: 159510) +ReservoirPriceOracleTest:testUpdatePrice_IntermediateRoutes() (gas: 10869893) +ReservoirPriceOracleTest:testUpdatePrice_NoPath() (gas: 17176) +ReservoirPriceOracleTest:testUpdatePrice_PriceOutOfRange() (gas: 5273125) +ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_ContractNoReceive() (gas: 157817) +ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_InsufficientReward(uint256) (runs: 256, μ: 214597, ~: 214621) +ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_ZeroRecipient() (gas: 150476) +ReservoirPriceOracleTest:testUpdatePrice_WriteToNonSimpleRoute() (gas: 502435) +ReservoirPriceOracleTest:testUpdateRewardGasAmount() (gas: 20597) +ReservoirPriceOracleTest:testUpdateRewardGasAmount_NotOwner() (gas: 12210) +ReservoirPriceOracleTest:testUpdateTwapPeriod(uint256) (runs: 256, μ: 22135, ~: 22186) +ReservoirPriceOracleTest:testUpdateTwapPeriod_InvalidTwapPeriod(uint256) (runs: 256, μ: 18914, ~: 19109) +ReservoirPriceOracleTest:testValidatePair_NoDesignatedPair() (gas: 123165) +ReservoirPriceOracleTest:testWritePriceCache(uint256) (runs: 256, μ: 30513, ~: 30362) +RoutesLibTest:testGetDecimalDifference() (gas: 4142) +RoutesLibTest:testIsCompositeRoute() (gas: 4474) +RoutesLibTest:testPackSimplePrice(int8,uint256) (runs: 256, μ: 7905, ~: 7828) +SamplesTest:testAccumulator() (gas: 3818) +SamplesTest:testAccumulator_BadVariableRequest() (gas: 3374) +SamplesTest:testInstant() (gas: 3876) +SamplesTest:testInstant_BadVariableRequest() (gas: 3496) \ No newline at end of file diff --git a/foundry.toml b/foundry.toml index 6e4272e..427d5c6 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,5 +1,6 @@ [profile.default] solc = "0.8.28" +via-ir = true evm_version = "cancun" bytecode_hash = "ipfs" optimizer_runs = 1_000_000 diff --git a/test/__fixtures/BaseTest.t.sol b/test/__fixtures/BaseTest.t.sol index 8ab1e97..546f505 100644 --- a/test/__fixtures/BaseTest.t.sol +++ b/test/__fixtures/BaseTest.t.sol @@ -71,4 +71,9 @@ contract BaseTest is Test { function _createPair(address aTokenA, address aTokenB, uint256 aCurveId) internal returns (address rPair) { rPair = _factory.createPair(IERC20(aTokenA), IERC20(aTokenB), aCurveId); } + + function _skip(uint256 aTime) internal { + vm.roll(vm.getBlockNumber() + 1); + vm.warp(vm.getBlockTimestamp() + aTime); + } } diff --git a/test/unit/ReservoirPriceOracle.t.sol b/test/unit/ReservoirPriceOracle.t.sol index 74b7eb2..26a1be6 100644 --- a/test/unit/ReservoirPriceOracle.t.sol +++ b/test/unit/ReservoirPriceOracle.t.sol @@ -473,9 +473,9 @@ contract ReservoirPriceOracleTest is BaseTest { assertEq(lPrice, 0); // arrange - skip(1); + _skip(1); _pair.sync(); - skip(_oracle.twapPeriod() * 2); + _skip(_oracle.twapPeriod() * 2); _pair.sync(); // act @@ -500,9 +500,9 @@ contract ReservoirPriceOracleTest is BaseTest { uint256 lStartingPrice = lCurrentPrice * WAD / (WAD + lPercentDiff); _writePriceCache(address(_tokenA), address(_tokenB), lStartingPrice); - skip(1); + _skip(1); _pair.sync(); - skip(_oracle.twapPeriod()); + _skip(_oracle.twapPeriod()); _pair.sync(); // act @@ -530,9 +530,9 @@ contract ReservoirPriceOracleTest is BaseTest { uint256 lStartingPrice = lCurrentPrice * WAD / (WAD + lPercentDiff); _writePriceCache(address(_tokenA), address(_tokenB), lStartingPrice); - skip(1); + _skip(1); _pair.sync(); - skip(_oracle.twapPeriod()); + _skip(_oracle.twapPeriod()); _pair.sync(); // act @@ -562,9 +562,9 @@ contract ReservoirPriceOracleTest is BaseTest { uint256 lStartingPrice = lCurrentPrice * WAD / (WAD + lPercentDiff); _writePriceCache(address(_tokenA), address(_tokenB), lStartingPrice); - skip(1); + _skip(1); _pair.sync(); - skip(_oracle.twapPeriod()); + _skip(_oracle.twapPeriod()); _pair.sync(); // act @@ -588,9 +588,9 @@ contract ReservoirPriceOracleTest is BaseTest { deal(address(_oracle), lRewardAvailable); _writePriceCache(address(_tokenA), address(_tokenB), 5e18); - skip(1); + _skip(1); _pair.sync(); - skip(_oracle.twapPeriod() * 2); + _skip(_oracle.twapPeriod() * 2); _tokenA.mint(address(_pair), 2e18); _pair.swap(2e18, true, address(this), ""); @@ -609,9 +609,9 @@ contract ReservoirPriceOracleTest is BaseTest { uint256 lOracleBalanceStart = address(_oracle).balance; _writePriceCache(address(_tokenA), address(_tokenB), 5e18); - skip(1); + _skip(1); _pair.sync(); - skip(_oracle.twapPeriod()); + _skip(_oracle.twapPeriod()); _pair.sync(); // act @@ -628,9 +628,9 @@ contract ReservoirPriceOracleTest is BaseTest { // arrange _writePriceCache(address(_tokenA), address(_tokenB), 5e18); - skip(1); + _skip(1); _pair.sync(); - skip(_oracle.twapPeriod()); + _skip(_oracle.twapPeriod()); _pair.sync(); // act @@ -671,12 +671,12 @@ contract ReservoirPriceOracleTest is BaseTest { _oracle.designatePair(lStart, lIntermediate1, lAC); _oracle.designatePair(lIntermediate2, lEnd, lBD); - skip(1); + _skip(1); _pair.sync(); lAC.sync(); _pairCD.sync(); lBD.sync(); - skip(_oracle.twapPeriod()); + _skip(_oracle.twapPeriod()); // act uint256 lReward = _oracle.updatePrice(address(_tokenA), address(_tokenB), address(this)); @@ -693,7 +693,7 @@ contract ReservoirPriceOracleTest is BaseTest { assertEq(lReward, 0); // arrange - skip(_oracle.twapPeriod()); + _skip(_oracle.twapPeriod()); // act uint256 lSwapAmt = 1_000_000; @@ -706,7 +706,7 @@ contract ReservoirPriceOracleTest is BaseTest { _tokenB.mint(address(lBD), lSwapAmt * 10 ** _tokenB.decimals()); lBD.swap(int256(lSwapAmt * 10 ** _tokenB.decimals()), true, address(this), ""); - skip(_oracle.twapPeriod()); + _skip(_oracle.twapPeriod()); lReward = _oracle.updatePrice(address(_tokenA), address(_tokenB), address(this)); assertGt(lReward, _oracle.rewardGasAmount() * 3); // ensure that rewards have been aggregated across routes @@ -955,9 +955,9 @@ contract ReservoirPriceOracleTest is BaseTest { _tokenC.mint(address(lPair), type(uint104).max); lPair.mint(address(this)); - skip(10); + _skip(10); lPair.sync(); - skip(_oracle.twapPeriod() * 2); + _skip(_oracle.twapPeriod() * 2); lPair.sync(); address[] memory lRoute = new address[](2); @@ -997,11 +997,11 @@ contract ReservoirPriceOracleTest is BaseTest { lModifiedRoute[2] = address(_tokenC); _oracle.setRoute(address(_tokenB), address(_tokenC), lModifiedRoute, lRewardThresholds); - skip(10); + _skip(10); _pair.sync(); _pairBC.sync(); _pairCD.sync(); - skip(_oracle.twapPeriod()); + _skip(_oracle.twapPeriod()); _pair.sync(); _pairBC.sync(); _pairCD.sync(); @@ -1192,9 +1192,9 @@ contract ReservoirPriceOracleTest is BaseTest { function testValidatePair_NoDesignatedPair() external { // arrange - skip(1); + _skip(1); _pair.sync(); - skip(_oracle.twapPeriod()); + _skip(_oracle.twapPeriod()); _pair.sync(); _oracle.undesignatePair(address(_tokenA), address(_tokenB)); diff --git a/test/unit/libraries/QueryProcessor.t.sol b/test/unit/libraries/QueryProcessor.t.sol index 41f37f7..9348e19 100644 --- a/test/unit/libraries/QueryProcessor.t.sol +++ b/test/unit/libraries/QueryProcessor.t.sol @@ -22,7 +22,7 @@ contract QueryProcessorTest is BaseTest { function _fillBuffer(uint256 aBlockTime, uint256 aObservationsToWrite) internal { for (uint256 i = 0; i < aObservationsToWrite; ++i) { - skip(aBlockTime); + _skip(aBlockTime); _pair.sync(); } } @@ -69,7 +69,7 @@ contract QueryProcessorTest is BaseTest { function testGetInstantValue() external { // arrange - skip(123); + _skip(123); _tokenB.mint(address(_pair), 105e18); _pair.swap(-105e18, true, address(this), ""); @@ -103,7 +103,7 @@ contract QueryProcessorTest is BaseTest { // arrange - perform some swaps uint256 lSwapAmt = 1e6; for (uint256 i = 0; i < lObservationsToWrite; ++i) { - skip(lBlockTime); + _skip(lBlockTime); _tokenA.mint(address(_pair), lSwapAmt); _pair.swap(int256(lSwapAmt), true, address(this), ""); } @@ -179,15 +179,15 @@ contract QueryProcessorTest is BaseTest { uint16 lObservationsToWrite = uint16(bound(aObservationsToWrite, 3, Buffer.SIZE * 3)); // go around it 3 times maximum // arrange - uint256 lStartTime = block.timestamp; + uint256 lStartTime = vm.getBlockTimestamp(); _fillBuffer(lBlockTime, lObservationsToWrite); (,,, uint16 lIndex) = _pair.getReserves(); // act vm.startPrank(address(_queryProcessor)); uint256 lAgo = lObservationsToWrite > Buffer.SIZE - ? block.timestamp - _pair.observation(lIndex.next()).timestamp - : block.timestamp - (lStartTime + lBlockTime); + ? vm.getBlockTimestamp() - _pair.observation(lIndex.next()).timestamp + : vm.getBlockTimestamp() - (lStartTime + lBlockTime); int256 lAcc = _queryProcessor.getPastAccumulator(_pair, PriceType.RAW_PRICE, lIndex, lAgo); // assert @@ -215,7 +215,7 @@ contract QueryProcessorTest is BaseTest { vm.startPrank(address(_queryProcessor)); Observation memory lPrevObs = _pair.observation(lRandomSlot); uint256 lWantedTimestamp = lPrevObs.timestamp + lBlockTime / 2; - uint256 lAgo = block.timestamp - lWantedTimestamp; + uint256 lAgo = vm.getBlockTimestamp() - lWantedTimestamp; int256 lAcc = _queryProcessor.getPastAccumulator(_pair, PriceType.RAW_PRICE, lIndex, lAgo); // assert @@ -240,7 +240,7 @@ contract QueryProcessorTest is BaseTest { // arrange _fillBuffer(lBlockTime, lObservationsToWrite); - skip(lTimeBeyondLatest); + _skip(lTimeBeyondLatest); (,,, uint16 lIndex) = _pair.getReserves(); // act @@ -323,7 +323,7 @@ contract QueryProcessorTest is BaseTest { // act (Observation memory prev, Observation memory next) = - _queryProcessor.findNearestSample(_pair, block.timestamp, 0, 1); + _queryProcessor.findNearestSample(_pair, vm.getBlockTimestamp(), 0, 1); // assert assertEq(prev.timestamp, next.timestamp); @@ -403,7 +403,7 @@ contract QueryProcessorTest is BaseTest { vm.prank(address(_queryProcessor)); uint256 lAgo = bound( aAgo, - block.timestamp - _pair.observation(lOldestSample).timestamp + 1, + vm.getBlockTimestamp() - _pair.observation(lOldestSample).timestamp + 1, aStartTime + lBlockTime * lObservationsToWrite );