Skip to content

Commit

Permalink
Merge pull request #1138 from JoinColony/fix/zero-reputation-motions
Browse files Browse the repository at this point in the history
Prevent creation of motions with 0 reputation in domain
  • Loading branch information
kronosapiens authored May 25, 2023
2 parents 13b005b + 0cea94d commit c767244
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/extensions/votingReputation/VotingReputation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ contract VotingReputation is ColonyExtension, BasicMetaTransaction, VotingReputa
motion.skillId = skillId;

motion.skillRep = checkReputation(motion.rootHash, skillId, address(0x0), _key, _value, _branchMask, _siblings);
require(motion.skillRep > 0, "voting-rep-no-reputation-in-domain");
motion.altTarget = _altTarget;
motion.action = _action;

Expand Down
26 changes: 26 additions & 0 deletions test/extensions/voting-rep.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ contract("Voting Reputation", (accounts) => {
let domain1;
let domain2;
let domain3;
let domain4;
let metaColony;
let colonyNetwork;
let tokenLocking;
Expand Down Expand Up @@ -140,9 +141,11 @@ contract("Voting Reputation", (accounts) => {
// 1 => { 2, 3 }
await colony.addDomain(1, UINT256_MAX, 1);
await colony.addDomain(1, UINT256_MAX, 1);
await colony.addDomain(1, UINT256_MAX, 1);
domain1 = await colony.getDomain(1);
domain2 = await colony.getDomain(2);
domain3 = await colony.getDomain(3);
domain4 = await colony.getDomain(4);

await colony.installExtension(VOTING_REPUTATION, version);
const votingAddress = await colonyNetwork.getExtensionInstallation(VOTING_REPUTATION, colony.address);
Expand Down Expand Up @@ -226,6 +229,16 @@ contract("Voting Reputation", (accounts) => {
makeReputationValue(WAD.muln(2), 12)
);

await reputationTree.insert(
makeReputationKey(colony.address, domain4.skillId), // Colony total, domain 4
makeReputationValue(0, 13)
);

await reputationTree.insert(
makeReputationKey(colony.address, domain4.skillId, USER1), // User1, domain 4
makeReputationValue(0, 14)
);

domain1Key = makeReputationKey(colony.address, domain1.skillId);
domain1Value = makeReputationValue(WAD.muln(3), 1);
[domain1Mask, domain1Siblings] = await reputationTree.getProof(domain1Key);
Expand Down Expand Up @@ -522,6 +535,19 @@ contract("Voting Reputation", (accounts) => {
// But is in the root domain
await voting.createMotion(1, UINT256_MAX, ADDRESS_ZERO, action, domain1Key, domain1Value, domain1Mask, domain1Siblings);
});

it("cannot create a motion if there is no reputation in the domain", async () => {
const key = makeReputationKey(colony.address, domain4.skillId);
const value = makeReputationValue(0, 13);
const [mask, siblings] = await reputationTree.getProof(key);

// Try to create motion in domain of action (4)
const action = await encodeTxData(colony, "makeTask", [1, 2, FAKE, 4, 0, 0]);
await checkErrorRevert(
voting.createMotion(4, UINT256_MAX, ADDRESS_ZERO, action, key, value, mask, siblings),
"voting-rep-no-reputation-in-domain"
);
});
});

describe("staking on motions", async () => {
Expand Down

0 comments on commit c767244

Please sign in to comment.