Skip to content

Commit 757ceb3

Browse files
committed
fix: Fix bugs from the v0.2.0-beta release
chore: Prepare for the v0.2.1-beta release
1 parent 3318bab commit 757ceb3

File tree

5 files changed

+96
-7
lines changed

5 files changed

+96
-7
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.1-beta] - 26 June 2024
9+
10+
### Dependencies
11+
12+
| Package | Version |
13+
| ------------------------- | ------- |
14+
| @chainlink/contracts-ccip | 1.4.0 |
15+
| @chainlink/contracts | 1.1.1 |
16+
17+
### Services
18+
19+
- [x] Chainlink CCIP
20+
- [x] Chainlink Data Feeds
21+
- [ ] Chainlink VRF 2
22+
- [ ] Chainlink VRF 2.5
23+
24+
### Fixed
25+
26+
- Bug in propose & confirm aggregator flow that could lead to aggregator being set to `address(0)`
27+
- The `maxAnswer` variable in the `MockOffchainAggregator.sol` contract was set to an incorrect value
28+
- Bug in the `MockOffchainAggregator.sol` contract where the `minAnswer` could've been set to the value greather than `maxAnswer`
29+
830
## [0.2.0-beta] - 24 June 2024
931

1032
### Dependencies
@@ -46,3 +68,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4668

4769
[0.1.0]: https://github.com/smartcontractkit/chainlink-local/releases/tag/v0.1.0
4870
[0.2.0-beta]: https://github.com/smartcontractkit/chainlink-local/releases/tag/v0.2.0-beta
71+
[0.2.1-beta]: https://github.com/smartcontractkit/chainlink-local/releases/tag/v0.2.1-beta

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@chainlink/local",
33
"description": "Chainlink Local Simulator",
44
"license": "MIT",
5-
"version": "0.1.0",
5+
"version": "0.2.1-beta",
66
"files": [
77
"src/**/*.sol",
88
"!src/test/**/*",
@@ -33,4 +33,4 @@
3333
"@chainlink/contracts": "^1.1.1",
3434
"@chainlink/contracts-ccip": "^1.4.0"
3535
}
36-
}
36+
}

src/data-feeds/MockOffchainAggregator.sol

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
pragma solidity ^0.8.0;
33

44
contract MockOffchainAggregator {
5+
int192 private constant MIN_ANSWER_POSSIBLE = 1;
6+
int192 private constant MAX_ANSWER_POSSIBLE = 95780971304118053647396689196894323976171195136475135; // type(uint176).max
7+
58
uint8 public decimals;
69
int256 public latestAnswer;
710
uint256 public latestTimestamp;
@@ -23,8 +26,8 @@ contract MockOffchainAggregator {
2326
updateAnswer(_initialAnswer);
2427
// If the minAnswer has a value of 1 and the maxAnswer has a value of 95780971304118053647396689196894323976171195136475135 then that theoretically means there is no min or max for that feed
2528
// If the minAnswer and maxAnswer values are set to other than those mentioned above, then there are actually min and max for that feed - which you will need to normalize using the demicals value
26-
minAnswer = 1;
27-
maxAnswer = type(int192).max;
29+
minAnswer = MIN_ANSWER_POSSIBLE;
30+
maxAnswer = MAX_ANSWER_POSSIBLE;
2831
}
2932

3033
function updateAnswer(int256 _answer) public {
@@ -68,6 +71,10 @@ contract MockOffchainAggregator {
6871
}
6972

7073
function updateMinAndMaxAnswers(int192 _minAnswer, int192 _maxAnswer) external {
74+
require(_minAnswer < _maxAnswer, "minAnswer must be less than maxAnswer");
75+
require(_minAnswer >= MIN_ANSWER_POSSIBLE, "minAnswer is too low");
76+
require(_maxAnswer <= MAX_ANSWER_POSSIBLE, "maxAnswer is too high");
77+
7178
minAnswer = _minAnswer;
7279
maxAnswer = _maxAnswer;
7380
}

src/data-feeds/MockV3Aggregator.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ contract MockV3Aggregator is AggregatorV2V3Interface {
6666
}
6767

6868
function proposeAggregator(AggregatorV2V3Interface _aggregator) external {
69+
require(address(_aggregator) != address(0), "Proposed aggregator cannot be zero address");
70+
require(address(_aggregator) != aggregator, "Proposed aggregator cannot be current aggregator");
6971
proposedAggregator = address(_aggregator);
7072
}
7173

72-
function confirmAggregator() external {
74+
function confirmAggregator(address _aggregator) external {
75+
require(_aggregator == address(proposedAggregator), "Invalid proposed aggregator");
7376
aggregator = proposedAggregator;
7477
proposedAggregator = address(0);
7578
}

test/unit/data-feeds/DataFeedsUnit.t.sol

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ contract BasicDataConsumerV3Test is Test {
134134
currentProposedAggregator = mockAggregator.proposedAggregator();
135135
assertEq(currentProposedAggregator, address(newMockOffchainAggregator));
136136

137-
mockAggregator.confirmAggregator();
137+
mockAggregator.confirmAggregator(address(newMockOffchainAggregator));
138138

139139
currentAggregator = mockAggregator.aggregator();
140140
currentProposedAggregator = mockAggregator.proposedAggregator();
@@ -148,7 +148,7 @@ contract BasicDataConsumerV3Test is Test {
148148

149149
function test_shouldReturnMinAndMaxAnswers() public {
150150
int192 minAnswer = 1;
151-
int192 maxAnswer = type(int192).max;
151+
int192 maxAnswer = 95780971304118053647396689196894323976171195136475135; // type(uint176).max
152152

153153
int192 resultMinAnswer = mockOffchainAggregator.minAnswer();
154154
int192 resultMaxAnswer = mockOffchainAggregator.maxAnswer();
@@ -169,4 +169,60 @@ contract BasicDataConsumerV3Test is Test {
169169
assertEq(resultMinAnswer, newMinAnswer);
170170
assertEq(resultMaxAnswer, newMaxAnswer);
171171
}
172+
173+
function test_shouldRevertIfProposedAggregatorIsZero() public {
174+
vm.expectRevert("Proposed aggregator cannot be zero address");
175+
mockAggregator.proposeAggregator(AggregatorV2V3Interface(address(0)));
176+
}
177+
178+
function test_shouldRevertIfProposedAggregatorIsCurrentAggregator() public {
179+
vm.expectRevert("Proposed aggregator cannot be current aggregator");
180+
mockAggregator.proposeAggregator(AggregatorV2V3Interface(address(mockOffchainAggregator)));
181+
}
182+
183+
function test_shouldRevertIfProposedAggregatorIsNotSet() public {
184+
vm.expectRevert("Invalid proposed aggregator");
185+
mockAggregator.confirmAggregator(address(1));
186+
}
187+
188+
function test_shouldRevertIfProposedAggregatorIsNotCorrect() public {
189+
int256 newAnswer = 200000000000;
190+
MockOffchainAggregator newMockOffchainAggregator = new MockOffchainAggregator(decimals, newAnswer);
191+
192+
mockAggregator.proposeAggregator(AggregatorV2V3Interface(address(newMockOffchainAggregator)));
193+
vm.expectRevert("Invalid proposed aggregator");
194+
mockAggregator.confirmAggregator(address(1));
195+
}
196+
197+
function test_shouldRevertIfMinAnswerIsGreaterThanMaxAnswer() public {
198+
int192 newMinAnswer = 1.5 ether;
199+
int192 newMaxAnswer = 0.5 ether;
200+
201+
vm.expectRevert("minAnswer must be less than maxAnswer");
202+
mockOffchainAggregator.updateMinAndMaxAnswers(newMinAnswer, newMaxAnswer);
203+
}
204+
205+
function test_shouldRevertIfMinAnswerIsEqualToMaxAnswer() public {
206+
int192 newMinAnswer = 1.5 ether;
207+
int192 newMaxAnswer = 1.5 ether;
208+
209+
vm.expectRevert("minAnswer must be less than maxAnswer");
210+
mockOffchainAggregator.updateMinAndMaxAnswers(newMinAnswer, newMaxAnswer);
211+
}
212+
213+
function test_shouldRevertIfMinAnswerIsLessMinAnswerPossible() public {
214+
int192 newMinAnswer = 0;
215+
int192 newMaxAnswer = 1.5 ether;
216+
217+
vm.expectRevert("minAnswer is too low");
218+
mockOffchainAggregator.updateMinAndMaxAnswers(newMinAnswer, newMaxAnswer);
219+
}
220+
221+
function test_shouldRevertIfMaxAnswerIsGreaterThanMaxAnswerPossible() public {
222+
int192 newMinAnswer = 0.5 ether;
223+
int192 newMaxAnswer = type(int192).max;
224+
225+
vm.expectRevert("maxAnswer is too high");
226+
mockOffchainAggregator.updateMinAndMaxAnswers(newMinAnswer, newMaxAnswer);
227+
}
172228
}

0 commit comments

Comments
 (0)