Skip to content

Commit

Permalink
Plugin testing WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Jan 30, 2024
1 parent 6953dda commit 2d0a721
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pragma solidity 0.8.17;
import {IDAO} from "@aragon/osx/core/dao/IDAO.sol";
import {PermissionCondition} from "@aragon/osx/core/permission/PermissionCondition.sol";
import {PermissionManager} from "@aragon/osx/core/permission/PermissionManager.sol";
import {MEMBER_PERMISSION_ID} from "../constants.sol";
import {MainVotingPlugin} from "../governance/MainVotingPlugin.sol";

/// @notice The condition associated with `TestSharedPlugin`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {SafeCastUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/mat
import {ProposalUpgradeable} from "@aragon/osx/core/plugin/proposal/ProposalUpgradeable.sol";
import {PluginCloneable} from "@aragon/osx/core/plugin/PluginCloneable.sol";
import {IDAO} from "@aragon/osx/core/dao/IDAO.sol";
import {EDITOR_PERMISSION_ID, MEMBER_PERMISSION_ID} from "../constants.sol";
import {EDITOR_PERMISSION_ID} from "../constants.sol";

/// @title PersonalSpaceAdminPlugin
/// @author Aragon - 2023
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {installPlugin} from '../helpers/setup';
import {deployTestDao} from '../helpers/test-dao';
import {
EXECUTE_PERMISSION_ID,
MEMBER_PERMISSION_ID,
ROOT_PERMISSION_ID,
UPGRADE_PLUGIN_PERMISSION_ID,
ONE_BYTES32,
Expand Down
62 changes: 23 additions & 39 deletions packages/contracts/test/unit-testing/main-voting-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
EMPTY_DATA,
EXECUTE_PERMISSION_ID,
getTime, // MAX_UINT64,
MEMBER_PERMISSION_ID,
mineBlock,
pctToRatio,
ROOT_PERMISSION_ID,
Expand All @@ -49,6 +48,7 @@ import {toUtf8Bytes} from 'ethers/lib/utils';
import {ethers} from 'hardhat';

type InitData = {contentUri: string};
const mainVotingPluginInterface = MainVotingPlugin__factory.createInterface();

describe('Main Voting Plugin', function () {
let signers: SignerWithAddress[];
Expand Down Expand Up @@ -95,23 +95,16 @@ describe('Main Voting Plugin', function () {
ADDRESS_ZERO
);

// Alice is already an editor (see initialize)

await dao.grant(
mainVotingPlugin.address,
bob.address,
MEMBER_PERMISSION_ID
);
// Bob is a member
// The plugin can execute on the DAO
await dao.grant(
dao.address,
mainVotingPlugin.address,
bob.address,
MEMBER_PERMISSION_ID
EXECUTE_PERMISSION_ID
);
// The plugin can execute on the DAO
// MemberAccessPlugin can execute on the DAO
await dao.grant(
dao.address,
mainVotingPlugin.address,
memberAccessPlugin.address,
EXECUTE_PERMISSION_ID
);
// The DAO can add/remove editors
Expand All @@ -136,6 +129,11 @@ describe('Main Voting Plugin', function () {
await dao.grant(dao.address, dao.address, ROOT_PERMISSION_ID);
// Alice can make the DAO execute arbitrary stuff (test)
await dao.grant(dao.address, alice.address, EXECUTE_PERMISSION_ID);

// Alice is already an editor (see initialize)

// Bob is a member
await memberAccessPlugin.proposeNewMember('0x', bob.address);
});

describe('initialize', async () => {
Expand Down Expand Up @@ -351,20 +349,10 @@ describe('Main Voting Plugin', function () {

expect(await memberAccessPlugin.isMember(carol.address)).to.eq(false);

await dao.grant(
mainVotingPlugin.address,
carol.address,
MEMBER_PERMISSION_ID
);

await memberAccessPlugin.proposeNewMember('0x', carol.address);
expect(await memberAccessPlugin.isMember(carol.address)).to.eq(true);

await dao.revoke(
mainVotingPlugin.address,
carol.address,
MEMBER_PERMISSION_ID
);

await memberAccessPlugin.proposeRemoveMember('0x', carol.address);
expect(await memberAccessPlugin.isMember(carol.address)).to.eq(false);

await makeEditor(carol.address);
Expand Down Expand Up @@ -426,14 +414,10 @@ describe('Main Voting Plugin', function () {
context('Multiple editors', () => {
it('Proposals created by a member require editor votes', async () => {
let pid = 0;
// Carol member
await memberAccessPlugin.proposeNewMember('0x', carol.address);
// Bob editor
await proposeNewEditor(bob.address);
// Carol member
await dao.grant(
mainVotingPlugin.address,
carol.address,
MEMBER_PERMISSION_ID
);

await expect(createDummyProposal(carol, false)).to.not.be.reverted;
pid++;
Expand Down Expand Up @@ -1030,7 +1014,7 @@ describe('Main Voting Plugin', function () {
{
to: mainVotingPlugin.address,
value: 0,
data: MainVotingPlugin__factory.createInterface().encodeFunctionData(
data: mainVotingPluginInterface.encodeFunctionData(
'updateVotingSettings',
[
{
Expand All @@ -1049,7 +1033,7 @@ describe('Main Voting Plugin', function () {
)
)
.to.emit(mainVotingPlugin, 'VotingSettingsUpdated')
.withArgs(0, 12345, 23456, 60 * 60 * 3, 0);
.withArgs(0, 12345, 23456, 60 * 60 * 3);
});

it('The DAO can add editors', async () => {
Expand All @@ -1068,7 +1052,7 @@ describe('Main Voting Plugin', function () {
{
to: mainVotingPlugin.address,
value: 0,
data: MainVotingPlugin__factory.createInterface().encodeFunctionData(
data: mainVotingPluginInterface.encodeFunctionData(
'addEditor',
[dave.address]
),
Expand Down Expand Up @@ -1096,7 +1080,7 @@ describe('Main Voting Plugin', function () {
{
to: mainVotingPlugin.address,
value: 0,
data: MainVotingPlugin__factory.createInterface().encodeFunctionData(
data: mainVotingPluginInterface.encodeFunctionData(
'removeEditor',
[bob.address]
),
Expand Down Expand Up @@ -1130,15 +1114,15 @@ describe('Main Voting Plugin', function () {
{
to: mainVotingPlugin.address,
value: 0,
data: MainVotingPlugin__factory.createInterface().encodeFunctionData(
data: mainVotingPluginInterface.encodeFunctionData(
'upgradeTo',
[await mainVotingPlugin.implementation()]
),
},
{
to: mainVotingPlugin.address,
value: 0,
data: MainVotingPlugin__factory.createInterface().encodeFunctionData(
data: mainVotingPluginInterface.encodeFunctionData(
'supportsInterface',
['0x12345678']
),
Expand Down Expand Up @@ -1176,7 +1160,7 @@ describe('Main Voting Plugin', function () {
{
to: mainVotingPlugin.address,
value: 0,
data: MainVotingPlugin__factory.createInterface().encodeFunctionData(
data: mainVotingPluginInterface.encodeFunctionData(
'addEditor',
[_editor]
),
Expand All @@ -1200,7 +1184,7 @@ describe('Main Voting Plugin', function () {
{
to: mainVotingPlugin.address,
value: 0,
data: MainVotingPlugin__factory.createInterface().encodeFunctionData(
data: mainVotingPluginInterface.encodeFunctionData(
'removeEditor',
[_editor]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ import {deployTestDao} from '../helpers/test-dao';
import {
ADDRESS_ONE,
ADDRESS_TWO,
ADDRESS_ZERO,
DEPLOYER_PERMISSION_ID,
EDITOR_PERMISSION_ID,
EXECUTE_PERMISSION_ID,
MEMBER_PERMISSION_ID,
ROOT_PERMISSION_ID,
EXECUTE_PERMISSION_ID,
} from './common';
import {hexlify} from '@ethersproject/bytes';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
Expand Down Expand Up @@ -159,33 +155,33 @@ describe('Member Access Condition', function () {
)
).to.eq(true);

// // Invalid
// actions[0].data = mainVotingPluginInterface.encodeFunctionData(
// 'removeEditor',
// [carol.address]
// );
// expect(
// await memberAccessExecuteCondition.isGranted(
// ADDRESS_ONE, // where (used)
// ADDRESS_TWO, // who (used)
// EXECUTE_PERMISSION_ID, // permission (used)
// daoInterface.encodeFunctionData('execute', [ONE_BYTES32, actions, 0])
// )
// ).to.eq(true);
// Invalid
actions[0].data = mainVotingPluginInterface.encodeFunctionData(
'addEditor',
[carol.address]
);
expect(
await memberAccessExecuteCondition.isGranted(
ADDRESS_ONE, // where (used)
ADDRESS_TWO, // who (used)
EXECUTE_PERMISSION_ID, // permission (used)
daoInterface.encodeFunctionData('execute', [ONE_BYTES32, actions, 0])
)
).to.eq(true);

// // Invalid
// actions[0].data = mainVotingPluginInterface.encodeFunctionData(
// 'addEditor',
// [carol.address]
// );
// expect(
// await memberAccessExecuteCondition.isGranted(
// ADDRESS_ONE, // where (used)
// ADDRESS_TWO, // who (used)
// EXECUTE_PERMISSION_ID, // permission (used)
// daoInterface.encodeFunctionData('execute', [ONE_BYTES32, actions, 0])
// )
// ).to.eq(true);
// Invalid
actions[0].data = mainVotingPluginInterface.encodeFunctionData(
'removeEditor',
[carol.address]
);
expect(
await memberAccessExecuteCondition.isGranted(
ADDRESS_ONE, // where (used)
ADDRESS_TWO, // who (used)
EXECUTE_PERMISSION_ID, // permission (used)
daoInterface.encodeFunctionData('execute', [ONE_BYTES32, actions, 0])
)
).to.eq(true);

// Invalid
actions[0].data = daoInterface.encodeFunctionData('grant', [
Expand Down
Loading

0 comments on commit 2d0a721

Please sign in to comment.