From 81935eb7f693b2394ed0bcea25eda216e74be1a6 Mon Sep 17 00:00:00 2001 From: Mark Tyneway Date: Thu, 17 Oct 2024 11:26:19 +0700 Subject: [PATCH] tests: add SystemConfig tests --- packages/contracts-bedrock/semver-lock.json | 2 +- .../test/L1/SystemConfig.t.sol | 36 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/packages/contracts-bedrock/semver-lock.json b/packages/contracts-bedrock/semver-lock.json index 1a5b12bd298be..d9e6d73e21b0f 100644 --- a/packages/contracts-bedrock/semver-lock.json +++ b/packages/contracts-bedrock/semver-lock.json @@ -235,4 +235,4 @@ "initCodeHash": "0x06ae2c0b39c215b7fa450d382916ce6f5c6f9f2d630e572db6b72d688255b3fd", "sourceCodeHash": "0xa014d9c992f439dee8221e065828c3326ca2c4f5db0e83431c64c20f7e51ec14" } -} +} \ No newline at end of file diff --git a/packages/contracts-bedrock/test/L1/SystemConfig.t.sol b/packages/contracts-bedrock/test/L1/SystemConfig.t.sol index cbd116e27bdeb..6af1ca652e3b8 100644 --- a/packages/contracts-bedrock/test/L1/SystemConfig.t.sol +++ b/packages/contracts-bedrock/test/L1/SystemConfig.t.sol @@ -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 }); } } @@ -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); + } }