diff --git a/test/fork/adapters/ChainlinkSourceAdapter.sol b/test/fork/adapters/ChainlinkSourceAdapter.sol index 3205226..6ec2c96 100644 --- a/test/fork/adapters/ChainlinkSourceAdapter.sol +++ b/test/fork/adapters/ChainlinkSourceAdapter.sol @@ -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) @@ -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; }