Skip to content

Commit 7b6366c

Browse files
committed
Add tests to improve coverage
1 parent c12d594 commit 7b6366c

File tree

4 files changed

+102
-7
lines changed

4 files changed

+102
-7
lines changed

contracts/extensions/VotingBase.sol

+1
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ abstract contract VotingBase is ColonyExtension, PatriciaTreeProofs {
558558
}
559559

560560
winFraction = winFraction / motion.votes.length;
561+
561562
uint256 winShare = wmul(winFraction, 2 * WAD); // On a scale of 0-2 WAD
562563
uint256 loserStake = sub(requiredStake, motion.paidVoterComp);
563564

test/extensions/voting-hybrid.js

+46
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ contract("Voting Hybrid", (accounts) => {
257257
expect(deprecated).to.equal(true);
258258
});
259259

260+
it("cannot make a motion before initialised", async () => {
261+
voting = await VotingHybrid.new();
262+
await voting.install(colony.address);
263+
264+
const action = await encodeTxData(colony, "makeTask", [1, UINT256_MAX, FAKE, 1, 0, 0]);
265+
await checkErrorRevert(
266+
voting.createRootMotion(ADDRESS_ZERO, action, domain1Key, domain1Value, domain1Mask, domain1Siblings),
267+
"voting-base-not-active"
268+
);
269+
});
270+
260271
it("cannot initialise twice or more if not root", async () => {
261272
await checkErrorRevert(voting.initialise(HALF, HALF, WAD, WAD, YEAR, YEAR, YEAR, YEAR), "voting-base-already-initialised");
262273
await checkErrorRevert(voting.initialise(HALF, HALF, WAD, WAD, YEAR, YEAR, YEAR, YEAR, { from: USER2 }), "voting-base-caller-not-root");
@@ -314,6 +325,15 @@ contract("Voting Hybrid", (accounts) => {
314325
expect(motion.skillId).to.eq.BN(domain1.skillId);
315326
});
316327

328+
it("does not lock the token when a motion is created", async () => {
329+
const action = await encodeTxData(colony, "makeTask", [1, UINT256_MAX, FAKE, 1, 0, 0]);
330+
await voting.createRootMotion(ADDRESS_ZERO, action, domain1Key, domain1Value, domain1Mask, domain1Siblings);
331+
const motionId = await voting.getMotionCount();
332+
333+
const lockId = await voting.getLockId(motionId);
334+
expect(lockId).to.be.zero;
335+
});
336+
317337
it("can create a motion with an alternative target", async () => {
318338
const action = await encodeTxData(colony, "makeTask", [1, 0, FAKE, 2, 0, 0]);
319339
await voting.createRootMotion(voting.address, action, domain1Key, domain1Value, domain1Mask, domain1Siblings);
@@ -742,6 +762,32 @@ contract("Voting Hybrid", (accounts) => {
742762
await voting.revealVote(motionId, SALT, NAY, { from: USER0 });
743763
});
744764

765+
it("locks the token when the first reveal is made", async () => {
766+
await voting.submitVote(motionId, soliditySha3(SALT, NAY), user0Key, user0Value, user0Mask, user0Siblings, { from: USER0 });
767+
768+
await forwardTime(SUBMIT_PERIOD, this);
769+
770+
let lockId = await voting.getLockId(motionId);
771+
expect(lockId).to.be.zero;
772+
773+
await voting.revealVote(motionId, SALT, NAY, { from: USER0 });
774+
775+
lockId = await voting.getLockId(motionId);
776+
expect(lockId).to.not.be.zero;
777+
});
778+
779+
it("can unlock the token once revealed", async () => {
780+
await voting.submitVote(motionId, soliditySha3(SALT, NAY), user0Key, user0Value, user0Mask, user0Siblings, { from: USER0 });
781+
782+
await forwardTime(SUBMIT_PERIOD, this);
783+
784+
await voting.revealVote(motionId, SALT, NAY, { from: USER0 });
785+
786+
const lockId = await voting.getLockId(motionId);
787+
const { lockCount } = await tokenLocking.getUserLock(token.address, USER0);
788+
expect(lockCount).to.eq.BN(lockId);
789+
});
790+
745791
it("can tally votes from two users", async () => {
746792
await voting.submitVote(motionId, soliditySha3(SALT, YAY), user0Key, user0Value, user0Mask, user0Siblings, { from: USER0 });
747793
await voting.submitVote(motionId, soliditySha3(SALT, YAY), user1Key, user1Value, user1Mask, user1Siblings, { from: USER1 });

test/extensions/voting-rep.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,24 @@ contract("Voting Reputation", (accounts) => {
289289
expect(deprecated).to.equal(true);
290290
});
291291

292+
it("can initialise with valid values and emit expected event", async () => {
293+
voting = await VotingReputation.new();
294+
await voting.install(colony.address);
295+
296+
await expectEvent(voting.initialise(HALF, HALF, WAD, WAD, YEAR, YEAR, YEAR, YEAR), "ExtensionInitialised", []);
297+
});
298+
299+
it("cannot make a motion before initialised", async () => {
300+
voting = await VotingReputation.new();
301+
await voting.install(colony.address);
302+
303+
const action = await encodeTxData(colony, "makeTask", [1, UINT256_MAX, FAKE, 1, 0, 0]);
304+
await checkErrorRevert(
305+
voting.createRootMotion(ADDRESS_ZERO, action, domain1Key, domain1Value, domain1Mask, domain1Siblings),
306+
"voting-base-not-active"
307+
);
308+
});
309+
292310
it("cannot initialise twice or more if not root", async () => {
293311
await checkErrorRevert(voting.initialise(HALF, HALF, WAD, WAD, YEAR, YEAR, YEAR, YEAR), "voting-base-already-initialised");
294312
await checkErrorRevert(voting.initialise(HALF, HALF, WAD, WAD, YEAR, YEAR, YEAR, YEAR, { from: USER2 }), "voting-base-caller-not-root");
@@ -308,13 +326,6 @@ contract("Voting Reputation", (accounts) => {
308326
await checkErrorRevert(voting.initialise(HALF, HALF, WAD, WAD, YEAR, YEAR, YEAR, YEAR + 1), "voting-base-period-too-long");
309327
});
310328

311-
it("can initialised with valid values and emit expected event", async () => {
312-
voting = await VotingReputation.new();
313-
await voting.install(colony.address);
314-
315-
await expectEvent(voting.initialise(HALF, HALF, WAD, WAD, YEAR, YEAR, YEAR, YEAR), "ExtensionInitialised", []);
316-
});
317-
318329
it("can query for initialisation values", async () => {
319330
const totalStakeFraction = await voting.getTotalStakeFraction();
320331
const voterRewardFraction = await voting.getVoterRewardFraction();

test/extensions/voting-token.js

+37
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ contract("Voting Token", (accounts) => {
188188
expect(deprecated).to.equal(true);
189189
});
190190

191+
it("cannot make a motion before initialised", async () => {
192+
voting = await VotingToken.new();
193+
await voting.install(colony.address);
194+
195+
const action = await encodeTxData(colony, "makeTask", [1, UINT256_MAX, FAKE, 1, 0, 0]);
196+
await checkErrorRevert(voting.createRootMotion(ADDRESS_ZERO, action), "voting-base-not-active");
197+
});
198+
191199
it("cannot initialise twice or more if not root", async () => {
192200
await checkErrorRevert(voting.initialise(HALF, HALF, WAD, WAD, YEAR, YEAR, YEAR, YEAR), "voting-base-already-initialised");
193201
await checkErrorRevert(voting.initialise(HALF, HALF, WAD, WAD, YEAR, YEAR, YEAR, YEAR, { from: USER2 }), "voting-base-caller-not-root");
@@ -1290,5 +1298,34 @@ contract("Voting Token", (accounts) => {
12901298
it("cannot claim rewards before a motion is finalized", async () => {
12911299
await checkErrorRevert(voting.claimReward(motionId, 1, UINT256_MAX, USER0, YAY), "voting-base-motion-not-claimable");
12921300
});
1301+
1302+
it("can unlock the token after claiming", async () => {
1303+
await voting.stakeMotion(motionId, 1, UINT256_MAX, YAY, requiredStake, { from: USER0 });
1304+
await voting.stakeMotion(motionId, 1, UINT256_MAX, NAY, requiredStake, { from: USER1 });
1305+
1306+
await voting.submitVote(motionId, soliditySha3(SALT, YAY), { from: USER0 });
1307+
await voting.submitVote(motionId, soliditySha3(SALT, NAY), { from: USER2 });
1308+
1309+
await forwardTime(SUBMIT_PERIOD, this);
1310+
1311+
await voting.revealVote(motionId, SALT, YAY, { from: USER0 });
1312+
await voting.revealVote(motionId, SALT, NAY, { from: USER2 });
1313+
1314+
await forwardTime(REVEAL_PERIOD, this);
1315+
await forwardTime(ESCALATION_PERIOD, this);
1316+
1317+
await voting.finalizeMotion(motionId);
1318+
1319+
let lockCount;
1320+
const lockId = await voting.getLockId(motionId);
1321+
1322+
({ lockCount } = await tokenLocking.getUserLock(token.address, USER1));
1323+
expect(lockCount).to.be.zero;
1324+
1325+
await voting.claimReward(motionId, 1, UINT256_MAX, USER1, NAY);
1326+
1327+
({ lockCount } = await tokenLocking.getUserLock(token.address, USER1));
1328+
expect(lockCount).to.eq.BN(lockId);
1329+
});
12931330
});
12941331
});

0 commit comments

Comments
 (0)