Skip to content

Commit

Permalink
Add VotingReputationFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Jun 21, 2019
1 parent 3886c62 commit eedc7ad
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
48 changes: 48 additions & 0 deletions contracts/extensions/VotingReputationFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
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 <http://www.gnu.org/licenses/>.
*/

pragma solidity 0.5.8;
pragma experimental ABIEncoderV2;

import "./../ColonyDataTypes.sol";
import "./../IColony.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);
}
}
16 changes: 12 additions & 4 deletions test/extensions/voting-rep.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -295,7 +303,7 @@ contract("Voting Reputation", accounts => {
});
});

describe.only("simple exceptions", async () => {
describe("simple exceptions", async () => {
let pollId;

beforeEach(async () => {
Expand Down

0 comments on commit eedc7ad

Please sign in to comment.