Skip to content

Commit

Permalink
testing protocol pause
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramarti committed Apr 13, 2024
1 parent 7f00590 commit 57f6714
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 15 deletions.
6 changes: 5 additions & 1 deletion contracts/modules/royalty/policies/IpRoyaltyVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ contract IpRoyaltyVault is IIpRoyaltyVault, ERC20SnapshotUpgradeable, Reentrancy
/// @param snapshotId The snapshot id
/// @param token The revenue token to claim
/// @return The amount of revenue token claimable
function claimableRevenue(address account, uint256 snapshotId, address token) external whenNotPaused view returns (uint256) {
function claimableRevenue(
address account,
uint256 snapshotId,
address token
) external view whenNotPaused returns (uint256) {
return _claimableRevenue(account, snapshotId, token);
}

Expand Down
7 changes: 6 additions & 1 deletion contracts/modules/royalty/policies/RoyaltyPolicyLAP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { ProtocolPausableUpgradeable } from "../../../pause/ProtocolPausableUpgr

/// @title Liquid Absolute Percentage Royalty Policy
/// @notice Defines the logic for splitting royalties for a given ipId using a liquid absolute percentage mechanism
contract RoyaltyPolicyLAP is IRoyaltyPolicyLAP, ProtocolPausableUpgradeable, ReentrancyGuardUpgradeable, UUPSUpgradeable {
contract RoyaltyPolicyLAP is
IRoyaltyPolicyLAP,
ProtocolPausableUpgradeable,
ReentrancyGuardUpgradeable,
UUPSUpgradeable
{
using SafeERC20 for IERC20;

/// @dev Storage structure for the RoyaltyPolicyLAP
Expand Down
1 change: 1 addition & 0 deletions contracts/pause/ProtocolPauser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ contract ProtocolPauser is IProtocolPauser, AccessManaged {
emit ProtocolUnpaused();
}

/// @notice Checks if all pausable contracts are paused.
function isAllProtocolPaused() external view returns (bool) {
uint256 length = _pausables.length();
for (uint256 i = 0; i < length; i++) {
Expand Down
9 changes: 9 additions & 0 deletions script/foundry/utils/DeployHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ contract DeployHelper is Script, BroadcastManager, JsonDeploymentHandler, Storag
function _configureDeployment() private {
IPAccountRegistry ipAccountRegistry = IPAccountRegistry(address(ipAssetRegistry));

// Protocol Pause
protocolPauser.addPausable(address(accessController));
protocolPauser.addPausable(address(disputeModule));
protocolPauser.addPausable(address(licensingModule));
protocolPauser.addPausable(address(royaltyModule));
protocolPauser.addPausable(address(royaltyPolicyLAP));
protocolPauser.addPausable(address(ipAssetRegistry));


// Module Registry
moduleRegistry.registerModule(DISPUTE_MODULE_KEY, address(disputeModule));
moduleRegistry.registerModule(LICENSING_MODULE_KEY, address(licensingModule));
Expand Down
10 changes: 10 additions & 0 deletions test/foundry/mocks/MockProtocolPausable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.23;

import { ProtocolPausableUpgradeable } from "contracts/pause/ProtocolPausableUpgradeable.sol";

contract MockProtocolPausable is ProtocolPausableUpgradeable {
function __MockPausable_init(address accessManager) public initializer {
__ProtocolPausable_init(accessManager);
}
}
90 changes: 77 additions & 13 deletions test/foundry/pause/ProtocolPauser.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,95 @@
pragma solidity 0.8.23;

import { Errors } from "contracts/lib/Errors.sol";
import { ProtocolAdmin } from "contracts/lib/ProtocolAdmin.sol";
import { IProtocolPauser } from "contracts/interfaces/pause/IProtocolPauser.sol";

import { MODULE_TYPE_DEFAULT, MODULE_TYPE_HOOK } from "contracts/lib/modules/Module.sol";
import { IModule } from "contracts/interfaces/modules/base/IModule.sol";
import { IHookModule } from "contracts/interfaces/modules/base/IHookModule.sol";

import { MockModule } from "../mocks/module/MockModule.sol";
import { ICustomModule, CustomModule } from "../mocks/CustomModuleType.sol";
import { MockTokenGatedHook } from "../mocks/MockTokenGatedHook.sol";
import { BaseTest } from "../utils/BaseTest.t.sol";
import { MockProtocolPausable } from "../mocks/MockProtocolPausable.sol";

contract ProtocolPauserTest is BaseTest {

contract ProtocolPauser is BaseTest {
MockProtocolPausable pausable = new MockProtocolPausable();

function test_protocolPauser_validate_config() public {
assertTrue(protocolPauser.isPausableRegistered(address(accessController)));
assertTrue(protocolPauser.isPausableRegistered(address(disputeModule)));
assertTrue(protocolPauser.isPausableRegistered(address(licensingModule)));
assertTrue(protocolPauser.isPausableRegistered(address(royaltyModule)));
assertTrue(protocolPauser.isPausableRegistered(address(royaltyPolicyLAP)));
assertTrue(protocolPauser.isPausableRegistered(address(ipAssetRegistry)));
}

function test_protocolPauser_addPausable() public {

vm.expectEmit();
emit IProtocolPauser.PausableAdded(address(pausable));
vm.prank(u.admin);
protocolPauser.addPausable(address(pausable));
assertTrue(protocolPauser.isPausableRegistered(address(pausable)));
}

function test_protocolPauser_addPausable_revert_zero() public {
vm.prank(u.admin);
vm.expectRevert(Errors.ProtocolPauser__ZeroAddress());
protocolPauser.addPausable(address(0));
}

function test_protocolPauser_addPausable_revert_notPausable() public {
vm.prank(u.admin);
vm.expectRevert(Errors.ProtocolPauser__NotPausable());
protocolPauser.addPausable(address(u.admin));
}

function test_protocolPauser_addPausable_revert_alreadyAdded() public {
vm.prank(u.admin);
vm.expectRevert(Errors.ProtocolPauser__PausableAlreadyAdded());
protocolPauser.addPausable(address(licensingModule));
}

function test_protocolPauser_addPausable_revert_notAdmin() public {
vm.expectRevert("");
protocolPauser.addPausable(address(protocolPauser));
}

function test_protocolPauser_removePausable() public {

vm.expectEmit();
emit IProtocolPauser.PausableRemoved(address(protocolPauser));
vm.prank(u.admin);
protocolPauser.removePausable(address(protocolPauser));
assertFalse(protocolPauser.isPausableRegistered(address(protocolPauser)));
}


function test_protocolPauser_removePausable_notFound() public {
vm.expectRevert("");
vm.prank(u.bob);
protocolPauser.removePausable(address(u.admin));
}

function test_ProtocolPauser_pause() public {

vm.prank(u.admin);
protocolAccessManager.grantRole(ProtocolAdmin.PAUSE_ADMIN_ROLE, address(u.bob));

vm.prank(u.bob);
vm.expectEmit();
emit IProtocolPauser.ProtocolPaused();
protocolPauser.pause();
assertTrue(protocolPauser.isAllProtocolPaused());
}

function test_ProtocolPauser_pause_revert_notPauser() public {
vm.expectRevert("");
protocolPauser.pause();
}

function test_ProtocolPauser_unpause() public {

vm.prank(u.admin);
protocolAccessManager.grantRole(ProtocolAdmin.PAUSE_ADMIN_ROLE, address(u.bob));

vm.startPrank(u.bob);
protocolPauser.pause();
vm.expectEmit();
emit IProtocolPauser.ProtocolUnpaused();
protocolPauser.unpause();
assertFalse(protocolPauser.isAllProtocolPaused());
}
}

0 comments on commit 57f6714

Please sign in to comment.