From cc4e794b754f978802e306e19a3107eacb184b0f Mon Sep 17 00:00:00 2001 From: orenyodfat Date: Thu, 26 Jul 2018 13:33:06 +0300 Subject: [PATCH] Redeemer - redeem from contribution reward only from positive proposal (#498) * Redeemer - do not redeem from cr for negative proposal * bump version to alpha.46 --- contracts/utils/Redeemer.sol | 5 +- package-lock.json | 6 +- package.json | 2 +- test/contributionreward.js | 160 +++++++++++++++++++++-------------- 4 files changed, 103 insertions(+), 70 deletions(-) diff --git a/contracts/utils/Redeemer.sol b/contracts/utils/Redeemer.sol index cd555cde..439c69d0 100644 --- a/contracts/utils/Redeemer.sol +++ b/contracts/utils/Redeemer.sol @@ -62,7 +62,10 @@ contract Redeemer { if ((daoBountyAmount > 0) && (genesisProtocol.stakingToken().balanceOf(_avatar) >= daoBountyAmount)) { result[2] = genesisProtocol.redeemDaoBounty(_proposalId,_beneficiary); } - (result[3],result[4],result[5],result[6]) = contributionRewardRedeem(_proposalId,_avatar); + //redeem from contributionReward only if it is positive decision + if (genesisProtocol.winningVote(_proposalId) == genesisProtocol.YES()) { + (result[3],result[4],result[5],result[6]) = contributionRewardRedeem(_proposalId,_avatar); + } } emit RedeemerRedeem( _proposalId, diff --git a/package-lock.json b/package-lock.json index 2ed117a3..f9a823c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc", - "version": "0.0.0-alpha.45", + "version": "0.0.0-alpha.46", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -7764,7 +7764,6 @@ "integrity": "sha1-PpcwauAk+yThCj11yIQwJWIhUSA=", "dev": true, "requires": { - "bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", "crypto-js": "^3.1.4", "utf8": "^2.1.1", "xhr2": "*", @@ -7773,8 +7772,7 @@ "dependencies": { "bignumber.js": { "version": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934", - "from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git", - "dev": true + "from": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934" }, "crypto-js": { "version": "3.1.8", diff --git a/package.json b/package.json index 7965760a..a715e08c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc", - "version": "0.0.0-alpha.45", + "version": "0.0.0-alpha.46", "description": "A platform for building DAOs", "files": [ "contracts/", diff --git a/test/contributionreward.js b/test/contributionreward.js index a6adf509..b7e2f04f 100644 --- a/test/contributionreward.js +++ b/test/contributionreward.js @@ -487,75 +487,107 @@ contract('ContributionReward', function(accounts) { }); - it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer", async function() { - var standardTokenMock = await StandardTokenMock.new(accounts[0],1000); - var testSetup = await setup(accounts,0,true,standardTokenMock.address); - var reputationReward = 12; - var nativeTokenReward = 12; - var ethReward = 12; - var periodLength = 50; - var numberOfPeriods = 1; - //send some ether to the org avatar - var otherAvatar = await Avatar.new('otheravatar', helpers.NULL_ADDRESS, helpers.NULL_ADDRESS); - web3.eth.sendTransaction({from:accounts[0],to:testSetup.org.avatar.address, value:20}); - var tx = await testSetup.contributionReward.proposeContributionReward(testSetup.org.avatar.address, - "description", - reputationReward, - [nativeTokenReward,ethReward,0,periodLength,numberOfPeriods], - testSetup.standardTokenMock.address, - otherAvatar.address - ); - //Vote with reputation to trigger execution - var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); - await testSetup.contributionRewardParams.votingMachine.genesisProtocol.vote(proposalId,1,{from:accounts[0]}); - await helpers.increaseTime(periodLength+1); - var arcUtils = await Redeemer.new(testSetup.contributionReward.address,testSetup.contributionRewardParams.votingMachine.genesisProtocol.address); - await arcUtils.redeem(proposalId,testSetup.org.avatar.address,accounts[0]); - var eth = web3.eth.getBalance(otherAvatar.address); - assert.equal(eth.toNumber(),ethReward); - assert.equal(await testSetup.org.reputation.reputationOf(otherAvatar.address),reputationReward); - assert.equal(await testSetup.org.token.balanceOf(otherAvatar.address),nativeTokenReward); - var reputation = await testSetup.org.reputation.reputationOf(accounts[0]); - assert.equal(reputation,1141); - }); - it("execute proposeContributionReward mint reputation with period 0 ", async function() { - var testSetup = await setup(accounts); - var reputationReward = 12; - var periodLength = 0; - var numberOfPeriods = 1; - var tx = await testSetup.contributionReward.proposeContributionReward(testSetup.org.avatar.address, + it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer", async function() { + var standardTokenMock = await StandardTokenMock.new(accounts[0],1000); + var testSetup = await setup(accounts,0,true,standardTokenMock.address); + var reputationReward = 12; + var nativeTokenReward = 12; + var ethReward = 12; + var periodLength = 50; + var numberOfPeriods = 1; + //send some ether to the org avatar + var otherAvatar = await Avatar.new('otheravatar', helpers.NULL_ADDRESS, helpers.NULL_ADDRESS); + web3.eth.sendTransaction({from:accounts[0],to:testSetup.org.avatar.address, value:20}); + var tx = await testSetup.contributionReward.proposeContributionReward(testSetup.org.avatar.address, + "description", + reputationReward, + [nativeTokenReward,ethReward,0,periodLength,numberOfPeriods], + testSetup.standardTokenMock.address, + otherAvatar.address + ); + //Vote with reputation to trigger execution + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + await testSetup.contributionRewardParams.votingMachine.genesisProtocol.vote(proposalId,1,{from:accounts[0]}); + await helpers.increaseTime(periodLength+1); + var arcUtils = await Redeemer.new(testSetup.contributionReward.address,testSetup.contributionRewardParams.votingMachine.genesisProtocol.address); + await arcUtils.redeem(proposalId,testSetup.org.avatar.address,accounts[0]); + var eth = web3.eth.getBalance(otherAvatar.address); + assert.equal(eth.toNumber(),ethReward); + assert.equal(await testSetup.org.reputation.reputationOf(otherAvatar.address),reputationReward); + assert.equal(await testSetup.org.token.balanceOf(otherAvatar.address),nativeTokenReward); + var reputation = await testSetup.org.reputation.reputationOf(accounts[0]); + assert.equal(reputation,1141); + }); + it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer for negative proposal", async function() { + var standardTokenMock = await StandardTokenMock.new(accounts[0],1000); + var testSetup = await setup(accounts,0,true,standardTokenMock.address); + var reputationReward = 12; + var nativeTokenReward = 12; + var ethReward = 12; + var periodLength = 50; + var numberOfPeriods = 1; + //send some ether to the org avatar + var otherAvatar = await Avatar.new('otheravatar', helpers.NULL_ADDRESS, helpers.NULL_ADDRESS); + web3.eth.sendTransaction({from:accounts[0],to:testSetup.org.avatar.address, value:20}); + var tx = await testSetup.contributionReward.proposeContributionReward(testSetup.org.avatar.address, + "description", + reputationReward, + [nativeTokenReward,ethReward,0,periodLength,numberOfPeriods], + testSetup.standardTokenMock.address, + otherAvatar.address + ); + //Vote with reputation to trigger execution + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + await testSetup.contributionRewardParams.votingMachine.genesisProtocol.vote(proposalId,2,{from:accounts[0]}); + await helpers.increaseTime(periodLength+1); + var arcUtils = await Redeemer.new(testSetup.contributionReward.address,testSetup.contributionRewardParams.votingMachine.genesisProtocol.address); + await arcUtils.redeem(proposalId,testSetup.org.avatar.address,accounts[0]); + var eth = web3.eth.getBalance(otherAvatar.address); + assert.equal(eth.toNumber(),0); + assert.equal(await testSetup.org.reputation.reputationOf(otherAvatar.address),0); + assert.equal(await testSetup.org.token.balanceOf(otherAvatar.address),0); + var reputation = await testSetup.org.reputation.reputationOf(accounts[0]); + assert.equal(reputation,1080); + }); + + it("execute proposeContributionReward mint reputation with period 0 ", async function() { + var testSetup = await setup(accounts); + var reputationReward = 12; + var periodLength = 0; + var numberOfPeriods = 1; + var tx = await testSetup.contributionReward.proposeContributionReward(testSetup.org.avatar.address, + "description", + reputationReward, + [0,0,0,periodLength,numberOfPeriods], + testSetup.standardTokenMock.address, + accounts[1] + ); + try { + await testSetup.contributionReward.proposeContributionReward(testSetup.org.avatar.address, "description", reputationReward, - [0,0,0,periodLength,numberOfPeriods], + [0,0,0,periodLength,2], testSetup.standardTokenMock.address, accounts[1] ); - try { - await testSetup.contributionReward.proposeContributionReward(testSetup.org.avatar.address, - "description", - reputationReward, - [0,0,0,periodLength,2], - testSetup.standardTokenMock.address, - accounts[1] - ); - assert(false, 'if periodLength==0 so numberOfPeriods must be 1'); - } catch (ex) { - helpers.assertVMException(ex); - } + assert(false, 'if periodLength==0 so numberOfPeriods must be 1'); + } catch (ex) { + helpers.assertVMException(ex); + } - //Vote with reputation to trigger execution - var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); - await testSetup.contributionRewardParams.votingMachine.absoluteVote.vote(proposalId,1,{from:accounts[2]}); - tx = await testSetup.contributionReward.redeem(proposalId,testSetup.org.avatar.address,[true,false,false,false]); - assert.equal(tx.logs.length, 1); - assert.equal(tx.logs[0].event, "RedeemReputation"); - assert.equal(tx.logs[0].args._amount, reputationReward); - var rep = await testSetup.org.reputation.reputationOf(accounts[1]); - assert.equal(rep.toNumber(),reputationReward); - //try to redeem again. - tx = await testSetup.contributionReward.redeem(proposalId,testSetup.org.avatar.address,[true,false,false,false]); - assert.equal(tx.logs.length, 0); - rep = await testSetup.org.reputation.reputationOf(accounts[1]); - assert.equal(rep.toNumber(),reputationReward); + //Vote with reputation to trigger execution + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + await testSetup.contributionRewardParams.votingMachine.absoluteVote.vote(proposalId,1,{from:accounts[2]}); + tx = await testSetup.contributionReward.redeem(proposalId,testSetup.org.avatar.address,[true,false,false,false]); + assert.equal(tx.logs.length, 1); + assert.equal(tx.logs[0].event, "RedeemReputation"); + assert.equal(tx.logs[0].args._amount, reputationReward); + var rep = await testSetup.org.reputation.reputationOf(accounts[1]); + assert.equal(rep.toNumber(),reputationReward); + //try to redeem again. + tx = await testSetup.contributionReward.redeem(proposalId,testSetup.org.avatar.address,[true,false,false,false]); + assert.equal(tx.logs.length, 0); + rep = await testSetup.org.reputation.reputationOf(accounts[1]); + assert.equal(rep.toNumber(),reputationReward); }); });