Skip to content
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 smartcontract/contracts/governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,12 @@ impl GovernanceContract {
.get(&DataKey::QuorumPercent)
.unwrap_or(50);

let quorum_threshold = (members.len() * quorum_percent) / 100;
let quorum_threshold = members
.len()
.checked_mul(quorum_percent)
.and_then(|votes| votes.checked_add(99))
.ok_or(Error::InvalidProposal)?
/ 100;
if proposal.total_votes < quorum_threshold {
proposal.status = ProposalStatus::Expired;
} else if proposal.votes_for > proposal.votes_against {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ fn governance_membership_lifecycle_updates_authorization() {
&newbie,
);
gov.vote(&members[0], &add, &true);
gov.vote(&members[1], &add, &true);
advance_seq(&env, 100);
assert_eq!(gov.finalize(&members[0], &add), ProposalStatus::Passed);
gov.execute_proposal(&admin, &add);
Expand All @@ -116,6 +117,7 @@ fn governance_membership_lifecycle_updates_authorization() {
&members[1],
);
gov.vote(&members[0], &rem, &true);
gov.vote(&members[2], &rem, &true);
advance_seq(&env, 100);
assert_eq!(gov.finalize(&members[0], &rem), ProposalStatus::Passed);
gov.execute_proposal(&admin, &rem);
Expand Down Expand Up @@ -175,6 +177,7 @@ fn terminal_operations_cannot_replay_across_contracts() {
&gmembers[0],
);
gov.vote(&gmembers[0], &pid, &true);
gov.vote(&gmembers[1], &pid, &true);
advance_seq(&env, 100);
gov.finalize(&gmembers[0], &pid);
gov.execute_proposal(&admin, &pid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ fn quorum_not_met_expires() {
);
}

/// INV-G4: quorum rounds up so a 50% quorum in a three-member DAO needs two votes.
#[test]
fn quorum_rounds_up_for_non_divisible_member_counts() {
let (env, _admin, members, c) = setup(3, 50, 100);
let id = mk_proposal(&c, &members[0]);
c.vote(&members[0], &id, &true);

advance_seq(&env, 200);
assert_eq!(c.finalize(&members[0], &id), ProposalStatus::Expired);
}

/// INV-G4: voting is closed once the proposal is finalized.
#[test]
fn cannot_vote_after_finalize() {
Expand Down
Loading