From 654f78dc5c075c2c6685fc7dba0ed87d11c317e1 Mon Sep 17 00:00:00 2001 From: orenyodfat Date: Mon, 8 Oct 2018 13:00:19 +0300 Subject: [PATCH] emit organization address (instead of organizationId) at events. (#19) * emit organization address (instead of organizationId) at events. * version 08 --- contracts/VotingMachines/AbsoluteVote.sol | 18 ++++++--- contracts/VotingMachines/GenesisProtocol.sol | 31 +++++++++------ contracts/VotingMachines/IntVoteInterface.sol | 10 ++--- contracts/VotingMachines/QuorumVote.sol | 2 +- package-lock.json | 26 ++++++------- package.json | 2 +- test/absolutevote.js | 39 +++++++++---------- test/genesisprotocol.js | 13 +++++-- test/helpers.js | 8 ++-- test/quorumvote.js | 18 ++++----- 10 files changed, 94 insertions(+), 73 deletions(-) diff --git a/contracts/VotingMachines/AbsoluteVote.sol b/contracts/VotingMachines/AbsoluteVote.sol index 1283ba8..82c74c8 100644 --- a/contracts/VotingMachines/AbsoluteVote.sol +++ b/contracts/VotingMachines/AbsoluteVote.sol @@ -39,6 +39,7 @@ contract AbsoluteVote is IntVoteInterface { mapping(bytes32=>Parameters) public parameters; // A mapping from hashes to parameters mapping(bytes32=>Proposal) public proposals; // Mapping from the ID of the proposal to the proposal itself. + mapping(bytes32 => address ) organizations; uint public constant MAX_NUM_OF_CHOICES = 10; uint public proposalsCnt; // Total amount of proposals @@ -86,7 +87,14 @@ contract AbsoluteVote is IntVoteInterface { proposal.owner = msg.sender; proposal.open = true; proposals[proposalId] = proposal; - emit NewProposal(proposalId, proposal.organizationId, _numOfChoices, msg.sender, _paramsHash); + if (organizations[proposal.organizationId] == 0) { + if (_organization == address(0)) { + organizations[proposal.organizationId] = msg.sender; + } else { + organizations[proposal.organizationId] = _organization; + } + } + emit NewProposal(proposalId, organizations[proposal.organizationId], _numOfChoices, msg.sender, _paramsHash); return proposalId; } @@ -100,7 +108,7 @@ contract AbsoluteVote is IntVoteInterface { } bytes32 organizationId = proposals[_proposalId].organizationId; deleteProposal(_proposalId); - emit CancelProposal(_proposalId, organizationId); + emit CancelProposal(_proposalId, organizations[organizationId]); return true; } @@ -241,7 +249,7 @@ contract AbsoluteVote is IntVoteInterface { proposal.votes[voter.vote] = (proposal.votes[voter.vote]).sub(voter.reputation); proposal.totalVotes = (proposal.totalVotes).sub(voter.reputation); delete proposal.voters[_voter]; - emit CancelVoting(_proposalId, proposal.organizationId, _voter); + emit CancelVoting(_proposalId, organizations[proposal.organizationId], _voter); } function deleteProposal(bytes32 _proposalId) internal { @@ -267,7 +275,7 @@ contract AbsoluteVote is IntVoteInterface { if (proposal.votes[cnt] > totalReputation*precReq/100) { Proposal memory tmpProposal = proposal; deleteProposal(_proposalId); - emit ExecuteProposal(_proposalId, tmpProposal.organizationId, cnt, totalReputation); + emit ExecuteProposal(_proposalId, organizations[tmpProposal.organizationId], cnt, totalReputation); ProposalExecuteInterface(tmpProposal.callbacks).executeProposal(_proposalId,int(cnt)); return true; } @@ -307,7 +315,7 @@ contract AbsoluteVote is IntVoteInterface { vote: _vote }); // Event: - emit VoteProposal(_proposalId, proposal.organizationId, _voter, _vote, reputation); + emit VoteProposal(_proposalId, organizations[proposal.organizationId], _voter, _vote, reputation); emit AVVoteProposal(_proposalId, (_voter != msg.sender)); // execute the proposal if this vote was decisive: return _execute(_proposalId); diff --git a/contracts/VotingMachines/GenesisProtocol.sol b/contracts/VotingMachines/GenesisProtocol.sol index bc917c0..8e3022d 100644 --- a/contracts/VotingMachines/GenesisProtocol.sol +++ b/contracts/VotingMachines/GenesisProtocol.sol @@ -88,10 +88,10 @@ contract GenesisProtocol is IntVoteInterface { mapping(address => Staker ) stakers; } - event Stake(bytes32 indexed _proposalId, bytes32 indexed _organizationId, address indexed _staker,uint _vote,uint _amount); - event Redeem(bytes32 indexed _proposalId, bytes32 indexed _organizationId, address indexed _beneficiary,uint _amount); - event RedeemDaoBounty(bytes32 indexed _proposalId, bytes32 indexed _organizationId, address indexed _beneficiary,uint _amount); - event RedeemReputation(bytes32 indexed _proposalId, bytes32 indexed _organizationId, address indexed _beneficiary,uint _amount); + event Stake(bytes32 indexed _proposalId, address indexed _organization, address indexed _staker,uint _vote,uint _amount); + event Redeem(bytes32 indexed _proposalId, address indexed _organization, address indexed _beneficiary,uint _amount); + event RedeemDaoBounty(bytes32 indexed _proposalId, address indexed _organization, address indexed _beneficiary,uint _amount); + event RedeemReputation(bytes32 indexed _proposalId, address indexed _organization, address indexed _beneficiary,uint _amount); event GPExecuteProposal(bytes32 indexed _proposalId, ExecutionState _executionState); mapping(bytes32=>Parameters) public parameters; // A mapping from hashes to parameters @@ -103,6 +103,8 @@ contract GenesisProtocol is IntVoteInterface { uint public proposalsCnt; // Total number of proposals mapping(bytes32=>uint) public orgBoostedProposalsCnt; mapping(bytes32=>OrderStatisticTree.Tree) proposalsExpiredTimes; //proposals expired times + //organizationId => organization + mapping(bytes32 => address ) organizations; StandardToken public stakingToken; mapping(bytes=>bool) stakeSignatures; //stake signatures address constant GEN_TOKEN_ADDRESS = 0x543Ff227F64Aa17eA132Bf9886cAb5DB55DCAddf; @@ -169,7 +171,14 @@ contract GenesisProtocol is IntVoteInterface { proposal.winningVote = NO; proposal.paramsHash = _paramsHash; proposals[proposalId] = proposal; - emit NewProposal(proposalId, proposal.organizationId, _numOfChoices, _proposer, _paramsHash); + if (organizations[proposal.organizationId] == 0) { + if (_organization == address(0)) { + organizations[proposal.organizationId] = msg.sender; + } else { + organizations[proposal.organizationId] = _organization; + } + } + emit NewProposal(proposalId, organizations[proposal.organizationId], _numOfChoices, _proposer, _paramsHash); return proposalId; } @@ -506,11 +515,11 @@ contract GenesisProtocol is IntVoteInterface { if (amount != 0) { proposal.totalStakes[1] = proposal.totalStakes[1].sub(amount); require(stakingToken.transfer(_beneficiary, amount)); - emit Redeem(_proposalId,proposal.organizationId,_beneficiary,amount); + emit Redeem(_proposalId,organizations[proposal.organizationId],_beneficiary,amount); } if (reputation != 0 ) { VotingMachineCallbacksInterface(proposal.callbacks).mintReputation(reputation,_beneficiary,_proposalId); - emit RedeemReputation(_proposalId,proposal.organizationId,_beneficiary,reputation); + emit RedeemReputation(_proposalId,organizations[proposal.organizationId],_beneficiary,reputation); } } @@ -549,7 +558,7 @@ contract GenesisProtocol is IntVoteInterface { require(VotingMachineCallbacksInterface(proposal.callbacks).stakingTokenTransfer(stakingToken,_beneficiary,potentialAmount,_proposalId)); proposal.stakers[_beneficiary].amountForBounty = 0; redeemedAmount = potentialAmount; - emit RedeemDaoBounty(_proposalId,proposal.organizationId,_beneficiary,redeemedAmount); + emit RedeemDaoBounty(_proposalId,organizations[proposal.organizationId],_beneficiary,redeemedAmount); } } @@ -766,7 +775,7 @@ contract GenesisProtocol is IntVoteInterface { } proposal.daoBountyRemain = daoBountyRemain; } - emit ExecuteProposal(_proposalId, proposal.organizationId, proposal.winningVote, totalReputation); + emit ExecuteProposal(_proposalId, organizations[proposal.organizationId], proposal.winningVote, totalReputation); emit GPExecuteProposal(_proposalId, executionState); ProposalExecuteInterface(proposal.callbacks).executeProposal(_proposalId,int(proposal.winningVote)); } @@ -815,7 +824,7 @@ contract GenesisProtocol is IntVoteInterface { amount = amount - ((params.stakerFeeRatioForVoters*amount)/100); proposal.totalStakes[0] = amount.add(proposal.totalStakes[0]); // Event: - emit Stake(_proposalId, proposal.organizationId, _staker, _vote, _amount); + emit Stake(_proposalId, organizations[proposal.organizationId], _staker, _vote, _amount); // execute the proposal if this vote was decisive: return _execute(_proposalId); } @@ -886,7 +895,7 @@ contract GenesisProtocol is IntVoteInterface { VotingMachineCallbacksInterface(proposal.callbacks).burnReputation(reputationDeposit,_voter,_proposalId); } // Event: - emit VoteProposal(_proposalId, proposal.organizationId, _voter, _vote, rep); + emit VoteProposal(_proposalId, organizations[proposal.organizationId], _voter, _vote, rep); // execute the proposal if this vote was decisive: return _execute(_proposalId); } diff --git a/contracts/VotingMachines/IntVoteInterface.sol b/contracts/VotingMachines/IntVoteInterface.sol index 425ff02..fcb1712 100644 --- a/contracts/VotingMachines/IntVoteInterface.sol +++ b/contracts/VotingMachines/IntVoteInterface.sol @@ -6,11 +6,11 @@ interface IntVoteInterface { modifier onlyProposalOwner(bytes32 _proposalId) {revert(); _;} modifier votable(bytes32 _proposalId) {revert(); _;} - event NewProposal(bytes32 indexed _proposalId, bytes32 indexed _organizationId, uint _numOfChoices, address _proposer, bytes32 _paramsHash); - event ExecuteProposal(bytes32 indexed _proposalId, bytes32 indexed _organizationId, uint _decision, uint _totalReputation); - event VoteProposal(bytes32 indexed _proposalId, bytes32 indexed _organizationId, address indexed _voter, uint _vote, uint _reputation); - event CancelProposal(bytes32 indexed _proposalId, bytes32 indexed _organizationId ); - event CancelVoting(bytes32 indexed _proposalId, bytes32 indexed _organizationId, address indexed _voter); + event NewProposal(bytes32 indexed _proposalId, address indexed _organization, uint _numOfChoices, address _proposer, bytes32 _paramsHash); + event ExecuteProposal(bytes32 indexed _proposalId, address indexed _organization, uint _decision, uint _totalReputation); + event VoteProposal(bytes32 indexed _proposalId, address indexed _organization, address indexed _voter, uint _vote, uint _reputation); + event CancelProposal(bytes32 indexed _proposalId, address indexed _organization ); + event CancelVoting(bytes32 indexed _proposalId, address indexed _organization, address indexed _voter); /** * @dev register a new proposal with the given parameters. Every proposal has a unique ID which is being diff --git a/contracts/VotingMachines/QuorumVote.sol b/contracts/VotingMachines/QuorumVote.sol index 827d7ac..de96bfc 100644 --- a/contracts/VotingMachines/QuorumVote.sol +++ b/contracts/VotingMachines/QuorumVote.sol @@ -34,7 +34,7 @@ contract QuorumVote is AbsoluteVote { } Proposal memory tmpProposal = proposal; deleteProposal(_proposalId); - emit ExecuteProposal(_proposalId, tmpProposal.organizationId, maxInd, totalReputation); + emit ExecuteProposal(_proposalId, organizations[tmpProposal.organizationId], maxInd, totalReputation); ProposalExecuteInterface(tmpProposal.callbacks).executeProposal(_proposalId,int(maxInd)); return true; } diff --git a/package-lock.json b/package-lock.json index c7ba859..d5c763d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/infra", - "version": "0.0.0-alpha.07", + "version": "0.0.0-alpha.08", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -5881,7 +5881,7 @@ }, "load-json-file": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", "dev": true, "requires": { @@ -6852,7 +6852,7 @@ }, "os-locale": { "version": "1.4.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", + "resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", "dev": true, "requires": { @@ -8786,9 +8786,9 @@ "dev": true }, "solc": { - "version": "0.4.24", - "resolved": "https://registry.npmjs.org/solc/-/solc-0.4.24.tgz", - "integrity": "sha512-2xd7Cf1HeVwrIb6Bu1cwY2/TaLRodrppCq3l7rhLimFQgmxptXhTC3+/wesVLpB09F1A2kZgvbMOgH7wvhFnBQ==", + "version": "0.4.25", + "resolved": "https://registry.npmjs.org/solc/-/solc-0.4.25.tgz", + "integrity": "sha512-jU1YygRVy6zatgXrLY2rRm7HW1d7a8CkkEgNJwvH2VLpWhMFsMdWcJn6kUqZwcSz/Vm+w89dy7Z/aB5p6AFTrg==", "dev": true, "requires": { "fs-extra": "^0.30.0", @@ -8813,7 +8813,7 @@ }, "jsonfile": { "version": "2.4.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", + "resolved": "http://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", "dev": true, "requires": { @@ -8822,7 +8822,7 @@ }, "yargs": { "version": "4.8.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-4.8.1.tgz", + "resolved": "http://registry.npmjs.org/yargs/-/yargs-4.8.1.tgz", "integrity": "sha1-wMQpJMpKqmsObaFznfshZDn53cA=", "dev": true, "requires": { @@ -9418,14 +9418,14 @@ "dev": true }, "truffle": { - "version": "5.0.0-beta.0", - "resolved": "https://registry.npmjs.org/truffle/-/truffle-5.0.0-beta.0.tgz", - "integrity": "sha512-hZ3TvO0ByHZabVvF5kH3phliAMLbeTM9XrBuJRTfM5x2Q4kHVYnTQa1oOhetPPVPaULsVai5T+iQPV3ptOq9jA==", + "version": "5.0.0-beta.1", + "resolved": "https://registry.npmjs.org/truffle/-/truffle-5.0.0-beta.1.tgz", + "integrity": "sha512-U9vNwUAX0kb+pgpUWsWDFQeU2XeCHYm4swVxQdRi37mDQCOedEVgiE+Lr87LNQMAIuAY+8sG/9KF7HwVks0ncQ==", "dev": true, "requires": { "mocha": "^4.1.0", "original-require": "1.0.1", - "solc": "0.4.24" + "solc": "0.4.25" } }, "tslib": { @@ -10376,7 +10376,7 @@ }, "yargs-parser": { "version": "2.4.1", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-2.4.1.tgz", + "resolved": "http://registry.npmjs.org/yargs-parser/-/yargs-parser-2.4.1.tgz", "integrity": "sha1-hVaN488VD/SfpRgl8DqMiA3cxcQ=", "dev": true, "requires": { diff --git a/package.json b/package.json index ea79ee6..7e57b52 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/infra", - "version": "0.0.0-alpha.07", + "version": "0.0.0-alpha.08", "description": "Base layer DAO's components", "files": [ "contracts/", diff --git a/test/absolutevote.js b/test/absolutevote.js index 7fe60a9..a3630cb 100644 --- a/test/absolutevote.js +++ b/test/absolutevote.js @@ -107,8 +107,7 @@ contract('AbsoluteVote', accounts => { const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - var organizationId = await helpers.getOrganizationId(tx,absoluteVote,"NewProposal"); - assert.equal(organizationId,await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS)); + var organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId, @@ -168,8 +167,8 @@ contract('AbsoluteVote', accounts => { const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - assert.equal(await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS), - await helpers.getOrganizationId(tx,absoluteVote,"NewProposal")); + assert.equal(absoluteVoteExecuteMock.address, + await helpers.getOrganization(tx,absoluteVote,"NewProposal")); }); it("should log the CancelProposal event on canceling a proposal", async function() { @@ -323,7 +322,8 @@ contract('AbsoluteVote', accounts => { const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - const organizationId = await helpers.getOrganizationId(tx,absoluteVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); + // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, @@ -352,7 +352,7 @@ contract('AbsoluteVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - const organizationId = await helpers.getOrganizationId(tx,absoluteVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -376,8 +376,7 @@ contract('AbsoluteVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - const organizationId = await helpers.getOrganizationId(tx,absoluteVote,"NewProposal"); - + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -399,7 +398,8 @@ contract('AbsoluteVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - const organizationId = await helpers.getOrganizationId(tx,absoluteVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); + // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -418,9 +418,7 @@ contract('AbsoluteVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - const organizationId = await helpers.getOrganizationId(tx,absoluteVote,"NewProposal"); - - + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -531,7 +529,7 @@ contract('AbsoluteVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - var organizationId = await helpers.getOrganizationId(tx,absoluteVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -564,7 +562,7 @@ contract('AbsoluteVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - const organizationId = await helpers.getOrganizationId(tx,absoluteVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -586,7 +584,7 @@ contract('AbsoluteVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - const organizationId = await helpers.getOrganizationId(tx,absoluteVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point @@ -611,7 +609,7 @@ contract('AbsoluteVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - var organizationId = await helpers.getOrganizationId(tx,absoluteVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address,6 , paramsHash, 0, true]); @@ -633,7 +631,7 @@ contract('AbsoluteVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,absoluteVote,"NewProposal"); assert.isOk(proposalId); - var organizationId = await helpers.getOrganizationId(tx,absoluteVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [ absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -859,7 +857,8 @@ contract('AbsoluteVote', accounts => { const proposalId1 = await helpers.getProposalId(tx1,absoluteVote1,"NewProposal"); assert.isOk(proposalId1); - var organizationId = await helpers.getOrganizationId(tx1,absoluteVote1,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); + // proposal 2 - Yes/No - 50% - ownerVote enabled @@ -871,9 +870,7 @@ contract('AbsoluteVote', accounts => { let tx2 = await absoluteVoteExecuteMock2.propose(2, paramsHash2, absoluteVoteExecuteMock2.address,accounts[0],helpers.NULL_ADDRESS, { from: accounts[1] }); const proposalId2 = await helpers.getProposalId(tx2,absoluteVote2,"NewProposal"); - - var organization2Id = await helpers.getOrganizationId(tx2,absoluteVote2,"NewProposal"); - + const organization2Id = await web3.utils.soliditySha3(absoluteVoteExecuteMock2.address,helpers.NULL_ADDRESS); assert.isOk(proposalId2); // Lets check the proposals diff --git a/test/genesisprotocol.js b/test/genesisprotocol.js index cd2212d..c2ffd8a 100644 --- a/test/genesisprotocol.js +++ b/test/genesisprotocol.js @@ -187,7 +187,7 @@ const propose = async function(_testSetup,_proposer = 0) { _proposer, helpers.NULL_ADDRESS); const proposalId = await getValueFromLogs(tx, '_proposalId'); - assert.equal(tx.logs.length, 1); + assert.equal(tx.logs.length, 2); assert.equal(tx.logs[0].event, "NewProposal"); assert.equal(tx.logs[0].args._proposalId, proposalId); assert.equal(tx.logs[0].args._proposer, _proposer); @@ -1628,12 +1628,19 @@ contract('GenesisProtocol Lite', accounts => { var tx = await testSetup.genesisProtocol.propose(2, testSetup.genesisProtocolParams.paramsHash,0,accounts[1]); assert.equal(tx.logs.length, 1); assert.equal(tx.logs[0].event, "NewProposal"); - assert.equal(tx.logs[0].args._organizationId,await web3.utils.soliditySha3(accounts[0],accounts[1])); + assert.equal(tx.logs[0].args._organization,accounts[1]); + var proposalId = await getValueFromLogs(tx, '_proposalId'); + var proposal = await testSetup.genesisProtocol.proposals(proposalId); + assert.equal(proposal[0],await web3.utils.soliditySha3(accounts[0],accounts[1])); + tx = await testSetup.genesisProtocol.propose(2, testSetup.genesisProtocolParams.paramsHash,0,accounts[1],{from : accounts[1]}); assert.equal(tx.logs.length, 1); assert.equal(tx.logs[0].event, "NewProposal"); - assert.equal(tx.logs[0].args._organizationId,await web3.utils.soliditySha3(accounts[1],accounts[1])); + assert.equal(tx.logs[0].args._organization,accounts[1]); + proposalId = await getValueFromLogs(tx, '_proposalId'); + proposal = await testSetup.genesisProtocol.proposals(proposalId); + assert.equal(proposal[0],await web3.utils.soliditySha3(accounts[1],accounts[1])); }); diff --git a/test/helpers.js b/test/helpers.js index 2d01dec..7e50abd 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -86,16 +86,16 @@ export async function getProposalId(tx,contract,eventName) { return proposalId; } -export async function getOrganizationId(tx,contract,eventName) { - var organizationId; +export async function getOrganization(tx,contract,eventName) { + var organization; await contract.getPastEvents(eventName, { fromBlock: tx.blockNumber, toBlock: 'latest' }) .then(function(events){ - organizationId = events[0].args._organizationId; + organization = events[0].args._organization; }); - return organizationId; + return organization; } export async function getProposal(tx) { diff --git a/test/quorumvote.js b/test/quorumvote.js index 6145355..0828aa9 100644 --- a/test/quorumvote.js +++ b/test/quorumvote.js @@ -70,7 +70,7 @@ contract('QuorumVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(5, paramsHash, absoluteVoteExecuteMock.address, accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,quorumVote,"NewProposal"); assert.isOk(proposalId); - var organizationId = await helpers.getOrganizationId(tx,quorumVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 5, paramsHash, 0, true]); @@ -105,7 +105,7 @@ contract('QuorumVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,quorumVote,"NewProposal"); assert.isOk(proposalId); - var organizationId = await helpers.getOrganizationId(tx,quorumVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -253,7 +253,7 @@ contract('QuorumVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,quorumVote,"NewProposal"); assert.isOk(proposalId); - var organizationId = await helpers.getOrganizationId(tx,quorumVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -277,7 +277,7 @@ contract('QuorumVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,quorumVote,"NewProposal"); assert.isOk(proposalId); - var organizationId = await helpers.getOrganizationId(tx,quorumVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -301,7 +301,7 @@ contract('QuorumVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,quorumVote,"NewProposal"); assert.isOk(proposalId); - var organizationId = await helpers.getOrganizationId(tx,quorumVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -323,7 +323,7 @@ contract('QuorumVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,quorumVote,"NewProposal"); assert.isOk(proposalId); - var organizationId = await helpers.getOrganizationId(tx,quorumVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -343,7 +343,7 @@ contract('QuorumVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,quorumVote,"NewProposal"); assert.isOk(proposalId); - var organizationId = await helpers.getOrganizationId(tx,quorumVote,"NewProposal"); + const organizationId = await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS); // no one has voted yet at this point await checkProposalInfo(proposalId, [absoluteVoteExecuteMock.address, organizationId,absoluteVoteExecuteMock.address, 6, paramsHash, 0, true]); @@ -455,8 +455,8 @@ contract('QuorumVote', accounts => { let tx = await absoluteVoteExecuteMock.propose(6, paramsHash, absoluteVoteExecuteMock.address,accounts[0],helpers.NULL_ADDRESS); const proposalId = await helpers.getProposalId(tx,quorumVote,"NewProposal"); assert.isOk(proposalId); - assert.equal(await web3.utils.soliditySha3(absoluteVoteExecuteMock.address,helpers.NULL_ADDRESS), - await helpers.getOrganizationId(tx,quorumVote,"NewProposal")); + assert.equal(absoluteVoteExecuteMock.address, + await helpers.getOrganization(tx,quorumVote,"NewProposal")); });