mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 07:01:03 +00:00
Post-condition checking for some pallets (#5591)
* add pre/post condition check to elections * Tests for staking * Better intersection fn * Fix build
This commit is contained in:
@@ -1083,7 +1083,7 @@ mod tests {
|
||||
self.genesis_members = members;
|
||||
self
|
||||
}
|
||||
pub fn build(self) -> sp_io::TestExternalities {
|
||||
pub fn build_and_execute(self, test: impl FnOnce() -> ()) {
|
||||
VOTING_BOND.with(|v| *v.borrow_mut() = self.voter_bond);
|
||||
TERM_DURATION.with(|v| *v.borrow_mut() = self.term_duration);
|
||||
DESIRED_RUNNERS_UP.with(|v| *v.borrow_mut() = self.desired_runners_up);
|
||||
@@ -1103,8 +1103,9 @@ mod tests {
|
||||
members: self.genesis_members
|
||||
}),
|
||||
}.build_storage().unwrap().into();
|
||||
ext.execute_with(|| System::set_block_number(1));
|
||||
ext
|
||||
ext.execute_with(pre_conditions);
|
||||
ext.execute_with(test);
|
||||
ext.execute_with(post_conditions)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1122,9 +1123,55 @@ mod tests {
|
||||
lock.amount
|
||||
}
|
||||
|
||||
fn intersects<T: PartialEq>(a: &[T], b: &[T]) -> bool {
|
||||
a.iter().any(|e| b.contains(e))
|
||||
}
|
||||
|
||||
fn ensure_members_sorted() {
|
||||
let mut members = Elections::members().clone();
|
||||
members.sort();
|
||||
assert_eq!(Elections::members(), members);
|
||||
}
|
||||
|
||||
fn ensure_candidates_sorted() {
|
||||
let mut candidates = Elections::candidates().clone();
|
||||
candidates.sort();
|
||||
assert_eq!(Elections::candidates(), candidates);
|
||||
}
|
||||
|
||||
fn ensure_members_has_approval_stake() {
|
||||
// we filter members that have no approval state. This means that even we have more seats
|
||||
// than candidates, we will never ever chose a member with no votes.
|
||||
assert!(
|
||||
Elections::members().iter().chain(
|
||||
Elections::runners_up().iter()
|
||||
).all(|(_, s)| *s != Zero::zero())
|
||||
);
|
||||
}
|
||||
|
||||
fn ensure_member_candidates_runners_up_disjoint() {
|
||||
// members, candidates and runners-up must always be disjoint sets.
|
||||
assert!(!intersects(&Elections::members_ids(), &Elections::candidates()));
|
||||
assert!(!intersects(&Elections::members_ids(), &Elections::runners_up_ids()));
|
||||
assert!(!intersects(&Elections::candidates(), &Elections::runners_up_ids()));
|
||||
}
|
||||
|
||||
fn pre_conditions() {
|
||||
System::set_block_number(1);
|
||||
ensure_members_sorted();
|
||||
ensure_candidates_sorted();
|
||||
}
|
||||
|
||||
fn post_conditions() {
|
||||
ensure_members_sorted();
|
||||
ensure_candidates_sorted();
|
||||
ensure_member_candidates_runners_up_disjoint();
|
||||
ensure_members_has_approval_stake();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn params_should_work() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(Elections::desired_members(), 2);
|
||||
assert_eq!(Elections::term_duration(), 5);
|
||||
assert_eq!(Elections::election_rounds(), 0);
|
||||
@@ -1143,7 +1190,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn genesis_members_should_work() {
|
||||
ExtBuilder::default().genesis_members(vec![(1, 10), (2, 20)]).build().execute_with(|| {
|
||||
ExtBuilder::default().genesis_members(vec![(1, 10), (2, 20)]).build_and_execute(|| {
|
||||
System::set_block_number(1);
|
||||
assert_eq!(Elections::members(), vec![(1, 10), (2, 20)]);
|
||||
|
||||
@@ -1160,7 +1207,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn genesis_members_unsorted_should_work() {
|
||||
ExtBuilder::default().genesis_members(vec![(2, 20), (1, 10)]).build().execute_with(|| {
|
||||
ExtBuilder::default().genesis_members(vec![(2, 20), (1, 10)]).build_and_execute(|| {
|
||||
System::set_block_number(1);
|
||||
assert_eq!(Elections::members(), vec![(1, 10), (2, 20)]);
|
||||
|
||||
@@ -1179,28 +1226,27 @@ mod tests {
|
||||
#[should_panic = "Genesis member does not have enough stake"]
|
||||
fn genesis_members_cannot_over_stake_0() {
|
||||
// 10 cannot lock 20 as their stake and extra genesis will panic.
|
||||
ExtBuilder::default().genesis_members(vec![(1, 20), (2, 20)]).build();
|
||||
ExtBuilder::default().genesis_members(vec![(1, 20), (2, 20)]).build_and_execute(|| {});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn genesis_members_cannot_over_stake_1() {
|
||||
// 10 cannot reserve 20 as voting bond and extra genesis will panic.
|
||||
ExtBuilder::default().voter_bond(20).genesis_members(vec![(1, 10), (2, 20)]).build();
|
||||
ExtBuilder::default().voter_bond(20).genesis_members(vec![(1, 10), (2, 20)]).build_and_execute(|| {});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic = "Duplicate member in elections phragmen genesis: 2"]
|
||||
fn genesis_members_cannot_be_duplicate() {
|
||||
ExtBuilder::default().genesis_members(vec![(1, 10), (2, 10), (2, 10)]).build();
|
||||
ExtBuilder::default().genesis_members(vec![(1, 10), (2, 10), (2, 10)]).build_and_execute(|| {});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn term_duration_zero_is_passive() {
|
||||
ExtBuilder::default()
|
||||
.term_duration(0)
|
||||
.build()
|
||||
.execute_with(||
|
||||
.build_and_execute(||
|
||||
{
|
||||
assert_eq!(Elections::term_duration(), 0);
|
||||
assert_eq!(Elections::desired_members(), 2);
|
||||
@@ -1221,7 +1267,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn simple_candidate_submission_should_work() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(Elections::candidates(), Vec::<u64>::new());
|
||||
assert!(Elections::is_candidate(&1).is_err());
|
||||
assert!(Elections::is_candidate(&2).is_err());
|
||||
@@ -1248,7 +1294,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn simple_candidate_submission_with_no_votes_should_work() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(Elections::candidates(), Vec::<u64>::new());
|
||||
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(1)));
|
||||
@@ -1275,7 +1321,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn dupe_candidate_submission_should_not_work() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(Elections::candidates(), Vec::<u64>::new());
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(1)));
|
||||
assert_eq!(Elections::candidates(), vec![1]);
|
||||
@@ -1289,7 +1335,7 @@ mod tests {
|
||||
#[test]
|
||||
fn member_candidacy_submission_should_not_work() {
|
||||
// critically important to make sure that outgoing candidates and losers are not mixed up.
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::vote(Origin::signed(2), vec![5], 20));
|
||||
|
||||
@@ -1309,7 +1355,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn runner_candidate_submission_should_not_work() {
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -1332,7 +1378,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn poor_candidate_submission_should_not_work() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(Elections::candidates(), Vec::<u64>::new());
|
||||
assert_noop!(
|
||||
Elections::submit_candidacy(Origin::signed(7)),
|
||||
@@ -1343,7 +1389,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn simple_voting_should_work() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(Elections::candidates(), Vec::<u64>::new());
|
||||
assert_eq!(balances(&2), (20, 0));
|
||||
|
||||
@@ -1357,7 +1403,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_vote_with_custom_stake() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(Elections::candidates(), Vec::<u64>::new());
|
||||
assert_eq!(balances(&2), (20, 0));
|
||||
|
||||
@@ -1371,7 +1417,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_update_votes_and_stake() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(balances(&2), (20, 0));
|
||||
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
@@ -1392,7 +1438,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn cannot_vote_for_no_candidate() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_noop!(
|
||||
Elections::vote(Origin::signed(2), vec![], 20),
|
||||
Error::<Test>::UnableToVote,
|
||||
@@ -1402,7 +1448,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_vote_for_old_members_even_when_no_new_candidates() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
|
||||
@@ -1420,7 +1466,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn prime_works() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
@@ -1444,7 +1490,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn prime_votes_for_exiting_members_are_removed() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
@@ -1469,7 +1515,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn cannot_vote_for_more_than_candidates() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
|
||||
@@ -1482,7 +1528,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn cannot_vote_for_less_than_ed() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
|
||||
@@ -1495,7 +1541,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_vote_for_more_than_total_balance_but_moot() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
|
||||
@@ -1508,7 +1554,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn remove_voter_should_work() {
|
||||
ExtBuilder::default().voter_bond(8).build().execute_with(|| {
|
||||
ExtBuilder::default().voter_bond(8).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
|
||||
assert_ok!(Elections::vote(Origin::signed(2), vec![5], 20));
|
||||
@@ -1533,14 +1579,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn non_voter_remove_should_not_work() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_noop!(Elections::remove_voter(Origin::signed(3)), Error::<Test>::MustBeVoter);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dupe_remove_should_fail() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::vote(Origin::signed(2), vec![5], 20));
|
||||
|
||||
@@ -1553,7 +1599,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn removed_voter_should_not_be_counted() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -1573,7 +1619,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn reporter_must_be_voter() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_noop!(
|
||||
Elections::report_defunct_voter(Origin::signed(1), 2),
|
||||
Error::<Test>::MustBeVoter,
|
||||
@@ -1583,7 +1629,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_detect_defunct_voter() {
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(6)));
|
||||
@@ -1622,7 +1668,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn report_voter_should_work_and_earn_reward() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
|
||||
@@ -1653,7 +1699,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn report_voter_should_slash_when_bad_report() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
|
||||
@@ -1682,7 +1728,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn simple_voting_rounds_should_work() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -1717,7 +1763,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn defunct_voter_will_be_counted() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
|
||||
// This guy's vote is pointless for this round.
|
||||
@@ -1745,7 +1791,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn only_desired_seats_are_chosen() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -1766,7 +1812,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn phragmen_should_not_self_vote() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
|
||||
@@ -1781,7 +1827,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn runners_up_should_be_kept() {
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -1808,7 +1854,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn runners_up_should_be_next_candidates() {
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -1835,7 +1881,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn runners_up_lose_bond_once_outgoing() {
|
||||
ExtBuilder::default().desired_runners_up(1).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(1).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2)));
|
||||
@@ -1863,7 +1909,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn members_lose_bond_once_outgoing() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_eq!(balances(&5), (50, 0));
|
||||
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
@@ -1889,7 +1935,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn losers_will_lose_the_bond() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
|
||||
@@ -1912,7 +1958,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn current_members_are_always_next_candidate() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
|
||||
@@ -1948,7 +1994,7 @@ mod tests {
|
||||
fn election_state_is_uninterrupted() {
|
||||
// what I mean by uninterrupted:
|
||||
// given no input or stimulants the same members are re-elected.
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -1981,7 +2027,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn remove_members_triggers_election() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
|
||||
@@ -2007,7 +2053,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn seats_should_be_released_when_no_vote() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -2041,7 +2087,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn incoming_outgoing_are_reported() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
|
||||
@@ -2088,7 +2134,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn invalid_votes_are_moot() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
|
||||
@@ -2106,7 +2152,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn members_are_sorted_based_on_id_runners_on_merit() {
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -2128,7 +2174,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn candidates_are_sorted() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
|
||||
@@ -2144,7 +2190,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn runner_up_replacement_maintains_members_order() {
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2)));
|
||||
@@ -2164,7 +2210,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn runner_up_replacement_works_when_out_of_order() {
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -2185,7 +2231,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_renounce_candidacy_member_with_runners_bond_is_refunded() {
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -2212,7 +2258,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_renounce_candidacy_member_without_runners_bond_is_refunded() {
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
|
||||
@@ -2244,7 +2290,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_renounce_candidacy_runner() {
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(4)));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3)));
|
||||
@@ -2271,7 +2317,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn can_renounce_candidacy_candidate() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5)));
|
||||
assert_eq!(balances(&5), (47, 3));
|
||||
assert_eq!(Elections::candidates(), vec![5]);
|
||||
@@ -2284,7 +2330,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn wrong_renounce_candidacy_should_fail() {
|
||||
ExtBuilder::default().build().execute_with(|| {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
assert_noop!(
|
||||
Elections::renounce_candidacy(Origin::signed(5)),
|
||||
Error::<Test>::InvalidOrigin,
|
||||
@@ -2294,7 +2340,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn behavior_with_dupe_candidate() {
|
||||
ExtBuilder::default().desired_runners_up(2).build().execute_with(|| {
|
||||
ExtBuilder::default().desired_runners_up(2).build_and_execute(|| {
|
||||
<Candidates<Test>>::put(vec![1, 1, 2, 3, 4]);
|
||||
|
||||
assert_ok!(Elections::vote(Origin::signed(5), vec![1], 50));
|
||||
|
||||
Reference in New Issue
Block a user