From 0cea94d7c1a6067ca3515790159c81b7d2666a12 Mon Sep 17 00:00:00 2001 From: Alex Rea Date: Wed, 10 May 2023 11:13:01 +0100 Subject: [PATCH] Prevent creation of motions with 0 reputation in domain --- .../votingReputation/VotingReputation.sol | 1 + test/extensions/voting-rep.js | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/contracts/extensions/votingReputation/VotingReputation.sol b/contracts/extensions/votingReputation/VotingReputation.sol index b0d1d457d1..9832db6bf2 100644 --- a/contracts/extensions/votingReputation/VotingReputation.sol +++ b/contracts/extensions/votingReputation/VotingReputation.sol @@ -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; diff --git a/test/extensions/voting-rep.js b/test/extensions/voting-rep.js index 330bafebb4..24242d12c5 100644 --- a/test/extensions/voting-rep.js +++ b/test/extensions/voting-rep.js @@ -52,6 +52,7 @@ contract("Voting Reputation", (accounts) => { let domain1; let domain2; let domain3; + let domain4; let metaColony; let colonyNetwork; let tokenLocking; @@ -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); @@ -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); @@ -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 () => {