Skip to content

Commit

Permalink
test: test case to make sure latest timestamp is written
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Jan 22, 2024
1 parent 3955483 commit d70a071
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions test/unit/OracleWriter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ contract OracleWriterTest is BaseTest {

function testUpdateOracle_WriteOldReservesNotNew() external allPairs {
// arrange
uint256 lStartingTimestamp = block.timestamp;
uint256 lJumpAhead = 10;
(uint104 lReserve0,,,) = _pair.getReserves();
assertEq(lReserve0, Constants.INITIAL_MINT_AMOUNT);
Expand All @@ -116,14 +115,31 @@ contract OracleWriterTest is BaseTest {

Observation memory lObs = _oracleCaller.observation(_pair, lIndex);
assertEq(lNewReserve0, 110e18);
assertEq(lObs.timestamp, lStartingTimestamp + lJumpAhead);
assertApproxEqRel(
LogCompression.fromLowResLog(lObs.logAccLiquidity / int56(int256(lJumpAhead))),
Constants.INITIAL_MINT_AMOUNT,
0.0001e18
);
}

function testUpdateOracle_LatestTimestampWritten(uint256 aJumpAhead) external allPairs {
// assume
uint256 lJumpAhead = bound(aJumpAhead, 10, type(uint16).max);

// arrange
uint256 lStartingTimestamp = block.timestamp;
_stepTime(lJumpAhead);

// act
_tokenA.mint(address(_pair), 5e18);
_pair.swap(5e18, true, address(this), "");

// assert
(,,, uint16 lIndex) = _pair.getReserves();
Observation memory lObs = _oracleCaller.observation(_pair, lIndex);
assertEq(lObs.timestamp, lStartingTimestamp + lJumpAhead);
}

function testOracle_CompareLiquidityTwoCurves_Balanced(uint32 aNewStartTime)
external
randomizeStartTime(aNewStartTime)
Expand Down

0 comments on commit d70a071

Please sign in to comment.