Skip to content

Commit 5933f78

Browse files
authored
build(contracts): enforce compiler warnings and fix test return value checks (#18264)
* build(contracts): enforce compiler warnings as errors - Add deny_warnings to foundry.toml default profile - Add set -e to pre-pr command in justfile * test(contracts-bedrock): fix unchecked low-level call return values in FeeSplitter tests - add proper return value checks for low-level .call() operations - fix Warning 9302 in FeeSplitter.t.sol (3 occurrences) - fix Warning 9302 in FeeSplitterVaults.t.sol (1 occurrence) * build(contracts): ignore too-many-warnings error in foundry config * fix(test): fix assertion logic in FeeSplitter expectRevert tests - remove assert(!success) after vm.expectRevert() calls - add success variable reference to suppress unused variable warning
1 parent b7d3fb4 commit 5933f78

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

packages/contracts-bedrock/foundry.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ fs_permissions = [
6868
]
6969

7070
# 5159 error code is selfdestruct error code
71-
ignored_error_codes = ["transient-storage", "code-size", "init-code-size", 5159]
71+
ignored_error_codes = ["transient-storage", "code-size", "init-code-size", "too-many-warnings", 5159]
72+
deny_warnings = true
7273
ffi = true
7374

7475
# We set the gas limit to max int64 to avoid running out of gas during testing, since the default

packages/contracts-bedrock/justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ pre-commit *ARGS:
352352
# Cleans, builds, lints, and runs all checks.
353353
pre-pr *ARGS:
354354
#!/bin/bash
355+
set -e
355356
# Optionally clean the previous build.
356357
# --clean is typically not needed but can force a clean build if you suspect cache issues.
357358
if [[ "{{ARGS}}" == *"--clean"* ]]; then

packages/contracts-bedrock/test/L2/FeeSplitter.t.sol

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ contract FeeSplitter_Initialize_Test is FeeSplitter_TestInit {
153153
contract FeeSplitter_Receive_Test is FeeSplitter_TestInit {
154154
/// @notice Test that receive function reverts when sender is not an approved vault
155155
function testFuzz_feeSplitterReceive_whenNotApprovedVault_reverts(address _caller, uint256 _amount) public {
156+
vm.assume(_caller != address(0));
156157
vm.assume(_caller != Predeploys.SEQUENCER_FEE_WALLET);
157158
vm.assume(_caller != Predeploys.BASE_FEE_VAULT);
158159
vm.assume(_caller != Predeploys.OPERATOR_FEE_VAULT);
@@ -161,11 +162,13 @@ contract FeeSplitter_Receive_Test is FeeSplitter_TestInit {
161162

162163
vm.prank(_caller);
163164
vm.expectRevert(IFeeSplitter.FeeSplitter_SenderNotCurrentVault.selector);
164-
payable(address(feeSplitter)).call{ value: _amount }("");
165+
(bool revertsAsExpected,) = payable(address(feeSplitter)).call{ value: _amount }("");
166+
assertTrue(revertsAsExpected, "FeeSplitter_Test: call did not revert");
165167
}
166168

167169
/// @notice Test receive function from non-approved vault reverts even during disbursement
168170
function testFuzz_feeSplitterReceive_whenNonFeeVault_reverts(address _caller, uint256 _amount) public {
171+
vm.assume(_caller != address(0));
169172
vm.assume(_caller != Predeploys.SEQUENCER_FEE_WALLET);
170173
vm.assume(_caller != Predeploys.BASE_FEE_VAULT);
171174
vm.assume(_caller != Predeploys.OPERATOR_FEE_VAULT);
@@ -177,7 +180,8 @@ contract FeeSplitter_Receive_Test is FeeSplitter_TestInit {
177180

178181
// Now we test the actual sender validation
179182
vm.expectRevert(IFeeSplitter.FeeSplitter_SenderNotCurrentVault.selector);
180-
payable(address(feeSplitter)).call{ value: _amount }("");
183+
(bool revertsAsExpected,) = payable(address(feeSplitter)).call{ value: _amount }("");
184+
assertTrue(revertsAsExpected, "FeeSplitter_Test: call did not revert");
181185
}
182186

183187
/// @notice Test receive function works during disbursement from SequencerFeeVault
@@ -659,7 +663,8 @@ contract FeeSplitter_DisburseFees_Test is FeeSplitter_TestInit {
659663
// Attempt to send ETH from the vault - should revert because transient storage was cleared
660664
vm.prank(_vault);
661665
vm.expectRevert(IFeeSplitter.FeeSplitter_SenderNotCurrentVault.selector);
662-
payable(address(feeSplitter)).call{ value: _attemptAmount }("");
666+
(bool revertsAsExpected,) = payable(address(feeSplitter)).call{ value: _attemptAmount }("");
667+
assertTrue(revertsAsExpected, "FeeSplitter_Test: call did not revert");
663668
}
664669
}
665670

packages/contracts-bedrock/test/L2/FeeSplitterVaults.t.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ contract FeeSplitterVaults_Receive_Test is Test {
5252
}
5353

5454
vm.prank(_selectedVault);
55-
payable(address(feeSplitter)).call{ value: _amount }("");
55+
(bool success,) = payable(address(feeSplitter)).call{ value: _amount }("");
56+
require(success, "FeeSplitterVaults_Test: call failed");
5657
}
5758
}
5859
}

0 commit comments

Comments
 (0)