Skip to content

Commit 40b6cc4

Browse files
zimphaThegaram
authored andcommitted
feat: support resetPauseCooldownPeriod (#127)
1 parent a2e3d94 commit 40b6cc4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/misc/PauseController.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ contract PauseController is OwnableUpgradeable {
2323
/// @param component The component that is unpaused.
2424
event Unpause(address indexed component);
2525

26+
/// @notice Emitted when the pause cooldown period of a component is reset.
27+
/// @param component The component that has its pause cooldown period reset.
28+
event ResetPauseCooldownPeriod(address indexed component);
29+
2630
/// @notice Emitted when the pause cooldown period is updated.
2731
/// @param oldPauseCooldownPeriod The old pause cooldown period.
2832
/// @param newPauseCooldownPeriod The new pause cooldown period.
@@ -150,6 +154,14 @@ contract PauseController is OwnableUpgradeable {
150154
emit Unpause(address(component));
151155
}
152156

157+
/// @notice Reset the pause cooldown period of a component.
158+
/// @param component The component to reset the pause cooldown period.
159+
function resetPauseCooldownPeriod(IPausable component) external onlyOwner {
160+
lastUnpauseTime[address(component)] = 0;
161+
162+
emit ResetPauseCooldownPeriod(address(component));
163+
}
164+
153165
/// @notice Set the pause cooldown period.
154166
/// @param newPauseCooldownPeriod The new pause cooldown period.
155167
function updatePauseCooldownPeriod(uint256 newPauseCooldownPeriod) external onlyOwner {

src/test/misc/PauseController.t.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ contract MockPausable is IPausable {
2525
contract PauseControllerTest is Test {
2626
event Pause(address indexed component);
2727
event Unpause(address indexed component);
28+
event ResetPauseCooldownPeriod(address indexed component);
2829
event UpdatePauseCooldownPeriod(uint256 oldPauseCooldownPeriod, uint256 newPauseCooldownPeriod);
2930

3031
uint256 public constant PAUSE_COOLDOWN_PERIOD = 1 days;
@@ -117,8 +118,22 @@ contract PauseControllerTest is Test {
117118
emit Unpause(address(mockPausable));
118119
pauseController.unpause(mockPausable);
119120
assertEq(pauseController.getLastUnpauseTime(mockPausable), block.timestamp);
121+
assertFalse(mockPausable.paused());
120122

123+
// cannot pause before cooldown period
124+
vm.expectRevert(PauseController.ErrorCooldownPeriodNotPassed.selector);
125+
pauseController.pause(mockPausable);
126+
127+
// reset pause cooldown period
128+
vm.expectEmit(true, false, false, true);
129+
emit ResetPauseCooldownPeriod(address(mockPausable));
130+
pauseController.resetPauseCooldownPeriod(mockPausable);
131+
assertEq(pauseController.getLastUnpauseTime(mockPausable), 0);
132+
133+
// can pause after reset
121134
assertFalse(mockPausable.paused());
135+
pauseController.pause(mockPausable);
136+
assertTrue(mockPausable.paused());
122137

123138
vm.stopPrank();
124139
}

0 commit comments

Comments
 (0)