Skip to content

Commit

Permalink
refactor: del test redstone oracle
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
  • Loading branch information
md0x committed May 20, 2024
1 parent fdafdc4 commit e4073cf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 112 deletions.
2 changes: 1 addition & 1 deletion lib/redstone-contracts
68 changes: 0 additions & 68 deletions src/oracles/RedstonePriceFeedWithRounds.sol

This file was deleted.

58 changes: 15 additions & 43 deletions test/unit/RedStoneOracle.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;

import {RedstoneConsumerNumericBase} from "@redstone-finance/evm-connector/contracts/core/RedstoneConsumerNumericBase.sol";
import {RedstoneConsumerNumericBase} from
"@redstone-finance/evm-connector/contracts/core/RedstoneConsumerNumericBase.sol";

import {CommonTest} from "../Common.sol";

import {BaseController} from "../../src/controllers/BaseController.sol";
import {ChainlinkSourceAdapter} from "../../src/adapters/source-adapters/ChainlinkSourceAdapter.sol";
import {DecimalLib} from "../../src/adapters/lib/DecimalLib.sol";
import {IAggregatorV3Source} from "../../src/interfaces/chainlink/IAggregatorV3Source.sol";
import {RedstonePriceFeedWithRounds} from "../../src/oracles/RedstonePriceFeedWithRounds.sol";
import {RedstonePriceFeedWithRounds} from "redstone-oracles-monorepo/packages/examples/RedstonePriceFeedWithRounds.sol";

import {IAggregatorV3Source} from "../../src/interfaces/chainlink/IAggregatorV3Source.sol";

Expand All @@ -18,9 +19,7 @@ import {TestedSourceAdapter} from "../fork/adapters/ChainlinkSourceAdapter.sol";
import "forge-std/console.sol";

contract MockRedstonePayload is CommonTest {
function getRedstonePayload(
string memory priceFeed
) public returns (bytes memory) {
function getRedstonePayload(string memory priceFeed) public returns (bytes memory) {
string[] memory args = new string[](4);
args[0] = "node";
args[1] = "--no-warnings";
Expand All @@ -37,31 +36,20 @@ contract RedstoneOracleAdapterTest is CommonTest, MockRedstonePayload {

function setUp() public {
redstoneOracle = new RedstonePriceFeedWithRounds(bytes32("BTC"));
sourceAdapter = new TestedSourceAdapter(
IAggregatorV3Source(address(redstoneOracle))
);
sourceAdapter = new TestedSourceAdapter(IAggregatorV3Source(address(redstoneOracle)));
}

function pushPrice() internal returns (uint256, uint256) {
bytes memory data = getRedstonePayload("BTC");

(
bytes memory redstonePayload,
uint256 timestampMilliseconds,
uint256 updatePrice
) = abi.decode(data, (bytes, uint256, uint256));
(bytes memory redstonePayload, uint256 timestampMilliseconds, uint256 updatePrice) =
abi.decode(data, (bytes, uint256, uint256));

uint256 timestampSeconds = timestampMilliseconds / 1000;

vm.warp(timestampSeconds);
bytes memory encodedFunction = abi.encodeWithSignature(
"updateDataFeedsValues(uint256)",
timestampMilliseconds
);
bytes memory encodedFunctionWithRedstonePayload = abi.encodePacked(
encodedFunction,
redstonePayload
);
bytes memory encodedFunction = abi.encodeWithSignature("updateDataFeedsValues(uint256)", timestampMilliseconds);
bytes memory encodedFunctionWithRedstonePayload = abi.encodePacked(encodedFunction, redstonePayload);

address(redstoneOracle).call(encodedFunctionWithRedstonePayload);

Expand All @@ -70,13 +58,8 @@ contract RedstoneOracleAdapterTest is CommonTest, MockRedstonePayload {

function testPushPrice() public {
(uint256 updatePrice, uint256 updateTimestamp) = pushPrice();
(
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
) = redstoneOracle.latestRoundData();
(uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) =
redstoneOracle.latestRoundData();

assertEq(roundId, 1);
assertEq(uint256(answer), updatePrice);
Expand All @@ -86,21 +69,10 @@ contract RedstoneOracleAdapterTest is CommonTest, MockRedstonePayload {
}

function testCorrectlyStandardizesOutputs() public {
(uint256 pushedPrice, ) = pushPrice();
(
,
int256 latestChainlinkAnswer,
,
uint256 latestChainlinkTimestamp,

) = redstoneOracle.latestRoundData();
(
int256 latestSourceAnswer,
uint256 latestSourceTimestamp
) = sourceAdapter.getLatestSourceData();
assertTrue(
scaleChainlinkTo18(latestChainlinkAnswer) == latestSourceAnswer
);
(uint256 pushedPrice,) = pushPrice();
(, int256 latestChainlinkAnswer,, uint256 latestChainlinkTimestamp,) = redstoneOracle.latestRoundData();
(int256 latestSourceAnswer, uint256 latestSourceTimestamp) = sourceAdapter.getLatestSourceData();
assertTrue(scaleChainlinkTo18(latestChainlinkAnswer) == latestSourceAnswer);
assertTrue(pushedPrice == uint256(latestChainlinkAnswer));
assertTrue(latestSourceTimestamp == latestChainlinkTimestamp);
}
Expand Down

0 comments on commit e4073cf

Please sign in to comment.