Skip to content

Commit

Permalink
remove early end on simple majority
Browse files Browse the repository at this point in the history
  • Loading branch information
pscott committed Sep 8, 2023
1 parent ac74e3c commit f6ac7e0
Showing 1 changed file with 4 additions and 46 deletions.
50 changes: 4 additions & 46 deletions starknet/src/utils/simple_majority.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use sx::types::{Proposal, FinalizationStatus, ProposalStatus};
/// Returns the status of a proposal, according to a 'Simple Majority' rule.
/// 'Simple Majority' is defined like so: a proposal is accepted if there are more `votes_for` than `votes_against`.
/// So, a proposal will return Accepted if `max_end_timestamp` has been reached, and `votes_for > votes_agasint`.

This comment has been minimized.

Copy link
@Orland0x

Orland0x Sep 8, 2023

Contributor

votes_against

/// A proposal will return `VotingPeriodAccepted` if `min_end_timestamp` has been reached and `votes_for > votes_against`.
fn get_proposal_status(
proposal: @Proposal, votes_for: u256, votes_against: u256, votes_abstain: u256,
) -> ProposalStatus {
Expand All @@ -17,14 +16,8 @@ fn get_proposal_status(
ProposalStatus::Executed(())
} else if timestamp < *proposal.start_timestamp {
ProposalStatus::VotingDelay(())
} else if timestamp < *proposal.min_end_timestamp {
ProposalStatus::VotingPeriod(())
} else if timestamp < *proposal.max_end_timestamp {
if accepted {
ProposalStatus::VotingPeriodAccepted(())
} else {
ProposalStatus::VotingPeriod(())
}
ProposalStatus::VotingPeriod(())
} else if accepted {
ProposalStatus::Accepted(())
} else {
Expand Down Expand Up @@ -78,6 +71,7 @@ mod tests {
fn voting_period() {
let mut proposal = ProposalDefault::default();
proposal.min_end_timestamp = 42424242;
proposal.max_end_timestamp = proposal.min_end_timestamp + 1;
let votes_for = 0;
let votes_against = 0;
let votes_abstain = 0;
Expand All @@ -87,50 +81,14 @@ mod tests {

#[test]
#[available_gas(10000000)]
fn shortcut_accepted() {
fn early_end_does_not_work() {
let mut proposal = ProposalDefault::default();
proposal.max_end_timestamp = 10;
let votes_for = 1;
let votes_against = 0;
let votes_abstain = 0;
let result = get_proposal_status(@proposal, votes_for, votes_against, votes_abstain);
assert(result == ProposalStatus::VotingPeriodAccepted(()), 'failed shortcut_accepted');
}

#[test]
#[available_gas(10000000)]
fn shortcut_only_abstains() {
let mut proposal = ProposalDefault::default();
proposal.max_end_timestamp = 10;
let votes_for = 0;
let votes_against = 0;
let votes_abstain = 1;
let result = get_proposal_status(@proposal, votes_for, votes_against, votes_abstain);
assert(result == ProposalStatus::VotingPeriod(()), 'failed shortcut_only_abstains');
}

#[test]
#[available_gas(10000000)]
fn shortcut_only_againsts() {
let mut proposal = ProposalDefault::default();
proposal.max_end_timestamp = 10;
let votes_for = 0;
let votes_against = 1;
let votes_abstain = 0;
let result = get_proposal_status(@proposal, votes_for, votes_against, votes_abstain);
assert(result == ProposalStatus::VotingPeriod(()), 'failed shortcut_only_againsts');
}

#[test]
#[available_gas(10000000)]
fn shortcut_balanced() {
let mut proposal = ProposalDefault::default();
proposal.max_end_timestamp = 10;
let votes_for = 1;
let votes_against = 1;
let votes_abstain = 0;
let result = get_proposal_status(@proposal, votes_for, votes_against, votes_abstain);
assert(result == ProposalStatus::VotingPeriod(()), 'failed shortcut_balanced');
assert(result == ProposalStatus::VotingPeriod(()), 'failed shortcut_accepted');
}

#[test]
Expand Down

0 comments on commit f6ac7e0

Please sign in to comment.