Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test upgrades and deploy setup #95

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion script/foundry/utils/upgrades/ERC7201Helper.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { console2 } from "forge-std/console2.sol";
contract ERC7201HelperScript is Script {

string constant NAMESPACE = "story-protocol";
string constant CONTRACT_NAME = "IPAssetRegistry";
string constant CONTRACT_NAME = "AccessControllerV2";

function run() external {
bytes memory erc7201Key = abi.encodePacked(NAMESPACE, ".", CONTRACT_NAME);
Expand Down
30 changes: 30 additions & 0 deletions test/foundry/mocks/module/MockAccessControllerV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { AccessController } from "contracts/access/AccessController.sol";

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.23;

contract MockAccessControllerV2 is AccessController {
/// @dev Storage structure for the AccessControllerV2
/// @custom:storage-location erc7201:story-protocol.AccessControllerV2
struct AccessControllerV2Storage {
string newState;
}

// keccak256(abi.encode(uint256(keccak256("story-protocol.AccessControllerV2")) - 1)) & ~bytes32(uint256(0xff));
bytes32 private constant AccessControllerV2StorageLocation = 0xf328f2cdee4ae4df23921504bfa43e3156fb4d18b23549ca0a43fd1e64947a00;

function initialize() public reinitializer(2) {
_getAccessControllerV2Storage().newState = "initialized";
}

function get() external view returns (string memory) {
return _getAccessControllerV2Storage().newState;
}

/// @dev Returns the storage struct of AccessControllerV2.
function _getAccessControllerV2Storage() private pure returns (AccessControllerV2Storage storage $) {
assembly {
$.slot := AccessControllerV2StorageLocation
}
}
}
40 changes: 0 additions & 40 deletions test/foundry/upgrades/IPRoyaltyVaults.t.sol

This file was deleted.

202 changes: 202 additions & 0 deletions test/foundry/upgrades/Upgrades.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.23;

import { ProtocolAdmin } from "contracts/lib/ProtocolAdmin.sol";
import { RoyaltyPolicyLAP } from "contracts/modules/royalty/policies/RoyaltyPolicyLAP.sol";

import { BaseTest } from "../utils/BaseTest.t.sol";

import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";

import { MockIpRoyaltyVaultV2 } from "../mocks/module/MockIpRoyaltyVaultV2.sol";
import { MockAccessControllerV2 } from "../mocks/module/MockAccessControllerV2.sol";

contract UpgradesTest is BaseTest {

uint32 execDelay = 600;

function setUp() public override {
super.setUp();
vm.prank(u.admin);
protocolAccessManager.grantRole(ProtocolAdmin.UPGRADER_ROLE, u.bob, upgraderExecDelay);
}

function test_upgradeVaults() public {
address newVault = address(new MockIpRoyaltyVaultV2(address(royaltyPolicyLAP), address(disputeModule)));
(bool immediate, uint32 delay) = protocolAccessManager.canCall(
u.bob,
address(royaltyPolicyLAP),
RoyaltyPolicyLAP.upgradeVaults.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);
vm.prank(u.bob);
(bytes32 operationId, uint32 nonce) = protocolAccessManager.schedule(
address(royaltyPolicyLAP),
abi.encodeCall(RoyaltyPolicyLAP.upgradeVaults, (newVault)),
0 // earliest time possible, upgraderExecDelay
);
vm.warp(upgraderExecDelay + 1);

vm.prank(u.bob);
royaltyPolicyLAP.upgradeVaults(newVault);

assertEq(ipRoyaltyVaultBeacon.implementation(), newVault);
}

function test_upgradeAccessController() public {

(bool immediate, uint32 delay) = protocolAccessManager.canCall(
u.bob,
address(accessController),
UUPSUpgradeable.upgradeToAndCall.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);


address newAccessController = address(new MockAccessControllerV2());
vm.prank(u.bob);
(bytes32 operationId, uint32 nonce) = protocolAccessManager.schedule(
address(accessController),
abi.encodeCall(
UUPSUpgradeable.upgradeToAndCall,
(newAccessController, abi.encodeCall(MockAccessControllerV2.initialize, ()))
),
0 // earliest time possible, upgraderExecDelay
);
vm.warp(upgraderExecDelay + 1);

vm.prank(u.bob);
accessController.upgradeToAndCall(newAccessController, abi.encodeCall(MockAccessControllerV2.initialize, ()));

assertEq(MockAccessControllerV2(address(accessController)).get(), "initialized");
}

function test_deploymentSetup() public {
// Deployer doesn't have the roles
(bool isMember, uint32 executionDelay) = protocolAccessManager.hasRole(ProtocolAdmin.PROTOCOL_ADMIN_ROLE, deployer);
assertFalse(isMember);
assertEq(executionDelay, 0);
(isMember, executionDelay) = protocolAccessManager.hasRole(ProtocolAdmin.UPGRADER_ROLE, deployer);
assertFalse(isMember);
assertEq(executionDelay, 0);
(isMember, executionDelay) = protocolAccessManager.hasRole(ProtocolAdmin.PAUSE_ADMIN_ROLE, deployer);
assertFalse(isMember);
assertEq(executionDelay, 0);

(isMember, executionDelay) = protocolAccessManager.hasRole(ProtocolAdmin.PROTOCOL_ADMIN_ROLE, multisig);
assertTrue(isMember);
assertEq(executionDelay, 0);
(isMember, executionDelay) = protocolAccessManager.hasRole(ProtocolAdmin.PAUSE_ADMIN_ROLE, multisig);
assertTrue(isMember);
assertEq(executionDelay, 0);
(isMember, executionDelay) = protocolAccessManager.hasRole(ProtocolAdmin.PAUSE_ADMIN_ROLE, address(protocolPauser));
assertTrue(isMember);
assertEq(executionDelay, 0);
(isMember, executionDelay) = protocolAccessManager.hasRole(ProtocolAdmin.UPGRADER_ROLE, multisig);
assertTrue(isMember);
assertEq(executionDelay, execDelay);

// Target function role wiring

(bool immediate, uint32 delay) = protocolAccessManager.canCall(
multisig,
address(royaltyPolicyLAP),
RoyaltyPolicyLAP.upgradeVaults.selector
);
assertFalse(immediate);
assertEq(delay, 600);
assertEq(protocolAccessManager.getTargetFunctionRole(address(royaltyPolicyLAP), RoyaltyPolicyLAP.upgradeVaults.selector), ProtocolAdmin.UPGRADER_ROLE);

(immediate, delay) = protocolAccessManager.canCall(
multisig,
address(accessController),
UUPSUpgradeable.upgradeToAndCall.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);
assertEq(protocolAccessManager.getTargetFunctionRole(address(accessController), UUPSUpgradeable.upgradeToAndCall.selector), ProtocolAdmin.UPGRADER_ROLE);

(immediate, delay) = protocolAccessManager.canCall(
multisig,
address(licenseToken),
UUPSUpgradeable.upgradeToAndCall.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);
assertEq(protocolAccessManager.getTargetFunctionRole(address(licenseToken), UUPSUpgradeable.upgradeToAndCall.selector), ProtocolAdmin.UPGRADER_ROLE);

(immediate, delay) = protocolAccessManager.canCall(
multisig,
address(disputeModule),
UUPSUpgradeable.upgradeToAndCall.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);
assertEq(protocolAccessManager.getTargetFunctionRole(address(disputeModule), UUPSUpgradeable.upgradeToAndCall.selector), ProtocolAdmin.UPGRADER_ROLE);

(immediate, delay) = protocolAccessManager.canCall(
multisig,
address(arbitrationPolicySP),
UUPSUpgradeable.upgradeToAndCall.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);
assertEq(protocolAccessManager.getTargetFunctionRole(address(arbitrationPolicySP), UUPSUpgradeable.upgradeToAndCall.selector), ProtocolAdmin.UPGRADER_ROLE);

(immediate, delay) = protocolAccessManager.canCall(
multisig,
address(licensingModule),
UUPSUpgradeable.upgradeToAndCall.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);
assertEq(protocolAccessManager.getTargetFunctionRole(address(licensingModule), UUPSUpgradeable.upgradeToAndCall.selector), ProtocolAdmin.UPGRADER_ROLE);

(immediate, delay) = protocolAccessManager.canCall(
multisig,
address(royaltyModule),
UUPSUpgradeable.upgradeToAndCall.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);
assertEq(protocolAccessManager.getTargetFunctionRole(address(royaltyModule), UUPSUpgradeable.upgradeToAndCall.selector), ProtocolAdmin.UPGRADER_ROLE);

(immediate, delay) = protocolAccessManager.canCall(
multisig,
address(licenseRegistry),
UUPSUpgradeable.upgradeToAndCall.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);
assertEq(protocolAccessManager.getTargetFunctionRole(address(licenseRegistry), UUPSUpgradeable.upgradeToAndCall.selector), ProtocolAdmin.UPGRADER_ROLE);

(immediate, delay) = protocolAccessManager.canCall(
multisig,
address(moduleRegistry),
UUPSUpgradeable.upgradeToAndCall.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);
assertEq(protocolAccessManager.getTargetFunctionRole(address(moduleRegistry), UUPSUpgradeable.upgradeToAndCall.selector), ProtocolAdmin.UPGRADER_ROLE);

(immediate, delay) = protocolAccessManager.canCall(
multisig,
address(ipAssetRegistry),
UUPSUpgradeable.upgradeToAndCall.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);
assertEq(protocolAccessManager.getTargetFunctionRole(address(ipAssetRegistry), UUPSUpgradeable.upgradeToAndCall.selector), ProtocolAdmin.UPGRADER_ROLE);

(immediate, delay) = protocolAccessManager.canCall(
multisig,
address(royaltyPolicyLAP),
UUPSUpgradeable.upgradeToAndCall.selector
);
assertFalse(immediate);
assertEq(delay, execDelay);
assertEq(protocolAccessManager.getTargetFunctionRole(address(royaltyPolicyLAP), UUPSUpgradeable.upgradeToAndCall.selector), ProtocolAdmin.UPGRADER_ROLE);
}
}
Loading