Make pallet use construct_runtime in tests instead of impl_* (#7986)

This commit is contained in:
Guillaume Thiolliere
2021-01-26 15:25:04 +01:00
committed by GitHub
parent 6ae24c91e9
commit b1888395e8
18 changed files with 304 additions and 351 deletions
+24 -43
View File
@@ -18,8 +18,9 @@
//! Test utilities
use crate::*;
use crate as staking;
use frame_support::{
assert_ok, impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types,
assert_ok, parameter_types,
traits::{Currency, FindAuthor, Get, OnFinalize, OnInitialize},
weights::{constants::RocksDbWeight, Weight},
IterableStorageMap, StorageDoubleMap, StorageMap, StorageValue,
@@ -87,32 +88,22 @@ pub fn is_disabled(controller: AccountId) -> bool {
SESSION.with(|d| d.borrow().1.contains(&stash))
}
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 {
staking::Staking,
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Staking: staking::{Module, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
}
}
mod staking {
// Re-export needed for `impl_outer_event!`.
pub use super::super::*;
}
use frame_system as system;
use pallet_balances as balances;
use pallet_session as session;
impl_outer_event! {
pub enum MetaEvent for Test {
system<T>,
balances<T>,
session,
staking<T>,
}
}
);
/// Author of block is always 11
pub struct Author11;
@@ -124,10 +115,6 @@ impl FindAuthor<AccountId> for Author11 {
}
}
// 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 =
@@ -158,10 +145,10 @@ impl frame_system::Config for Test {
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = MetaEvent;
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
@@ -171,7 +158,7 @@ impl frame_system::Config for Test {
impl pallet_balances::Config for Test {
type MaxLocks = MaxLocks;
type Balance = Balance;
type Event = MetaEvent;
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
@@ -191,7 +178,7 @@ impl pallet_session::Config for Test {
type Keys = SessionKeys;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type SessionHandler = (OtherSessionHandler,);
type Event = MetaEvent;
type Event = Event;
type ValidatorId = AccountId;
type ValidatorIdOf = crate::StashOf<Test>;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
@@ -257,7 +244,7 @@ impl Config for Test {
type UnixTime = Timestamp;
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
type RewardRemainder = RewardRemainderMock;
type Event = MetaEvent;
type Event = Event;
type Slash = ();
type Reward = ();
type SessionsPerEra = SessionsPerEra;
@@ -450,7 +437,7 @@ impl ExtBuilder {
(101, 100, balance_factor * 500, StakerStatus::<AccountId>::Nominator(nominated))
];
}
let _ = GenesisConfig::<Test>{
let _ = staking::GenesisConfig::<Test>{
stakers: stakers,
validator_count: self.validator_count,
minimum_validator_count: self.minimum_validator_count,
@@ -495,12 +482,6 @@ impl ExtBuilder {
}
}
pub type System = frame_system::Module<Test>;
pub type Balances = pallet_balances::Module<Test>;
pub type Session = pallet_session::Module<Test>;
pub type Timestamp = pallet_timestamp::Module<Test>;
pub type Staking = Module<Test>;
fn post_conditions() {
check_nominators();
check_exposures();
@@ -1016,9 +997,9 @@ macro_rules! assert_session_era {
};
}
pub(crate) fn staking_events() -> Vec<Event<Test>> {
pub(crate) fn staking_events() -> Vec<staking::Event<Test>> {
System::events().into_iter().map(|r| r.event).filter_map(|e| {
if let MetaEvent::staking(inner) = e {
if let Event::staking(inner) = e {
Some(inner)
} else {
None
+7 -4
View File
@@ -3181,7 +3181,7 @@ mod offchain_election {
.into_iter()
.map(|r| r.event)
.filter_map(|e| {
if let MetaEvent::staking(inner) = e {
if let mock::Event::staking(inner) = e {
Some(inner)
} else {
None
@@ -3266,7 +3266,7 @@ mod offchain_election {
.into_iter()
.map(|r| r.event)
.filter_map(|e| {
if let MetaEvent::staking(inner) = e {
if let mock::Event::staking(inner) = e {
Some(inner)
} else {
None
@@ -3285,7 +3285,7 @@ mod offchain_election {
.into_iter()
.map(|r| r.event)
.filter_map(|e| {
if let MetaEvent::staking(inner) = e {
if let mock::Event::staking(inner) = e {
Some(inner)
} else {
None
@@ -3322,7 +3322,7 @@ mod offchain_election {
.into_iter()
.map(|r| r.event)
.filter_map(|e| {
if let MetaEvent::staking(inner) = e {
if let mock::Event::staking(inner) = e {
Some(inner)
} else {
None
@@ -3458,6 +3458,7 @@ mod offchain_election {
let call = extrinsic.call;
let inner = match call {
mock::Call::Staking(inner) => inner,
_ => unreachable!(),
};
assert_eq!(
@@ -3501,6 +3502,7 @@ mod offchain_election {
let call = extrinsic.call;
let inner = match call {
mock::Call::Staking(inner) => inner,
_ => unreachable!(),
};
assert_eq!(
@@ -3548,6 +3550,7 @@ mod offchain_election {
let call = extrinsic.call;
let inner = match call {
mock::Call::Staking(inner) => inner,
_ => unreachable!(),
};
// pass this call to ValidateUnsigned