-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Governance: Voters put money where mouth is #1183
Changes from 1 commit
06cef2a
e1853be
edc91aa
ef6c402
4e846d6
e2f715c
d993469
f6bd896
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,8 @@ decl_storage! { | |
trait Store for Module<T: Trait> as CouncilVoting { | ||
pub CooloffPeriod get(cooloff_period) config(): T::BlockNumber = T::BlockNumber::sa(1000); | ||
pub VotingPeriod get(voting_period) config(): T::BlockNumber = T::BlockNumber::sa(3); | ||
/// Number of blocks by which to delay enactment of successful, non-unanimous-council-instigated referendum proposals. | ||
pub EnactDelayPeriod get(enact_delay_period) config(): T::BlockNumber = T::BlockNumber::sa(0); | ||
pub Proposals get(proposals) build(|_| vec![0u8; 0]): Vec<(T::BlockNumber, T::Hash)>; // ordered by expiry. | ||
pub ProposalOf get(proposal_of): map T::Hash => Option<T::Proposal>; | ||
pub ProposalVoters get(proposal_voters): map T::Hash => Vec<T::AccountId>; | ||
|
@@ -215,10 +217,18 @@ impl<T: Trait> Module<T> { | |
Self::deposit_event(RawEvent::TallyReferendum(proposal_hash.clone(), tally.0, tally.1, tally.2)); | ||
if tally.0 > tally.1 + tally.2 { | ||
Self::kill_veto_of(&proposal_hash); | ||
match tally { | ||
(_, 0, 0) => <democracy::Module<T>>::internal_start_referendum(proposal, democracy::VoteThreshold::SuperMajorityAgainst, Zero::zero()).map(|_| ())?, | ||
_ => <democracy::Module<T>>::internal_start_referendum(proposal, democracy::VoteThreshold::SimpleMajority, Zero::zero()).map(|_| ())?, | ||
// If there were no nay-votes from the council, then it's weakly uncontroversial; we enact immediately. | ||
let period = match tally.1 { | ||
0 => Zero::zero(), | ||
_ => Self::enact_delay_period(), | ||
}; | ||
// If all council members voted yes, then it's strongly unconversial; we require a negative | ||
// super-majority at referendum in order to defeat it. | ||
let threshold = match tally { | ||
(_, 0, 0) => democracy::VoteThreshold::SuperMajorityAgainst, | ||
_ => democracy::VoteThreshold::SimpleMajority, | ||
}; | ||
<democracy::Module<T>>::internal_start_referendum(proposal, threshold, period).map(|_| ())?; | ||
} | ||
} | ||
} | ||
|
@@ -267,8 +277,8 @@ mod tests { | |
with_externalities(&mut new_test_ext(true), || { | ||
System::set_block_number(1); | ||
let proposal = set_balance_proposal(42); | ||
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove), 0); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove)]); | ||
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove, 0), 0); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove, 0)]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would there be any benefit to using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not within tests, where the type is concrete. |
||
|
||
let cancellation = cancel_referendum_proposal(0); | ||
let hash = cancellation.blake2_256().into(); | ||
|
@@ -290,7 +300,7 @@ mod tests { | |
with_externalities(&mut new_test_ext(true), || { | ||
System::set_block_number(1); | ||
let proposal = set_balance_proposal(42); | ||
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove), 0); | ||
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove, 0), 0); | ||
|
||
let cancellation = cancel_referendum_proposal(0); | ||
let hash = cancellation.blake2_256().into(); | ||
|
@@ -301,7 +311,7 @@ mod tests { | |
|
||
System::set_block_number(2); | ||
assert_ok!(CouncilVoting::end_block(System::block_number())); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove)]); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove, 0)]); | ||
}); | ||
} | ||
|
||
|
@@ -310,7 +320,7 @@ mod tests { | |
with_externalities(&mut new_test_ext(true), || { | ||
System::set_block_number(1); | ||
let proposal = set_balance_proposal(42); | ||
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove), 0); | ||
assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove, 0), 0); | ||
|
||
let cancellation = cancel_referendum_proposal(0); | ||
let hash = cancellation.blake2_256().into(); | ||
|
@@ -320,7 +330,7 @@ mod tests { | |
|
||
System::set_block_number(2); | ||
assert_ok!(CouncilVoting::end_block(System::block_number())); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove)]); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 4, proposal, VoteThreshold::SuperMajorityApprove, 0)]); | ||
}); | ||
} | ||
|
||
|
@@ -384,7 +394,7 @@ mod tests { | |
System::set_block_number(4); | ||
assert_ok!(CouncilVoting::end_block(System::block_number())); | ||
assert_eq!(CouncilVoting::proposals().len(), 0); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 7, set_balance_proposal(42), VoteThreshold::SimpleMajority)]); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 7, set_balance_proposal(42), VoteThreshold::SimpleMajority, 0)]); | ||
}); | ||
} | ||
|
||
|
@@ -449,7 +459,7 @@ mod tests { | |
System::set_block_number(2); | ||
assert_ok!(CouncilVoting::end_block(System::block_number())); | ||
assert_eq!(CouncilVoting::proposals().len(), 0); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 5, proposal, VoteThreshold::SuperMajorityAgainst)]); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 5, proposal, VoteThreshold::SuperMajorityAgainst, 0)]); | ||
}); | ||
} | ||
|
||
|
@@ -467,7 +477,7 @@ mod tests { | |
System::set_block_number(2); | ||
assert_ok!(CouncilVoting::end_block(System::block_number())); | ||
assert_eq!(CouncilVoting::proposals().len(), 0); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 5, proposal, VoteThreshold::SimpleMajority)]); | ||
assert_eq!(Democracy::active_referendums(), vec![(0, 5, proposal, VoteThreshold::SimpleMajority, 0)]); | ||
}); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -581,7 +581,7 @@ mod tests { | |
fn simple_passing_should_work() { | ||
with_externalities(&mut new_test_ext(), || { | ||
System::set_block_number(1); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as per previous comment, any benefit in using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not within tests, where the type is concrete. |
||
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), true)); | ||
|
||
assert_eq!(Democracy::voters_for(r), vec![1]); | ||
|
@@ -598,7 +598,7 @@ mod tests { | |
fn cancel_referendum_should_work() { | ||
with_externalities(&mut new_test_ext(), || { | ||
System::set_block_number(1); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); | ||
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), true)); | ||
assert_ok!(Democracy::cancel_referendum(r.into())); | ||
|
||
|
@@ -612,7 +612,7 @@ mod tests { | |
fn simple_failing_should_work() { | ||
with_externalities(&mut new_test_ext(), || { | ||
System::set_block_number(1); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); | ||
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), false)); | ||
|
||
assert_eq!(Democracy::voters_for(r), vec![1]); | ||
|
@@ -629,7 +629,7 @@ mod tests { | |
fn controversial_voting_should_work() { | ||
with_externalities(&mut new_test_ext(), || { | ||
System::set_block_number(1); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); | ||
assert_ok!(Democracy::vote(Origin::signed(1), r.into(), true)); | ||
assert_ok!(Democracy::vote(Origin::signed(2), r.into(), false)); | ||
assert_ok!(Democracy::vote(Origin::signed(3), r.into(), false)); | ||
|
@@ -649,7 +649,7 @@ mod tests { | |
fn controversial_low_turnout_voting_should_work() { | ||
with_externalities(&mut new_test_ext(), || { | ||
System::set_block_number(1); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); | ||
assert_ok!(Democracy::vote(Origin::signed(5), r.into(), false)); | ||
assert_ok!(Democracy::vote(Origin::signed(6), r.into(), true)); | ||
|
||
|
@@ -668,7 +668,7 @@ mod tests { | |
assert_eq!(Balances::total_issuance(), 210); | ||
|
||
System::set_block_number(1); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove).unwrap(); | ||
let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); | ||
assert_ok!(Democracy::vote(Origin::signed(4), r.into(), true)); | ||
assert_ok!(Democracy::vote(Origin::signed(5), r.into(), false)); | ||
assert_ok!(Democracy::vote(Origin::signed(6), r.into(), true)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nitpick) typo
uncontroversial