generated from aragon/osx-plugin-template-hardhat
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
225 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/contracts/src/personal-space-voting-build-metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"ui": {}, | ||
"change": "Initial build.", | ||
"pluginSetup": { | ||
"prepareInstallation": { | ||
"description": "The information required for the installation of build 1.", | ||
"inputs": [ | ||
{ | ||
"name": "_initialEditorAddress", | ||
"type": "address", | ||
"internalType": "address", | ||
"description": "The address of the first address to be granted the editor permission." | ||
} | ||
] | ||
}, | ||
"prepareUpdate": {}, | ||
"prepareUninstallation": { | ||
"description": "The information required for the uninstallation of build 1.", | ||
"inputs": [] | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/contracts/src/personal-space-voting-release-metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Personal Space Voting Plugin", | ||
"description": "", | ||
"images": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "SpacePlugin", | ||
"name": "Space Plugin", | ||
"description": "", | ||
"images": {} | ||
} |
186 changes: 186 additions & 0 deletions
186
packages/contracts/test/unit-testing/personal-space-governance-setup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
import { expect } from "chai"; | ||
import { ethers } from "hardhat"; | ||
|
||
import { | ||
PersonalSpaceVotingPlugin__factory, | ||
PersonalSpaceVotingPluginSetup, | ||
PersonalSpaceVotingPluginSetup__factory, | ||
} from "../../typechain"; | ||
import metadata from "../../src/personal-space-voting-build-metadata.json"; | ||
import { psvpInterface } from "./personal-space-governance"; | ||
import { getNamedTypesFromMetadata, Operation } from "../helpers/types"; | ||
import { deployTestDao } from "../helpers/test-dao"; | ||
import { getInterfaceID } from "../../utils/interfaces"; | ||
|
||
const abiCoder = ethers.utils.defaultAbiCoder; | ||
const AddressZero = ethers.constants.AddressZero; | ||
const EMPTY_DATA = "0x"; | ||
|
||
// Permissions | ||
const EDITOR_PERMISSION_ID = ethers.utils.id( | ||
"EDITOR_PERMISSION", | ||
); | ||
const EXECUTE_PERMISSION_ID = ethers.utils.id("EXECUTE_PERMISSION"); | ||
|
||
describe("Personal Space Voting Plugin Setup", function () { | ||
let ownerAddress: string; | ||
let signers: any; | ||
let adminSetup: PersonalSpaceVotingPluginSetup; | ||
let implementationAddress: string; | ||
let targetDao: any; | ||
let minimum_data: any; | ||
|
||
before(async () => { | ||
signers = await ethers.getSigners(); | ||
ownerAddress = await signers[0].getAddress(); | ||
targetDao = await deployTestDao(signers[0]); | ||
|
||
minimum_data = abiCoder.encode( | ||
getNamedTypesFromMetadata( | ||
metadata.pluginSetup.prepareInstallation.inputs, | ||
), | ||
[ownerAddress], | ||
); | ||
|
||
const PersonalSpaceVotingPluginSetup = | ||
new PersonalSpaceVotingPluginSetup__factory(signers[0]); | ||
adminSetup = await PersonalSpaceVotingPluginSetup.deploy(); | ||
|
||
implementationAddress = await adminSetup.implementation(); | ||
}); | ||
|
||
it("does not support the empty interface", async () => { | ||
expect(await adminSetup.supportsInterface("0xffffffff")).to.be.false; | ||
}); | ||
|
||
it("creates admin address base with the correct interface", async () => { | ||
const factory = new PersonalSpaceVotingPlugin__factory(signers[0]); | ||
const adminAddressContract = factory.attach(implementationAddress); | ||
|
||
expect( | ||
await adminAddressContract.supportsInterface( | ||
getInterfaceID(psvpInterface), | ||
), | ||
).to.be.eq(true); | ||
}); | ||
|
||
describe("prepareInstallation", async () => { | ||
it("fails if data is empty, or not of minimum length", async () => { | ||
await expect( | ||
adminSetup.prepareInstallation(targetDao.address, EMPTY_DATA), | ||
).to.be.reverted; | ||
|
||
await expect( | ||
adminSetup.prepareInstallation( | ||
targetDao.address, | ||
minimum_data.substring(0, minimum_data.length - 2), | ||
), | ||
).to.be.reverted; | ||
|
||
await expect( | ||
adminSetup.prepareInstallation(targetDao.address, minimum_data), | ||
).not.to.be.reverted; | ||
}); | ||
|
||
it("reverts if encoded address in `_data` is zero", async () => { | ||
const dataWithAddressZero = abiCoder.encode( | ||
getNamedTypesFromMetadata( | ||
metadata.pluginSetup.prepareInstallation.inputs, | ||
), | ||
[AddressZero], | ||
); | ||
|
||
await expect( | ||
adminSetup.prepareInstallation(targetDao.address, dataWithAddressZero), | ||
) | ||
.to.be.revertedWithCustomError( | ||
adminSetup, | ||
"EditorAddressInvalid", | ||
) | ||
.withArgs(AddressZero); | ||
}); | ||
|
||
it("correctly returns plugin, helpers and permissions", async () => { | ||
const nonce = await ethers.provider.getTransactionCount( | ||
adminSetup.address, | ||
); | ||
const anticipatedPluginAddress = ethers.utils.getContractAddress({ | ||
from: adminSetup.address, | ||
nonce, | ||
}); | ||
|
||
const { | ||
plugin, | ||
preparedSetupData: { helpers, permissions }, | ||
} = await adminSetup.callStatic.prepareInstallation( | ||
targetDao.address, | ||
minimum_data, | ||
); | ||
|
||
expect(plugin).to.be.equal(anticipatedPluginAddress); | ||
expect(helpers.length).to.be.equal(0); | ||
expect(permissions.length).to.be.equal(2); | ||
expect(permissions).to.deep.equal([ | ||
[ | ||
Operation.Grant, | ||
plugin, | ||
ownerAddress, | ||
AddressZero, | ||
EDITOR_PERMISSION_ID, | ||
], | ||
[ | ||
Operation.Grant, | ||
targetDao.address, | ||
plugin, | ||
AddressZero, | ||
EXECUTE_PERMISSION_ID, | ||
], | ||
]); | ||
}); | ||
|
||
it("correctly sets up the plugin", async () => { | ||
const daoAddress = targetDao.address; | ||
|
||
const nonce = await ethers.provider.getTransactionCount( | ||
adminSetup.address, | ||
); | ||
const anticipatedPluginAddress = ethers.utils.getContractAddress({ | ||
from: adminSetup.address, | ||
nonce, | ||
}); | ||
|
||
await adminSetup.prepareInstallation(daoAddress, minimum_data); | ||
|
||
const factory = new PersonalSpaceVotingPlugin__factory(signers[0]); | ||
const adminAddressContract = factory.attach(anticipatedPluginAddress); | ||
|
||
expect(await adminAddressContract.dao()).to.be.equal(daoAddress); | ||
}); | ||
}); | ||
|
||
describe("prepareUninstallation", async () => { | ||
it("correctly returns permissions", async () => { | ||
const plugin = ethers.Wallet.createRandom().address; | ||
|
||
const permissions = await adminSetup.callStatic.prepareUninstallation( | ||
targetDao.address, | ||
{ | ||
plugin, | ||
currentHelpers: [], | ||
data: EMPTY_DATA, | ||
}, | ||
); | ||
|
||
expect(permissions.length).to.be.equal(1); | ||
expect(permissions).to.deep.equal([ | ||
[ | ||
Operation.Revoke, | ||
targetDao.address, | ||
plugin, | ||
AddressZero, | ||
EXECUTE_PERMISSION_ID, | ||
], | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters