Skip to content

Commit

Permalink
test: chainlink source round data
Browse files Browse the repository at this point in the history
Signed-off-by: Reinis Martinsons <[email protected]>
  • Loading branch information
Reinis-FRP committed May 10, 2024
1 parent bbd4af5 commit 4029077
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/fork/adapters/ChainlinkSourceAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ contract ChainlinkSourceAdapterTest is CommonTest {
assertTrue(latestSourceTimestamp == latestChainlinkTimestamp);
}

function testCorrectlyStandardizesRoundOutputs() public {
(uint80 latestRound,,,,) = chainlink.latestRoundData();
(, int256 chainlinkAnswer,, uint256 chainlinkTimestamp,) = chainlink.getRoundData(latestRound);
(int256 sourceAnswer, uint256 sourceTimestamp) = sourceAdapter.getSourceDataAtRound(latestRound);
assertTrue(scaleChainlinkTo18(chainlinkAnswer) == sourceAnswer);
assertTrue(sourceTimestamp == chainlinkTimestamp);
}

function testCorrectlyLooksBackThroughRounds() public {
// Try fetching the price an hour before. At the sample data block there was not a lot of price action and one
// hour ago is simply the previous round (there was only one update in that interval due to chainlink heartbeat)
Expand Down Expand Up @@ -131,6 +139,13 @@ contract ChainlinkSourceAdapterTest is CommonTest {
assertTrue(uint256(latestRound) == lookBackRoundId);
}

function testNonExistentRoundData() public {
(uint80 latestRound,,,,) = chainlink.latestRoundData();
(int256 sourceAnswer, uint256 sourceTimestamp) = sourceAdapter.getSourceDataAtRound(latestRound + 1);
assertTrue(sourceAnswer == 0);
assertTrue(sourceTimestamp == 0);
}

function scaleChainlinkTo18(int256 input) public pure returns (int256) {
return (input * 10 ** 18) / 10 ** 8;
}
Expand Down

0 comments on commit 4029077

Please sign in to comment.