Skip to content

JoinAndQuit : add rageQuitEnable param #745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion contracts/schemes/JoinAndQuit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ contract JoinAndQuit is
uint256 public fundingGoal;
uint256 public fundingGoalDeadline;
uint256 public totalDonation;
bool public rageQuitEnable;

/**
* @dev initialize
Expand All @@ -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,
Expand All @@ -91,7 +93,8 @@ contract JoinAndQuit is
uint256 _minFeeToJoin,
uint256 _memberReputation,
uint256 _fundingGoal,
uint256 _fundingGoalDeadline
uint256 _fundingGoalDeadline,
bool _rageQuitEnable
)
external
{
Expand All @@ -101,6 +104,7 @@ contract JoinAndQuit is
memberReputation = _memberReputation;
fundingGoal = _fundingGoal;
fundingGoalDeadline = _fundingGoalDeadline;
rageQuitEnable = _rageQuitEnable;
}

/**
Expand Down Expand Up @@ -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;
Expand Down
99 changes: 59 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions test/fundingrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -54,7 +55,8 @@ const setupJoinAndQuit = async function(
_minFeeToJoin,
_memberReputation,
_fundingGoal,
_fundingGoalDeadline)
_fundingGoalDeadline,
false)
.encodeABI();
}
return joinAndQuitParams;
Expand Down
37 changes: 32 additions & 5 deletions test/joinandquit.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const setupJoinAndQuit = async function(
_minFeeToJoin,
_memberReputation,
_fundingGoal,
_fundingGoalDeadline
_fundingGoalDeadline,
_rageQuitEnable = true,
) {
var joinAndQuitParams = new JoinAndQuitParams();

Expand All @@ -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);
Expand All @@ -67,7 +69,8 @@ const setupJoinAndQuit = async function(
_minFeeToJoin,
_memberReputation,
_fundingGoal,
_fundingGoalDeadline)
_fundingGoalDeadline,
_rageQuitEnable)
.encodeABI();
}
return joinAndQuitParams;
Expand All @@ -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();
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
});

});