Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
unit test: instant fast track to the next block referendum is backed
  • Loading branch information
muharem committed Jun 22, 2022
commit 2e06e88f26c5ea482c9deffcd0ca79ecd67aae97
54 changes: 54 additions & 0 deletions frame/democracy/src/tests/fast_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,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 affect 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 backed 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(|| {
Expand Down