Skip to content

Commit

Permalink
Merge pull request #29 from AxLabs/develop
Browse files Browse the repository at this point in the history
Circumvent potential division by zero case
  • Loading branch information
csmuller authored May 21, 2022
2 parents 3976310 + 9420756 commit 7adc030
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/com/axlabs/neo/grantshares/GrantSharesGov.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ public static Object[] execute(int id) {
if (voteCount * 100 / Storage.getInt(getReadOnlyContext(), MEMBERS_COUNT_KEY) < data.quorum)
fireErrorAndAbort("Quorum not reached", "execute");
int yesNoCount = votes.approve + votes.reject;
if (votes.approve * 100 / yesNoCount <= data.acceptanceRate) fireErrorAndAbort("Proposal rejected", "execute");
if (yesNoCount == 0 || (votes.approve * 100 / yesNoCount <= data.acceptanceRate))
fireErrorAndAbort("Proposal rejected", "execute");

proposal.executed = true;
Object[] returnVals = new Object[data.intents.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,30 @@ public void fail_executing_proposal_quorum_reached_but_rejected() throws Throwab
assertAborted(tx, "Proposal rejected", neow3j);
}

@Test
public void fail_executing_proposal_quorum_reached_but_all_abstained() throws Throwable {
ContractParameter intents = array(array(gov.getScriptHash(), CHANGE_PARAM,
array(MIN_ACCEPTANCE_RATE_KEY, 40), CallFlags.ALL.getValue()));
String offchainUri = "fail_executing_proposal_quorum_reached_but_all_abstained";

// 1. Create and endorse proposal, then skip till voting phase.
int id = createAndEndorseProposal(gov, neow3j, bob, alice, intents, offchainUri);
ext.fastForwardOneBlock(PHASE_LENGTH);

// 2. Vote abstained for all members.
voteForProposal(gov, neow3j, id, 0, alice);
voteForProposal(gov, neow3j, id, 0, charlie);
voteForProposal(gov, neow3j, id, 0, denise);
voteForProposal(gov, neow3j, id, 0, eve);
voteForProposal(gov, neow3j, id, 0, florian);
ext.fastForwardOneBlock(PHASE_LENGTH + PHASE_LENGTH);

// 3. Call execute
Hash256 tx = gov.execute(id).signers(AccountSigner.calledByEntry(bob))
.sign().send().getSendRawTransaction().getHash();
assertAborted(tx, "Proposal rejected", neow3j);
}

@Test
public void fail_executing_proposal_quorum_not_reached() throws Throwable {
ContractParameter intents = array(array(gov.getScriptHash(), CHANGE_PARAM,
Expand Down

0 comments on commit 7adc030

Please sign in to comment.