Skip to content

Commit

Permalink
Adding an event to announce the space's predecessor
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Oct 13, 2023
1 parent f9e584e commit 82baf6c
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 17 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ This plugin is upgradeable.

#### Methods

- `function initialize(IDAO _dao, string _firstBlockContentUri)`
- `function initialize(IDAO _dao, string _firstBlockContentUri, address predecessorSpace)`
- `function processGeoProposal(uint32 _blockIndex, uint32 _itemIndex, string _contentUri)`
- `function acceptSubspace(address _dao)`
- `function removeSubspace(address _dao)`
Expand All @@ -234,6 +234,7 @@ Inherited:
#### Events

- `event GeoProposalProcessed(uint32 blockIndex, uint32 itemIndex, string contentUri)`
- `event SuccessorSpaceCreated(address predecessorSpace)`
- `event SubspaceAccepted(address dao)`
- `event SubspaceRemoved(address dao)`

Expand Down
14 changes: 13 additions & 1 deletion packages/contracts/src/SpacePlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ contract SpacePlugin is PluginUUPSUpgradeable {
/// @param contentUri An IPFS URI pointing to the new contents behind the block's item.
event GeoProposalProcessed(uint32 blockIndex, uint32 itemIndex, string contentUri);

/// @notice Announces that the current space plugin is the successor of an already existing Space
/// @param predecessorSpace The address of the space contract that the plugin will replace
event SuccessorSpaceCreated(address predecessorSpace);

/// @notice Emitted when the DAO accepts another DAO as a subspace.
/// @param subspaceDao The address of the DAO to be accepted as a subspace.
event SubspaceAccepted(address subspaceDao);
Expand All @@ -29,9 +33,17 @@ contract SpacePlugin 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 first block's item (title).
function initialize(IDAO _dao, string memory _firstBlockContentUri) external initializer {
/// @param _predecessorSpace Optionally, the address of the space contract preceding this one
function initialize(
IDAO _dao,
string memory _firstBlockContentUri,
address _predecessorSpace
) external initializer {
__PluginUUPSUpgradeable_init(_dao);

if (_predecessorSpace != address(0)) {
emit SuccessorSpaceCreated(_predecessorSpace);
}
emit GeoProposalProcessed({blockIndex: 0, itemIndex: 0, contentUri: _firstBlockContentUri});
}

Expand Down
16 changes: 11 additions & 5 deletions packages/contracts/src/SpacePluginSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ contract SpacePluginSetup is PluginSetup {
bytes memory _data
) external returns (address plugin, PreparedSetupData memory preparedSetupData) {
// Decode incoming params
(string memory firstBlockContentUri, address _pluginUpgrader) = abi.decode(
_data,
(string, address)
);
(
string memory _firstBlockContentUri,
address _predecessorAddress,
address _pluginUpgrader
) = abi.decode(_data, (string, address, address));

// Deploy new plugin instance
plugin = createERC1967Proxy(
pluginImplementation,
abi.encodeWithSelector(SpacePlugin.initialize.selector, _dao, firstBlockContentUri)
abi.encodeWithSelector(
SpacePlugin.initialize.selector,
_dao,
_firstBlockContentUri,
_predecessorAddress
)
);

PermissionLib.MultiTargetPermission[]
Expand Down
5 changes: 5 additions & 0 deletions packages/contracts/src/space-build-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"internalType": "string",
"description": "The inital contents of the first block item."
},
{
"internalType": "address",
"name": "predecessorAddress",
"type": "address"
},
{
"internalType": "address",
"name": "pluginUpgrader",
Expand Down
12 changes: 10 additions & 2 deletions packages/contracts/test/unit-testing/main-voting-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ describe("Main Voting Plugin", function () {
defaultMainVotingSettings,
[alice.address],
);
await spacePlugin.initialize(dao.address, defaultInput.contentUri);
await spacePlugin.initialize(
dao.address,
defaultInput.contentUri,
ADDRESS_ZERO,
);

// Alice is already an editor (see initialize)

Expand Down Expand Up @@ -153,7 +157,11 @@ describe("Main Voting Plugin", function () {
),
).to.be.revertedWith("Initializable: contract is already initialized");
await expect(
spacePlugin.initialize(dao.address, defaultInput.contentUri),
spacePlugin.initialize(
dao.address,
defaultInput.contentUri,
ADDRESS_ZERO,
),
).to.be.revertedWith("Initializable: contract is already initialized");
});

Expand Down
12 changes: 10 additions & 2 deletions packages/contracts/test/unit-testing/member-access-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ describe("Member Access Plugin", function () {
defaultMainVotingSettings,
[alice.address],
);
await spacePlugin.initialize(dao.address, defaultInput.contentUri);
await spacePlugin.initialize(
dao.address,
defaultInput.contentUri,
ADDRESS_ZERO,
);

// Alice is an editor (see mainVotingPlugin initialize)

Expand Down Expand Up @@ -1381,7 +1385,11 @@ describe("Member Access Plugin", function () {
),
).to.be.revertedWith("Initializable: contract is already initialized");
await expect(
spacePlugin.initialize(dao.address, defaultInput.contentUri),
spacePlugin.initialize(
dao.address,
defaultInput.contentUri,
ADDRESS_ZERO,
),
).to.be.revertedWith("Initializable: contract is already initialized");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ describe("Personal Space Admin Plugin", function () {
spacePlugin = await deployWithProxy<SpacePlugin>(
new SpacePlugin__factory(alice),
);
await spacePlugin.initialize(dao.address, defaultInput.contentUri);
await spacePlugin.initialize(
dao.address,
defaultInput.contentUri,
ADDRESS_ZERO,
);

// Personal Space Voting
const PersonalSpaceVotingFactory = new PersonalSpaceAdminPlugin__factory(
Expand Down
6 changes: 3 additions & 3 deletions packages/contracts/test/unit-testing/space-plugin-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { deployTestDao } from "../helpers/test-dao";
import { getNamedTypesFromMetadata, Operation } from "../helpers/types";
import {
abiCoder,
ADDRESS_TWO,
ADDRESS_ONE,
ADDRESS_ZERO,
CONTENT_PERMISSION_ID,
NO_CONDITION,
Expand Down Expand Up @@ -42,7 +42,7 @@ describe("Space Plugin Setup", function () {
getNamedTypesFromMetadata(
buildMetadata.pluginSetup.prepareInstallation.inputs,
),
[defaultInitData.contentUri, ADDRESS_ZERO],
[defaultInitData.contentUri, ADDRESS_ZERO, ADDRESS_ZERO],
);
const nonce = await ethers.provider.getTransactionCount(
spacePluginSetup.address,
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("Space Plugin Setup", function () {
getNamedTypesFromMetadata(
buildMetadata.pluginSetup.prepareInstallation.inputs,
),
[defaultInitData.contentUri, pluginUpgrader],
[defaultInitData.contentUri, ADDRESS_ONE, pluginUpgrader],
);
const nonce = await ethers.provider.getTransactionCount(
spacePluginSetup.address,
Expand Down
52 changes: 50 additions & 2 deletions packages/contracts/test/unit-testing/space-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { deployTestDao } from "../helpers/test-dao";
import {
ADDRESS_ONE,
ADDRESS_TWO,
ADDRESS_ZERO,
CONTENT_PERMISSION_ID,
EXECUTE_PERMISSION_ID,
SUBSPACE_PERMISSION_ID,
Expand Down Expand Up @@ -39,15 +40,62 @@ describe("Space Plugin", function () {
new SpacePlugin__factory(alice),
);

await spacePlugin.initialize(dao.address, defaultInput.contentUri);
await spacePlugin.initialize(
dao.address,
defaultInput.contentUri,
ADDRESS_ZERO,
);
});

describe("initialize", async () => {
it("The Space plugin reverts if trying to re-initialize", async () => {
await expect(
spacePlugin.initialize(dao.address, defaultInput.contentUri),
spacePlugin.initialize(
dao.address,
defaultInput.contentUri,
ADDRESS_ZERO,
),
).to.be.revertedWith("Initializable: contract is already initialized");
});

it("Should emit a new content event", async () => {
spacePlugin = await deployWithProxy<SpacePlugin>(
new SpacePlugin__factory(alice),
);

await expect(spacePlugin.initialize(
dao.address,
defaultInput.contentUri,
ADDRESS_ZERO,
)).to.emit(spacePlugin, "GeoProposalProcessed")
.withArgs(0, 0, defaultInput.contentUri);
});

it("Should emit a successor space event", async () => {
// 1
spacePlugin = await deployWithProxy<SpacePlugin>(
new SpacePlugin__factory(alice),
);

await expect(spacePlugin.initialize(
dao.address,
defaultInput.contentUri,
ADDRESS_ONE,
)).to.emit(spacePlugin, "SuccessorSpaceCreated")
.withArgs(ADDRESS_ONE);

// 2
spacePlugin = await deployWithProxy<SpacePlugin>(
new SpacePlugin__factory(alice),
);

await expect(spacePlugin.initialize(
dao.address,
defaultInput.contentUri,
ADDRESS_TWO,
)).to.emit(spacePlugin, "SuccessorSpaceCreated")
.withArgs(ADDRESS_TWO);
});
});

it("The Space plugin emits an event when new content is published", async () => {
Expand Down

0 comments on commit 82baf6c

Please sign in to comment.