mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 19:51:05 +00:00
Move Externalities into its own crate (#3775)
* Move `Externalities` into `substrate-externalities` - `Externalities` now support generic extensions - Split of `primtives-storage` for storage primitive types * Move the externalities scoping into `substrate-externalities` * Fix compilation * Review feedback * Adds macro for declaring extensions * Fix benchmarks * Introduce `ExtensionStore` trait * Last review comments * Implement it for `ExtensionStore`
This commit is contained in:
@@ -23,11 +23,9 @@ use support::{
|
||||
StorageValue, StorageMap, parameter_types, assert_ok,
|
||||
traits::{Get, ChangeMembers, Currency}
|
||||
};
|
||||
use runtime_io::with_externalities;
|
||||
use primitives::{H256, Blake2Hasher};
|
||||
use primitives::H256;
|
||||
use sr_primitives::{
|
||||
Perbill, BuildStorage,
|
||||
testing::Header,
|
||||
Perbill, BuildStorage, set_and_run_with_externalities, testing::Header,
|
||||
traits::{BlakeTwo256, IdentityLookup, Block as BlockT},
|
||||
};
|
||||
use crate as elections;
|
||||
@@ -213,7 +211,7 @@ impl ExtBuilder {
|
||||
self.desired_seats = seats;
|
||||
self
|
||||
}
|
||||
pub fn build(self) -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
pub fn build(self) -> runtime_io::TestExternalities {
|
||||
VOTER_BOND.with(|v| *v.borrow_mut() = self.voter_bond);
|
||||
VOTING_FEE.with(|v| *v.borrow_mut() = self.voting_fee);
|
||||
PRESENT_SLASH_PER_VOTER.with(|v| *v.borrow_mut() = self.bad_presentation_punishment);
|
||||
@@ -283,9 +281,9 @@ pub(crate) fn locks(who: &u64) -> Vec<u64> {
|
||||
Balances::locks(who).iter().map(|l| l.amount).collect::<Vec<u64>>()
|
||||
}
|
||||
|
||||
pub(crate) fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
pub(crate) fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities {
|
||||
let mut t = ExtBuilder::default().build();
|
||||
with_externalities(&mut t, || {
|
||||
set_and_run_with_externalities(&mut t, || {
|
||||
<elections::Candidates<Test>>::put(vec![0, 0, 1]);
|
||||
elections::CandidateCount::put(1);
|
||||
<elections::RegisterInfoOf<Test>>::insert(1, (0, 2));
|
||||
|
||||
@@ -22,11 +22,11 @@ use crate::mock::*;
|
||||
use crate::*;
|
||||
|
||||
use support::{assert_ok, assert_err, assert_noop};
|
||||
use runtime_io::with_externalities;
|
||||
use sr_primitives::set_and_run_with_externalities;
|
||||
|
||||
#[test]
|
||||
fn params_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
assert_eq!(Elections::next_vote_from(1), 4);
|
||||
assert_eq!(Elections::next_vote_from(4), 4);
|
||||
@@ -53,7 +53,7 @@ fn params_should_work() {
|
||||
|
||||
#[test]
|
||||
fn chunking_bool_to_flag_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
assert_eq!(Elections::bool_to_flag(vec![]), vec![]);
|
||||
assert_eq!(Elections::bool_to_flag(vec![false]), vec![0]);
|
||||
assert_eq!(Elections::bool_to_flag(vec![true]), vec![1]);
|
||||
@@ -98,7 +98,7 @@ fn chunking_bool_to_flag_should_work() {
|
||||
|
||||
#[test]
|
||||
fn chunking_voter_set_growth_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
|
||||
// create 65. 64 (set0) + 1 (set1)
|
||||
@@ -122,7 +122,7 @@ fn chunking_voter_set_growth_should_work() {
|
||||
|
||||
#[test]
|
||||
fn chunking_voter_set_reclaim_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
|
||||
(1..=129).for_each(|i| vote(i, 0));
|
||||
@@ -159,7 +159,7 @@ fn chunking_voter_set_reclaim_should_work() {
|
||||
|
||||
#[test]
|
||||
fn chunking_approvals_set_growth_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
// create candidates and voters.
|
||||
(1..=250).for_each(|i| create_candidate(i, (i-1) as u32));
|
||||
(1..=250).for_each(|i| vote(i, i as usize));
|
||||
@@ -221,7 +221,7 @@ fn chunking_approvals_set_growth_should_work() {
|
||||
|
||||
#[test]
|
||||
fn chunking_cell_status_works() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
|
||||
(1..=63).for_each(|i| vote(i, 0));
|
||||
@@ -240,7 +240,7 @@ fn chunking_cell_status_works() {
|
||||
|
||||
#[test]
|
||||
fn chunking_voter_index_does_not_take_holes_into_account() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
|
||||
// create 65. 64 (set0) + 1 (set1)
|
||||
@@ -265,7 +265,7 @@ fn chunking_voter_index_does_not_take_holes_into_account() {
|
||||
|
||||
#[test]
|
||||
fn chunking_approval_storage_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3), 1));
|
||||
|
||||
@@ -285,7 +285,7 @@ fn chunking_approval_storage_should_work() {
|
||||
|
||||
#[test]
|
||||
fn voting_initial_set_approvals_ignores_voter_index() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
|
||||
// Last argument is essentially irrelevant. You might get or miss a tip.
|
||||
@@ -299,7 +299,7 @@ fn voting_initial_set_approvals_ignores_voter_index() {
|
||||
}
|
||||
#[test]
|
||||
fn voting_bad_approval_index_slashes_voters_and_bond_reduces_stake() {
|
||||
with_externalities(&mut ExtBuilder::default().voting_fee(5).voter_bond(2).build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().voting_fee(5).voter_bond(2).build(), || {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
|
||||
(1..=63).for_each(|i| vote(i, 0));
|
||||
@@ -329,7 +329,7 @@ fn voting_bad_approval_index_slashes_voters_and_bond_reduces_stake() {
|
||||
|
||||
#[test]
|
||||
fn voting_subsequent_set_approvals_checks_voter_index() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
|
||||
assert_ok!(Elections::set_approvals(Origin::signed(3), vec![], 0, 0, 30));
|
||||
@@ -353,7 +353,7 @@ fn voting_subsequent_set_approvals_checks_voter_index() {
|
||||
|
||||
#[test]
|
||||
fn voting_cannot_lock_less_than_limit() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
|
||||
assert_noop!(
|
||||
@@ -366,7 +366,7 @@ fn voting_cannot_lock_less_than_limit() {
|
||||
|
||||
#[test]
|
||||
fn voting_locking_more_than_total_balance_is_moot() {
|
||||
with_externalities(&mut ExtBuilder::default().voter_bond(2).build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().voter_bond(2).build(), || {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
|
||||
assert_eq!(balances(&3), (30, 0));
|
||||
@@ -382,7 +382,7 @@ fn voting_locking_more_than_total_balance_is_moot() {
|
||||
|
||||
#[test]
|
||||
fn voting_locking_stake_and_reserving_bond_works() {
|
||||
with_externalities(&mut ExtBuilder::default().voter_bond(2).build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().voter_bond(2).build(), || {
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
|
||||
|
||||
assert_eq!(balances(&2), (20, 0));
|
||||
@@ -408,7 +408,7 @@ fn voting_locking_stake_and_reserving_bond_works() {
|
||||
|
||||
#[test]
|
||||
fn voting_without_any_candidate_count_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
|
||||
assert_eq!(Elections::candidates().len(), 0);
|
||||
@@ -422,7 +422,7 @@ fn voting_without_any_candidate_count_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn voting_setting_an_approval_vote_count_more_than_candidate_count_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
|
||||
@@ -437,7 +437,7 @@ fn voting_setting_an_approval_vote_count_more_than_candidate_count_should_not_wo
|
||||
|
||||
#[test]
|
||||
fn voting_resubmitting_approvals_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
|
||||
@@ -456,7 +456,7 @@ fn voting_resubmitting_approvals_should_work() {
|
||||
|
||||
#[test]
|
||||
fn voting_retracting_voter_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
|
||||
@@ -501,7 +501,7 @@ fn voting_retracting_voter_should_work() {
|
||||
|
||||
#[test]
|
||||
fn voting_invalid_retraction_index_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3), 0));
|
||||
|
||||
@@ -514,7 +514,7 @@ fn voting_invalid_retraction_index_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn voting_overflow_retraction_index_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3), 0));
|
||||
|
||||
@@ -525,7 +525,7 @@ fn voting_overflow_retraction_index_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn voting_non_voter_retraction_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3), 0));
|
||||
|
||||
@@ -536,7 +536,7 @@ fn voting_non_voter_retraction_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn retracting_inactive_voter_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
assert_ok!(Elections::set_approvals(Origin::signed(2), vec![true], 0, 0, 20));
|
||||
@@ -570,7 +570,7 @@ fn retracting_inactive_voter_should_work() {
|
||||
|
||||
#[test]
|
||||
fn retracting_inactive_voter_with_other_candidates_in_slots_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().voter_bond(2).build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().voter_bond(2).build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
assert_ok!(Elections::set_approvals(Origin::signed(2), vec![true], 0, 0, 20));
|
||||
@@ -605,7 +605,7 @@ fn retracting_inactive_voter_with_other_candidates_in_slots_should_work() {
|
||||
|
||||
#[test]
|
||||
fn retracting_inactive_voter_with_bad_reporter_index_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
assert_ok!(Elections::set_approvals(Origin::signed(2), vec![true], 0, 0, 20));
|
||||
@@ -634,7 +634,7 @@ fn retracting_inactive_voter_with_bad_reporter_index_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn retracting_inactive_voter_with_bad_target_index_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
assert_ok!(Elections::set_approvals(Origin::signed(2), vec![true], 0, 0, 20));
|
||||
@@ -663,7 +663,7 @@ fn retracting_inactive_voter_with_bad_target_index_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn retracting_active_voter_should_slash_reporter() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(3), 1));
|
||||
@@ -711,7 +711,7 @@ fn retracting_active_voter_should_slash_reporter() {
|
||||
|
||||
#[test]
|
||||
fn retracting_inactive_voter_by_nonvoter_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
assert_ok!(Elections::set_approvals(Origin::signed(2), vec![true], 0, 0, 20));
|
||||
@@ -740,7 +740,7 @@ fn retracting_inactive_voter_by_nonvoter_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn candidacy_simple_candidate_submission_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
assert_eq!(Elections::candidates(), Vec::<u64>::new());
|
||||
assert_eq!(Elections::candidate_reg_info(1), None);
|
||||
@@ -768,7 +768,7 @@ fn candidacy_simple_candidate_submission_should_work() {
|
||||
fn candidacy_submission_using_free_slot_should_work() {
|
||||
let mut t = new_test_ext_with_candidate_holes();
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
set_and_run_with_externalities(&mut t, || {
|
||||
System::set_block_number(1);
|
||||
assert_eq!(Elections::candidates(), vec![0, 0, 1]);
|
||||
|
||||
@@ -784,7 +784,7 @@ fn candidacy_submission_using_free_slot_should_work() {
|
||||
fn candidacy_submission_using_alternative_free_slot_should_work() {
|
||||
let mut t = new_test_ext_with_candidate_holes();
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
set_and_run_with_externalities(&mut t, || {
|
||||
System::set_block_number(1);
|
||||
assert_eq!(Elections::candidates(), vec![0, 0, 1]);
|
||||
|
||||
@@ -800,7 +800,7 @@ fn candidacy_submission_using_alternative_free_slot_should_work() {
|
||||
fn candidacy_submission_not_using_free_slot_should_not_work() {
|
||||
let mut t = new_test_ext_with_candidate_holes();
|
||||
|
||||
with_externalities(&mut t, || {
|
||||
set_and_run_with_externalities(&mut t, || {
|
||||
System::set_block_number(1);
|
||||
assert_noop!(
|
||||
Elections::submit_candidacy(Origin::signed(4), 3),
|
||||
@@ -811,7 +811,7 @@ fn candidacy_submission_not_using_free_slot_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn candidacy_bad_candidate_slot_submission_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
assert_eq!(Elections::candidates(), Vec::<u64>::new());
|
||||
assert_noop!(
|
||||
@@ -823,7 +823,7 @@ fn candidacy_bad_candidate_slot_submission_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn candidacy_non_free_candidate_slot_submission_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
assert_eq!(Elections::candidates(), Vec::<u64>::new());
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(1), 0));
|
||||
@@ -837,7 +837,7 @@ fn candidacy_non_free_candidate_slot_submission_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn candidacy_dupe_candidate_submission_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
assert_eq!(Elections::candidates(), Vec::<u64>::new());
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(1), 0));
|
||||
@@ -851,7 +851,7 @@ fn candidacy_dupe_candidate_submission_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn candidacy_poor_candidate_submission_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
assert_eq!(Elections::candidates(), Vec::<u64>::new());
|
||||
assert_noop!(
|
||||
@@ -863,7 +863,7 @@ fn candidacy_poor_candidate_submission_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn election_voting_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
|
||||
@@ -892,7 +892,7 @@ fn election_voting_should_work() {
|
||||
|
||||
#[test]
|
||||
fn election_proxy_voting_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(1);
|
||||
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 0));
|
||||
@@ -933,7 +933,7 @@ fn election_proxy_voting_should_work() {
|
||||
|
||||
#[test]
|
||||
fn election_simple_tally_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert!(!Elections::presentation_active());
|
||||
|
||||
@@ -972,7 +972,7 @@ fn election_simple_tally_should_work() {
|
||||
|
||||
#[test]
|
||||
fn election_seats_should_be_released() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 1));
|
||||
@@ -1006,7 +1006,7 @@ fn election_seats_should_be_released() {
|
||||
|
||||
#[test]
|
||||
fn election_presentations_with_zero_staked_deposit_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
assert_ok!(Elections::set_approvals(Origin::signed(2), vec![true], 0, 0, 20));
|
||||
@@ -1022,7 +1022,7 @@ fn election_presentations_with_zero_staked_deposit_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn election_double_presentations_should_be_punished() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
assert!(Balances::can_slash(&4, 10));
|
||||
|
||||
System::set_block_number(4);
|
||||
@@ -1045,7 +1045,7 @@ fn election_double_presentations_should_be_punished() {
|
||||
|
||||
#[test]
|
||||
fn election_presenting_for_double_election_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_eq!(Elections::submit_candidacy(Origin::signed(2), 0), Ok(()));
|
||||
assert_ok!(Elections::set_approvals(Origin::signed(2), vec![true], 0, 0, 20));
|
||||
@@ -1072,7 +1072,7 @@ fn election_presenting_for_double_election_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn election_presenting_loser_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(1), 0));
|
||||
assert_ok!(Elections::set_approvals(Origin::signed(6), vec![true], 0, 0, 60));
|
||||
@@ -1105,7 +1105,7 @@ fn election_presenting_loser_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn election_presenting_loser_first_should_not_matter() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(1), 0));
|
||||
assert_ok!(Elections::set_approvals(Origin::signed(6), vec![true], 0, 0, 60));
|
||||
@@ -1137,7 +1137,7 @@ fn election_presenting_loser_first_should_not_matter() {
|
||||
|
||||
#[test]
|
||||
fn election_present_outside_of_presentation_period_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert!(!Elections::presentation_active());
|
||||
assert_noop!(
|
||||
@@ -1149,7 +1149,7 @@ fn election_present_outside_of_presentation_period_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn election_present_with_invalid_vote_index_should_not_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(2), 0));
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(5), 1));
|
||||
@@ -1165,7 +1165,7 @@ fn election_present_with_invalid_vote_index_should_not_work() {
|
||||
#[test]
|
||||
fn election_present_when_presenter_is_poor_should_not_work() {
|
||||
let test_present = |p| {
|
||||
with_externalities(&mut ExtBuilder::default()
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default()
|
||||
.voting_fee(5)
|
||||
.voter_bond(2)
|
||||
.bad_presentation_punishment(p)
|
||||
@@ -1199,7 +1199,7 @@ fn election_present_when_presenter_is_poor_should_not_work() {
|
||||
|
||||
#[test]
|
||||
fn election_invalid_present_tally_should_slash() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert!(!Elections::presentation_active());
|
||||
assert_eq!(Balances::total_balance(&4), 40);
|
||||
@@ -1219,7 +1219,7 @@ fn election_invalid_present_tally_should_slash() {
|
||||
|
||||
#[test]
|
||||
fn election_runners_up_should_be_kept() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert!(!Elections::presentation_active());
|
||||
|
||||
@@ -1280,7 +1280,7 @@ fn election_runners_up_should_be_kept() {
|
||||
|
||||
#[test]
|
||||
fn election_second_tally_should_use_runners_up() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
System::set_block_number(4);
|
||||
assert_ok!(Elections::submit_candidacy(Origin::signed(1), 0));
|
||||
assert_ok!(Elections::set_approvals(Origin::signed(6), vec![true], 0, 0, 60));
|
||||
@@ -1335,7 +1335,7 @@ fn election_second_tally_should_use_runners_up() {
|
||||
|
||||
#[test]
|
||||
fn election_loser_candidates_bond_gets_slashed() {
|
||||
with_externalities(&mut ExtBuilder::default().desired_seats(1).build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().desired_seats(1).build(), || {
|
||||
System::set_block_number(4);
|
||||
assert!(!Elections::presentation_active());
|
||||
|
||||
@@ -1374,7 +1374,7 @@ fn election_loser_candidates_bond_gets_slashed() {
|
||||
|
||||
#[test]
|
||||
fn pot_accumulating_weight_and_decaying_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().balance_factor(10).build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().balance_factor(10).build(), || {
|
||||
System::set_block_number(4);
|
||||
assert!(!Elections::presentation_active());
|
||||
|
||||
@@ -1502,7 +1502,7 @@ fn pot_accumulating_weight_and_decaying_should_work() {
|
||||
|
||||
#[test]
|
||||
fn pot_winning_resets_accumulated_pot() {
|
||||
with_externalities(&mut ExtBuilder::default().balance_factor(10).build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().balance_factor(10).build(), || {
|
||||
System::set_block_number(4);
|
||||
assert!(!Elections::presentation_active());
|
||||
|
||||
@@ -1564,7 +1564,7 @@ fn pot_winning_resets_accumulated_pot() {
|
||||
|
||||
#[test]
|
||||
fn pot_resubmitting_approvals_stores_pot() {
|
||||
with_externalities(&mut ExtBuilder::default()
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default()
|
||||
.voter_bond(0)
|
||||
.voting_fee(0)
|
||||
.balance_factor(10)
|
||||
@@ -1629,7 +1629,7 @@ fn pot_resubmitting_approvals_stores_pot() {
|
||||
|
||||
#[test]
|
||||
fn pot_get_offset_should_work() {
|
||||
with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().build(), || {
|
||||
assert_eq!(Elections::get_offset(100, 0), 0);
|
||||
assert_eq!(Elections::get_offset(100, 1), 96);
|
||||
assert_eq!(Elections::get_offset(100, 2), 96 + 93);
|
||||
@@ -1653,7 +1653,7 @@ fn pot_get_offset_should_work() {
|
||||
|
||||
#[test]
|
||||
fn pot_get_offset_with_zero_decay() {
|
||||
with_externalities(&mut ExtBuilder::default().decay_ratio(0).build(), || {
|
||||
set_and_run_with_externalities(&mut ExtBuilder::default().decay_ratio(0).build(), || {
|
||||
assert_eq!(Elections::get_offset(100, 0), 0);
|
||||
assert_eq!(Elections::get_offset(100, 1), 0);
|
||||
assert_eq!(Elections::get_offset(100, 2), 0);
|
||||
|
||||
Reference in New Issue
Block a user