From ff2a495389589549905eca37f0c7bf0c87e80295 Mon Sep 17 00:00:00 2001 From: Yorke Rhodes Date: Fri, 18 Aug 2023 16:13:42 -0400 Subject: [PATCH] Add pausable ism (#2675) --- solidity/contracts/isms/PausableIsm.sol | 34 +++++++++++++++++++++++++ solidity/test/isms/PausableIsm.t.sol | 32 +++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 solidity/contracts/isms/PausableIsm.sol create mode 100644 solidity/test/isms/PausableIsm.t.sol diff --git a/solidity/contracts/isms/PausableIsm.sol b/solidity/contracts/isms/PausableIsm.sol new file mode 100644 index 000000000..54c054104 --- /dev/null +++ b/solidity/contracts/isms/PausableIsm.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +pragma solidity >=0.8.0; + +// ============ External Imports ============ +import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol"; +import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; + +// ============ Internal Imports ============ +import {IInterchainSecurityModule} from "../interfaces/IInterchainSecurityModule.sol"; + +contract PausableIsm is IInterchainSecurityModule, Ownable, Pausable { + uint8 public constant override moduleType = uint8(Types.NULL); + + /** + * @inheritdoc IInterchainSecurityModule + * @dev Reverts when paused, otherwise returns `true`. + */ + function verify(bytes calldata, bytes calldata) + external + view + whenNotPaused + returns (bool) + { + return true; + } + + function pause() external onlyOwner { + _pause(); + } + + function unpause() external onlyOwner { + _unpause(); + } +} diff --git a/solidity/test/isms/PausableIsm.t.sol b/solidity/test/isms/PausableIsm.t.sol new file mode 100644 index 000000000..74a2bfdd7 --- /dev/null +++ b/solidity/test/isms/PausableIsm.t.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT or Apache-2.0 +pragma solidity ^0.8.13; + +import {Test} from "forge-std/Test.sol"; + +import {PausableIsm} from "../../contracts/isms/PausableIsm.sol"; + +contract PausableIsmTest is Test { + PausableIsm ism; + + function setUp() public { + ism = new PausableIsm(); + } + + function test_verify() public { + assertTrue(ism.verify("", "")); + ism.pause(); + vm.expectRevert(bytes("Pausable: paused")); + ism.verify("", ""); + } + + function test_pause() public { + ism.pause(); + assertTrue(ism.paused()); + } + + function test_unpause() public { + ism.pause(); + ism.unpause(); + assertFalse(ism.paused()); + } +}