Migrate more pallet tests to construct_runtime (#8051)

* Migrate bounties tests to use construct_runtime

* Migrate contracts tests to use construct_runtime

* Migrate democracy tests to use construct_runtime

* review: rename TreasuryEvent -> TreasuryError
This commit is contained in:
Andrew Jones
2021-02-04 16:34:15 +00:00
committed by GitHub
parent 86498a1a0c
commit e5ef38330d
4 changed files with 105 additions and 141 deletions
+19 -35
View File
@@ -17,11 +17,12 @@
//! The crate's tests.
use crate as pallet_democracy;
use super::*;
use codec::Encode;
use frame_support::{
impl_outer_origin, impl_outer_dispatch, assert_noop, assert_ok, parameter_types,
impl_outer_event, ord_parameter_types, traits::{Contains, OnInitialize, Filter},
assert_noop, assert_ok, parameter_types, ord_parameter_types,
traits::{Contains, OnInitialize, Filter},
weights::Weight,
};
use sp_core::H256;
@@ -50,30 +51,21 @@ const BIG_NAY: Vote = Vote { aye: false, conviction: Conviction::Locked1x };
const MAX_PROPOSALS: u32 = 100;
impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
}
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
impl_outer_dispatch! {
pub enum Call for Test where origin: Origin {
frame_system::System,
pallet_balances::Balances,
democracy::Democracy,
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Scheduler: pallet_scheduler::{Module, Call, Storage, Config, Event<T>},
Democracy: pallet_democracy::{Module, Call, Storage, Config, Event<T>},
}
}
mod democracy {
pub use crate::Event;
}
impl_outer_event! {
pub enum Event for Test {
system<T>,
pallet_balances<T>,
pallet_scheduler<T>,
democracy<T>,
}
}
);
// Test that a fitlered call can be dispatched.
pub struct BaseFilter;
@@ -83,9 +75,6 @@ impl Filter<Call> for BaseFilter {
}
}
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, Eq, PartialEq, Debug)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
@@ -108,7 +97,7 @@ impl frame_system::Config for Test {
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
@@ -169,7 +158,7 @@ impl Contains<u64> for OneToFive {
fn add(_m: &u64) {}
}
impl super::Config for Test {
impl Config for Test {
type Proposal = Call;
type Event = Event;
type Currency = pallet_balances::Module<Self>;
@@ -204,7 +193,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
pallet_balances::GenesisConfig::<Test>{
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
}.assimilate_storage(&mut t).unwrap();
GenesisConfig::default().assimilate_storage(&mut t).unwrap();
pallet_democracy::GenesisConfig::default().assimilate_storage(&mut t).unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
@@ -216,11 +205,6 @@ pub fn new_test_ext_execute_with_cond(execute: impl FnOnce(bool) -> () + Clone)
new_test_ext().execute_with(|| execute(true));
}
type System = frame_system::Module<Test>;
type Balances = pallet_balances::Module<Test>;
type Scheduler = pallet_scheduler::Module<Test>;
type Democracy = Module<Test>;
#[test]
fn params_should_work() {
new_test_ext().execute_with(|| {