Skip to content

Commit

Permalink
Fix reputation redeem after ragequit (#730)
Browse files Browse the repository at this point in the history
* fix rageQuit function

* bump version

* bool rageQuit to MemberFund
  • Loading branch information
orenyodfat authored Mar 29, 2020
1 parent 6d8986f commit f04d0d6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
17 changes: 12 additions & 5 deletions contracts/schemes/JoinAndQuit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ contract JoinAndQuit is
uint256 funding;
}

struct MemberFund {
bool rageQuit;
uint256 funding;
}

mapping(bytes32=>Proposal) public proposals;
mapping(address=>uint256) public fundings;
mapping(address=>MemberFund) public fundings;

IntVoteInterface public votingMachine;
bytes32 public voteParams;
Expand Down Expand Up @@ -125,7 +130,7 @@ contract JoinAndQuit is
} else {
address(fundingToken).safeTransfer(address(avatar), proposal.funding);
}
fundings[proposal.proposedMember] = proposal.funding;
fundings[proposal.proposedMember].funding = proposal.funding;
totalDonation = totalDonation.add(proposal.funding);
setFundingGoalReachedFlag();
} else {
Expand Down Expand Up @@ -196,6 +201,7 @@ contract JoinAndQuit is
Proposal memory _proposal = proposals[_proposalId];
Proposal storage proposal = proposals[_proposalId];
require(proposal.proposedMember != address(0), "no member to redeem");
require(!fundings[proposal.proposedMember].rageQuit, "member already rageQuit");
//set proposal proposedMember to zero to prevent reentrancy attack.
proposal.proposedMember = address(0);
require(proposal.accepted == true, " proposal not accepted");
Expand All @@ -218,9 +224,10 @@ contract JoinAndQuit is
* @return refund the refund amount
*/
function rageQuit() public returns(uint256 refund) {
require(fundings[msg.sender] > 0, "no fund to RageQuit");
uint256 userDonation = fundings[msg.sender];
fundings[msg.sender] = 0;
require(fundings[msg.sender].funding > 0, "no fund to RageQuit");
uint256 userDonation = fundings[msg.sender].funding;
fundings[msg.sender].funding = 0;
fundings[msg.sender].rageQuit = true;
if (fundingToken == IERC20(0)) {
refund = userDonation.mul(address(avatar.vault()).balance).div(totalDonation);
require(
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daostack/arc-experimental",
"version": "0.1.1-rc.10",
"version": "0.1.1-rc.11",
"description": "A platform for building DAOs",
"files": [
"contracts/",
Expand Down
20 changes: 10 additions & 10 deletions test/joinandquit.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ contract('JoinAndQuit', accounts => {
assert.equal(proposal.accepted,true);
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.org.avatar.address),testSetup.minFeeToJoin);
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.joinAndQuit.address),0);
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),testSetup.minFeeToJoin);
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,testSetup.minFeeToJoin);
});

it("execute proposeJoinAndQuit yes with eth", async function() {
Expand All @@ -261,7 +261,7 @@ contract('JoinAndQuit', accounts => {
assert.equal(proposal.accepted,true);
assert.equal(await avatarBalance(testSetup),testSetup.minFeeToJoin);
assert.equal(await web3.eth.getBalance(testSetup.joinAndQuit.address),0);
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),testSetup.minFeeToJoin);
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,testSetup.minFeeToJoin);
});

it("execute proposeJoinAndQuit no", async function() {
Expand All @@ -279,7 +279,7 @@ contract('JoinAndQuit', accounts => {
assert.equal(proposal.accepted,false);
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.org.avatar.address),0);
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.joinAndQuit.address),0);
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),0);
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,0);
assert.equal(await testSetup.standardTokenMock.balanceOf(accounts[3]),10000);
});

Expand All @@ -299,7 +299,7 @@ contract('JoinAndQuit', accounts => {
assert.equal(proposal.accepted,false);
assert.equal(await avatarBalance(testSetup),0);
assert.equal(await web3.eth.getBalance(testSetup.joinAndQuit.address),0);
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),0);
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,0);
var BN = web3.utils.BN;
var a = new BN(balanceBefore);
var b = new BN(testSetup.minFeeToJoin);
Expand Down Expand Up @@ -361,11 +361,11 @@ contract('JoinAndQuit', accounts => {
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]),testSetup.minFeeToJoin);
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,testSetup.minFeeToJoin);
await testSetup.joinAndQuit.rageQuit({from:accounts[3]});
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.joinAndQuit.address),0);
assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.org.avatar.address),0);
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),0);
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,0);
try {
await testSetup.joinAndQuit.rageQuit({from:accounts[3]});
assert(false, 'cannot rage quite twice without refunding');
Expand All @@ -384,7 +384,7 @@ contract('JoinAndQuit', accounts => {
await addMember(accounts,testSetup,500,accounts[4]);

assert.equal(await testSetup.standardTokenMock.balanceOf(testSetup.org.avatar.address),900);
assert.equal(await testSetup.joinAndQuit.fundings(accounts[0]),300);
assert.equal((await testSetup.joinAndQuit.fundings(accounts[0])).funding,300);
assert.equal(await testSetup.joinAndQuit.totalDonation(),900);
tx = await testSetup.joinAndQuit.rageQuit({from:accounts[0]});
assert.equal(tx.logs[0].event, "RageQuit");
Expand All @@ -406,11 +406,11 @@ contract('JoinAndQuit', accounts => {
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 avatarBalance(testSetup),testSetup.minFeeToJoin);
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),testSetup.minFeeToJoin);
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,testSetup.minFeeToJoin);
await testSetup.joinAndQuit.rageQuit({from:accounts[3]});
assert.equal(await web3.eth.getBalance(testSetup.joinAndQuit.address),0);
assert.equal(await avatarBalance(testSetup),0);
assert.equal(await testSetup.joinAndQuit.fundings(accounts[3]),0);
assert.equal((await testSetup.joinAndQuit.fundings(accounts[3])).funding,0);

try {
await testSetup.joinAndQuit.rageQuit({from:accounts[3]});
Expand All @@ -424,7 +424,7 @@ contract('JoinAndQuit', accounts => {
await addMember(accounts,testSetup,500,accounts[4]);

assert.equal(await avatarBalance(testSetup),900);
assert.equal(await testSetup.joinAndQuit.fundings(accounts[0]),300);
assert.equal((await testSetup.joinAndQuit.fundings(accounts[0])).funding,300);
assert.equal(await testSetup.joinAndQuit.totalDonation(),900);
tx = await testSetup.joinAndQuit.rageQuit({from:accounts[0]});
assert.equal(tx.logs[0].event, "RageQuit");
Expand Down

0 comments on commit f04d0d6

Please sign in to comment.