From 9c61adca42962a7f581428bd578567446b91ed61 Mon Sep 17 00:00:00 2001 From: Oren Sokolowsky Date: Fri, 7 Feb 2020 20:56:21 +0200 Subject: [PATCH] competition repchange >=0 --- contracts/schemes/Competition.sol | 4 +-- contracts/schemes/ContributionRewardExt.sol | 2 +- package-lock.json | 19 ++++---------- package.json | 2 +- test/competition.js | 11 ++++++++ test/contributionrewardext.js | 29 +++++++++++++++++++++ 6 files changed, 49 insertions(+), 18 deletions(-) diff --git a/contracts/schemes/Competition.sol b/contracts/schemes/Competition.sol index e6b56a44..5be081ac 100644 --- a/contracts/schemes/Competition.sol +++ b/contracts/schemes/Competition.sol @@ -96,7 +96,7 @@ contract Competition { /** * @dev Submit a competion proposal * @param _descriptionHash A hash of the proposal's description - * @param _reputationChange - Amount of reputation change requested .Can be negative. + * @param _reputationChange - Amount of reputation change requested. * @param _rewards rewards array: * rewards[0] - Amount of tokens requested per period * rewards[1] - Amount of ETH requested per period @@ -146,7 +146,7 @@ contract Competition { if (_rewards[2] > 0) { require(_externalToken != ERC20(0), "extenal token cannot be zero"); } - require(_reputationChange > 0, "only positive rep change(minting) allowed for a competition"); + require(_reputationChange >= 0, "negative reputation change is not allowed for a competition"); uint256 totalRewardSplit; for (uint256 i = 0; i < numberOfWinners; i++) { totalRewardSplit = totalRewardSplit.add(_rewardSplit[i]); diff --git a/contracts/schemes/ContributionRewardExt.sol b/contracts/schemes/ContributionRewardExt.sol index e4617a15..294345d1 100644 --- a/contracts/schemes/ContributionRewardExt.sol +++ b/contracts/schemes/ContributionRewardExt.sol @@ -162,7 +162,7 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa beneficiary = msg.sender; } if (beneficiary == address(this)) { - require(_reputationChange > 0, "only positive rep change(minting) allowed for this case"); + require(_reputationChange >= 0, "negative rep change not allowed for this case"); } ContributionProposal memory proposal = ContributionProposal({ diff --git a/package-lock.json b/package-lock.json index 8cd8a30f..dd6c72e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc", - "version": "0.0.1-rc.40", + "version": "0.0.1-rc.41", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -4380,13 +4380,10 @@ "dev": true }, "is-finite": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.0.2.tgz", - "integrity": "sha1-zGZ3aVYCvlUO8R6LSqYwU0K20Ko=", - "dev": true, - "requires": { - "number-is-nan": "^1.0.0" - } + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.1.0.tgz", + "integrity": "sha512-cdyMtqX/BOqqNBBiKlIVkytNHm49MtMlYyn1zxzvJKWmFMlGzm+ry5BBfYyeY9YmNKbRSo/o7OX9w9ale0wg3w==", + "dev": true }, "is-fullwidth-code-point": { "version": "2.0.0", @@ -5028,12 +5025,6 @@ } } }, - "number-is-nan": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true - }, "oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", diff --git a/package.json b/package.json index 393f01ba..1f9593c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc", - "version": "0.0.1-rc.40", + "version": "0.0.1-rc.41", "description": "A platform for building DAOs", "files": [ "contracts/", diff --git a/test/competition.js b/test/competition.js index 615dd14b..c976990c 100644 --- a/test/competition.js +++ b/test/competition.js @@ -519,6 +519,17 @@ contract('Competition', accounts => { }); + it("negative reputation change is not allowed", async function() { + var testSetup = await setup(accounts); + try { + await proposeCompetition(testSetup,"description-hash",-1000); + assert(false, 'negative reputation change is not allowed'); + } catch (ex) { + helpers.assertVMException(ex); + } + await proposeCompetition(testSetup,"description-hash",0); + }); + it("redeem multipe suggestions", async function() { var testSetup = await setup(accounts); await testSetup.standardTokenMock.transfer(testSetup.org.avatar.address,3000,{from:accounts[1]}); diff --git a/test/contributionrewardext.js b/test/contributionrewardext.js index 55cd3e3e..708f4696 100644 --- a/test/contributionrewardext.js +++ b/test/contributionrewardext.js @@ -667,4 +667,33 @@ contract('ContributionRewardExt', accounts => { }); + it("negativ rep change is not allowed for rewarder to set ", async function() { + var testSetup = await setup(accounts,false,0,accounts[0]); + var reputationReward = -12; + var nativeTokenReward = 12; + var ethReward = 12; + var externalTokenReward = 12; + try { + await testSetup.contributionRewardExt.proposeContributionReward( + web3.utils.asciiToHex("description"), + reputationReward, + [nativeTokenReward,ethReward,externalTokenReward], + testSetup.standardTokenMock.address, + testSetup.contributionRewardExt.address, + helpers.NULL_ADDRESS + ); + assert(false, 'negativ rep change is not allowed for rewarder to set'); + } catch (ex) { + helpers.assertVMException(ex); + } + await testSetup.contributionRewardExt.proposeContributionReward( + web3.utils.asciiToHex("description"), + 0, + [nativeTokenReward,ethReward,externalTokenReward], + testSetup.standardTokenMock.address, + testSetup.contributionRewardExt.address, + helpers.NULL_ADDRESS + ); + }); + });