Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add coverage #24

Merged
merged 8 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 65 additions & 58 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,68 +1,75 @@
QueryProcessorTest:testFindNearestSample_CanFindExactValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 69038209, ~: 78939846)
QueryProcessorTest:testFindNearestSample_CanFindIntermediateValue(uint32,uint256,uint256,uint256) (runs: 256, μ: 68311518, ~: 79140121)
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, μ: 80622, ~: 80652)
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, μ: 69204608, ~: 69204518)
QueryProcessorTest:testGetPastAccumulator_BufferEmpty(uint8) (runs: 256, μ: 26930, ~: 26984)
QueryProcessorTest:testGetPastAccumulator_ExactMatch(uint32,uint256,uint256,uint16) (runs: 256, μ: 73842560, ~: 83474413)
QueryProcessorTest:testGetPastAccumulator_ExactMatch_LatestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 68671249, ~: 78734958)
QueryProcessorTest:testGetPastAccumulator_ExactMatch_OldestAccumulator(uint32,uint256,uint256) (runs: 256, μ: 68701118, ~: 78766725)
QueryProcessorTest:testGetPastAccumulator_ExtrapolatesBeyondLatest(uint32,uint256,uint256,uint256) (runs: 256, μ: 68285121, ~: 79111756)
QueryProcessorTest:testGetPastAccumulator_InterpolatesBetweenPastAccumulators(uint32,uint256,uint256,uint256) (runs: 256, μ: 68319459, ~: 79146413)
QueryProcessorTest:testGetPastAccumulator_InvalidAgo(uint32,uint256,uint256,uint256) (runs: 256, μ: 68276708, ~: 79102843)
QueryProcessorTest:testGetPastAccumulator_QueryTooOld(uint32,uint256,uint256,uint256) (runs: 256, μ: 68288213, ~: 79113100)
QueryProcessorTest:testGetTimeWeightedAverage(uint32,uint256,uint256,uint256,uint256) (runs: 256, μ: 103845966, ~: 112262763)
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: 159631)
ReservoirPriceOracleTest:testDesignatePair() (gas: 29056)
ReservoirPriceOracleTest:testDesignatePair_IncorrectPair() (gas: 21148)
ReservoirPriceOracleTest:testDesignatePair_NotOwner() (gas: 17541)
ReservoirPriceOracleTest:testDesignatePair_TokenOrderReversed() (gas: 30605)
ReservoirPriceOracleTest:testGetQuote(uint256,uint256) (runs: 256, μ: 33696, ~: 33805)
ReservoirPriceOracleTest:testGetQuote_AmountInTooLarge() (gas: 12950)
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: 10361834)
ReservoirPriceOracleTest:testGetQuote_Inverse(uint256,uint256) (runs: 256, μ: 35820, ~: 35987)
ReservoirPriceOracleTest:testGetQuote_MultipleHops() (gas: 111582)
ReservoirPriceOracleTest:testGetQuote_MultipleHops_Inverse() (gas: 111900)
ReservoirPriceOracleTest:testGetQuote_MultipleHops_PriceZero() (gas: 122208)
ReservoirPriceOracleTest:testGetQuote_NoFallbackOracle() (gas: 20776)
ReservoirPriceOracleTest:testGetQuote_PriceZero() (gas: 15930)
ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_1HopRoute(uint256,uint256,address,address,uint8,uint8) (runs: 256, μ: 5316035, ~: 5316010)
ReservoirPriceOracleTest:testGetQuote_RandomizeAllParam_2HopRoute(uint256,uint256,uint256,address,address,address,uint8,uint8,uint8) (runs: 256, μ: 10503497, ~: 10503613)
ReservoirPriceOracleTest:testGetQuote_SameBaseQuote(uint256,address) (runs: 256, μ: 8927, ~: 8927)
ReservoirPriceOracleTest:testGetQuote_UseFallback() (gas: 38244)
ReservoirPriceOracleTest:testGetQuote_ZeroIn() (gas: 36635)
ReservoirPriceOracleTest:testGetQuotes(uint256,uint256) (runs: 256, μ: 26240, ~: 26349)
ReservoirPriceOracleTest:testPriceCache_Inverted() (gas: 21949)
ReservoirPriceOracleTest:testSetFallbackOracle_NotOwner() (gas: 10928)
ReservoirPriceOracleTest:testSetRoute() (gas: 61014)
ReservoirPriceOracleTest:testSetRoute_InvalidRewardThreshold() (gas: 37278)
ReservoirPriceOracleTest:testSetRoute_InvalidRoute() (gas: 20106)
ReservoirPriceOracleTest:testSetRoute_InvalidRouteLength() (gas: 19253)
ReservoirPriceOracleTest:testSetRoute_MultipleHops() (gas: 201105)
ReservoirPriceOracleTest:testSetRoute_NotSorted() (gas: 13006)
ReservoirPriceOracleTest:testSetRoute_OverwriteExisting() (gas: 169482)
ReservoirPriceOracleTest:testSetRoute_SameToken() (gas: 13019)
ReservoirPriceOracleTest:testUndesignatePair() (gas: 30237)
ReservoirPriceOracleTest:testUndesignatePair_NotOwner() (gas: 15344)
ReservoirPriceOracleTest:testUpdatePrice_AboveThresholdBelowMaxReward(uint256) (runs: 256, μ: 164717, ~: 164737)
ReservoirPriceOracleTest:testUpdatePrice_BelowThreshold(uint256) (runs: 256, μ: 149562, ~: 149238)
ReservoirPriceOracleTest:testUpdatePrice_BeyondMaxReward(uint256) (runs: 256, μ: 162212, ~: 162240)
ReservoirPriceOracleTest:testUpdatePrice_FirstUpdate() (gas: 153342)
ReservoirPriceOracleTest:testUpdatePrice_IntermediateRoutes() (gas: 16283142)
ReservoirPriceOracleTest:testUpdatePrice_PriceOutOfRange() (gas: 5408263)
ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_ContractNoReceive() (gas: 152501)
ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_InsufficientReward(uint256) (runs: 256, μ: 210795, ~: 211013)
ReservoirPriceOracleTest:testUpdatePrice_RewardEligible_ZeroRecipient() (gas: 146149)
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: 10952)
ReservoirPriceOracleTest:testUpdateTwapPeriod(uint256) (runs: 256, μ: 21576, ~: 21667)
ReservoirPriceOracleTest:testUpdateTwapPeriod_InvalidTwapPeriod(uint256) (runs: 256, μ: 17701, ~: 17994)
ReservoirPriceOracleTest:testWritePriceCache(uint256) (runs: 256, μ: 30057, ~: 29819)
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)
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,23 @@ jobs:
- run: forge snapshot --check
env:
FOUNDRY_PROFILE: default

coverage:
needs: [test-unit]
if: false # skip this job for now as it always makes the github CI timeout
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- run: forge coverage --report lcov

- uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
files: ./lcov.info
3 changes: 3 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ fs_permissions = [
ignored_error_codes = []
skip = ["test/large/*.sol"]

[profile.default.fuzz]
seed = "0xe9cdc8fb2a2c0d1c046034d74d6498826ae3f1d9877353cf40d8a6a7aedfe875"

[profile.large-test]
via_ir = true
match_path = "test/large/*.sol"
Expand Down
2 changes: 1 addition & 1 deletion src/ReservoirPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ contract ReservoirPriceOracle is IPriceOracle, Owned(msg.sender), ReentrancyGuar
_validateTokens(aToken0, aToken1);
require(lRouteLength > 1 && lRouteLength <= Constants.MAX_ROUTE_LENGTH, OracleErrors.InvalidRouteLength());
require(aRoute[0] == aToken0 && aRoute[lRouteLength - 1] == aToken1, OracleErrors.InvalidRoute());
require(aRewardThresholds.length == lRouteLength - 1, OracleErrors.InvalidArrayLengthRewardThresholds());
require(aRewardThresholds.length == lRouteLength - 1, OracleErrors.InvalidRewardThresholdsLength());

bytes32 lSlot = Utils.calculateSlot(aToken0, aToken1);

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/OracleErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library OracleErrors {
// config errors
error IncorrectTokensDesignatePair();
error InvalidRewardThreshold();
error InvalidArrayLengthRewardThresholds();
error InvalidRewardThresholdsLength();
error InvalidRoute();
error InvalidRouteLength();
error InvalidTokensProvided();
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), 1));
_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), 100 * 10 ** _tokenC.decimals());
_tokenD.mint(address(_pairCD), 200 * 10 ** _tokenD.decimals());
_pairCD.mint(address(this));
}

function _createPair(address aTokenA, address aTokenB, uint256 aCurveId) internal returns (address rPair) {
Expand Down
Loading