|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import "../lib/forge-std/src/Test.sol"; |
| 5 | +import "../src/adapters/WstEthOracle.sol"; |
| 6 | + |
| 7 | +contract ChainlinkOracleTest is Test { |
| 8 | + IStETH internal constant ST_ETH = IStETH(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84); |
| 9 | + |
| 10 | + WstEthOracle internal oracle; |
| 11 | + |
| 12 | + function setUp() public { |
| 13 | + vm.createSelectFork(vm.envString("ETH_RPC_URL")); |
| 14 | + oracle = new WstEthOracle(address(ST_ETH)); |
| 15 | + } |
| 16 | + |
| 17 | + function testLastRoundDataUintMax() public { |
| 18 | + vm.mockCall( |
| 19 | + address(ST_ETH), |
| 20 | + abi.encodeWithSelector(ST_ETH.getPooledEthByShares.selector, 10 ** 18), |
| 21 | + abi.encode(type(uint256).max) |
| 22 | + ); |
| 23 | + vm.expectRevert("WstEthOracle: OVERFLOW"); |
| 24 | + oracle.latestRoundData(); |
| 25 | + } |
| 26 | + |
| 27 | + function testGetRoundDataUintMax() public { |
| 28 | + vm.mockCall( |
| 29 | + address(ST_ETH), |
| 30 | + abi.encodeWithSelector(ST_ETH.getPooledEthByShares.selector, 10 ** 18), |
| 31 | + abi.encode(type(uint256).max) |
| 32 | + ); |
| 33 | + vm.expectRevert("WstEthOracle: OVERFLOW"); |
| 34 | + oracle.getRoundData(1); |
| 35 | + } |
| 36 | + |
| 37 | + function testDecimals() public { |
| 38 | + assertEq(oracle.decimals(), uint8(18)); |
| 39 | + } |
| 40 | + |
| 41 | + function testDeployZeroAddress() public { |
| 42 | + vm.expectRevert("WstEthOracle: ZERO_ADDRESS"); |
| 43 | + new WstEthOracle(address(0)); |
| 44 | + } |
| 45 | + |
| 46 | + function testConfig() public { |
| 47 | + assertEq(oracle.description(), "wstETH/ETH exchange rate price"); |
| 48 | + assertEq(oracle.version(), 1); |
| 49 | + } |
| 50 | + |
| 51 | + function testLastRoundData() public { |
| 52 | + (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) = oracle.latestRoundData(); |
| 53 | + assertEq(roundId, 0); |
| 54 | + assertEq(answer,int256(ST_ETH.getPooledEthByShares(10 ** 18))); |
| 55 | + assertEq(startedAt, 0); |
| 56 | + assertEq(updatedAt, 0); |
| 57 | + assertEq(answeredInRound, 0); |
| 58 | + } |
| 59 | + |
| 60 | + function testGetLastRoundData() public { |
| 61 | + (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) = oracle.getRoundData(1); |
| 62 | + assertEq(roundId, 0); |
| 63 | + assertEq(answer, int256(ST_ETH.getPooledEthByShares(10 ** 18))); |
| 64 | + assertEq(startedAt, 0); |
| 65 | + assertEq(updatedAt, 0); |
| 66 | + assertEq(answeredInRound, 0); |
| 67 | + } |
| 68 | +} |
0 commit comments