Skip to content

Commit

Permalink
tests: add SystemConfig tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tynes authored and roberto-bayardo committed Oct 21, 2024
1 parent 0ef14e8 commit 81935eb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,4 @@
"initCodeHash": "0x06ae2c0b39c215b7fa450d382916ce6f5c6f9f2d630e572db6b72d688255b3fd",
"sourceCodeHash": "0xa014d9c992f439dee8221e065828c3326ca2c4f5db0e83431c64c20f7e51ec14"
}
}
}
36 changes: 33 additions & 3 deletions packages/contracts-bedrock/test/L1/SystemConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,24 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
systemConfig.setGasLimit(maximumGasLimit + 1);
}

/// @dev Tests that `setGasLimit` reverts if the caller is not the owner.
function test_setEIP1559Params_notOwner_reverts() external {
/// @dev Tests that `setEIP1559Params` reverts if the caller is not the owner.
function test_setEIP1559Params_notOwner_reverts(uint32 _denominator, uint32 _elasticity) external {
vm.expectRevert("Ownable: caller is not the owner");
systemConfig.setEIP1559Params(1, 1);
systemConfig.setEIP1559Params({ _denominator: _denominator, _elasticity: _elasticity });
}

/// @dev Tests that `setEIP1559Params` reverts if the denominator is zero.
function test_setEIP1559Params_zeroDenominator_reverts(uint32 _elasticity) external {
vm.prank(systemConfig.owner());
vm.expectRevert("SystemConfig: denominator must be >= 1");
systemConfig.setEIP1559Params({ _denominator: 0, _elasticity: _elasticity });
}

/// @dev Tests that `setEIP1559Params` reverts if the elasticity is zero.
function test_setEIP1559Params_zeroElasticity_reverts(uint32 _denominator) external {
vm.prank(systemConfig.owner());
vm.expectRevert("SystemConfig: elasticity must be >= 1");
systemConfig.setEIP1559Params({ _denominator: _denominator, _elasticity: 0 });
}
}

Expand Down Expand Up @@ -599,4 +613,20 @@ contract SystemConfig_Setters_Test is SystemConfig_Init {
systemConfig.setUnsafeBlockSigner(newUnsafeSigner);
assertEq(systemConfig.unsafeBlockSigner(), newUnsafeSigner);
}

/// @dev Tests that `setEIP1559Params` updates the EIP1559 parameters successfully.
function testFuzz_setEIP1559Params_succeeds(uint32 _denominator, uint32 _elasticity) external {
vm.assume(_denominator > 1);
vm.assume(_elasticity > 1);

vm.expectEmit(address(systemConfig));
emit ConfigUpdate(
0, ISystemConfig.UpdateType.EIP_1559_PARAMS, abi.encode(uint256(_denominator) << 32 | uint64(_elasticity))
);

vm.prank(systemConfig.owner());
systemConfig.setEIP1559Params(_denominator, _elasticity);
assertEq(systemConfig.eip1559Denominator(), _denominator);
assertEq(systemConfig.eip1559Elasticity(), _elasticity);
}
}

0 comments on commit 81935eb

Please sign in to comment.