From bd9aea78dfb536fe629bcf9df47bd09b8e9fe7c4 Mon Sep 17 00:00:00 2001 From: orenyodfat Date: Mon, 4 May 2020 17:47:38 +0300 Subject: [PATCH] JoinAndQuit : add rageQuitEnable param (#745) * JoinAndQuit : add rageQuitEnable param * fundingRequest test --- contracts/schemes/JoinAndQuit.sol | 7 ++- package-lock.json | 99 ++++++++++++++++++------------- test/fundingrequest.js | 6 +- test/joinandquit.js | 37 ++++++++++-- 4 files changed, 101 insertions(+), 48 deletions(-) diff --git a/contracts/schemes/JoinAndQuit.sol b/contracts/schemes/JoinAndQuit.sol index 24194b18..62e65834 100644 --- a/contracts/schemes/JoinAndQuit.sol +++ b/contracts/schemes/JoinAndQuit.sol @@ -66,6 +66,7 @@ contract JoinAndQuit is uint256 public fundingGoal; uint256 public fundingGoalDeadline; uint256 public totalDonation; + bool public rageQuitEnable; /** * @dev initialize @@ -80,6 +81,7 @@ contract JoinAndQuit is if this param is zero so the repution will be allocated proportional to the fee paid * @param _fundingGoal the funding goal * @param _fundingGoalDeadline the funding goal deadline + * @param _rageQuitEnable rageQuit enabling flag */ function initialize( Avatar _avatar, @@ -91,7 +93,8 @@ contract JoinAndQuit is uint256 _minFeeToJoin, uint256 _memberReputation, uint256 _fundingGoal, - uint256 _fundingGoalDeadline + uint256 _fundingGoalDeadline, + bool _rageQuitEnable ) external { @@ -101,6 +104,7 @@ contract JoinAndQuit is memberReputation = _memberReputation; fundingGoal = _fundingGoal; fundingGoalDeadline = _fundingGoalDeadline; + rageQuitEnable = _rageQuitEnable; } /** @@ -219,6 +223,7 @@ contract JoinAndQuit is * @return refund the refund amount */ function rageQuit() public returns(uint256 refund) { + require(rageQuitEnable, "RageQuit disabled"); require(fundings[msg.sender].funding > 0, "no fund to RageQuit"); uint256 userDonation = fundings[msg.sender].funding; fundings[msg.sender].funding = 0; diff --git a/package-lock.json b/package-lock.json index 0ae09694..c44076a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -264,9 +264,9 @@ } }, "@nomiclabs/buidler": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@nomiclabs/buidler/-/buidler-1.3.1.tgz", - "integrity": "sha512-ponVA2N7Y5T2pFBIr5Lzil5CtCz0TOh3PQHqPnJECGVH81vskB6PY+ISDi2O9imSvuBlbmQ0zVMUTh8GaynaBA==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@nomiclabs/buidler/-/buidler-1.3.2.tgz", + "integrity": "sha512-eq8zVvyTNOWuIpTaCnIzbpC35XcUBBOxVWALTQSENmIPK5f6fQd8B00yvBxMOhi4v0L3Fcj2DnSIe9JuvIZWqw==", "dev": true, "requires": { "@nomiclabs/ethereumjs-vm": "^4.1.1", @@ -312,6 +312,12 @@ "ws": "^7.2.1" }, "dependencies": { + "@solidity-parser/parser": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.5.2.tgz", + "integrity": "sha512-uRyvnvVYmgNmTBpWDbBsH/0kPESQhQpEc4KsvMRLVzFJ1o1s0uIv0Y6Y9IB5vI1Dwz2CbS4X/y4Wyw/75cTFnQ==", + "dev": true + }, "@types/node": { "version": "11.11.6", "resolved": "https://registry.npmjs.org/@types/node/-/node-11.11.6.tgz", @@ -706,18 +712,18 @@ } }, "@nomiclabs/buidler-solhint": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@nomiclabs/buidler-solhint/-/buidler-solhint-1.3.1.tgz", - "integrity": "sha512-FyAk9L9tsInBTEA3bF8KeG3gy9bE4rv03Z6poDErH3JOJihB9JAlyT0/XolvOxHGIuojr5bOPOJfBsLnjlO+FA==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@nomiclabs/buidler-solhint/-/buidler-solhint-1.3.2.tgz", + "integrity": "sha512-qGu/J/Rh4qcTtL5/llnKCC7GrDxg3qSHMS7lhowhhQV52/ft9+1qgGL2Si55YmXMcPcYkIbhts07Dm2IzmmH+w==", "dev": true, "requires": { "solhint": "^2.0.0" } }, "@nomiclabs/buidler-truffle5": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@nomiclabs/buidler-truffle5/-/buidler-truffle5-1.3.1.tgz", - "integrity": "sha512-YDX/CZV8s8to80+JVIWvMbC5hvuoxQgOw2J40jI4L8hgaQ3XbKbYZ0zUHG1pNGp+70AbkOc2b/f/Xa/NxJXyaA==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@nomiclabs/buidler-truffle5/-/buidler-truffle5-1.3.2.tgz", + "integrity": "sha512-trAlqQoLygQ3Mz+klL3T7HN1Nh4giWtQ4Qo0BdPRla+KcmUeSAyXl/2O42DX2iKa40p3xpmasqpLmIPBEZmR+w==", "dev": true, "requires": { "@nomiclabs/truffle-contract": "^4.1.2", @@ -741,9 +747,9 @@ } }, "@nomiclabs/buidler-web3": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@nomiclabs/buidler-web3/-/buidler-web3-1.3.1.tgz", - "integrity": "sha512-0ZBfaLR0Hu4lTRLpbdGcRkafWIfTVKrEY1iDw46JEvBbQ/Ll4SnUOi9qK2mBYvjPdhm1h9xHZB6ksoH4gGNeng==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@nomiclabs/buidler-web3/-/buidler-web3-1.3.2.tgz", + "integrity": "sha512-8jDl49z+QnJVqfu9OyABYjrJDin6JTY5c+YrgcoFnMwiFbbbXlZUseU+q77I4MLLO+V+21AqgmNnYuAplgAnPA==", "dev": true, "requires": { "@types/bignumber.js": "^5.0.0" @@ -1679,9 +1685,9 @@ "integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==" }, "@solidity-parser/parser": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.5.2.tgz", - "integrity": "sha512-uRyvnvVYmgNmTBpWDbBsH/0kPESQhQpEc4KsvMRLVzFJ1o1s0uIv0Y6Y9IB5vI1Dwz2CbS4X/y4Wyw/75cTFnQ==" + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@solidity-parser/parser/-/parser-0.6.0.tgz", + "integrity": "sha512-RiJXfS22frulogcfQCFhbKrd5ATu6P4tYUv/daChiIh6VHyKQ1kkVZVfX6aP7c2YGU/Bf9RwGNKdwLjfpaoqYQ==" }, "@szmarczak/http-timer": { "version": "1.1.2", @@ -3850,9 +3856,9 @@ "dev": true }, "dayjs": { - "version": "1.8.25", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.25.tgz", - "integrity": "sha512-Pk36juDfQQGDCgr0Lqd1kw15w3OS6xt21JaLPE3lCfsEf8KrERGwDNwvK1tRjrjqFC0uZBJncT4smZQ4F+uV5g==", + "version": "1.8.26", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.26.tgz", + "integrity": "sha512-KqtAuIfdNfZR5sJY1Dixr2Is4ZvcCqhb0dZpCOt5dGEFiMzoIbjkTSzUb4QKTCsP+WNpGwUjAFIZrnZvUxxkhw==", "dev": true }, "death": { @@ -7867,9 +7873,9 @@ "dev": true }, "uglify-js": { - "version": "3.9.1", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.9.1.tgz", - "integrity": "sha512-JUPoL1jHsc9fOjVFHdQIhqEEJsQvfKDjlubcCilu8U26uZ73qOg8VsN8O1jbuei44ZPlwL7kmbAdM4tzaUvqnA==", + "version": "3.9.2", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.9.2.tgz", + "integrity": "sha512-zGVwKslUAD/EeqOrD1nQaBmXIHl1Vw371we8cvS8I6mYK9rmgX5tv8AAeJdfsQ3Kk5mGax2SVV/AizxdNGhl7Q==", "dev": true, "optional": true, "requires": { @@ -7972,12 +7978,25 @@ } }, "hash-base": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", - "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.1.0.tgz", + "integrity": "sha512-1nmYp/rhMDiE7AYkDw+lLwlAzz0AntGIe51F3RfFfEqyQ3feY2eI/NcwC6umIQVOASPMsWJLJScWKSSvzL9IVA==", "requires": { - "inherits": "^2.0.1", - "safe-buffer": "^5.0.1" + "inherits": "^2.0.4", + "readable-stream": "^3.6.0", + "safe-buffer": "^5.2.0" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } } }, "hash.js": { @@ -9905,9 +9924,9 @@ } }, "moment": { - "version": "2.24.0", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", - "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==", + "version": "2.25.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.25.1.tgz", + "integrity": "sha512-nRKMf9wDS4Fkyd0C9LXh2FFXinD+iwbJ5p/lh3CHitW9kZbRbJ8hCruiadiIXZVbeAqKZzqcTvHnK3mRhFjb6w==", "dev": true }, "moment-timezone": { @@ -12414,12 +12433,12 @@ } }, "solidity-coverage": { - "version": "0.7.4", - "resolved": "https://registry.npmjs.org/solidity-coverage/-/solidity-coverage-0.7.4.tgz", - "integrity": "sha512-eaYjKLJK7n+uAN9Xrm2kDujXOkxxBbHfNrjK+ZabU1DR4QWSVQiwDDF2JLciN943kkZdd2JOzJGp32NxCbdCWA==", + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/solidity-coverage/-/solidity-coverage-0.7.5.tgz", + "integrity": "sha512-UaNwVhK7I1ULYK3qDTATs7Hz0YKhJnE+rm5aU9ufUBowOImB2dWYXox2l/tMbSkHfTMWwHE/6TNqn0/ec0rwOw==", "dev": true, "requires": { - "@solidity-parser/parser": "^0.5.2", + "@solidity-parser/parser": "^0.6.0", "@truffle/provider": "^0.1.17", "chalk": "^2.4.2", "death": "^1.1.0", @@ -13890,9 +13909,9 @@ } }, "systeminformation": { - "version": "4.23.9", - "resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-4.23.9.tgz", - "integrity": "sha512-GdBWl5kSbFVFbd56TqwoUX6HMsq9OgkC8D/Ght8o4LyEPYSQv+jWMlvvCVbTJE3RUk5tFgV6LIy9aiXyOg5cFA==", + "version": "4.24.1", + "resolved": "https://registry.npmjs.org/systeminformation/-/systeminformation-4.24.1.tgz", + "integrity": "sha512-LRksOe2mBvtbD0Y1hZMsaICHpIglhjz758K5XKUiHKcTBc6BV4O7ozbExZc+5BcCYrniMI9ka7piXFeCaymRRQ==", "dev": true, "optional": true }, @@ -14140,12 +14159,12 @@ } }, "truffle-flattener": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/truffle-flattener/-/truffle-flattener-1.4.3.tgz", - "integrity": "sha512-r29fkSkV8i9oMW35KbpKR0bP4iPnzIJqlW2S+CL3BjLsxq6YnlMn9+e0BpiJIJPmeXJgeYHQvCGceucpM0Dovg==", + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/truffle-flattener/-/truffle-flattener-1.4.4.tgz", + "integrity": "sha512-S/WmvubzlUj1mn56wEI6yo1bmPpKDNdEe5rtyVC1C5iNfZWobD/V69pAYI15IBDJrDqUyh+iXgpTkzov50zpQw==", "requires": { "@resolver-engine/imports-fs": "^0.2.2", - "@solidity-parser/parser": "^0.5.2", + "@solidity-parser/parser": "^0.6.0", "find-up": "^2.1.0", "mkdirp": "^1.0.4", "tsort": "0.0.1" diff --git a/test/fundingrequest.js b/test/fundingrequest.js index da0f4aac..c27b3bb8 100644 --- a/test/fundingrequest.js +++ b/test/fundingrequest.js @@ -39,7 +39,8 @@ const setupJoinAndQuit = async function( _minFeeToJoin, _memberReputation, _fundingGoal, - _fundingGoalDeadline) + _fundingGoalDeadline, + false) .encodeABI(); } else { joinAndQuitParams.votingMachine = await helpers.setupAbsoluteVote(helpers.NULL_ADDRESS,50); @@ -54,7 +55,8 @@ const setupJoinAndQuit = async function( _minFeeToJoin, _memberReputation, _fundingGoal, - _fundingGoalDeadline) + _fundingGoalDeadline, + false) .encodeABI(); } return joinAndQuitParams; diff --git a/test/joinandquit.js b/test/joinandquit.js index 7c290bdc..952b7ce0 100644 --- a/test/joinandquit.js +++ b/test/joinandquit.js @@ -35,7 +35,8 @@ const setupJoinAndQuit = async function( _minFeeToJoin, _memberReputation, _fundingGoal, - _fundingGoalDeadline + _fundingGoalDeadline, + _rageQuitEnable = true, ) { var joinAndQuitParams = new JoinAndQuitParams(); @@ -52,7 +53,8 @@ const setupJoinAndQuit = async function( _minFeeToJoin, _memberReputation, _fundingGoal, - _fundingGoalDeadline) + _fundingGoalDeadline, + _rageQuitEnable) .encodeABI(); } else { joinAndQuitParams.votingMachine = await helpers.setupAbsoluteVote(helpers.NULL_ADDRESS,50); @@ -67,7 +69,8 @@ const setupJoinAndQuit = async function( _minFeeToJoin, _memberReputation, _fundingGoal, - _fundingGoalDeadline) + _fundingGoalDeadline, + _rageQuitEnable) .encodeABI(); } return joinAndQuitParams; @@ -80,7 +83,8 @@ const setup = async function (accounts, minFeeToJoin = 100, memberReputation = 100, fundingGoal = 1000, - fundingGoalDeadline = 3000) { + fundingGoalDeadline = 3000, + rageQuitEnable = true) { var testSetup = new helpers.TestSetup(); testSetup.standardTokenMock = await ERC20Mock.new(accounts[0],100000); registration = await helpers.registerImplementation(); @@ -111,7 +115,8 @@ const setup = async function (accounts, minFeeToJoin, memberReputation, fundingGoal, - testSetup.fundingGoalDeadline); + testSetup.fundingGoalDeadline, + rageQuitEnable); var permissions = "0x00000000"; var tx = await registration.daoFactory.setSchemes( @@ -615,4 +620,26 @@ contract('JoinAndQuit', accounts => { }); }); + + it("rageQuit not enable", async function() { + var testSetup = await setup(accounts, false, false, helpers.NULL_ADDRESS, 100, 0,1000,3000,false); + await testSetup.standardTokenMock.approve(testSetup.joinAndQuit.address,testSetup.minFeeToJoin,{from:accounts[3]}); + var tx = await testSetup.joinAndQuit.proposeToJoin( + "description-hash", + testSetup.minFeeToJoin, + {from:accounts[3]}); + + //Vote with reputation to trigger execution + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + await testSetup.joinAndQuitParams.votingMachine.absoluteVote.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]}); + assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.org.avatar.address),testSetup.minFeeToJoin); + assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,testSetup.minFeeToJoin); + try { + await testSetup.joinAndQuit.rageQuit({from:accounts[3]}); + assert(false, 'rageQuitEnable is false'); + } catch (ex) { + helpers.assertVMException(ex); + } + }); + });