Skip to content

Commit 5039212

Browse files
Merge pull request #194 from bancorprotocol/fix-forge-tests
fix forge tests
2 parents 6cd4454 + 0a7ba86 commit 5039212

File tree

11 files changed

+582
-360
lines changed

11 files changed

+582
-360
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
- name: Install Foundry
7171
uses: foundry-rs/foundry-toolchain@v1
7272
with:
73-
version: nightly-56dbd20c7179570c53b6c17ff34daa7273a4ddae
73+
version: v1.3.5 # stable version 09.09.2025
7474

7575
- name: Install dependencies
7676
run: pnpm install

test/forge/CarbonPOL.t.sol

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
22
pragma solidity 0.8.19;
33

4+
import { Vm } from "forge-std/Vm.sol";
5+
46
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
57

68
import { TestFixture } from "./TestFixture.t.sol";
@@ -88,7 +90,7 @@ contract CarbonPOLTest is TestFixture {
8890
testCaseParser = new POLTestCaseParser();
8991
}
9092

91-
function testShouldBeInitialized() public {
93+
function testShouldBeInitialized() public view {
9294
uint16 version = carbonPOL.version();
9395
assertEq(version, 2);
9496
}
@@ -124,12 +126,22 @@ contract CarbonPOLTest is TestFixture {
124126
carbonPOL.setMarketPriceMultiply(0);
125127
}
126128

127-
/// @dev test that setMarketPriceMultiply with the same value should be ignored
128-
function testFailShouldIgnoreSettingTheSameMarketPriceMultiply() public {
129-
vm.prank(admin);
130-
vm.expectEmit(false, false, false, false);
131-
emit MarketPriceMultiplyUpdated(MARKET_PRICE_MULTIPLY_DEFAULT, MARKET_PRICE_MULTIPLY_DEFAULT);
129+
/// @dev should ignore setting the same MarketPriceMultiply (no events emitted)
130+
function testShouldIgnoreSettingTheSameMarketPriceMultiply() public {
131+
vm.startPrank(admin);
132+
133+
// first set establishes the default value
132134
carbonPOL.setMarketPriceMultiply(MARKET_PRICE_MULTIPLY_DEFAULT);
135+
136+
// record logs for the redundant call
137+
vm.recordLogs();
138+
carbonPOL.setMarketPriceMultiply(MARKET_PRICE_MULTIPLY_DEFAULT);
139+
Vm.Log[] memory logs = vm.getRecordedLogs();
140+
141+
// ensure no events were emitted
142+
assertEq(logs.length, 0, "expected no events to be emitted");
143+
144+
vm.stopPrank();
133145
}
134146

135147
/// @dev test that admin should be able to update the market price multiply
@@ -165,12 +177,22 @@ contract CarbonPOLTest is TestFixture {
165177
carbonPOL.setPriceDecayHalfLife(0);
166178
}
167179

168-
/// @dev test that setPriceDecayHalfLife with the same value should be ignored
169-
function testFailShouldIgnoreSettingTheSamePriceDecayHalfLife() public {
170-
vm.prank(admin);
171-
vm.expectEmit(false, false, false, false);
172-
emit PriceDecayHalfLifeUpdated(PRICE_DECAY_HALFLIFE_DEFAULT, PRICE_DECAY_HALFLIFE_DEFAULT);
180+
/// @dev should ignore setting the same PriceDecayHalfLife (no events emitted)
181+
function testShouldIgnoreSettingTheSamePriceDecayHalfLife() public {
182+
vm.startPrank(admin);
183+
184+
// first set establishes the default value
185+
carbonPOL.setPriceDecayHalfLife(PRICE_DECAY_HALFLIFE_DEFAULT);
186+
187+
// record logs for the redundant call
188+
vm.recordLogs();
173189
carbonPOL.setPriceDecayHalfLife(PRICE_DECAY_HALFLIFE_DEFAULT);
190+
Vm.Log[] memory logs = vm.getRecordedLogs();
191+
192+
// ensure no events were emitted
193+
assertEq(logs.length, 0, "expected no events to be emitted");
194+
195+
vm.stopPrank();
174196
}
175197

176198
/// @dev test that admin should be able to update the price decay half-life
@@ -206,12 +228,22 @@ contract CarbonPOLTest is TestFixture {
206228
carbonPOL.setEthSaleAmount(0);
207229
}
208230

209-
/// @dev test that setEthSaleAmount with the same value should be ignored
210-
function testFailShouldIgnoreSettingTheSameEthSaleAmount() public {
211-
vm.prank(admin);
212-
vm.expectEmit(false, false, false, false);
213-
emit EthSaleAmountUpdated(ETH_SALE_AMOUNT_DEFAULT, ETH_SALE_AMOUNT_DEFAULT);
231+
/// @dev should ignore setting the same EthSaleAmount (no events emitted)
232+
function testShouldIgnoreSettingTheSameEthSaleAmount() public {
233+
vm.startPrank(admin);
234+
235+
// first set establishes the default value
236+
carbonPOL.setEthSaleAmount(ETH_SALE_AMOUNT_DEFAULT);
237+
238+
// record logs for the redundant call
239+
vm.recordLogs();
214240
carbonPOL.setEthSaleAmount(ETH_SALE_AMOUNT_DEFAULT);
241+
Vm.Log[] memory logs = vm.getRecordedLogs();
242+
243+
// ensure no events were emitted
244+
assertEq(logs.length, 0, "expected no events to be emitted");
245+
246+
vm.stopPrank();
215247
}
216248

217249
/// @dev test that admin should be able to update the eth sale amount
@@ -247,12 +279,22 @@ contract CarbonPOLTest is TestFixture {
247279
carbonPOL.setMinEthSaleAmount(0);
248280
}
249281

250-
/// @dev test that setMinEthSaleAmount with the same value should be ignored
251-
function testFailShouldIgnoreSettingTheSameMinEthSaleAmount() public {
252-
vm.prank(admin);
253-
vm.expectEmit(false, false, false, false);
254-
emit MinEthSaleAmountUpdated(MIN_ETH_SALE_AMOUNT_DEFAULT, MIN_ETH_SALE_AMOUNT_DEFAULT);
282+
/// @dev should ignore setting the same MinEthSaleAmount (no events emitted)
283+
function testShouldIgnoreSettingTheSameMinEthSaleAmount() public {
284+
vm.startPrank(admin);
285+
286+
// first set establishes the default value
287+
carbonPOL.setMinEthSaleAmount(MIN_ETH_SALE_AMOUNT_DEFAULT);
288+
289+
// record logs for the redundant call
290+
vm.recordLogs();
255291
carbonPOL.setMinEthSaleAmount(MIN_ETH_SALE_AMOUNT_DEFAULT);
292+
Vm.Log[] memory logs = vm.getRecordedLogs();
293+
294+
// ensure no events were emitted
295+
assertEq(logs.length, 0, "expected no events to be emitted");
296+
297+
vm.stopPrank();
256298
}
257299

258300
/// @dev test that admin should be able to update the min eth sale amount
@@ -300,7 +342,7 @@ contract CarbonPOLTest is TestFixture {
300342
*/
301343

302344
/// @dev test trading should be disabled initially for all tokens
303-
function testTradingShouldBeDisabledInitially(uint256 i) public {
345+
function testTradingShouldBeDisabledInitially(uint256 i) public view {
304346
// pick one of these tokens to test
305347
Token[4] memory tokens = [token1, token2, bnt, NATIVE_TOKEN];
306348
// pick a random number from 0 to 2 for the tokens

0 commit comments

Comments
 (0)