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 Jun 4, 2024
1 parent 6459412 commit 87873e5
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 343 deletions.
2 changes: 1 addition & 1 deletion packages/contracts/src/governance/MemberAccessPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ contract MemberAccessPlugin is IMultisig, PluginUUPSUpgradeable, ProposalUpgrade
bytes calldata _metadata,
address _proposedMember,
address _proposer
) external auth(PROPOSER_PERMISSION_ID) returns (uint256 proposalId) {
) public auth(PROPOSER_PERMISSION_ID) returns (uint256 proposalId) {
// Check that the caller supports the `addMember` function
if (
!MainVotingPlugin(msg.sender).supportsInterface(MAIN_SPACE_VOTING_INTERFACE_ID) ||
Expand Down
8 changes: 8 additions & 0 deletions packages/contracts/src/test/TestMemberAccessPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ contract TestMemberAccessPlugin is MemberAccessPlugin {

_updateMultisigSettings(_multisigSettings);
}

function devProposeAddMember(
bytes calldata _metadata,
address _proposedMember,
address _proposer
) public returns (uint256 proposalId) {
return proposeAddMember(_metadata, _proposedMember, _proposer);
}
}
159 changes: 7 additions & 152 deletions packages/contracts/test/integration-testing/member-access-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,159 +162,14 @@ describe('Member Access Condition E2E', () => {
it('Executing a proposal to add membership works', async () => {
expect(await mainVotingPlugin.isMember(alice.address)).to.eq(false);

await expect(memberAccessPlugin.proposeNewMember('0x', alice.address)).to
.not.be.reverted;
await expect(
memberAccessPlugin.devProposeAddMember(
'0x',
alice.address,
deployer.address
)
).to.not.be.reverted;

expect(await mainVotingPlugin.isMember(alice.address)).to.eq(true);

// Valid addition
const actions: IDAO.ActionStruct[] = [
{
to: mainVotingPlugin.address,
value: 0,
data: mainVotingInterface.encodeFunctionData('addMember', [
bob.address,
]),
},
];

// Via direct create proposal
expect(await mainVotingPlugin.isMember(bob.address)).to.eq(false);

await expect(memberAccessPlugin.createArbitraryProposal('0x', actions)).to
.not.be.reverted;

expect(await mainVotingPlugin.isMember(bob.address)).to.eq(true);
});

it('Executing a proposal to do something else reverts', async () => {
const validActions = [
{
to: mainVotingPlugin.address,
value: 0,
data: mainVotingInterface.encodeFunctionData('addMember', [
bob.address,
]),
},
{
to: mainVotingPlugin.address,
value: 0,
data: mainVotingInterface.encodeFunctionData('addMember', [
ADDRESS_ONE,
]),
},
];
const invalidActions = [
{
to: mainVotingPlugin.address,
value: 0,
data: mainVotingInterface.encodeFunctionData('removeMember', [
bob.address,
]),
},
{
to: dao.address,
value: 0,
data: daoInterface.encodeFunctionData('grant', [
mainVotingPlugin.address,
bob.address,
EXECUTE_PERMISSION_ID,
]),
},
{
to: dao.address,
value: 0,
data: daoInterface.encodeFunctionData('grant', [
dao.address,
alice.address,
EXECUTE_PERMISSION_ID,
]),
},
{
to: dao.address,
value: 0,
data: daoInterface.encodeFunctionData('grant', [
dao.address,
alice.address,
ROOT_PERMISSION_ID,
]),
},
{
to: dao.address,
value: 0,
data: daoInterface.encodeFunctionData('grant', [
psp.address,
alice.address,
ethers.utils.id('APPLY_INSTALLATION_PERMISSION'),
]),
},
{
to: dao.address,
value: 0,
data: daoInterface.encodeFunctionData('grant', [
psp.address,
alice.address,
ethers.utils.id('APPLY_UPDATE_PERMISSION'),
]),
},
{
to: dao.address,
value: 0,
data: daoInterface.encodeFunctionData('grant', [
psp.address,
alice.address,
ethers.utils.id('APPLY_UNINSTALLATION_PERMISSION'),
]),
},
{
to: dao.address,
value: 0,
data: daoInterface.encodeFunctionData('grant', [
mainVotingPlugin.address,
alice.address,
UPGRADE_PLUGIN_PERMISSION_ID,
]),
},
{
to: dao.address,
value: 0,
data: daoInterface.encodeFunctionData('revoke', [
mainVotingPlugin.address,
bob.address,
ROOT_PERMISSION_ID,
]),
},
{
to: dao.address,
value: 0,
data: daoInterface.encodeFunctionData('execute', [
ONE_BYTES32,
validActions,
0,
]),
},
{
to: dao.address,
value: 0,
data: daoInterface.encodeFunctionData('setMetadata', ['0x']),
},
{
to: dao.address,
value: 0,
data: daoInterface.encodeFunctionData('setDaoURI', ['0x']),
},
];

// Should work
for (const action of validActions) {
await expect(memberAccessPlugin.createArbitraryProposal('0x', [action]))
.to.not.be.reverted;
}

// Should fail
for (const action of invalidActions) {
await expect(memberAccessPlugin.createArbitraryProposal('0x', [action]))
.to.be.reverted;
}
});
});
1 change: 1 addition & 0 deletions packages/contracts/test/unit-testing/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const UPDATE_ADDRESSES_PERMISSION_ID = ethers.utils.id(
export const UPGRADE_PLUGIN_PERMISSION_ID = ethers.utils.id(
'UPGRADE_PLUGIN_PERMISSION'
);
export const PROPOSER_PERMISSION_ID = ethers.utils.id('PROPOSER_PERMISSION');
export const ROOT_PERMISSION_ID = ethers.utils.id('ROOT_PERMISSION');

export const MAX_UINT64 = ethers.BigNumber.from(2).pow(64).sub(1);
Expand Down
45 changes: 37 additions & 8 deletions packages/contracts/test/unit-testing/governance-plugins-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EXECUTE_PERMISSION_ID,
NO_CONDITION,
pctToRatio,
PROPOSER_PERMISSION_ID,
UPDATE_ADDRESSES_PERMISSION_ID,
UPDATE_MULTISIG_SETTINGS_PERMISSION_ID,
UPDATE_VOTING_SETTINGS_PERMISSION_ID,
Expand Down Expand Up @@ -58,12 +59,12 @@ describe('Governance Plugins Setup', function () {
const nonce = await ethers.provider.getTransactionCount(
governancePluginsSetup.address
);
const anticipatedMainVotingPluginAddress =
const anticipatedMemberAccessPluginAddress =
ethers.utils.getContractAddress({
from: governancePluginsSetup.address,
nonce,
});
const anticipatedMemberAccessPluginAddress =
const anticipatedMainVotingPluginAddress =
ethers.utils.getContractAddress({
from: governancePluginsSetup.address,
nonce: nonce + 1,
Expand All @@ -86,7 +87,7 @@ describe('Governance Plugins Setup', function () {
const [memberAccessPlugin] = helpers;
expect(memberAccessPlugin).to.eq(anticipatedMemberAccessPluginAddress);

expect(permissions.length).to.be.equal(5);
expect(permissions.length).to.be.equal(6);
expect(permissions).to.deep.equal([
[
Operation.Grant,
Expand All @@ -109,6 +110,13 @@ describe('Governance Plugins Setup', function () {
NO_CONDITION,
UPDATE_ADDRESSES_PERMISSION_ID,
],
[
Operation.Grant,
memberAccessPlugin,
mainVotingPlugin,
NO_CONDITION,
PROPOSER_PERMISSION_ID,
],
[
Operation.GrantWithCondition,
dao.address,
Expand Down Expand Up @@ -152,12 +160,12 @@ describe('Governance Plugins Setup', function () {
const nonce = await ethers.provider.getTransactionCount(
governancePluginsSetup.address
);
const anticipatedMainVotingPluginAddress =
const anticipatedMemberAccessPluginAddress =
ethers.utils.getContractAddress({
from: governancePluginsSetup.address,
nonce,
});
const anticipatedMemberAccessPluginAddress =
const anticipatedMainVotingPluginAddress =
ethers.utils.getContractAddress({
from: governancePluginsSetup.address,
nonce: nonce + 1,
Expand Down Expand Up @@ -185,7 +193,7 @@ describe('Governance Plugins Setup', function () {
const [memberAccessPlugin] = helpers;
expect(memberAccessPlugin).to.eq(anticipatedMemberAccessPluginAddress);

expect(permissions.length).to.be.equal(6);
expect(permissions.length).to.be.equal(7);
expect(permissions).to.deep.equal([
[
Operation.Grant,
Expand All @@ -208,6 +216,13 @@ describe('Governance Plugins Setup', function () {
NO_CONDITION,
UPDATE_ADDRESSES_PERMISSION_ID,
],
[
Operation.Grant,
memberAccessPlugin,
mainVotingPlugin,
NO_CONDITION,
PROPOSER_PERMISSION_ID,
],
[
Operation.GrantWithCondition,
dao.address,
Expand Down Expand Up @@ -264,7 +279,7 @@ describe('Governance Plugins Setup', function () {
}
);

expect(permissions.length).to.be.equal(5);
expect(permissions.length).to.be.equal(6);
expect(permissions).to.deep.equal([
[
Operation.Revoke,
Expand All @@ -287,6 +302,13 @@ describe('Governance Plugins Setup', function () {
NO_CONDITION,
UPDATE_ADDRESSES_PERMISSION_ID,
],
[
Operation.Revoke,
memberAccessPlugin,
mainVotingPlugin,
NO_CONDITION,
PROPOSER_PERMISSION_ID,
],
[
Operation.Revoke,
dao.address,
Expand Down Expand Up @@ -325,7 +347,7 @@ describe('Governance Plugins Setup', function () {
}
);

expect(permissions.length).to.be.equal(6);
expect(permissions.length).to.be.equal(7);
expect(permissions).to.deep.equal([
[
Operation.Revoke,
Expand All @@ -348,6 +370,13 @@ describe('Governance Plugins Setup', function () {
NO_CONDITION,
UPDATE_ADDRESSES_PERMISSION_ID,
],
[
Operation.Revoke,
memberAccessPlugin,
mainVotingPlugin,
NO_CONDITION,
PROPOSER_PERMISSION_ID,
],
[
Operation.Revoke,
dao.address,
Expand Down
7 changes: 7 additions & 0 deletions packages/contracts/test/unit-testing/main-voting-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
VotingSettings,
ZERO_BYTES32,
SUBSPACE_PERMISSION_ID,
PROPOSER_PERMISSION_ID,
} from './common';
import {defaultMainVotingSettings} from './common';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
Expand Down Expand Up @@ -137,6 +138,12 @@ describe('Main Voting Plugin', function () {
await dao.grant(spacePlugin.address, dao.address, SUBSPACE_PERMISSION_ID);
// The DAO is ROOT on itself
await dao.grant(dao.address, dao.address, ROOT_PERMISSION_ID);
// The plugin can propose members on the member access helper
await dao.grant(
memberAccessPlugin.address,
mainVotingPlugin.address,
PROPOSER_PERMISSION_ID
);
// Alice can make the DAO execute arbitrary stuff (test)
await dao.grant(dao.address, alice.address, EXECUTE_PERMISSION_ID);

Expand Down
Loading

0 comments on commit 87873e5

Please sign in to comment.