Skip to content

Commit

Permalink
fix(contracts/dao): add missing condition check in reedeem for avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustoL committed Mar 1, 2023
1 parent f99c903 commit deec1aa
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contracts/dao/votingMachine/VotingMachine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ contract VotingMachine {
}

// If also a stake was done by the avatar, the stake redeem is done
if (staked > 0) {
if (staked > 0 && staker.option == NO) {
reward = (staked * totalStakesWithoutDaoBounty) / proposalStakes[proposalId][NO];

schemes[proposal.schemeId].stakingTokenBalance =
Expand Down
129 changes: 129 additions & 0 deletions test/dao/votingMachines/VotingMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,135 @@ contract("VotingMachine", function (accounts) {
);
});

it("Stake on YES by user and stake on YES by avatar, NO wins", async function () {
const testProposalId = await helpers.getValueFromLogs(
await masterAvatarScheme.proposeCalls(
[actionMock.address],
[helpers.testCallFrom(org.avatar.address)],
[0],
2,
constants.TEST_TITLE,
constants.SOME_HASH
),
"proposalId"
);

await dxdVotingMachine.stake(
testProposalId,
constants.YES_OPTION,
web3.utils.toWei("0.1"),
{
from: accounts[1],
}
);

const stakeProposalId = await helpers.getValueFromLogs(
await masterAvatarScheme.proposeCalls(
[dxdVotingMachine.address],
[
web3.eth.abi.encodeFunctionCall(
VotingMachine.abi.find(x => x.name === "stake"),
[testProposalId, constants.YES_OPTION, web3.utils.toWei("0.4")]
),
],
[0],
2,
constants.TEST_TITLE,
constants.SOME_HASH
),
"proposalId"
);
const stakeByAvatarTx = await dxdVotingMachine.vote(
stakeProposalId,
constants.YES_OPTION,
0,
{
from: accounts[3],
}
);
await expectEvent.inTransaction(
stakeByAvatarTx.tx,
dxdVotingMachine.contract,
"ProposalExecuteResult",
{ 0: "" }
);

await dxdVotingMachine.stake(
testProposalId,
constants.YES_OPTION,
web3.utils.toWei("1"),
{
from: accounts[1],
}
);
const finalVoteTx = await dxdVotingMachine.vote(
testProposalId,
constants.NO_OPTION,
0,
{
from: accounts[3],
}
);

await expectEvent.inTransaction(
finalVoteTx.tx,
dxdVotingMachine.contract,
"StateChange",
{
proposalId: testProposalId,
proposalState:
constants.VOTING_MACHINE_PROPOSAL_STATES.ExecutedInQueue,
}
);

const daoBounty = new BN(helpers.defaultParameters.daoBounty);
const stakedOnYes = new BN(web3.utils.toWei("1.5"));
const totalStakedNo = new BN("0");

assert(
(
await dxdVotingMachine.getStaker(testProposalId, org.avatar.address)
).amount.eq(new BN(web3.utils.toWei("0.4")))
);

const daoBountyRewardToAvatar = stakedOnYes
.mul(daoBounty)
.div(totalStakedNo.add(daoBounty));

assert.equal(
(await dxdVotingMachine.proposals(testProposalId)).daoRedeemedWinnings,
false
);

const avatarRedeemTx = await dxdVotingMachine.redeem(
testProposalId,
org.avatar.address
);
await expectEvent.inTransaction(
avatarRedeemTx.tx,
stakingToken.contract,
"Transfer",
{
from: dxdVotingMachine.address,
to: org.avatar.address,
value: daoBountyRewardToAvatar,
}
);

assert.equal(
(await dxdVotingMachine.proposals(testProposalId)).daoRedeemedWinnings,
true
);

await expectEvent.notEmitted.inTransaction(
(
await dxdVotingMachine.redeem(testProposalId, org.avatar.address)
).tx,
stakingToken.contract,
"Transfer"
);
});

it("Stake on multiple proposals in a row and check threshold increase", async function () {
const testProposalId1 = await helpers.getValueFromLogs(
await masterAvatarScheme.proposeCalls(
Expand Down

0 comments on commit deec1aa

Please sign in to comment.