Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
237a351f
Unverified
Commit
237a351f
authored
Nov 28, 2022
by
Maurelian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ctb: Add unit and fuzz tests to SystemConfig
parent
d288b2bb
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
145 additions
and
0 deletions
+145
-0
chatty-dogs-brush.md
.changeset/chatty-dogs-brush.md
+5
-0
.gas-snapshot
packages/contracts-bedrock/.gas-snapshot
+7
-0
SystemConfig.t.sol
packages/contracts-bedrock/contracts/test/SystemConfig.t.sol
+133
-0
No files found.
.changeset/chatty-dogs-brush.md
0 → 100644
View file @
237a351f
---
'
@eth-optimism/contracts-bedrock'
:
patch
---
Add tests to the SystemConfig contract
packages/contracts-bedrock/.gas-snapshot
View file @
237a351f
...
...
@@ -290,3 +290,10 @@ SequencerFeeVault_Test:test_minWithdrawalAmount_succeeds() (gas: 5420)
SequencerFeeVault_Test:test_receive_succeeds() (gas: 17336)
SequencerFeeVault_Test:test_withdraw_notEnough_reverts() (gas: 9310)
SequencerFeeVault_Test:test_withdraw_succeeds() (gas: 135878)
SystemConfig_Initialize_TestFail:test_initialize_lowGasLimit_reverts() (gas: 61634)
SystemConfig_Setters_Test:test_setBatcherHash_succeeds() (gas: 24298)
SystemConfig_Setters_Test:test_setGasConfig_succeeds() (gas: 30855)
SystemConfig_Setters_Test:test_setGasLimit_succeeds() (gas: 24435)
SystemConfig_Setters_TestFail:test_setBatcherHash_notOwner_reverts() (gas: 10501)
SystemConfig_Setters_TestFail:test_setGasConfig_notOwner_reverts() (gas: 10576)
SystemConfig_Setters_TestFail:test_setGasLimit_notOwner_reverts() (gas: 10592)
packages/contracts-bedrock/contracts/test/SystemConfig.t.sol
0 → 100644
View file @
237a351f
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { CommonTest } from "./CommonTest.t.sol";
import { SystemConfig } from "../L1/SystemConfig.sol";
contract SystemConfig_Init is CommonTest {
SystemConfig sysConf;
function setUp() external {
sysConf = new SystemConfig({
_owner: alice,
_overhead: 2100,
_scalar: 1000000,
_batcherHash: bytes32(hex"abcd"),
_gasLimit: 9_000_000
});
}
}
contract SystemConfig_Initialize_TestFail is CommonTest {
function test_initialize_lowGasLimit_reverts() external {
vm.expectRevert("SystemConfig: gas limit too low");
new SystemConfig({
_owner: alice,
_overhead: 0,
_scalar: 0,
_batcherHash: bytes32(hex""),
_gasLimit: 7_999_999
});
}
}
contract SystemConfig_Setters_TestFail is SystemConfig_Init {
function test_setBatcherHash_notOwner_reverts() external {
vm.expectRevert("Ownable: caller is not the owner");
sysConf.setBatcherHash(bytes32(hex""));
}
function test_setGasConfig_notOwner_reverts() external {
vm.expectRevert("Ownable: caller is not the owner");
sysConf.setGasConfig(0, 0);
}
function test_setGasLimit_notOwner_reverts() external {
vm.expectRevert("Ownable: caller is not the owner");
sysConf.setGasLimit(0);
}
}
contract SystemConfig_Setters_Test is SystemConfig_Init {
event ConfigUpdate(
uint256 indexed version,
SystemConfig.UpdateType indexed updateType,
bytes data
);
function test_setBatcherHash_succeeds() external {
bytes32 newBatcherHash = bytes32(hex"1234");
vm.expectEmit(true, true, true, true);
emit ConfigUpdate(0, SystemConfig.UpdateType.BATCHER, abi.encode(newBatcherHash));
vm.prank(alice);
sysConf.setBatcherHash(newBatcherHash);
assertEq(sysConf.batcherHash(), newBatcherHash);
}
function testFuzz_setBatcherHash_succeeds(bytes32 newBatcherHash) external {
vm.expectEmit(true, true, true, true);
emit ConfigUpdate(0, SystemConfig.UpdateType.BATCHER, abi.encode(newBatcherHash));
vm.prank(alice);
sysConf.setBatcherHash(newBatcherHash);
assertEq(sysConf.batcherHash(), newBatcherHash);
}
function test_setGasConfig_succeeds() external {
uint256 newOverhead = 1234;
uint256 newScalar = 5678;
vm.expectEmit(true, true, true, true);
emit ConfigUpdate(
0,
SystemConfig.UpdateType.GAS_CONFIG,
abi.encode(newOverhead, newScalar)
);
vm.prank(alice);
sysConf.setGasConfig(newOverhead, newScalar);
assertEq(sysConf.overhead(), newOverhead);
assertEq(sysConf.scalar(), newScalar);
}
function testFuzz_setGasConfig_succeeds(uint256 newOverhead, uint256 newScalar) external {
vm.expectEmit(true, true, true, true);
emit ConfigUpdate(
0,
SystemConfig.UpdateType.GAS_CONFIG,
abi.encode(newOverhead, newScalar)
);
vm.prank(alice);
sysConf.setGasConfig(newOverhead, newScalar);
assertEq(sysConf.overhead(), newOverhead);
assertEq(sysConf.scalar(), newScalar);
}
function test_setGasLimit_succeeds() external {
uint64 newGasLimit = 9_876_543;
vm.expectEmit(true, true, true, true);
emit ConfigUpdate(0, SystemConfig.UpdateType.GAS_LIMIT, abi.encode(newGasLimit));
vm.prank(alice);
sysConf.setGasLimit(newGasLimit);
assertEq(sysConf.gasLimit(), newGasLimit);
}
function testFuzz_setGasLimit_succeeds(uint64 newGasLimit) external {
uint64 minimumGasLimit = sysConf.MINIMUM_GAS_LIMIT();
newGasLimit = uint64(
bound(uint256(newGasLimit), uint256(minimumGasLimit), uint256(type(uint64).max))
);
vm.expectEmit(true, true, true, true);
emit ConfigUpdate(0, SystemConfig.UpdateType.GAS_LIMIT, abi.encode(newGasLimit));
vm.prank(alice);
sysConf.setGasLimit(newGasLimit);
assertEq(sysConf.gasLimit(), newGasLimit);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment