Commit 75a05bd5 authored by Mark Tyneway's avatar Mark Tyneway

tests: add for initialize events

parent 158bf1fd
...@@ -165,12 +165,12 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -165,12 +165,12 @@ contract SystemConfig is OwnableUpgradeable, Semver {
__Ownable_init(); __Ownable_init();
transferOwnership(_owner); transferOwnership(_owner);
_setGasConfig({ _overhead: _overhead, _scalar: _scalar }); // These are set in ascending order of their UpdateTypes.
_setBatcherHash(_batcherHash); _setBatcherHash(_batcherHash);
_setGasConfig({ _overhead: _overhead, _scalar: _scalar });
_setGasLimit(_gasLimit); _setGasLimit(_gasLimit);
_setUnsafeBlockSigner(_unsafeBlockSigner);
_setAddress(_unsafeBlockSigner, UNSAFE_BLOCK_SIGNER_SLOT);
_setAddress(_batchInbox, BATCH_INBOX_SLOT); _setAddress(_batchInbox, BATCH_INBOX_SLOT);
_setAddress(_addresses.l1CrossDomainMessenger, L1_CROSS_DOMAIN_MESSENGER_SLOT); _setAddress(_addresses.l1CrossDomainMessenger, L1_CROSS_DOMAIN_MESSENGER_SLOT);
_setAddress(_addresses.l1ERC721Bridge, L1_ERC_721_BRIDGE_SLOT); _setAddress(_addresses.l1ERC721Bridge, L1_ERC_721_BRIDGE_SLOT);
...@@ -282,9 +282,15 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -282,9 +282,15 @@ contract SystemConfig is OwnableUpgradeable, Semver {
} }
} }
/// @notice Updates the unsafe block signer address. /// @notice Updates the unsafe block signer address. Can only be called by the owner.
/// @param _unsafeBlockSigner New unsafe block signer address. /// @param _unsafeBlockSigner New unsafe block signer address.
function setUnsafeBlockSigner(address _unsafeBlockSigner) external onlyOwner { function setUnsafeBlockSigner(address _unsafeBlockSigner) external onlyOwner {
_setUnsafeBlockSigner(_unsafeBlockSigner);
}
/// @notice Updates the unsafe block signer address.
/// @param _unsafeBlockSigner New unsafe block signer address.
function _setUnsafeBlockSigner(address _unsafeBlockSigner) internal {
_setAddress(_unsafeBlockSigner, UNSAFE_BLOCK_SIGNER_SLOT); _setAddress(_unsafeBlockSigner, UNSAFE_BLOCK_SIGNER_SLOT);
bytes memory data = abi.encode(_unsafeBlockSigner); bytes memory data = abi.encode(_unsafeBlockSigner);
......
...@@ -51,6 +51,9 @@ contract CommonTest is Test { ...@@ -51,6 +51,9 @@ contract CommonTest is Test {
event TransactionDeposited(address indexed from, address indexed to, uint256 indexed version, bytes opaqueData); event TransactionDeposited(address indexed from, address indexed to, uint256 indexed version, bytes opaqueData);
/// @dev OpenZeppelin Ownable.sol transferOwnership event
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
FFIInterface ffi; FFIInterface ffi;
function setUp() public virtual { function setUp() public virtual {
......
...@@ -26,9 +26,6 @@ contract XDomainSetter3 is CrossDomainOwnable3 { ...@@ -26,9 +26,6 @@ contract XDomainSetter3 is CrossDomainOwnable3 {
contract CrossDomainOwnable3_Test is Messenger_Initializer { contract CrossDomainOwnable3_Test is Messenger_Initializer {
XDomainSetter3 setter; XDomainSetter3 setter;
/// @dev OpenZeppelin Ownable.sol transferOwnership event
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/// @dev CrossDomainOwnable3.sol transferOwnership event /// @dev CrossDomainOwnable3.sol transferOwnership event
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner, bool isLocal); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner, bool isLocal);
......
...@@ -18,6 +18,8 @@ contract SystemConfig_Init is CommonTest { ...@@ -18,6 +18,8 @@ contract SystemConfig_Init is CommonTest {
SystemConfig sysConf; SystemConfig sysConf;
SystemConfig systemConfigImpl; SystemConfig systemConfigImpl;
event ConfigUpdate(uint256 indexed version, SystemConfig.UpdateType indexed updateType, bytes data);
// Dummy addresses used to test getters // Dummy addresses used to test getters
address constant batchInbox = address(0x18); address constant batchInbox = address(0x18);
address constant l1CrossDomainMessenger = address(0x20); address constant l1CrossDomainMessenger = address(0x20);
...@@ -138,6 +140,51 @@ contract SystemConfig_Initialize_Test is SystemConfig_Init { ...@@ -138,6 +140,51 @@ contract SystemConfig_Initialize_Test is SystemConfig_Init {
); );
assertEq(sysConf.startBlock(), startBlock); assertEq(sysConf.startBlock(), startBlock);
} }
/// @dev Ensures that the events are emitted during initialization.
function test_initialize_events_succeeds() external {
// Wipe out the initialized slot so the proxy can be initialized again
vm.store(address(sysConf), bytes32(0), bytes32(0));
vm.store(address(sysConf), bytes32(uint256(106)), bytes32(0));
assertEq(sysConf.startBlock(), 0);
// The order depends here
vm.expectEmit(true, true, true, true, address(sysConf));
emit ConfigUpdate(0, SystemConfig.UpdateType.BATCHER, abi.encode(batcherHash));
vm.expectEmit(true, true, true, true, address(sysConf));
emit ConfigUpdate(0, SystemConfig.UpdateType.GAS_CONFIG, abi.encode(overhead, scalar));
vm.expectEmit(true, true, true, true, address(sysConf));
emit ConfigUpdate(0, SystemConfig.UpdateType.GAS_LIMIT, abi.encode(gasLimit));
vm.expectEmit(true, true, true, true, address(sysConf));
emit ConfigUpdate(0, SystemConfig.UpdateType.UNSAFE_BLOCK_SIGNER, abi.encode(unsafeBlockSigner));
vm.prank(multisig);
Proxy(payable(address(sysConf))).upgradeToAndCall(
address(systemConfigImpl),
abi.encodeCall(
SystemConfig.initialize,
(
alice, // _owner,
overhead, // _overhead,
scalar, // _scalar,
batcherHash, // _batcherHash
gasLimit, // _gasLimit,
unsafeBlockSigner, // _unsafeBlockSigner,
Constants.DEFAULT_RESOURCE_CONFIG(), // _config,
0, // _startBlock
batchInbox, // _batchInbox
SystemConfig.Addresses({ // _addresses
l1CrossDomainMessenger: l1CrossDomainMessenger,
l1ERC721Bridge: l1ERC721Bridge,
l1StandardBridge: l1StandardBridge,
l2OutputOracle: l2OutputOracle,
optimismPortal: optimismPortal,
optimismMintableERC20Factory: optimismMintableERC20Factory
})
)
)
);
}
} }
contract SystemConfig_Initialize_TestFail is SystemConfig_Init { contract SystemConfig_Initialize_TestFail is SystemConfig_Init {
...@@ -318,8 +365,6 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init { ...@@ -318,8 +365,6 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
} }
contract SystemConfig_Setters_Test is SystemConfig_Init { contract SystemConfig_Setters_Test is SystemConfig_Init {
event ConfigUpdate(uint256 indexed version, SystemConfig.UpdateType indexed updateType, bytes data);
/// @dev Tests that `setBatcherHash` updates the batcher hash successfully. /// @dev Tests that `setBatcherHash` updates the batcher hash successfully.
function testFuzz_setBatcherHash_succeeds(bytes32 newBatcherHash) external { function testFuzz_setBatcherHash_succeeds(bytes32 newBatcherHash) external {
vm.expectEmit(true, true, true, true); vm.expectEmit(true, true, true, true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment