Skip to content

Commit

Permalink
bump v to 0.0.1.rc.5 (#41)
Browse files Browse the repository at this point in the history
* bum v to 0.0.0.rc.5

* slight efficiente storge
  • Loading branch information
orenyodfat authored and leviadam committed Jan 7, 2019
1 parent cfb5c13 commit 8178ae7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion contracts/votingMachines/AbsoluteVote.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down
58 changes: 32 additions & 26 deletions test/absolutevote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
};
Expand Down Expand Up @@ -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 => {
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);
});
Expand Down Expand Up @@ -302,19 +307,20 @@ 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);
await checkVoteInfo(proposalId, accounts[0], [1, reputationArray[0]]);
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]);
});

Expand All @@ -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);
Expand All @@ -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]);
});

Expand All @@ -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 {
Expand All @@ -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]});
});

Expand Down Expand Up @@ -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] });
Expand Down Expand Up @@ -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] });

Expand All @@ -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] });

Expand Down Expand Up @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions test/quorumvote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

});
Expand All @@ -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 () {
Expand Down Expand Up @@ -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);
Expand All @@ -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]);
});

Expand All @@ -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);
Expand All @@ -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]);
});

Expand All @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 8178ae7

Please sign in to comment.