Commit a9168407 authored by Maurelian's avatar Maurelian

contracts-bedrock: Add tests for xdm pausability

parent cdb8400f
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { CommonTest } from "test/setup/CommonTest.sol";
import { SuperchainConfig } from "src/L1/SuperchainConfig.sol";
contract ExtendedPause_Test is CommonTest {
/// @dev Tests that other contracts are paused when the superchain config is paused
/// This test is somewhat redundant with tests in the SuperchainConfig and other pausable contracts, however
/// it is worthwhile to pull them into one location to ensure that the behavior is consistent.
function test_pause_fullSystem_succeeds() external {
assertFalse(superchainConfig.paused());
assertEq(l1CrossDomainMessenger.paused(), superchainConfig.paused());
vm.prank(superchainConfig.guardian());
superchainConfig.pause("identifier");
assertTrue(superchainConfig.paused());
assertEq(l1CrossDomainMessenger.paused(), superchainConfig.paused());
// The following is hacky approach which ensures that this test will fail if the paused() function is
// added to the L1StandardBridge or the L1ERC721Bridge. At that point this test should be updated to include
// those methods.
try SuperchainConfig(address(l1StandardBridge)).paused() {
revert("The L1StandardBridge has a paused() function, but is not tested as part of the ExtendedPause");
} catch (bytes memory) {
assertTrue(true);
}
try SuperchainConfig(address(l1ERC721Bridge)).paused() {
revert("The L1ERC721Bridge has a paused() function, but is not tested as part of the ExtendedPause");
} catch (bytes memory) {
assertTrue(true);
}
}
}
......@@ -13,6 +13,7 @@ import { Encoding } from "src/libraries/Encoding.sol";
// Target contract dependencies
import { OptimismPortal } from "src/L1/OptimismPortal.sol";
import { SuperchainConfig } from "src/L1/SuperchainConfig.sol";
contract L1CrossDomainMessenger_Test is Bridge_Initializer {
/// @dev The receiver address
......@@ -558,4 +559,39 @@ contract L1CrossDomainMessenger_Test is Bridge_Initializer {
hex"1111"
);
}
/// @dev Tests that the relayMessage function is able to relay a message
/// successfully by calling the target contract.
function test_relayMessage_paused_reverts() external {
vm.prank(superchainConfig.guardian());
superchainConfig.pause("identifier");
vm.expectRevert("CrossDomainMessenger: paused");
l1CrossDomainMessenger.relayMessage(
Encoding.encodeVersionedNonce({ _nonce: 0, _version: 1 }), // nonce
address(0),
address(0),
0, // value
0,
hex"1111"
);
}
/// @dev Tests that the superchain config is called by the messengers paused function
function test_pause_callsSuperchainConfig_succeeds() external {
vm.expectCall(address(superchainConfig), abi.encodeWithSelector(SuperchainConfig.paused.selector));
l1CrossDomainMessenger.paused();
}
/// @dev Tests that changing the superchain config paused status changes the return value of the messenger
function test_pause_matchesSuperchainConfig_succeeds() external {
assertFalse(l1CrossDomainMessenger.paused());
assertEq(l1CrossDomainMessenger.paused(), superchainConfig.paused());
vm.prank(superchainConfig.guardian());
superchainConfig.pause("identifier");
assertTrue(l1CrossDomainMessenger.paused());
assertEq(l1CrossDomainMessenger.paused(), superchainConfig.paused());
}
}
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