@@ -11,6 +11,8 @@ AggregatorV3Interface constant stEthEthFeed = AggregatorV3Interface(0x86392dC19c
11
11
AggregatorV3Interface constant usdcEthFeed = AggregatorV3Interface (0x986b5E1e1755e3C2440e960477f25201B0a8bbD4 );
12
12
// 8 decimals of precision
13
13
AggregatorV3Interface constant ethUsdFeed = AggregatorV3Interface (0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419 );
14
+ // 8 decimals of precision
15
+ AggregatorV3Interface constant usdcUsd = AggregatorV3Interface (0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6 );
14
16
15
17
contract FakeAggregator {
16
18
int256 public answer;
@@ -37,25 +39,32 @@ contract OracleTest is Test {
37
39
Oracle2 oracle = new Oracle2 (stEthEthFeed, usdcEthFeed, 18 , 6 );
38
40
(, int256 baseAnswer ,,,) = stEthEthFeed.latestRoundData ();
39
41
(, int256 quoteAnswer ,,,) = usdcEthFeed.latestRoundData ();
40
- assertEq (oracle.price (), uint256 (baseAnswer) * 10 ** (36 + 18 + 18 - 18 - 6 ) / uint256 (quoteAnswer));
42
+ assertEq (oracle.price (), uint256 (baseAnswer) * 10 ** (36 + 18 + 6 - 18 - 18 ) / uint256 (quoteAnswer));
41
43
}
42
44
43
45
function testOracleEthUsd () public {
44
46
Oracle2 oracle = new Oracle2 (ethUsdFeed, AggregatorV3Interface (address (0 )), 18 , 0 );
45
47
(, int256 expectedPrice ,,,) = ethUsdFeed.latestRoundData ();
46
- assertEq (oracle.price (), uint256 (expectedPrice) * 10 ** (36 + 18 - 8 ));
48
+ assertEq (oracle.price (), uint256 (expectedPrice) * 10 ** (36 - 18 - 8 ));
47
49
}
48
50
49
51
function testOracleStEthEth () public {
50
- Oracle2 oracle = new Oracle2 (stEthEthFeed, AggregatorV3Interface (address (0 )), 18 , 0 );
52
+ Oracle2 oracle = new Oracle2 (stEthEthFeed, AggregatorV3Interface (address (0 )), 18 , 18 );
51
53
(, int256 expectedPrice ,,,) = stEthEthFeed.latestRoundData ();
52
- assertEq (oracle.price (), uint256 (expectedPrice) * 10 ** (36 + 18 - 18 ));
54
+ assertEq (oracle.price (), uint256 (expectedPrice) * 10 ** (36 + 18 - 18 - 18 ));
55
+ assertApproxEqRel (oracle.price (), 1e36 , 0.01 ether);
53
56
}
54
57
55
58
function testOracleEthStEth () public {
56
- Oracle2 oracle = new Oracle2 (AggregatorV3Interface (address (0 )), stEthEthFeed, 0 , 18 );
59
+ Oracle2 oracle = new Oracle2 (AggregatorV3Interface (address (0 )), stEthEthFeed, 18 , 18 );
57
60
(, int256 expectedPrice ,,,) = stEthEthFeed.latestRoundData ();
58
- assertEq (oracle.price (), 10 ** (36 + 18 - 18 ) / uint256 (expectedPrice));
61
+ assertEq (oracle.price (), 10 ** (36 + 18 + 18 - 18 ) / uint256 (expectedPrice));
62
+ assertApproxEqRel (oracle.price (), 1e36 , 0.01 ether);
63
+ }
64
+
65
+ function testOracleUsdcUsd () public {
66
+ Oracle2 oracle = new Oracle2 (usdcUsd, AggregatorV3Interface (address (0 )), 6 , 0 );
67
+ assertApproxEqRel (oracle.price (), 1e36 / 1e6 , 0.01 ether);
59
68
}
60
69
61
70
function testNegativeAnswer () public {
0 commit comments