Skip to content

Commit

Permalink
Tidingy up the existing template code
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Aug 24, 2023
1 parent 8ab5396 commit fd4e591
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 123 deletions.
8 changes: 3 additions & 5 deletions packages/contracts/plugin-settings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import buildMetadata from './src/build-metadata.json';
import releaseMetadata from './src/release-metadata.json';
import buildMetadata from "./src/space-build-metadata.json";
import releaseMetadata from "./src/space-release-metadata.json";

export const PLUGIN_REPO_ENS_NAME = 'test-2';
export const PLUGIN_CONTRACT_NAME = 'MyPlugin';
export const PLUGIN_SETUP_CONTRACT_NAME = 'MyPluginSetup';
export const PLUGIN_REPO_ENS_NAME = "test-2";

export const VERSION = {
release: 1, // Increment this number ONLY if breaking/incompatible changes were made. Updates between releases are NOT possible.
Expand Down
6 changes: 1 addition & 5 deletions packages/contracts/src/MemberAccessPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ contract MemberAccessPlugin is PluginUUPSUpgradeable {
}

/// @notice Initializes the plugin when build 1 is installed.
/// @param _number The number to be stored.
function initialize(IDAO _dao, uint256 _number) external initializer {
function initialize(IDAO _dao) external initializer {
__PluginUUPSUpgradeable_init(_dao);
number = _number;

emit NumberStored({number: _number});
}

/// @notice Stores a new number to storage. Caller needs STORE_PERMISSION.
Expand Down
22 changes: 1 addition & 21 deletions packages/contracts/src/PersonalSpaceVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,13 @@ import {IDAO, PluginUUPSUpgradeable} from "@aragon/osx/core/plugin/PluginUUPSUpg
/// @title PersonalSpaceVotingPlugin
/// @dev Release 1, Build 1
contract PersonalSpaceVotingPlugin is PluginUUPSUpgradeable {
bytes32 public constant STORE_PERMISSION_ID = keccak256("STORE_PERMISSION");

uint256 public number; // added in build 1

/// @notice Emitted when a number is stored.
/// @param number The number.
event NumberStored(uint256 number);

constructor() {
_disableInitializers();
}

/// @notice Initializes the plugin when build 1 is installed.
/// @param _number The number to be stored.
function initialize(IDAO _dao, uint256 _number) external initializer {
function initialize(IDAO _dao) external initializer {
__PluginUUPSUpgradeable_init(_dao);
number = _number;

emit NumberStored({number: _number});
}

/// @notice Stores a new number to storage. Caller needs STORE_PERMISSION.
/// @param _number The number to be stored.
function storeNumber(uint256 _number) external auth(STORE_PERMISSION_ID) {
number = _number;

emit NumberStored({number: _number});
}

/// @notice This empty reserved space is put in place to allow future versions to add new variables without shifting down storage in the inheritance chain (see [OpenZeppelin's guide about storage gaps](https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps)).
Expand Down
3 changes: 1 addition & 2 deletions packages/contracts/src/SpaceVotingPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ contract SpaceVotingPlugin is PluginUUPSUpgradeable {

/// @notice Initializes the plugin when build 1 is installed.
/// @param _dao The address of the DAO to read the permissions from.
/// @param _firstBlockContentUri A IPFS URI pointing to the contents of the very first block.
function initialize(IDAO _dao, string memory _firstBlockContentUri) external initializer {
function initialize(IDAO _dao) external initializer {
__PluginUUPSUpgradeable_init(_dao);
}

Expand Down
5 changes: 0 additions & 5 deletions packages/contracts/src/release-metadata.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"description": "The information required for the installation of build 1.",
"inputs": [
{
"name": "number",
"type": "uint256",
"internalType": "uint256",
"description": "The inital number to be stored."
"name": "_firstBlockContentUri",
"type": "string",
"internalType": "string",
"description": "The inital contents of the first block item."
}
]
},
Expand Down
5 changes: 5 additions & 0 deletions packages/contracts/src/space-release-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "SpacePlugin",
"description": "",
"images": {}
}
12 changes: 6 additions & 6 deletions packages/contracts/test/integration-testing/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
MyPluginSetup,
MyPluginSetup__factory,
PluginRepo,
SpacePluginSetup,
SpacePluginSetup__factory,
} from "../../typechain";
import { getPluginInfo, osxContracts } from "../../utils/helpers";
import { toHex } from "../../utils/ipfs";
Expand Down Expand Up @@ -82,12 +82,12 @@ describe("PluginRepo Deployment", function () {
).to.be.true;
});

context("PluginSetup Publication", async () => {
let setup: MyPluginSetup;
context("SpacePluginSetup Publication", () => {
let setup: SpacePluginSetup;

before(async () => {
setup = MyPluginSetup__factory.connect(
(await deployments.get("MyPluginSetup")).address,
setup = SpacePluginSetup__factory.connect(
(await deployments.get("SpacePluginSetup")).address,
alice,
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import {METADATA} from '../../plugin-settings';
import { METADATA } from "../../plugin-settings";
import {
PluginRepo,
MyPlugin,
MyPluginSetup,
MyPluginSetup__factory,
MyPlugin__factory,
} from '../../typechain';
import {PluginSetupRefStruct} from '../../typechain/@aragon/osx/framework/dao/DAOFactory';
import {getPluginInfo, osxContracts} from '../../utils/helpers';
import {initializeFork} from '../helpers/fixture';
import {installPLugin, uninstallPLugin} from '../helpers/setup';
import {deployTestDao} from '../helpers/test-dao';
import {getNamedTypesFromMetadata} from '../helpers/types';
SpacePlugin,
SpacePlugin__factory,
SpacePluginSetup,
SpacePluginSetup__factory,
} from "../../typechain";
import { PluginSetupRefStruct } from "../../typechain/@aragon/osx/framework/dao/DAOFactory";
import { getPluginInfo, osxContracts } from "../../utils/helpers";
import { initializeFork } from "../helpers/fixture";
import { installPLugin, uninstallPLugin } from "../helpers/setup";
import { deployTestDao } from "../helpers/test-dao";
import { getNamedTypesFromMetadata } from "../helpers/types";
import {
DAO,
PluginRepo__factory,
PluginSetupProcessor,
PluginSetupProcessor__factory,
} from '@aragon/osx-ethers';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {expect} from 'chai';
import {BigNumber} from 'ethers';
import {ethers} from 'hardhat';
} from "@aragon/osx-ethers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { BigNumber } from "ethers";
import { ethers } from "hardhat";

describe('PluginSetup Processing', function () {
describe("PluginSetup Processing", function () {
let alice: SignerWithAddress;

let psp: PluginSetupProcessor;
Expand All @@ -33,19 +33,19 @@ describe('PluginSetup Processing', function () {
before(async () => {
[alice] = await ethers.getSigners();

const hardhatForkNetwork = 'goerli';
const hardhatForkNetwork = "goerli";

await initializeFork(
hardhatForkNetwork,
getPluginInfo(hardhatForkNetwork)[hardhatForkNetwork]['releases']['1'][
'builds'
]['1']['blockNumberOfPublication']
getPluginInfo(hardhatForkNetwork)[hardhatForkNetwork]["releases"]["1"][
"builds"
]["1"]["blockNumberOfPublication"],
);

// PSP
psp = PluginSetupProcessor__factory.connect(
osxContracts[hardhatForkNetwork]['PluginSetupProcessor'],
alice
osxContracts[hardhatForkNetwork]["PluginSetupProcessor"],
alice,
);

// Deploy DAO.
Expand All @@ -54,40 +54,40 @@ describe('PluginSetup Processing', function () {
await dao.grant(
dao.address,
psp.address,
ethers.utils.id('ROOT_PERMISSION')
ethers.utils.id("ROOT_PERMISSION"),
);
await dao.grant(
psp.address,
alice.address,
ethers.utils.id('APPLY_INSTALLATION_PERMISSION')
ethers.utils.id("APPLY_INSTALLATION_PERMISSION"),
);
await dao.grant(
psp.address,
alice.address,
ethers.utils.id('APPLY_UNINSTALLATION_PERMISSION')
ethers.utils.id("APPLY_UNINSTALLATION_PERMISSION"),
);
await dao.grant(
psp.address,
alice.address,
ethers.utils.id('APPLY_UPDATE_PERMISSION')
ethers.utils.id("APPLY_UPDATE_PERMISSION"),
);

pluginRepo = PluginRepo__factory.connect(
getPluginInfo(hardhatForkNetwork)[hardhatForkNetwork].address,
alice
alice,
);
});

context('Build 1', async () => {
let setup: MyPluginSetup;
context("Build 1", async () => {
let setup: SpacePluginSetup;
let pluginSetupRef: PluginSetupRefStruct;
let plugin: MyPlugin;
let plugin: SpacePlugin;

before(async () => {
// Deploy setups.
setup = MyPluginSetup__factory.connect(
(await pluginRepo['getLatestVersion(uint8)'](1)).pluginSetup,
alice
setup = SpacePluginSetup__factory.connect(
(await pluginRepo["getLatestVersion(uint8)"](1)).pluginSetup,
alice,
);

pluginSetupRef = {
Expand All @@ -108,27 +108,24 @@ describe('PluginSetup Processing', function () {
pluginSetupRef,
ethers.utils.defaultAbiCoder.encode(
getNamedTypesFromMetadata(
METADATA.build.pluginSetup.prepareInstallation.inputs
METADATA.build.pluginSetup.prepareInstallation.inputs,
),
[123]
)
[123],
),
);

plugin = MyPlugin__factory.connect(
plugin = SpacePlugin__factory.connect(
results.preparedEvent.args.plugin,
alice
alice,
);
});

it('installs & uninstalls', async () => {
it("installs & uninstalls", async () => {
// Check implementation.
expect(await plugin.implementation()).to.be.eq(
await setup.implementation()
await setup.implementation(),
);

// Check state.
expect(await plugin.number()).to.eq(123);

// Uninstall build 1.
await uninstallPLugin(
psp,
Expand All @@ -137,11 +134,11 @@ describe('PluginSetup Processing', function () {
pluginSetupRef,
ethers.utils.defaultAbiCoder.encode(
getNamedTypesFromMetadata(
METADATA.build.pluginSetup.prepareUninstallation.inputs
METADATA.build.pluginSetup.prepareUninstallation.inputs,
),
[]
[],
),
[]
[],
);
});
});
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 @@ -7,6 +7,9 @@ export const DEPLOYER_PERMISSION_ID = ethers.utils.id("DEPLOYER_PERMISSION");
export const EDITOR_PERMISSION_ID = ethers.utils.id("EDITOR_PERMISSION");
export const MEMBER_PERMISSION_ID = ethers.utils.id("MEMBER_PERMISSION");

export const CONTENT_PERMISSION_ID = ethers.utils.id("CONTENT_PERMISSION");
export const SUBSPACE_PERMISSION_ID = ethers.utils.id("SUBSPACE_PERMISSION");

export const ADDRESS_ZERO = ethers.constants.AddressZero;
export const ADDRESS_ONE = `0x${"0".repeat(39)}1`;
export const ADDRESS_TWO = `0x${"0".repeat(39)}2`;
Expand Down
19 changes: 9 additions & 10 deletions packages/contracts/test/unit-testing/default-space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import { deployTestDao } from "../helpers/test-dao";
import { EDITOR_PERMISSION_ID, MEMBER_PERMISSION_ID } from "./common";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { BigNumber } from "ethers";
import { ethers } from "hardhat";

export type InitData = { number: BigNumber };
export type InitData = { contentUri: string };
export const defaultInitData: InitData = {
number: BigNumber.from(123),
contentUri: "ipfs://",
};

describe("Default Geo Browser Space", function () {
Expand All @@ -34,7 +33,7 @@ describe("Default Geo Browser Space", function () {
[alice, bob, charlie] = await ethers.getSigners();
dao = await deployTestDao(alice);

defaultInput = { number: BigNumber.from(123) };
defaultInput = { contentUri: "ipfs://" };
});

beforeEach(async () => {
Expand All @@ -48,9 +47,9 @@ describe("Default Geo Browser Space", function () {
new SpacePlugin__factory(alice),
);

await memberAccessPlugin.initialize(dao.address, defaultInput.number);
await spaceVotingPlugin.initialize(dao.address, defaultInput.number);
await spacePlugin.initialize(dao.address, defaultInput.number);
await memberAccessPlugin.initialize(dao.address);
await spaceVotingPlugin.initialize(dao.address);
await spacePlugin.initialize(dao.address, defaultInput.contentUri);

await dao.grant(
memberAccessPlugin.address,
Expand All @@ -77,13 +76,13 @@ describe("Default Geo Browser Space", function () {
describe("initialize", async () => {
it("reverts if trying to re-initialize", async () => {
await expect(
memberAccessPlugin.initialize(dao.address, defaultInput.number),
memberAccessPlugin.initialize(dao.address),
).to.be.revertedWith("Initializable: contract is already initialized");
await expect(
spaceVotingPlugin.initialize(dao.address, defaultInput.number),
spaceVotingPlugin.initialize(dao.address),
).to.be.revertedWith("Initializable: contract is already initialized");
await expect(
spacePlugin.initialize(dao.address, defaultInput.number),
spacePlugin.initialize(dao.address, defaultInput.contentUri),
).to.be.revertedWith("Initializable: contract is already initialized");
});
});
Expand Down
Loading

0 comments on commit fd4e591

Please sign in to comment.