Skip to content

Commit

Permalink
test: add assert to make sure latest timestamp written
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Jan 22, 2024
1 parent fb7777e commit 3955483
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions test/unit/OracleWriter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,6 @@ contract OracleWriterTest is BaseTest {
_pair.observation(lIndex);
}

function testUpdateOracle_WriteOldReservesNotNew() external allPairs {
// arrange
uint256 lJumpAhead = 10;
(uint104 lReserve0,,,) = _pair.getReserves();
assertEq(lReserve0, Constants.INITIAL_MINT_AMOUNT);
_tokenA.mint(address(_pair), 10e18);

// act - call sync to trigger a write to the oracle
_stepTime(lJumpAhead);
_pair.sync();

// assert - make sure that the written observation is of the previous reserves, not the new reserves
(uint256 lNewReserve0,,, uint16 lIndex) = _pair.getReserves();

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

function testUpdateOracleCaller() external allPairs {
// arrange
address lNewOracleCaller = address(0x555);
Expand Down Expand Up @@ -122,6 +99,31 @@ contract OracleWriterTest is BaseTest {
_pair.setMaxChangeRate(lMaxChangeRate);
}

function testUpdateOracle_WriteOldReservesNotNew() external allPairs {
// arrange
uint256 lStartingTimestamp = block.timestamp;
uint256 lJumpAhead = 10;
(uint104 lReserve0,,,) = _pair.getReserves();
assertEq(lReserve0, Constants.INITIAL_MINT_AMOUNT);
_tokenA.mint(address(_pair), 10e18);

// act - call sync to trigger a write to the oracle
_stepTime(lJumpAhead);
_pair.sync();

// assert - make sure that the written observation is of the previous reserves, not the new reserves
(uint256 lNewReserve0,,, uint16 lIndex) = _pair.getReserves();

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 testOracle_CompareLiquidityTwoCurves_Balanced(uint32 aNewStartTime)
external
randomizeStartTime(aNewStartTime)
Expand Down

0 comments on commit 3955483

Please sign in to comment.