Skip to content

Commit f123b32

Browse files
committed
Release locks properly in VotingToken
1 parent 74566d2 commit f123b32

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

contracts/extensions/VotingBase.sol

+2
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ abstract contract VotingBase is ColonyExtension {
238238
emit MotionEventSet(_motionId, REVEAL_END);
239239
}
240240

241+
postReveal(_motionId, msg.sender);
242+
241243
tokenLocking.transfer(token, voterReward, msg.sender, true);
242244
}
243245

contracts/extensions/VotingToken.sol

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ contract VotingToken is VotingBase {
4141
mapping (uint256 => uint256) totalInfluences;
4242

4343
// [motionId] => lockId
44-
mapping (uint256 => uint256) locks;
44+
mapping (uint256 => uint256) lockIds;
4545

4646
// Public
4747

@@ -57,15 +57,15 @@ contract VotingToken is VotingBase {
5757
}
5858

5959
function postReveal(uint256 _motionId, address _user) internal override {
60-
colony.unlockTokenForUser(_user, locks[_motionId]);
60+
colony.unlockTokenForUser(_user, lockIds[_motionId]);
6161
}
6262

6363
function postClaim(uint256 _motionId, address _user) internal override {
6464
uint256 lockCount = tokenLocking.getUserLock(token, _user).lockCount;
6565

6666
// Lock may have already been released during reveal
67-
if (lockCount < locks[_motionId]) {
68-
colony.unlockTokenForUser(_user, locks[_motionId]);
67+
if (lockCount < lockIds[_motionId]) {
68+
colony.unlockTokenForUser(_user, lockIds[_motionId]);
6969
}
7070
}
7171

@@ -77,7 +77,7 @@ contract VotingToken is VotingBase {
7777
{
7878
createMotion(_altTarget, _action, 1);
7979
motions[motionCount].maxVotes = ERC20Extended(token).totalSupply();
80-
locks[motionCount] = colony.lockToken();
80+
lockIds[motionCount] = colony.lockToken();
8181
}
8282

8383
/// @notice Stake on a motion
@@ -109,8 +109,8 @@ contract VotingToken is VotingBase {
109109
internalSubmitVote(_motionId, _voteSecret);
110110
}
111111

112-
function getLock(uint256 _motionId) public view returns (uint256) {
113-
return locks[_motionId];
112+
function getLockId(uint256 _motionId) public view returns (uint256) {
113+
return lockIds[_motionId];
114114
}
115115

116116
// Internal functions

test/extensions/voting-token.js

+29
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@ contract("Voting Token", (accounts) => {
245245
expect(motion.skillId).to.eq.BN(domain1.skillId);
246246
});
247247

248+
it("can lock the token when a motion is created", async () => {
249+
const action = await encodeTxData(colony, "makeTask", [1, UINT256_MAX, FAKE, 1, 0, 0]);
250+
await voting.createRootMotion(ADDRESS_ZERO, action);
251+
const motionId = await voting.getMotionCount();
252+
253+
const lockId = await voting.getLockId(motionId);
254+
expect(lockId).to.not.be.zero;
255+
});
256+
248257
it("can create a motion with an alternative target", async () => {
249258
const action = await encodeTxData(colony, "makeTask", [1, 0, FAKE, 2, 0, 0]);
250259
await voting.createRootMotion(voting.address, action);
@@ -635,6 +644,18 @@ contract("Voting Token", (accounts) => {
635644
await voting.revealVote(motionId, SALT, NAY, { from: USER0 });
636645
});
637646

647+
it("can unlock the token once revealed", async () => {
648+
await voting.submitVote(motionId, soliditySha3(SALT, NAY), { from: USER0 });
649+
650+
await forwardTime(SUBMIT_PERIOD, this);
651+
652+
await voting.revealVote(motionId, SALT, NAY, { from: USER0 });
653+
654+
const lockId = await voting.getLockId(motionId);
655+
const { lockCount } = await tokenLocking.getUserLock(token.address, USER0);
656+
expect(lockCount).to.eq.BN(lockId);
657+
});
658+
638659
it("can tally votes from two users", async () => {
639660
await voting.submitVote(motionId, soliditySha3(SALT, YAY), { from: USER0 });
640661
await voting.submitVote(motionId, soliditySha3(SALT, YAY), { from: USER1 });
@@ -910,6 +931,10 @@ contract("Voting Token", (accounts) => {
910931
});
911932

912933
it("cannot take an action if there is insufficient voting power (state change actions)", async () => {
934+
// Clear the locks
935+
await tokenLocking.methods["deposit(address,uint256,bool)"](token.address, 0, true, { from: USER0 });
936+
await tokenLocking.methods["deposit(address,uint256,bool)"](token.address, 0, true, { from: USER1 });
937+
913938
// Set globalClaimDelay to WAD
914939
await colony.makeExpenditure(1, UINT256_MAX, 1);
915940
const expenditureId = await colony.getExpenditureCount();
@@ -955,6 +980,10 @@ contract("Voting Token", (accounts) => {
955980
});
956981

957982
it("can set vote power correctly after a vote", async () => {
983+
// Clear the locks
984+
await tokenLocking.methods["deposit(address,uint256,bool)"](token.address, 0, true, { from: USER0 });
985+
await tokenLocking.methods["deposit(address,uint256,bool)"](token.address, 0, true, { from: USER1 });
986+
958987
await colony.makeExpenditure(1, UINT256_MAX, 1);
959988
const expenditureId = await colony.getExpenditureCount();
960989

0 commit comments

Comments
 (0)