|
2 | 2 | pragma solidity ^0.8.0;
|
3 | 3 |
|
4 | 4 | import "forge-std/Test.sol";
|
5 |
| -import "src/chainlink/Oracle2.sol"; |
| 5 | +import "src/chainlink/OracleTwoFeeds.sol"; |
6 | 6 | import "src/chainlink/libraries/ErrorsLib.sol";
|
7 | 7 |
|
8 | 8 | // 18 decimals of precision
|
@@ -30,48 +30,49 @@ contract FakeAggregator {
|
30 | 30 | }
|
31 | 31 | }
|
32 | 32 |
|
33 |
| -contract OracleTest is Test { |
| 33 | +contract OracleTwoFeedsTest is Test { |
34 | 34 | function setUp() public {
|
35 | 35 | vm.selectFork(vm.createFork(vm.envString("ETH_RPC_URL")));
|
36 | 36 | }
|
37 | 37 |
|
38 | 38 | function testOracleStEthUsdc() public {
|
39 |
| - Oracle2 oracle = new Oracle2(stEthEthFeed, usdcEthFeed, 18, 6); |
| 39 | + OracleTwoFeeds oracle = new OracleTwoFeeds(stEthEthFeed, usdcEthFeed, 18, 6); |
40 | 40 | (, int256 baseAnswer,,,) = stEthEthFeed.latestRoundData();
|
41 | 41 | (, int256 quoteAnswer,,,) = usdcEthFeed.latestRoundData();
|
42 | 42 | assertEq(oracle.price(), uint256(baseAnswer) * 10 ** (36 + 18 + 6 - 18 - 18) / uint256(quoteAnswer));
|
43 | 43 | }
|
44 | 44 |
|
45 | 45 | function testOracleEthUsd() public {
|
46 |
| - Oracle2 oracle = new Oracle2(ethUsdFeed, AggregatorV3Interface(address(0)), 18, 0); |
| 46 | + OracleTwoFeeds oracle = new OracleTwoFeeds(ethUsdFeed, AggregatorV3Interface(address(0)), 18, 0); |
47 | 47 | (, int256 expectedPrice,,,) = ethUsdFeed.latestRoundData();
|
48 | 48 | assertEq(oracle.price(), uint256(expectedPrice) * 10 ** (36 - 18 - 8));
|
49 | 49 | }
|
50 | 50 |
|
51 | 51 | function testOracleStEthEth() public {
|
52 |
| - Oracle2 oracle = new Oracle2(stEthEthFeed, AggregatorV3Interface(address(0)), 18, 18); |
| 52 | + OracleTwoFeeds oracle = new OracleTwoFeeds(stEthEthFeed, AggregatorV3Interface(address(0)), 18, 18); |
53 | 53 | (, int256 expectedPrice,,,) = stEthEthFeed.latestRoundData();
|
54 | 54 | assertEq(oracle.price(), uint256(expectedPrice) * 10 ** (36 + 18 - 18 - 18));
|
55 | 55 | assertApproxEqRel(oracle.price(), 1e36, 0.01 ether);
|
56 | 56 | }
|
57 | 57 |
|
58 | 58 | function testOracleEthStEth() public {
|
59 |
| - Oracle2 oracle = new Oracle2(AggregatorV3Interface(address(0)), stEthEthFeed, 18, 18); |
| 59 | + OracleTwoFeeds oracle = new OracleTwoFeeds(AggregatorV3Interface(address(0)), stEthEthFeed, 18, 18); |
60 | 60 | (, int256 expectedPrice,,,) = stEthEthFeed.latestRoundData();
|
61 | 61 | assertEq(oracle.price(), 10 ** (36 + 18 + 18 - 18) / uint256(expectedPrice));
|
62 | 62 | assertApproxEqRel(oracle.price(), 1e36, 0.01 ether);
|
63 | 63 | }
|
64 | 64 |
|
65 | 65 | function testOracleUsdcUsd() public {
|
66 |
| - Oracle2 oracle = new Oracle2(usdcUsd, AggregatorV3Interface(address(0)), 6, 0); |
| 66 | + OracleTwoFeeds oracle = new OracleTwoFeeds(usdcUsd, AggregatorV3Interface(address(0)), 6, 0); |
67 | 67 | assertApproxEqRel(oracle.price(), 1e36 / 1e6, 0.01 ether);
|
68 | 68 | }
|
69 | 69 |
|
70 |
| - function testNegativeAnswer() public { |
| 70 | + function testNegativeAnswer(int price) public { |
| 71 | + vm.assume(price < 0); |
71 | 72 | FakeAggregator aggregator = new FakeAggregator();
|
72 |
| - Oracle2 oracle = |
73 |
| - new Oracle2(AggregatorV3Interface(address(aggregator)), AggregatorV3Interface(address(0)), 18, 0); |
74 |
| - aggregator.setAnwser(-1); |
| 73 | + OracleTwoFeeds oracle = |
| 74 | + new OracleTwoFeeds(AggregatorV3Interface(address(aggregator)), AggregatorV3Interface(address(0)), 18, 0); |
| 75 | + aggregator.setAnwser(price); |
75 | 76 | vm.expectRevert(bytes(ErrorsLib.NEGATIVE_ANSWER));
|
76 | 77 | oracle.price();
|
77 | 78 | }
|
|
0 commit comments