Skip to content

Commit

Permalink
Adapting the tests - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Aug 9, 2024
1 parent 64c4a37 commit 70ac124
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/contracts/src/personal/PersonalAdminPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contract PersonalAdminPlugin is PluginCloneable, ProposalUpgradeable, IEditors,
this.submitEdits.selector ^
this.submitAcceptSubspace.selector ^
this.submitRemoveSubspace.selector ^
this.proposeAddMember.selector ^
this.addMember.selector ^
this.submitRemoveMember.selector ^
this.submitNewEditor.selector ^
Expand Down
10 changes: 9 additions & 1 deletion packages/contracts/src/personal/PersonalAdminSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ contract PersonalAdminSetup is PluginSetup {
SetupPayload calldata _payload
) external view returns (PermissionLib.MultiTargetPermission[] memory permissions) {
// Prepare permissions
permissions = new PermissionLib.MultiTargetPermission[](1);
permissions = new PermissionLib.MultiTargetPermission[](2);

// Revoke EXECUTE on the DAO
permissions[0] = PermissionLib.MultiTargetPermission(
Expand All @@ -141,6 +141,14 @@ contract PersonalAdminSetup is PluginSetup {
PermissionLib.NO_CONDITION,
DAO(payable(_dao)).EXECUTE_PERMISSION_ID()
);
// Revoke conditional EXECUTE on the DAO
permissions[1] = PermissionLib.MultiTargetPermission(
PermissionLib.Operation.Revoke,
_dao,
_payload.currentHelpers[0],
address(0),
DAO(payable(_dao)).EXECUTE_PERMISSION_ID()
);
}

/// @inheritdoc IPluginSetup
Expand Down
3 changes: 3 additions & 0 deletions packages/contracts/test/unit-testing/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const UPGRADE_PLUGIN_PERMISSION_ID = ethers.utils.id(
export const ADD_MEMBER_PERMISSION_ID = ethers.utils.id(
'ADD_MEMBER_PERMISSION'
);
export const UPDATE_SETTINGS_PERMISSION_ID = ethers.utils.id(
'UPDATE_SETTINGS_PERMISSION'
);
export const PROPOSER_PERMISSION_ID = ethers.utils.id('PROPOSER_PERMISSION');
export const ROOT_PERMISSION_ID = ethers.utils.id('ROOT_PERMISSION');

Expand Down
13 changes: 9 additions & 4 deletions packages/contracts/test/unit-testing/personal-admin-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export const psvpInterface = new ethers.utils.Interface([
'function submitAcceptSubspace(address _subspaceDao, address _spacePlugin)',
'function submitRemoveSubspace(address _subspaceDao, address _spacePlugin)',
'function submitNewEditor(address _newEditor)',
'function submitNewMember(address _newMember)',
'function proposeAddMember(address _newMember)',
'function addMember(address _newMember)',
'function submitRemoveEditor(address _editor)',
'function submitRemoveMember(address _member)',
'function leaveSpace()',
Expand Down Expand Up @@ -108,7 +109,7 @@ describe('Personal Admin Plugin', function () {

// Personal admin (plugin)
const PersonalAdminPluginFactory = new PersonalAdminPlugin__factory(alice);
let nonce = await ethers.provider.getTransactionCount(
const nonce = await ethers.provider.getTransactionCount(
testCloneFactory.address
);
let anticipatedAddress = ethers.utils.getContractAddress({
Expand Down Expand Up @@ -335,7 +336,7 @@ describe('Personal Admin Plugin', function () {
.be.reverted;

expect(await personalAdminPlugin.proposalCount()).to.equal(
BigNumber.from(4)
BigNumber.from(3)
);

// Non editors
Expand Down Expand Up @@ -371,14 +372,18 @@ describe('Personal Admin Plugin', function () {
carol.address,
EDITOR_PERMISSION_ID
);

expect(await personalAdminPlugin.proposalCount()).to.equal(
BigNumber.from(3)
);
});

it('Anyone can call proposeAddMember', async () => {
for (const account of [alice, bob, carol, david]) {
await expect(
personalAdminPlugin
.connect(account)
.proposeAddMember('ipfs://', account.address)
.proposeAddMember('0x', account.address)
).to.not.be.reverted;
}
expect(await personalAdminPlugin.proposalCount()).to.equal(
Expand Down
63 changes: 56 additions & 7 deletions packages/contracts/test/unit-testing/personal-admin-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import {
import {getInterfaceID} from '../../utils/interfaces';
import {deployTestDao} from '../helpers/test-dao';
import {Operation} from '../helpers/types';
import {
ADD_MEMBER_PERMISSION_ID,
PROPOSER_PERMISSION_ID,
UPDATE_SETTINGS_PERMISSION_ID,
} from './common';
import {psvpInterface} from './personal-admin-plugin';
import {expect} from 'chai';
import {ethers} from 'hardhat';
Expand Down Expand Up @@ -46,10 +51,10 @@ describe('Personal Admin Plugin Setup', function () {

it('creates admin address base with the correct interface', async () => {
const factory = new PersonalAdminPlugin__factory(signers[0]);
const adminAddressContract = factory.attach(implementationAddress);
const personalAddressPlugin = factory.attach(implementationAddress);

expect(
await adminAddressContract.supportsInterface(
await personalAddressPlugin.supportsInterface(
getInterfaceID(psvpInterface)
)
).to.be.eq(true);
Expand Down Expand Up @@ -99,6 +104,14 @@ describe('Personal Admin Plugin Setup', function () {
from: adminSetup.address,
nonce,
});
const anticipatedHelperAddress = ethers.utils.getContractAddress({
from: adminSetup.address,
nonce: nonce + 1,
});
const anticipatedConditionAddress = ethers.utils.getContractAddress({
from: adminSetup.address,
nonce: nonce + 2,
});

const {
plugin,
Expand All @@ -109,9 +122,17 @@ describe('Personal Admin Plugin Setup', function () {
);

expect(plugin).to.be.equal(anticipatedPluginAddress);
expect(helpers.length).to.be.equal(0);
expect(permissions.length).to.be.equal(2);
expect(helpers.length).to.be.equal(1);
expect(helpers[0]).to.be.equal(anticipatedHelperAddress);
expect(permissions.length).to.be.equal(6);
expect(permissions).to.deep.equal([
[
Operation.Grant,
targetDao.address,
plugin,
AddressZero,
EXECUTE_PERMISSION_ID,
],
[
Operation.Grant,
plugin,
Expand All @@ -121,11 +142,32 @@ describe('Personal Admin Plugin Setup', function () {
],
[
Operation.Grant,
targetDao.address,
helpers[0],
plugin,
AddressZero,
PROPOSER_PERMISSION_ID,
],
[
Operation.Grant,
targetDao,
helpers[0],
anticipatedConditionAddress,
EXECUTE_PERMISSION_ID,
],
[
Operation.Grant,
plugin,
targetDao,
AddressZero,
ADD_MEMBER_PERMISSION_ID,
],
[
Operation.Grant,
helpers[0],
targetDao,
AddressZero,
UPDATE_SETTINGS_PERMISSION_ID,
],
]);
});

Expand Down Expand Up @@ -157,12 +199,12 @@ describe('Personal Admin Plugin Setup', function () {
targetDao.address,
{
plugin,
currentHelpers: [],
currentHelpers: ['0x1234567890123456789012345678901234567890'],
data: EMPTY_DATA,
}
);

expect(permissions.length).to.be.equal(1);
expect(permissions.length).to.be.equal(0);
expect(permissions).to.deep.equal([
[
Operation.Revoke,
Expand All @@ -171,6 +213,13 @@ describe('Personal Admin Plugin Setup', function () {
AddressZero,
EXECUTE_PERMISSION_ID,
],
[
Operation.Revoke,
targetDao.address,
'0x1234567890123456789012345678901234567890',
AddressZero,
EXECUTE_PERMISSION_ID,
],
]);
});
});
Expand Down

0 comments on commit 70ac124

Please sign in to comment.