diff --git a/contracts/extensions/VotingReputationFactory.sol b/contracts/extensions/VotingReputationFactory.sol new file mode 100644 index 0000000000..3ef1705872 --- /dev/null +++ b/contracts/extensions/VotingReputationFactory.sol @@ -0,0 +1,49 @@ +/* + This file is part of The Colony Network. + + The Colony Network is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + The Colony Network is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with The Colony Network. If not, see . +*/ + +pragma solidity 0.5.8; +pragma experimental ABIEncoderV2; + +import "./../ColonyDataTypes.sol"; +import "./../IColony.sol"; +import "./../ColonyAuthority.sol"; +import "./ExtensionFactory.sol"; +import "./VotingReputation.sol"; + + +contract VotingReputationFactory is ExtensionFactory, ColonyDataTypes { // ignore-swc-123 + mapping (address => VotingReputation) public deployedExtensions; + + modifier isRoot(address _colony) { + require(IColony(_colony).hasUserRole(msg.sender, 1, ColonyRole.Root), "colony-extension-user-not-root"); // ignore-swc-123 + _; + } + + function deployExtension(address _colony) external isRoot(_colony) { + require(deployedExtensions[_colony] == VotingReputation(0x00), "colony-extension-already-deployed"); + VotingReputation newExtensionAddress = new VotingReputation(_colony); + deployedExtensions[_colony] = newExtensionAddress; + + emit ExtensionDeployed("VotingReputation", _colony, address(newExtensionAddress)); + } + + function removeExtension(address _colony) external isRoot(_colony) { + deployedExtensions[_colony] = VotingReputation(0x00); + + emit ExtensionRemoved("VotingReputation", _colony); + } +} diff --git a/test/extensions/voting-rep.js b/test/extensions/voting-rep.js index 20bc9f125d..a882df8df0 100644 --- a/test/extensions/voting-rep.js +++ b/test/extensions/voting-rep.js @@ -21,12 +21,16 @@ const { expect } = chai; chai.use(bnChai(web3.utils.BN)); const VotingReputation = artifacts.require("VotingReputation"); +const VotingReputationFactory = artifacts.require("VotingReputationFactory"); contract("Voting Reputation", accounts => { let colony; let metaColony; let colonyNetwork; + let voting; + let votingFactory; + let reputationTree; const USER0 = accounts[0]; @@ -43,11 +47,15 @@ contract("Voting Reputation", accounts => { await giveUserCLNYTokensAndStake(colonyNetwork, MINER, DEFAULT_STAKE); await colonyNetwork.initialiseReputationMining(); await colonyNetwork.startNextCycle(); + + votingFactory = await VotingReputationFactory.new(); }); beforeEach(async () => { ({ colony } = await setupRandomColony(colonyNetwork)); - voting = await VotingReputation.new(colony.address); + await votingFactory.deployExtension(colony.address); + const votingAddress = await votingFactory.deployedExtensions(colony.address); + voting = await VotingReputation.at(votingAddress); reputationTree = new PatriciaTree(); await reputationTree.insert( @@ -74,7 +82,7 @@ contract("Voting Reputation", accounts => { await repCycle.confirmNewHash(0); }); - describe.only("creating and editing polls", async () => { + describe("creating and editing polls", async () => { it("can create a new poll", async () => { let pollId = await voting.getPollCount(); expect(pollId).to.be.zero; @@ -143,7 +151,7 @@ contract("Voting Reputation", accounts => { }); }); - describe.only("voting on polls", async () => { + describe("voting on polls", async () => { let key, value, mask, siblings, pollId; // eslint-disable-line one-var beforeEach(async () => { @@ -295,7 +303,7 @@ contract("Voting Reputation", accounts => { }); }); - describe.only("simple exceptions", async () => { + describe("simple exceptions", async () => { let pollId; beforeEach(async () => {