Skip to content

Commit 5a3cc1f

Browse files
committed
test: add simple tests with ChainlinkOracle
1 parent bddff40 commit 5a3cc1f

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

test/ChainlinkOracleTest.sol

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,7 @@ import "../lib/forge-std/src/Test.sol";
55
import "../src/ChainlinkOracle.sol";
66
import "../src/libraries/ErrorsLib.sol";
77
import "./mocks/ChainlinkAggregatorMock.sol";
8-
9-
AggregatorV3Interface constant feedZero = AggregatorV3Interface(address(0));
10-
// 8 decimals of precision
11-
AggregatorV3Interface constant btcUsdFeed = AggregatorV3Interface(0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c);
12-
// 8 decimals of precision
13-
AggregatorV3Interface constant usdcUsdFeed = AggregatorV3Interface(0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6);
14-
// 18 decimals of precision
15-
AggregatorV3Interface constant btcEthFeed = AggregatorV3Interface(0xdeb288F737066589598e9214E782fa5A8eD689e8);
16-
// 8 decimals of precision
17-
AggregatorV3Interface constant wBtcBtcFeed = AggregatorV3Interface(0xfdFD9C85aD200c506Cf9e21F1FD8dd01932FBB23);
18-
// 18 decimals of precision
19-
AggregatorV3Interface constant stEthEthFeed = AggregatorV3Interface(0x86392dC19c0b719886221c78AB11eb8Cf5c52812);
20-
// 18 decimals of precision
21-
AggregatorV3Interface constant usdcEthFeed = AggregatorV3Interface(0x986b5E1e1755e3C2440e960477f25201B0a8bbD4);
22-
// 8 decimals of precision
23-
AggregatorV3Interface constant ethUsdFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
24-
// 18 decimals of precision
25-
AggregatorV3Interface constant daiEthFeed = AggregatorV3Interface(0x773616E4d11A78F511299002da57A0a94577F1f4);
26-
27-
IERC4626 constant vaultZero = IERC4626(address(0));
28-
IERC4626 constant sDaiVault = IERC4626(0x83F20F44975D03b1b09e64809B757c47f942BEeA);
8+
import "./helpers/Constants.sol";
299

3010
contract ChainlinkOracleTest is Test {
3111
function setUp() public {

test/WstEthEthExchangeRateChainlinkAdapterTest.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,28 @@ import "../src/libraries/ErrorsLib.sol";
55

66
import "../lib/forge-std/src/Test.sol";
77
import "../src/adapters/WstEthEthExchangeRateChainlinkAdapter.sol";
8+
import "../src/ChainlinkOracle.sol";
9+
import "./helpers/Constants.sol";
810

911
contract WstEthEthExchangeRateChainlinkAdapterTest is Test {
1012
IStEth internal constant ST_ETH = IStEth(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
1113

1214
WstEthEthExchangeRateChainlinkAdapter internal oracle;
15+
ChainlinkOracle internal chainlinkOracle;
1316

1417
function setUp() public {
1518
vm.createSelectFork(vm.envString("ETH_RPC_URL"));
1619
oracle = new WstEthEthExchangeRateChainlinkAdapter(address(ST_ETH));
20+
chainlinkOracle = new ChainlinkOracle(
21+
vaultZero,
22+
oracle,
23+
feedZero,
24+
feedZero,
25+
feedZero,
26+
1,
27+
18,
28+
18
29+
);
1730
}
1831

1932
function testDecimals() public {
@@ -53,4 +66,9 @@ contract WstEthEthExchangeRateChainlinkAdapterTest is Test {
5366
assertGe(uint256(answer), 1154690031824824994); // Exchange rate queried at block 19070943
5467
assertLe(uint256(answer), 1.5e18); // Max bounds of the exchange rate. Should work for a long enough time.
5568
}
69+
70+
function testOracleWstEthEthExchangeRate() public {
71+
(, int256 expectedPrice,,,) = oracle.latestRoundData();
72+
assertEq(chainlinkOracle.price(), uint256(expectedPrice) * 10 ** (36 + 18 - 18 - 18));
73+
}
5674
}

test/helpers/Constants.sol

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity ^0.8.0;
3+
4+
import {IERC4626, AggregatorV3Interface} from "../../src/ChainlinkOracle.sol";
5+
6+
AggregatorV3Interface constant feedZero = AggregatorV3Interface(address(0));
7+
// 8 decimals of precision
8+
AggregatorV3Interface constant btcUsdFeed = AggregatorV3Interface(0xF4030086522a5bEEa4988F8cA5B36dbC97BeE88c);
9+
// 8 decimals of precision
10+
AggregatorV3Interface constant usdcUsdFeed = AggregatorV3Interface(0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6);
11+
// 18 decimals of precision
12+
AggregatorV3Interface constant btcEthFeed = AggregatorV3Interface(0xdeb288F737066589598e9214E782fa5A8eD689e8);
13+
// 8 decimals of precision
14+
AggregatorV3Interface constant wBtcBtcFeed = AggregatorV3Interface(0xfdFD9C85aD200c506Cf9e21F1FD8dd01932FBB23);
15+
// 18 decimals of precision
16+
AggregatorV3Interface constant stEthEthFeed = AggregatorV3Interface(0x86392dC19c0b719886221c78AB11eb8Cf5c52812);
17+
// 18 decimals of precision
18+
AggregatorV3Interface constant usdcEthFeed = AggregatorV3Interface(0x986b5E1e1755e3C2440e960477f25201B0a8bbD4);
19+
// 8 decimals of precision
20+
AggregatorV3Interface constant ethUsdFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
21+
// 18 decimals of precision
22+
AggregatorV3Interface constant daiEthFeed = AggregatorV3Interface(0x773616E4d11A78F511299002da57A0a94577F1f4);
23+
24+
IERC4626 constant vaultZero = IERC4626(address(0));
25+
IERC4626 constant sDaiVault = IERC4626(0x83F20F44975D03b1b09e64809B757c47f942BEeA);

0 commit comments

Comments
 (0)