mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 12:27:56 +00:00
Democracy.fast_track not allowed with zero voting period (#11666)
* Democracy.fast_track not allowed with zero voting period * revert static parameter alter line * ensure voting period greater zero * update doc for fast_track * unit test: instant fast track to the next block referendum is backed * fix typos in comments
This commit is contained in:
@@ -600,6 +600,8 @@ pub mod pallet {
|
||||
MaxVotesReached,
|
||||
/// Maximum number of proposals reached.
|
||||
TooManyProposals,
|
||||
/// Voting period too low
|
||||
VotingPeriodLow,
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
@@ -800,8 +802,9 @@ pub mod pallet {
|
||||
/// The dispatch of this call must be `FastTrackOrigin`.
|
||||
///
|
||||
/// - `proposal_hash`: The hash of the current external proposal.
|
||||
/// - `voting_period`: The period that is allowed for voting on this proposal. Increased to
|
||||
/// `FastTrackVotingPeriod` if too low.
|
||||
/// - `voting_period`: The period that is allowed for voting on this proposal.
|
||||
/// Must be always greater than zero.
|
||||
/// For `FastTrackOrigin` must be equal or greater than `FastTrackVotingPeriod`.
|
||||
/// - `delay`: The number of block after voting has ended in approval and this should be
|
||||
/// enacted. This doesn't have a minimum amount.
|
||||
///
|
||||
@@ -830,7 +833,7 @@ pub mod pallet {
|
||||
T::InstantOrigin::ensure_origin(ensure_instant)?;
|
||||
ensure!(T::InstantAllowed::get(), Error::<T>::InstantNotAllowed);
|
||||
}
|
||||
|
||||
ensure!(voting_period > T::BlockNumber::zero(), Error::<T>::VotingPeriodLow);
|
||||
let (e_proposal_hash, threshold) =
|
||||
<NextExternal<T>>::get().ok_or(Error::<T>::ProposalMissing)?;
|
||||
ensure!(
|
||||
|
||||
@@ -67,6 +67,10 @@ fn instant_referendum_works() {
|
||||
Error::<Test>::InstantNotAllowed
|
||||
);
|
||||
INSTANT_ALLOWED.with(|v| *v.borrow_mut() = true);
|
||||
assert_noop!(
|
||||
Democracy::fast_track(Origin::signed(6), h, 0, 0),
|
||||
Error::<Test>::VotingPeriodLow
|
||||
);
|
||||
assert_ok!(Democracy::fast_track(Origin::signed(6), h, 1, 0));
|
||||
assert_eq!(
|
||||
Democracy::referendum_status(0),
|
||||
@@ -81,6 +85,60 @@ fn instant_referendum_works() {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn instant_next_block_referendum_backed() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// arrange
|
||||
let start_block_number = 10;
|
||||
let majority_origin_id = 3;
|
||||
let instant_origin_id = 6;
|
||||
let voting_period = 1;
|
||||
let proposal_hash = set_balance_proposal_hash_and_note(2);
|
||||
let delay = 2; // has no effect on test
|
||||
|
||||
// init
|
||||
System::set_block_number(start_block_number);
|
||||
InstantAllowed::set(true);
|
||||
|
||||
// propose with majority origin
|
||||
assert_ok!(Democracy::external_propose_majority(
|
||||
Origin::signed(majority_origin_id),
|
||||
proposal_hash
|
||||
));
|
||||
|
||||
// fast track with instant origin and voting period pointing to the next block
|
||||
assert_ok!(Democracy::fast_track(
|
||||
Origin::signed(instant_origin_id),
|
||||
proposal_hash,
|
||||
voting_period,
|
||||
delay
|
||||
));
|
||||
|
||||
// fetch the status of the only referendum at index 0
|
||||
assert_eq!(
|
||||
Democracy::referendum_status(0),
|
||||
Ok(ReferendumStatus {
|
||||
end: start_block_number + voting_period,
|
||||
proposal_hash,
|
||||
threshold: VoteThreshold::SimpleMajority,
|
||||
delay,
|
||||
tally: Tally { ayes: 0, nays: 0, turnout: 0 },
|
||||
})
|
||||
);
|
||||
|
||||
// referendum expected to be baked with the start of the next block
|
||||
next_block();
|
||||
|
||||
// assert no active referendums
|
||||
assert_noop!(Democracy::referendum_status(0), Error::<Test>::ReferendumInvalid);
|
||||
// the only referendum in the storage is finished and not approved
|
||||
assert_eq!(
|
||||
ReferendumInfoOf::<Test>::get(0).unwrap(),
|
||||
ReferendumInfo::Finished { approved: false, end: start_block_number + voting_period }
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fast_track_referendum_fails_when_no_simple_majority() {
|
||||
new_test_ext().execute_with(|| {
|
||||
|
||||
Reference in New Issue
Block a user