diff --git a/test/integration/AggorIntegration_eth_ETH_USD.t.sol b/test/integration/AggorIntegration_eth_ETH_USD.t.sol index 726aa1d..1ac7999 100644 --- a/test/integration/AggorIntegration_eth_ETH_USD.t.sol +++ b/test/integration/AggorIntegration_eth_ETH_USD.t.sol @@ -381,6 +381,81 @@ contract AggorIntegrationTest_eth_ETH_USD is Test { } } } + + function test_TwapScaleUp() public { + uint price = wrapper.readOracle( + uniswapPool, uniswapBaseToken, uniswapQuoteToken, uniswapBaseDec, uniswapLookback + ); + + // Scale price up from USDC.decimals() + uint128 wantVal = uint128(price * 10 ** (/*aggor.decimals()*/ 8 - 6)); + assertTrue(wantVal > price); + + // Make TWAP value the median. + uint128 chrVal = uint128(wantVal) - 1; + uint128 chlVal = uint128(wantVal) + 1; + + // Let oracles be stale + uint32 chlAge = 0; + uint32 chrAge = 0; + + // Set oracles. + _setChronicle(chrVal, chrAge); + _setChainlink(chlVal, chlAge); + + // Read aggor. + uint gotVal; + (gotVal, , ) = aggor.readWithStatus(); + assertEq(gotVal, wantVal); + } + + // Note we reverse the default base/quote for this test + function test_TwapScaleDown() public { + uint price = wrapper.readOracle( + uniswapPool, uniswapQuoteToken, uniswapBaseToken, uniswapQuoteDec, uniswapLookback + ); + + // Scale price down from WETH.decimals() + uint128 wantVal = uint128(price / 10 ** (18 - 8)); + assertTrue(wantVal < price); + + // Redeploy aggor with Uniswap params reversed. + aggor = new Aggor( + address(this), + address(this), + chronicle, + chainlink, + uniswapPool, + uniswapQuoteToken, + uniswapBaseToken, + uniswapQuoteDec, + uniswapBaseDec, + uniswapLookback, + agreementDistance, + ageThreshold + ); + + // Kiss aggor on chronicle oracle. + vm.prank(IAuth(chronicle).authed()[0]); + IToll(chronicle).kiss(address(aggor)); + + // Make TWAP value the median. + uint128 chrVal = wantVal - 1; + uint128 chlVal = wantVal + 1; + + // Let oracles be stale + uint32 chlAge = 0; + uint32 chrAge = 0; + + // Set oracles. + _setChronicle(chrVal, chrAge); + _setChainlink(chlVal, chlAge); + + // Read aggor. + uint gotVal; + (gotVal, , ) = aggor.readWithStatus(); + assertEq(gotVal, wantVal); + } } interface IChainlinkAggregatorV3_Aggregator {