Skip to content
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

Voting: Allow to modify required support #458

Merged
merged 3 commits into from
Sep 18, 2018
Merged

Voting: Allow to modify required support #458

merged 3 commits into from
Sep 18, 2018

Conversation

bingen
Copy link
Contributor

@bingen bingen commented Sep 18, 2018

Snapshot it for each vote, create role for it and add tests.

Needed for #270.

Users can always upgrade their Voting apps to modify how the supporting threshold is calculated if they wanted to modify their behaviour. This directly exposes that functionality to avoid convoluted situations like that. Also useful when changing the size or required threshold in multisig scenarios.

Snapshot it for each vote, create role for it and add tests.
@bingen bingen added this to the sprint: 1.3 milestone Sep 18, 2018
@bingen bingen self-assigned this Sep 18, 2018
@bingen bingen requested review from izqui and sohkai September 18, 2018 06:14
Copy link
Contributor

@sohkai sohkai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Awesome!

@@ -85,6 +88,21 @@ contract Voting is IForwarder, AragonApp {
voteTime = _voteTime;
}

/**
* @notice Change required support to `(_supportRequiredPct - _supportRequiredPct % 10^16) / 10^14`%
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never understood this radspec calculation (here and elsewhere) 😅. Why not just supportRequiredPct / 10^14?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was supposed to round to 2 decimals, but I think it's wrong, 14 and 16 should be reverted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I changed it in commit 6bb186b 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever it's the good solution, will fix it in another PR as it affects to other functions here and Survey too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another helper function for radspec :)


assert.isTrue(isOpen, 'vote should be open')
assert.isFalse(isExecuted, 'vote should not be executed')
assert.equal(creator, holder50, 'creator should be correct')
assert.equal(snapshotBlock, await getBlockNumber() - 1, 'snapshot block should be correct')
assert.deepEqual(supportRequired, neededSupport, 'required support should be app required support')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems weird to need the deepEqual in the tests (here and elsewhere), since both supportRequired and minQuorum are numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

@coveralls
Copy link

coveralls commented Sep 18, 2018

Coverage Status

Coverage decreased (-0.3%) to 96.667% when pulling b468b83 on issue270 into 6193cc0 on master.

assert.equal((await voting.supportRequiredPct()).toString(), neededSupport.add(1).toString(), 'should have changed required support')
})

it('fails changing required supoprt lower than minimum acceptance quorum', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: supoprt -> support

@@ -251,6 +271,7 @@ contract Voting is IForwarder, AragonApp {
vote_.metadata = _metadata;
vote_.snapshotBlock = getBlockNumber() - 1; // avoid double voting in this very block
vote_.totalVoters = token.totalSupplyAt(vote_.snapshotBlock);
vote_.supportRequiredPct = supportRequiredPct;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 The cached vote_.supportRequiredPct is currently not being used to check whether a vote can be executed in canExecute().

if (!_isValuePct(vote_.yea, totalVotes, supportRequiredPct)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!! I see that the test for it below is wrong too.

await timeTravel(votingTime + 1)

const state = await voting.getVote(voteId)
assert.equal(state[5].toNumber(), neededSupport.toNumber(), 'required support in vote should stay equal')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proper indent 🙏

// it will succeed

await voting.vote(voteId, true, true, { from: holder50 })
await voting.vote(voteId, true, true, { from: holder19 })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not actually testing the logic we want to test, as both holders are voting YES, the support for the proposal is 100%.

Because we are not properly using the cached supportRequiredPct for the canExecute calculation.

We should add a NO vote by holder31, which would make the support of the proposal be 69, and would make this test fail until the issue with canExecute is fixed

@bingen bingen merged commit 738387c into master Sep 18, 2018
@sohkai sohkai deleted the issue270 branch September 18, 2018 12:57
ramilexe pushed a commit to ConsiderItDone/aragon-apps that referenced this pull request Dec 9, 2021
ramilexe pushed a commit to ConsiderItDone/aragon-apps that referenced this pull request Dec 9, 2021
ramilexe pushed a commit to ConsiderItDone/aragon-apps that referenced this pull request Dec 9, 2021
Voting: Allow to modify required support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants