From 8178ae774b467aa284c327ea9dab86932eba857a Mon Sep 17 00:00:00 2001 From: orenyodfat Date: Mon, 7 Jan 2019 12:03:53 +0200 Subject: [PATCH] bump v to 0.0.1.rc.5 (#41) * bum v to 0.0.0.rc.5 * slight efficiente storge --- contracts/votingMachines/AbsoluteVote.sol | 2 +- package-lock.json | 2 +- package.json | 2 +- test/absolutevote.js | 58 +++++++++++++---------- test/quorumvote.js | 26 +++++----- 5 files changed, 48 insertions(+), 42 deletions(-) diff --git a/contracts/votingMachines/AbsoluteVote.sol b/contracts/votingMachines/AbsoluteVote.sol index 96d5c55..7fc87b0 100644 --- a/contracts/votingMachines/AbsoluteVote.sol +++ b/contracts/votingMachines/AbsoluteVote.sol @@ -23,13 +23,13 @@ contract AbsoluteVote is IntVoteInterface { struct Proposal { bytes32 organizationId; // the organization Id + bool open; // voting open flag address callbacks; uint256 numOfChoices; bytes32 paramsHash; // the hash of the parameters of the proposal uint256 totalVotes; mapping(uint=>uint) votes; mapping(address=>Voter) voters; - bool open; // voting open flag } event AVVoteProposal(bytes32 indexed _proposalId, bool _isProxyVote); diff --git a/package-lock.json b/package-lock.json index bca3556..9f2f820 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/infra", - "version": "0.0.1-rc.4", + "version": "0.0.1-rc.5", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0b6da39..e248b08 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/infra", - "version": "0.0.1-rc.4", + "version": "0.0.1-rc.5", "description": "Base layer DAO's components", "files": [ "contracts/", diff --git a/test/absolutevote.js b/test/absolutevote.js index 52d4573..367a571 100644 --- a/test/absolutevote.js +++ b/test/absolutevote.js @@ -29,15 +29,16 @@ const checkProposalInfo = async function(proposalId, _proposalInfo) { // proposalInfo has the following structure // bytes32 organization; assert.equal(proposalInfo[0], _proposalInfo[0]); - // uint numOfChoices; + // bool opened; // voting opened flag assert.equal(proposalInfo[1], _proposalInfo[1]); - // bytes32 paramsHash; + // uint numOfChoices; assert.equal(proposalInfo[2], _proposalInfo[2]); - // uint totalVotes; + // bytes32 paramsHash; assert.equal(proposalInfo[3], _proposalInfo[3]); - // - the mapping is simply not returned at all in the array - // bool opened; // voting opened flag + // uint totalVotes; assert.equal(proposalInfo[4], _proposalInfo[4]); + // - the mapping is simply not returned at all in the array + assert.equal(proposalInfo[5], _proposalInfo[5]); assert.equal(proposalInfo[6], _proposalInfo[6]); }; @@ -80,15 +81,16 @@ const checkProposalInfoWithAbsoluteVote = async function(proposalId, _proposalIn // proposalInfo has the following structure // address organization; assert.equal(proposalInfo[0], _proposalInfo[0]); - // address numOfChoices; + // bool opened; // voting opened flag assert.equal(proposalInfo[1], _proposalInfo[1]); - // bytes32 paramsHash; + // address numOfChoices; assert.equal(proposalInfo[2], _proposalInfo[2]); - // uint totalVotes; + // bytes32 paramsHash; assert.equal(proposalInfo[3], _proposalInfo[3]); - // - the mapping is simply not returned at all in the array - // bool opened; // voting opened flag + // uint totalVotes; assert.equal(proposalInfo[4], _proposalInfo[4]); + // - the mapping is simply not returned at all in the array + }; contract('AbsoluteVote', accounts => { @@ -107,11 +109,12 @@ contract('AbsoluteVote', accounts => { // no one has voted yet at this point await checkProposalInfo(proposalId, [ organizationId, + true, absoluteVoteExecuteMock.address, 5, paramsHash, - 0, - true]); + 0 + ]); await checkVotesStatus(proposalId, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); await checkIsVotable(proposalId, true); @@ -121,11 +124,12 @@ contract('AbsoluteVote', accounts => { await checkVoteInfo(proposalId, accounts[0], [1, reputationArray[0]]); await checkProposalInfo(proposalId, [ organizationId, + true, absoluteVoteExecuteMock.address, 5, paramsHash, reputationArray[0], - true]); + ]); await checkVotesStatus(proposalId, [0, reputationArray[0], 0, 0, 0, 0, 0, 0, 0, 0]); await checkIsVotable(proposalId, true); @@ -134,11 +138,12 @@ contract('AbsoluteVote', accounts => { await checkVoteInfo(proposalId, accounts[1], [0, reputationArray[1]]); await checkProposalInfo(proposalId, [ organizationId, + true, absoluteVoteExecuteMock.address, 5, paramsHash, (reputationArray[0] + reputationArray[1]), - true]); + ]); await checkVotesStatus(proposalId, [reputationArray[1], reputationArray[0], 0, 0, 0, 0, 0, 0, 0, 0]); await checkIsVotable(proposalId, true); @@ -148,7 +153,7 @@ contract('AbsoluteVote', accounts => { await checkVoteInfo(proposalId, accounts[2], [5, reputationArray[2]]); // Proposal should be empty (being deleted after execution) - await checkProposalInfo(proposalId, [ helpers.NULL_HASH,helpers.NULL_ADDRESS, 0,helpers.NULL_HASH, 0, false]); + await checkProposalInfo(proposalId, [ helpers.NULL_HASH,false,helpers.NULL_ADDRESS, 0,helpers.NULL_HASH, 0]); await checkVotesStatus(proposalId, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); await checkIsVotable(proposalId, false); }); @@ -302,11 +307,12 @@ contract('AbsoluteVote', accounts => { // no one has voted yet at this point await checkProposalInfo(proposalId, [ organizationId, + true, absoluteVoteExecuteMock.address, 6, paramsHash, 0, - true]); + ]); // Lets try to vote twice from the same address await absoluteVote.vote(proposalId, 1,0,helpers.NULL_ADDRESS); @@ -314,7 +320,7 @@ contract('AbsoluteVote', accounts => { await absoluteVote.vote(proposalId, 1,0,helpers.NULL_ADDRESS); await checkVoteInfo(proposalId, accounts[0], [1, reputationArray[0]]); // Total 'Option 2' should be equal to the voter's reputation exactly, even though we voted twice - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, reputationArray[0], true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, reputationArray[0]]); await checkVotesStatus(proposalId, [0,reputationArray[0],0, 0, 0, 0, 0, 0, 0, 0]); }); @@ -329,7 +335,7 @@ contract('AbsoluteVote', accounts => { const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0]); // Lets try to vote and then cancel our vote await absoluteVote.vote(proposalId, 1,0,helpers.NULL_ADDRESS); @@ -338,7 +344,7 @@ contract('AbsoluteVote', accounts => { await checkVoteInfo(proposalId, accounts[0], [0, 0]); // Proposal's votes supposed to be zero again. - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0]); await checkVotesStatus(proposalId, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); }); @@ -353,7 +359,7 @@ contract('AbsoluteVote', accounts => { assert.isOk(proposalId); const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0]); // Lets try to vote on the behalf of someone else try { @@ -364,7 +370,7 @@ contract('AbsoluteVote', accounts => { } // The vote should not be counted - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0]); await absoluteVote.vote(proposalId, 1,0, accounts[0], {from: accounts[5]}); }); @@ -458,7 +464,7 @@ contract('AbsoluteVote', accounts => { const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0]); try { await absoluteVote.vote(proposalId, 3,0, helpers.NULL_ADDRESS, { from: accounts[3] }); @@ -493,7 +499,7 @@ contract('AbsoluteVote', accounts => { const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0]); await absoluteVote.vote(proposalId, 0,0,helpers.NULL_ADDRESS, { from: accounts[1] }); @@ -516,7 +522,7 @@ contract('AbsoluteVote', accounts => { // no one has voted yet at this point - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0]); await absoluteVote.vote(proposalId, 2,0,helpers.NULL_ADDRESS, { from: accounts[1] }); @@ -749,8 +755,8 @@ contract('AbsoluteVote', accounts => { assert.isOk(proposalId2); // Lets check the proposals - await checkProposalInfoWithAbsoluteVote(proposalId1, [organizationId,absoluteVoteExecuteMock.address, 6, paramsHash1, 0, true], absoluteVote1); - await checkProposalInfoWithAbsoluteVote(proposalId2, [organization2Id,absoluteVoteExecuteMock2.address, 2, paramsHash2, 0, true], absoluteVote2); + await checkProposalInfoWithAbsoluteVote(proposalId1, [organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash1, 0], absoluteVote1); + await checkProposalInfoWithAbsoluteVote(proposalId2, [organization2Id,true,absoluteVoteExecuteMock2.address, 2, paramsHash2, 0], absoluteVote2); // Account 0 votes in both proposals, and on behalf of Account 1 - should get an exception for that await absoluteVote1.vote(proposalId1, 2, 2, helpers.NULL_ADDRESS); await absoluteVote2.vote(proposalId2, 0,0,helpers.NULL_ADDRESS); diff --git a/test/quorumvote.js b/test/quorumvote.js index c8e2479..b3fa6b3 100644 --- a/test/quorumvote.js +++ b/test/quorumvote.js @@ -70,26 +70,26 @@ contract('QuorumVote', accounts => { const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 5, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true, absoluteVoteExecuteMock.address, 5, paramsHash, 0]); await checkVotesStatus(proposalId, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); // now lets vote Option 1 with a minority reputation await quorumVote.vote(proposalId, 1,0,helpers.NULL_ADDRESS); await checkVoteInfo(proposalId, accounts[0], [1, reputationArray[0]]); - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 5, paramsHash, reputationArray[0], true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 5, paramsHash, reputationArray[0]]); await checkVotesStatus(proposalId, [0, reputationArray[0], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); // another minority reputation (Option 0): await quorumVote.vote(proposalId, 0,0,helpers.NULL_ADDRESS, { from: accounts[1] }); await checkVoteInfo(proposalId, accounts[1], [0, reputationArray[1]]); - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 5, paramsHash, (reputationArray[0] + reputationArray[1]), true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 5, paramsHash, (reputationArray[0] + reputationArray[1])]); await checkVotesStatus(proposalId, [reputationArray[1], reputationArray[0], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); // the decisive vote is cast now and the proposal will be executed with option 5 tx = await quorumVote.vote(proposalId, 5,0, accounts[2],{from:accounts[2]}); await checkVoteInfo(proposalId, accounts[2], [5, reputationArray[2]]); // Proposal should be empty (being deleted after execution) - await checkProposalInfo(proposalId, [ helpers.NULL_HASH,helpers.NULL_ADDRESS, 0,helpers.NULL_HASH, 0, false]); + await checkProposalInfo(proposalId, [ helpers.NULL_HASH,false,helpers.NULL_ADDRESS, 0,helpers.NULL_HASH, 0]); await checkVotesStatus(proposalId, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); }); @@ -105,19 +105,19 @@ contract('QuorumVote', accounts => { const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true ,absoluteVoteExecuteMock.address, 6, paramsHash, 0]); await checkVotesStatus(proposalId, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); // now lets vote 'Option 0' with 20% of the reputation - should not be executed yet (didn't reach 25%). await quorumVote.vote(proposalId, 0,0,helpers.NULL_ADDRESS); await checkVoteInfo(proposalId, accounts[0], [0, reputationArray[0]]); - await checkProposalInfo(proposalId, [ organizationId, absoluteVoteExecuteMock.address,6, paramsHash, reputationArray[0], true]); + await checkProposalInfo(proposalId, [ organizationId,true, absoluteVoteExecuteMock.address,6, paramsHash, reputationArray[0]]); await checkVotesStatus(proposalId, [reputationArray[0], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); // now lets vote 'Option 1' with 10% of the reputation - should be executed with 'Option 0'! (reached 30% and the 'Option 1' is the majority). await quorumVote.vote(proposalId, 1,0,helpers.NULL_ADDRESS, { from: accounts[1] }); await checkVoteInfo(proposalId, accounts[1], [1, reputationArray[1]]); - await checkProposalInfo(proposalId, [helpers.NULL_HASH,helpers.NULL_ADDRESS, 0,helpers.NULL_HASH, 0, false]); + await checkProposalInfo(proposalId, [helpers.NULL_HASH,false,helpers.NULL_ADDRESS, 0,helpers.NULL_HASH, 0]); }); it("Invalid inputs shouldn't work (precReq, vote)", async function () { @@ -253,7 +253,7 @@ contract('QuorumVote', accounts => { const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0]); // Lets try to vote twice from the same address await quorumVote.vote(proposalId, 1,0,helpers.NULL_ADDRESS); @@ -262,7 +262,7 @@ contract('QuorumVote', accounts => { await checkVoteInfo(proposalId, accounts[0], [1, reputationArray[0]]); // Total 'Option 2' should be equal to the voter's reputation exactly, even though we voted twice - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, reputationArray[0], true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, reputationArray[0], true]); await checkVotesStatus(proposalId, [0, reputationArray[0], 0, 0, 0, 0, 0, 0, 0, 0, 0]); }); @@ -277,7 +277,7 @@ contract('QuorumVote', accounts => { const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); // Lets try to vote and then cancel our vote await quorumVote.vote(proposalId, 1,0,helpers.NULL_ADDRESS); @@ -286,7 +286,7 @@ contract('QuorumVote', accounts => { await checkVoteInfo(proposalId, accounts[0], [0, 0]); // Proposal's votes supposed to be zero again. - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); await checkVotesStatus(proposalId, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); }); @@ -300,7 +300,7 @@ contract('QuorumVote', accounts => { assert.isOk(proposalId); const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0]); // Lets try to vote on the behalf of someone else try { @@ -311,7 +311,7 @@ contract('QuorumVote', accounts => { } // The vote should not be counted - await checkProposalInfo(proposalId, [ organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); + await checkProposalInfo(proposalId, [ organizationId,true,absoluteVoteExecuteMock.address, 6, paramsHash, 0]); await quorumVote.vote(proposalId, 1,0, accounts[0], {from: accounts[5]}); }); // [TODO] Check why this test doesn't work