From a043bae5126977977dfdaf964603dd1cdcfd4e27 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Mon, 13 May 2024 08:51:48 +0000 Subject: [PATCH] fix: test timestamps Signed-off-by: Reinis Martinsons --- .../unit/Oval.ChainlinkDestinationAdapter.sol | 34 +++++++++++++++---- test/unit/Oval.UnlockLatestValue.sol | 27 +++++++++++++++ 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/test/unit/Oval.ChainlinkDestinationAdapter.sol b/test/unit/Oval.ChainlinkDestinationAdapter.sol index 458ec4b..8522757 100644 --- a/test/unit/Oval.ChainlinkDestinationAdapter.sol +++ b/test/unit/Oval.ChainlinkDestinationAdapter.sol @@ -65,7 +65,7 @@ contract OvalChainlinkDestinationAdapter is CommonTest { // Advance time to within the lock window and update the source. uint256 beforeLockWindow = block.timestamp + oval.lockWindow() - 1; vm.warp(beforeLockWindow); - publishRoundData(newAnswer, beforeLockWindow); + publishRoundData(newAnswer, newTimestamp); // Before updating, initial values from cache would be returned. (int256 latestAnswer, uint256 latestTimestamp, uint256 latestRoundId) = oval.internalLatestData(); @@ -76,24 +76,39 @@ contract OvalChainlinkDestinationAdapter is CommonTest { vm.prank(permissionedUnlocker); oval.unlockLatestValue(); verifyOvalMatchesOval(); + + (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) = + oval.latestRoundData(); + + // Check that Oval return the correct values scaled to the source oracle decimals. + assertTrue(roundId == latestPublishedRound); + assertTrue(answer == newAnswer / internalDecimalsToSourceDecimals); + assertTrue(startedAt == newTimestamp); + assertTrue(updatedAt == newTimestamp); + assertTrue(answeredInRound == latestPublishedRound); } function testReturnUninitializedRoundData() public { // Advance time to within the lock window and update the source. uint256 beforeLockWindow = block.timestamp + oval.lockWindow() - 1; vm.warp(beforeLockWindow); - publishRoundData(newAnswer, beforeLockWindow); + publishRoundData(newAnswer, newTimestamp); // Before updating, uninitialized values would be returned. - (int256 latestAnswer, uint256 latestTimestamp) = oval.internalDataAtRound(latestPublishedRound); - assertTrue(latestAnswer == 0 && latestTimestamp == 0); + (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) = + oval.getRoundData(uint80(latestPublishedRound)); + assertTrue(roundId == latestPublishedRound); + assertTrue(answer == 0); + assertTrue(startedAt == 0); + assertTrue(updatedAt == 0); + assertTrue(answeredInRound == latestPublishedRound); } function testReturnUnlockedRoundData() public { // Advance time to within the lock window and update the source. uint256 beforeLockWindow = block.timestamp + oval.lockWindow() - 1; vm.warp(beforeLockWindow); - publishRoundData(newAnswer, beforeLockWindow); + publishRoundData(newAnswer, newTimestamp); // Unlock new round values. vm.prank(permissionedUnlocker); @@ -101,7 +116,12 @@ contract OvalChainlinkDestinationAdapter is CommonTest { verifyOvalMatchesOval(); // After unlock we should return the new values. - (int256 latestAnswer, uint256 latestTimestamp) = oval.internalDataAtRound(latestPublishedRound); - assertTrue(latestAnswer == newAnswer && latestTimestamp == beforeLockWindow); + (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) = + oval.getRoundData(uint80(latestPublishedRound)); + assertTrue(roundId == latestPublishedRound); + assertTrue(answer == newAnswer / internalDecimalsToSourceDecimals); + assertTrue(startedAt == newTimestamp); + assertTrue(updatedAt == newTimestamp); + assertTrue(answeredInRound == latestPublishedRound); } } diff --git a/test/unit/Oval.UnlockLatestValue.sol b/test/unit/Oval.UnlockLatestValue.sol index dc67f1c..f254bc3 100644 --- a/test/unit/Oval.UnlockLatestValue.sol +++ b/test/unit/Oval.UnlockLatestValue.sol @@ -174,4 +174,31 @@ contract OvalUnlockLatestValue is CommonTest { assertTrue(latestAnswer == newAnswer && latestTimestamp == beforeLockWindow); assertTrue(latestRoundId == latestPublishedRound - 1); } + + function testReturnUninitializedRoundData() public { + // Advance time to within the lock window and update the source. + uint256 beforeLockWindow = block.timestamp + oval.lockWindow() - 1; + vm.warp(beforeLockWindow); + publishRoundData(newAnswer, newTimestamp); + + // Before updating, uninitialized values would be returned. + (int256 latestAnswer, uint256 latestTimestamp) = oval.internalDataAtRound(latestPublishedRound); + assertTrue(latestAnswer == 0 && latestTimestamp == 0); + } + + function testReturnUnlockedRoundData() public { + // Advance time to within the lock window and update the source. + uint256 beforeLockWindow = block.timestamp + oval.lockWindow() - 1; + vm.warp(beforeLockWindow); + publishRoundData(newAnswer, newTimestamp); + + // Unlock new round values. + vm.prank(permissionedUnlocker); + oval.unlockLatestValue(); + verifyOvalMatchesOval(); + + // After unlock we should return the new values. + (int256 latestAnswer, uint256 latestTimestamp) = oval.internalDataAtRound(latestPublishedRound); + assertTrue(latestAnswer == newAnswer && latestTimestamp == newTimestamp); + } }