Skip to content

Commit bd9aea7

Browse files
authored
JoinAndQuit : add rageQuitEnable param (#745)
* JoinAndQuit : add rageQuitEnable param * fundingRequest test
1 parent 39c063b commit bd9aea7

File tree

4 files changed

+101
-48
lines changed

4 files changed

+101
-48
lines changed

contracts/schemes/JoinAndQuit.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ contract JoinAndQuit is
6666
uint256 public fundingGoal;
6767
uint256 public fundingGoalDeadline;
6868
uint256 public totalDonation;
69+
bool public rageQuitEnable;
6970

7071
/**
7172
* @dev initialize
@@ -80,6 +81,7 @@ contract JoinAndQuit is
8081
if this param is zero so the repution will be allocated proportional to the fee paid
8182
* @param _fundingGoal the funding goal
8283
* @param _fundingGoalDeadline the funding goal deadline
84+
* @param _rageQuitEnable rageQuit enabling flag
8385
*/
8486
function initialize(
8587
Avatar _avatar,
@@ -91,7 +93,8 @@ contract JoinAndQuit is
9193
uint256 _minFeeToJoin,
9294
uint256 _memberReputation,
9395
uint256 _fundingGoal,
94-
uint256 _fundingGoalDeadline
96+
uint256 _fundingGoalDeadline,
97+
bool _rageQuitEnable
9598
)
9699
external
97100
{
@@ -101,6 +104,7 @@ contract JoinAndQuit is
101104
memberReputation = _memberReputation;
102105
fundingGoal = _fundingGoal;
103106
fundingGoalDeadline = _fundingGoalDeadline;
107+
rageQuitEnable = _rageQuitEnable;
104108
}
105109

106110
/**
@@ -219,6 +223,7 @@ contract JoinAndQuit is
219223
* @return refund the refund amount
220224
*/
221225
function rageQuit() public returns(uint256 refund) {
226+
require(rageQuitEnable, "RageQuit disabled");
222227
require(fundings[msg.sender].funding > 0, "no fund to RageQuit");
223228
uint256 userDonation = fundings[msg.sender].funding;
224229
fundings[msg.sender].funding = 0;

package-lock.json

Lines changed: 59 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fundingrequest.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const setupJoinAndQuit = async function(
3939
_minFeeToJoin,
4040
_memberReputation,
4141
_fundingGoal,
42-
_fundingGoalDeadline)
42+
_fundingGoalDeadline,
43+
false)
4344
.encodeABI();
4445
} else {
4546
joinAndQuitParams.votingMachine = await helpers.setupAbsoluteVote(helpers.NULL_ADDRESS,50);
@@ -54,7 +55,8 @@ const setupJoinAndQuit = async function(
5455
_minFeeToJoin,
5556
_memberReputation,
5657
_fundingGoal,
57-
_fundingGoalDeadline)
58+
_fundingGoalDeadline,
59+
false)
5860
.encodeABI();
5961
}
6062
return joinAndQuitParams;

test/joinandquit.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const setupJoinAndQuit = async function(
3535
_minFeeToJoin,
3636
_memberReputation,
3737
_fundingGoal,
38-
_fundingGoalDeadline
38+
_fundingGoalDeadline,
39+
_rageQuitEnable = true,
3940
) {
4041
var joinAndQuitParams = new JoinAndQuitParams();
4142

@@ -52,7 +53,8 @@ const setupJoinAndQuit = async function(
5253
_minFeeToJoin,
5354
_memberReputation,
5455
_fundingGoal,
55-
_fundingGoalDeadline)
56+
_fundingGoalDeadline,
57+
_rageQuitEnable)
5658
.encodeABI();
5759
} else {
5860
joinAndQuitParams.votingMachine = await helpers.setupAbsoluteVote(helpers.NULL_ADDRESS,50);
@@ -67,7 +69,8 @@ const setupJoinAndQuit = async function(
6769
_minFeeToJoin,
6870
_memberReputation,
6971
_fundingGoal,
70-
_fundingGoalDeadline)
72+
_fundingGoalDeadline,
73+
_rageQuitEnable)
7174
.encodeABI();
7275
}
7376
return joinAndQuitParams;
@@ -80,7 +83,8 @@ const setup = async function (accounts,
8083
minFeeToJoin = 100,
8184
memberReputation = 100,
8285
fundingGoal = 1000,
83-
fundingGoalDeadline = 3000) {
86+
fundingGoalDeadline = 3000,
87+
rageQuitEnable = true) {
8488
var testSetup = new helpers.TestSetup();
8589
testSetup.standardTokenMock = await ERC20Mock.new(accounts[0],100000);
8690
registration = await helpers.registerImplementation();
@@ -111,7 +115,8 @@ const setup = async function (accounts,
111115
minFeeToJoin,
112116
memberReputation,
113117
fundingGoal,
114-
testSetup.fundingGoalDeadline);
118+
testSetup.fundingGoalDeadline,
119+
rageQuitEnable);
115120

116121
var permissions = "0x00000000";
117122
var tx = await registration.daoFactory.setSchemes(
@@ -615,4 +620,26 @@ contract('JoinAndQuit', accounts => {
615620
});
616621
});
617622

623+
624+
it("rageQuit not enable", async function() {
625+
var testSetup = await setup(accounts, false, false, helpers.NULL_ADDRESS, 100, 0,1000,3000,false);
626+
await testSetup.standardTokenMock.approve(testSetup.joinAndQuit.address,testSetup.minFeeToJoin,{from:accounts[3]});
627+
var tx = await testSetup.joinAndQuit.proposeToJoin(
628+
"description-hash",
629+
testSetup.minFeeToJoin,
630+
{from:accounts[3]});
631+
632+
//Vote with reputation to trigger execution
633+
var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1);
634+
await testSetup.joinAndQuitParams.votingMachine.absoluteVote.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]});
635+
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.org.avatar.address),testSetup.minFeeToJoin);
636+
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,testSetup.minFeeToJoin);
637+
try {
638+
await testSetup.joinAndQuit.rageQuit({from:accounts[3]});
639+
assert(false, 'rageQuitEnable is false');
640+
} catch (ex) {
641+
helpers.assertVMException(ex);
642+
}
643+
});
644+
618645
});

0 commit comments

Comments
 (0)