From 2a14489644273e1aba364c9b4f47ae6effeb9117 Mon Sep 17 00:00:00 2001 From: jtfirek Date: Thu, 19 Sep 2024 15:25:06 -0500 Subject: [PATCH] check for duplicates --- src/Pauser.sol | 5 +++++ test/Pauser.t.sol | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Pauser.sol b/src/Pauser.sol index a7b132fa..cfc9a150 100644 --- a/src/Pauser.sol +++ b/src/Pauser.sol @@ -62,6 +62,11 @@ contract Pauser is Initializable, UUPSUpgradeable, OwnableUpgradeable { * @notice Adds a contract to the list of pausables. */ function addPausable(IPausable _pausable) external onlyRole(PAUSER_ADMIN) { + for (uint256 i = 0; i < pausables.length; ++i) { + if (address(pausables[i]) == address(_pausable)) { + revert("Contract already in pausables"); + } + } pausables.push(_pausable); emit PausableAdded(address(_pausable)); } diff --git a/test/Pauser.t.sol b/test/Pauser.t.sol index cbaf86fc..f25e877a 100644 --- a/test/Pauser.t.sol +++ b/test/Pauser.t.sol @@ -86,4 +86,13 @@ contract PauserTest is TestSetup { vm.expectRevert("Sender requires permission"); pauserInstance.pauseSingle(IPausable(address(liquidityPoolInstance))); } + + function test_pushDuplicate() public { + vm.expectRevert("Contract already in pausables"); + pauserInstance.addPausable(IPausable(address(liquidityPoolInstance))); + + pauserInstance.removePausable(0); + + pauserInstance.addPausable(IPausable(address(liquidityPoolInstance))); + } }