Skip to content

Commit 79d1486

Browse files
committed
test: extract ChainlinkAggregatorMock
1 parent c05a52e commit 79d1486

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

test/ChainlinkOracleTest.sol

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
44
import "forge-std/Test.sol";
55
import "src/ChainlinkOracle.sol";
66
import "src/libraries/ErrorsLib.sol";
7+
import "./mock/ChainlinkAggregatorMock.sol";
78

89
AggregatorV3Interface constant feedZero = AggregatorV3Interface(address(0));
910
// 8 decimals of precision
@@ -21,22 +22,6 @@ AggregatorV3Interface constant usdcEthFeed = AggregatorV3Interface(0x986b5E1e175
2122
// 8 decimals of precision
2223
AggregatorV3Interface constant ethUsdFeed = AggregatorV3Interface(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419);
2324

24-
contract FakeAggregator {
25-
int256 public answer;
26-
27-
function setAnwser(int256 newAnswer) external {
28-
answer = newAnswer;
29-
}
30-
31-
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
32-
return (0, answer, 0, 0, 0);
33-
}
34-
35-
function decimals() external pure returns (uint256) {
36-
return 8;
37-
}
38-
}
39-
4025
contract ChainlinkOracleTest is Test {
4126
function setUp() public {
4227
vm.createSelectFork(vm.envString("ETH_RPC_URL"));
@@ -107,7 +92,7 @@ contract ChainlinkOracleTest is Test {
10792

10893
function testNegativeAnswer(int256 price) public {
10994
price = bound(price, type(int256).min, -1);
110-
FakeAggregator aggregator = new FakeAggregator();
95+
ChainlinkAggregatorMock aggregator = new ChainlinkAggregatorMock();
11196
ChainlinkOracle oracle =
11297
new ChainlinkOracle(AggregatorV3Interface(address(aggregator)), feedZero, feedZero, feedZero, 18, 0);
11398
aggregator.setAnwser(price);

test/mock/ChainlinkAggregatorMock.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.0;
3+
4+
contract ChainlinkAggregatorMock {
5+
int256 public answer;
6+
7+
function setAnwser(int256 newAnswer) external {
8+
answer = newAnswer;
9+
}
10+
11+
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
12+
return (0, answer, 0, 0, 0);
13+
}
14+
15+
function decimals() external pure returns (uint256) {
16+
return 8;
17+
}
18+
}

0 commit comments

Comments
 (0)