@@ -16,21 +16,25 @@ contract ChainlinkOracleTest is Test {
16
16
oracle = new WstEthChainlinkAdapter (address (ST_ETH));
17
17
}
18
18
19
- function testLastRoundDataUintMax () public {
19
+ function testLatestRoundDataOverflow (uint256 ethByShares ) public {
20
+ ethByShares = bound (ethByShares, uint256 (type (int256 ).max) + 1 , type (uint256 ).max);
21
+
20
22
vm.mockCall (
21
23
address (ST_ETH),
22
24
abi.encodeWithSelector (ST_ETH.getPooledEthByShares.selector , 10 ** 18 ),
23
- abi.encode (type ( uint256 ).max )
25
+ abi.encode (ethByShares )
24
26
);
25
27
vm.expectRevert (bytes (ErrorsLib.OVERFLOW));
26
28
oracle.latestRoundData ();
27
29
}
28
30
29
- function testGetRoundDataUintMax () public {
31
+ function testGetRoundDataOverflow (uint256 ethByShares ) public {
32
+ ethByShares = bound (ethByShares, uint256 (type (int256 ).max) + 1 , type (uint256 ).max);
33
+
30
34
vm.mockCall (
31
35
address (ST_ETH),
32
36
abi.encodeWithSelector (ST_ETH.getPooledEthByShares.selector , 10 ** 18 ),
33
- abi.encode (type ( uint256 ).max )
37
+ abi.encode (ethByShares )
34
38
);
35
39
vm.expectRevert (bytes (ErrorsLib.OVERFLOW));
36
40
oracle.getRoundData (1 );
@@ -50,7 +54,7 @@ contract ChainlinkOracleTest is Test {
50
54
assertEq (oracle.version (), 1 );
51
55
}
52
56
53
- function testLastRoundData () public {
57
+ function testLatestRoundData () public {
54
58
(uint80 roundId , int256 answer , uint256 startedAt , uint256 updatedAt , uint80 answeredInRound ) =
55
59
oracle.latestRoundData ();
56
60
assertEq (roundId, 0 );
@@ -60,7 +64,7 @@ contract ChainlinkOracleTest is Test {
60
64
assertEq (answeredInRound, 0 );
61
65
}
62
66
63
- function testGetLastRoundData () public {
67
+ function testGetRoundData () public {
64
68
(uint80 roundId , int256 answer , uint256 startedAt , uint256 updatedAt , uint80 answeredInRound ) =
65
69
oracle.getRoundData (1 );
66
70
assertEq (roundId, 0 );
@@ -70,7 +74,33 @@ contract ChainlinkOracleTest is Test {
70
74
assertEq (answeredInRound, 0 );
71
75
}
72
76
73
- function testLastRoundDataBounds () public {
77
+ function testLatestRoundDataNoOverflow (uint256 ethByShares ) public {
78
+ ethByShares = bound (ethByShares, 0 , uint256 (type (int256 ).max));
79
+
80
+ vm.mockCall (
81
+ address (ST_ETH),
82
+ abi.encodeWithSelector (ST_ETH.getPooledEthByShares.selector , 10 ** 18 ),
83
+ abi.encode (ethByShares)
84
+ );
85
+
86
+ (, int256 answer ,,,) = oracle.latestRoundData ();
87
+ assertEq (uint256 (answer), ethByShares);
88
+ }
89
+
90
+ function testGetRoundDataNoOverflow (uint256 ethByShares ) public {
91
+ ethByShares = bound (ethByShares, 0 , uint256 (type (int256 ).max));
92
+
93
+ vm.mockCall (
94
+ address (ST_ETH),
95
+ abi.encodeWithSelector (ST_ETH.getPooledEthByShares.selector , 10 ** 18 ),
96
+ abi.encode (ethByShares)
97
+ );
98
+
99
+ (, int256 answer ,,,) = oracle.getRoundData (1 );
100
+ assertEq (uint256 (answer), ethByShares);
101
+ }
102
+
103
+ function testLatestRoundDataBounds () public {
74
104
(, int256 answer ,,,) = oracle.latestRoundData ();
75
105
assertGe (uint256 (answer), 1154690031824824994 ); // Exchange rate queried at block 19070943
76
106
assertLe (uint256 (answer), 1.5e18 ); // Max bounds of the exchange rate. Should work for a long enough time.
0 commit comments