Skip to content

Commit

Permalink
test: get round data
Browse files Browse the repository at this point in the history
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
  • Loading branch information
Reinis-FRP committed May 13, 2024
1 parent 66f417c commit b9b4b2f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/mocks/MockSourceAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract contract MockSourceAdapter is DiamondRootOval {
}

function getSourceDataAtRound(uint256 roundId) public view virtual override returns (int256, uint256) {
if (roundId == 0 || rounds.length <= roundId) return (0, 0);
if (roundId == 0 || rounds.length < roundId) return (0, 0);
RoundData memory roundData = rounds[roundId - 1];
return (roundData.answer, roundData.timestamp);
}
Expand Down
27 changes: 27 additions & 0 deletions test/unit/Oval.ChainlinkDestinationAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,31 @@ contract OvalChainlinkDestinationAdapter is CommonTest {
oval.unlockLatestValue();
verifyOvalMatchesOval();
}

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);

// 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, beforeLockWindow);

// 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 == beforeLockWindow);
}
}

0 comments on commit b9b4b2f

Please sign in to comment.