Skip to content

Commit

Permalink
Testing work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Nov 29, 2023
1 parent 90c6471 commit 27786ae
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 142 deletions.
21 changes: 15 additions & 6 deletions packages/contracts/deploy/02_setup/10_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,35 @@ import {
PersonalSpaceAdminPluginSetupParams,
SpacePluginSetupParams,
} from '../../plugin-setup-params';
import {activeContractsList} from '@aragon/osx-ethers';
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployments, getNamedAccounts} = hre;
const {deployments, getNamedAccounts, network} = hre;
const {deploy} = deployments;
const {deployer} = await getNamedAccounts();

// Space
const pspAddress =
activeContractsList[network.name as keyof typeof activeContractsList]
.PluginSetupProcessor;

console.log(
`\nUsing the PluginSetupProcessor address ${pspAddress} on ${network.name}`
);

// Space Setup
console.log(
`\nDeploying ${SpacePluginSetupParams.PLUGIN_SETUP_CONTRACT_NAME}`
);

await deploy(SpacePluginSetupParams.PLUGIN_SETUP_CONTRACT_NAME, {
from: deployer,
args: [],
args: [pspAddress],
log: true,
});

// Personal Space
// Personal Space Setup
console.log(
`\nDeploying ${PersonalSpaceAdminPluginSetupParams.PLUGIN_SETUP_CONTRACT_NAME}`
);
Expand All @@ -33,14 +42,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
});

// Governance
// Governance Setup
console.log(
`\nDeploying ${GovernancePluginsSetupParams.PLUGIN_SETUP_CONTRACT_NAME}`
);

await deploy(GovernancePluginsSetupParams.PLUGIN_SETUP_CONTRACT_NAME, {
from: deployer,
args: [],
args: [pspAddress],
log: true,
});
};
Expand Down
22 changes: 11 additions & 11 deletions packages/contracts/src/GovernancePluginsSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract GovernancePluginsSetup is PluginSetup {
function prepareInstallation(
address _dao,
bytes memory _data
) external returns (address _mainVotingPlugin, PreparedSetupData memory _preparedSetupData) {
) external returns (address mainVotingPlugin, PreparedSetupData memory preparedSetupData) {
// Decode the custom installation parameters
(
MajorityVotingBase.VotingSettings memory _votingSettings,
Expand All @@ -46,7 +46,7 @@ contract GovernancePluginsSetup is PluginSetup {
) = decodeInstallationParams(_data);

// Deploy the main voting plugin
_mainVotingPlugin = createERC1967Proxy(
mainVotingPlugin = createERC1967Proxy(
mainVotingPluginImplementation,
abi.encodeCall(
MainVotingPlugin.initialize,
Expand All @@ -57,7 +57,7 @@ contract GovernancePluginsSetup is PluginSetup {
// Deploy the member access plugin
MemberAccessPlugin.MultisigSettings memory _multisigSettings;
_multisigSettings.proposalDuration = _memberAccessProposalDuration;
_multisigSettings.mainVotingPlugin = MainVotingPlugin(_mainVotingPlugin);
_multisigSettings.mainVotingPlugin = MainVotingPlugin(mainVotingPlugin);

address _memberAccessPlugin = createERC1967Proxy(
memberAccessPluginImplementation,
Expand All @@ -66,7 +66,7 @@ contract GovernancePluginsSetup is PluginSetup {

// Condition contract (member access plugin execute)
address _memberAccessExecuteCondition = address(
new MemberAccessExecuteCondition(_mainVotingPlugin)
new MemberAccessExecuteCondition(mainVotingPlugin)
);

// List the requested permissions
Expand All @@ -79,14 +79,14 @@ contract GovernancePluginsSetup is PluginSetup {
permissions[0] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Grant,
where: _dao,
who: _mainVotingPlugin,
who: mainVotingPlugin,
condition: PermissionLib.NO_CONDITION,
permissionId: DAO(payable(_dao)).EXECUTE_PERMISSION_ID()
});
// The DAO can update the main voting plugin settings
permissions[1] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Grant,
where: _mainVotingPlugin,
where: mainVotingPlugin,
who: _dao,
condition: PermissionLib.NO_CONDITION,
permissionId: MainVotingPlugin(mainVotingPluginImplementation)
Expand All @@ -95,7 +95,7 @@ contract GovernancePluginsSetup is PluginSetup {
// The DAO can manage the list of addresses
permissions[2] = PermissionLib.MultiTargetPermission({
operation: PermissionLib.Operation.Grant,
where: _mainVotingPlugin,
where: mainVotingPlugin,
who: _dao,
condition: PermissionLib.NO_CONDITION,
permissionId: MainVotingPlugin(mainVotingPluginImplementation)
Expand Down Expand Up @@ -127,7 +127,7 @@ contract GovernancePluginsSetup is PluginSetup {
// pluginUpgrader can make the DAO execute applyUpdate
// pluginUpgrader can make the DAO execute grant/revoke
address[] memory _targetPluginAddresses = new address[](2);
_targetPluginAddresses[0] = _mainVotingPlugin;
_targetPluginAddresses[0] = mainVotingPlugin;
_targetPluginAddresses[1] = _memberAccessPlugin;
OnlyPluginUpgraderCondition _onlyPluginUpgraderCondition = new OnlyPluginUpgraderCondition(
DAO(payable(_dao)),
Expand All @@ -143,9 +143,9 @@ contract GovernancePluginsSetup is PluginSetup {
});
}

_preparedSetupData.permissions = permissions;
_preparedSetupData.helpers = new address[](1);
_preparedSetupData.helpers[0] = _memberAccessPlugin;
preparedSetupData.permissions = permissions;
preparedSetupData.helpers = new address[](1);
preparedSetupData.helpers[0] = _memberAccessPlugin;
}

/// @inheritdoc IPluginSetup
Expand Down
115 changes: 27 additions & 88 deletions packages/contracts/test/unit-testing/governance-plugins-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
UPGRADE_PLUGIN_PERMISSION_ID,
VotingMode,
} from './common';
import {activeContractsList} from '@aragon/osx-ethers';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {expect} from 'chai';
import {ethers} from 'hardhat';
Expand All @@ -34,9 +35,14 @@ describe('Governance Plugins Setup', function () {
[alice, bob] = await ethers.getSigners();
dao = await deployTestDao(alice);

const hardhatForkNetwork = (process.env.NETWORK_NAME ??
'mainnet') as keyof typeof activeContractsList;
const pspAddress =
activeContractsList[hardhatForkNetwork].PluginSetupProcessor;

governancePluginsSetup = await new GovernancePluginsSetup__factory(
alice
).deploy();
).deploy(pspAddress);
});

describe('prepareInstallation', async () => {
Expand Down Expand Up @@ -74,12 +80,11 @@ describe('Governance Plugins Setup', function () {
from: governancePluginsSetup.address,
nonce: nonce + 1,
});
const anticipatedConditionPluginAddress = ethers.utils.getContractAddress(
{
const anticipatedMemberAccessConditionAddress =
ethers.utils.getContractAddress({
from: governancePluginsSetup.address,
nonce: nonce + 2,
}
);
});

const {
mainVotingPlugin,
Expand All @@ -93,7 +98,7 @@ describe('Governance Plugins Setup', function () {
const [memberAccessPlugin] = helpers;
expect(memberAccessPlugin).to.eq(anticipatedMemberAccessPluginAddress);

expect(permissions.length).to.be.equal(7);
expect(permissions.length).to.be.equal(5);
expect(permissions).to.deep.equal([
[
Operation.Grant,
Expand All @@ -116,18 +121,11 @@ describe('Governance Plugins Setup', function () {
NO_CONDITION,
UPDATE_ADDRESSES_PERMISSION_ID,
],
[
Operation.Grant,
mainVotingPlugin,
dao.address,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
],
[
Operation.Grant,
dao.address,
memberAccessPlugin,
anticipatedConditionPluginAddress,
anticipatedMemberAccessConditionAddress,
EXECUTE_PERMISSION_ID,
],
[
Expand All @@ -137,13 +135,6 @@ describe('Governance Plugins Setup', function () {
NO_CONDITION,
UPDATE_MULTISIG_SETTINGS_PERMISSION_ID,
],
[
Operation.Grant,
memberAccessPlugin,
dao.address,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
],
]);

await governancePluginsSetup.prepareInstallation(dao.address, initData);
Expand Down Expand Up @@ -190,12 +181,16 @@ describe('Governance Plugins Setup', function () {
from: governancePluginsSetup.address,
nonce: nonce + 1,
});
const anticipatedConditionPluginAddress = ethers.utils.getContractAddress(
{
const anticipatedMemberAccessConditionAddress =
ethers.utils.getContractAddress({
from: governancePluginsSetup.address,
nonce: nonce + 2,
}
);
});
const anticipatedOnlyPluginUpgraderConditionAddress =
ethers.utils.getContractAddress({
from: governancePluginsSetup.address,
nonce: nonce + 3,
});

const {
mainVotingPlugin,
Expand All @@ -209,7 +204,7 @@ describe('Governance Plugins Setup', function () {
const [memberAccessPlugin] = helpers;
expect(memberAccessPlugin).to.eq(anticipatedMemberAccessPluginAddress);

expect(permissions.length).to.be.equal(9);
expect(permissions.length).to.be.equal(6);
expect(permissions).to.deep.equal([
[
Operation.Grant,
Expand All @@ -232,18 +227,11 @@ describe('Governance Plugins Setup', function () {
NO_CONDITION,
UPDATE_ADDRESSES_PERMISSION_ID,
],
[
Operation.Grant,
mainVotingPlugin,
dao.address,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
],
[
Operation.Grant,
dao.address,
memberAccessPlugin,
anticipatedConditionPluginAddress,
anticipatedMemberAccessConditionAddress,
EXECUTE_PERMISSION_ID,
],
[
Expand All @@ -255,24 +243,10 @@ describe('Governance Plugins Setup', function () {
],
[
Operation.Grant,
memberAccessPlugin,
dao.address,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
],
[
Operation.Grant,
mainVotingPlugin,
pluginUpgrader,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
],
[
Operation.Grant,
memberAccessPlugin,
pluginUpgrader,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
anticipatedOnlyPluginUpgraderConditionAddress,
EXECUTE_PERMISSION_ID,
],
]);

Expand Down Expand Up @@ -313,7 +287,7 @@ describe('Governance Plugins Setup', function () {
}
);

expect(permissions.length).to.be.equal(7);
expect(permissions.length).to.be.equal(5);
expect(permissions).to.deep.equal([
[
Operation.Revoke,
Expand All @@ -336,13 +310,6 @@ describe('Governance Plugins Setup', function () {
NO_CONDITION,
UPDATE_ADDRESSES_PERMISSION_ID,
],
[
Operation.Revoke,
mainVotingPlugin.address,
dao.address,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
],
[
Operation.Revoke,
dao.address,
Expand All @@ -357,13 +324,6 @@ describe('Governance Plugins Setup', function () {
NO_CONDITION,
UPDATE_MULTISIG_SETTINGS_PERMISSION_ID,
],
[
Operation.Revoke,
memberAccessPlugin.address,
dao.address,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
],
]);
});

Expand Down Expand Up @@ -392,7 +352,7 @@ describe('Governance Plugins Setup', function () {
}
);

expect(permissions.length).to.be.equal(9);
expect(permissions.length).to.be.equal(6);
expect(permissions).to.deep.equal([
[
Operation.Revoke,
Expand All @@ -415,13 +375,6 @@ describe('Governance Plugins Setup', function () {
NO_CONDITION,
UPDATE_ADDRESSES_PERMISSION_ID,
],
[
Operation.Revoke,
mainVotingPlugin.address,
dao.address,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
],
[
Operation.Revoke,
dao.address,
Expand All @@ -438,24 +391,10 @@ describe('Governance Plugins Setup', function () {
],
[
Operation.Revoke,
memberAccessPlugin.address,
dao.address,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
],
[
Operation.Revoke,
mainVotingPlugin.address,
pluginUpgrader,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
],
[
Operation.Revoke,
memberAccessPlugin.address,
pluginUpgrader,
NO_CONDITION,
UPGRADE_PLUGIN_PERMISSION_ID,
EXECUTE_PERMISSION_ID,
],
]);
});
Expand Down
Loading

0 comments on commit 27786ae

Please sign in to comment.