Skip to content

Commit

Permalink
Adds tests for _readTwap scale
Browse files Browse the repository at this point in the history
  • Loading branch information
jar-o committed Jul 30, 2024
1 parent 67151b8 commit 8cb11d0
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/integration/AggorIntegration_eth_ETH_USD.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8cb11d0

Please sign in to comment.