diff --git a/Cargo.lock b/Cargo.lock index 9d29777fd5bc2..c938978802df5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4860,6 +4860,7 @@ dependencies = [ "frame-system", "parity-scale-codec", "safe-mix", + "serde", "sp-core", "sp-io", "sp-runtime", diff --git a/frame/randomness-collective-flip/Cargo.toml b/frame/randomness-collective-flip/Cargo.toml index 0f6b48ff0757a..9d2683a8a8f85 100644 --- a/frame/randomness-collective-flip/Cargo.toml +++ b/frame/randomness-collective-flip/Cargo.toml @@ -23,6 +23,7 @@ sp-std = { version = "2.0.0", default-features = false, path = "../../primitives [dev-dependencies] sp-core = { version = "2.0.0", path = "../../primitives/core" } sp-io = { version = "2.0.0", path = "../../primitives/io" } +serde = { version = "1.0.101" } [features] default = ["std"] diff --git a/frame/randomness-collective-flip/src/lib.rs b/frame/randomness-collective-flip/src/lib.rs index b3eb64db9a0ce..0dba6727da60a 100644 --- a/frame/randomness-collective-flip/src/lib.rs +++ b/frame/randomness-collective-flip/src/lib.rs @@ -132,6 +132,7 @@ impl Randomness for Module { #[cfg(test)] mod tests { + use crate as pallet_randomness_collective_flip; use super::*; use sp_core::H256; use sp_runtime::{ @@ -139,16 +140,21 @@ mod tests { traits::{BlakeTwo256, Header as _, IdentityLookup}, }; use frame_system::limits; - use frame_support::{ - impl_outer_origin, parameter_types, traits::{Randomness, OnInitialize}, - }; - - #[derive(Clone, PartialEq, Eq)] - pub struct Test; - - impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} - } + use frame_support::{parameter_types, traits::{Randomness, OnInitialize}}; + + type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + type Block = frame_system::mocking::MockBlock; + + frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + CollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage}, + } + ); parameter_types! { pub const BlockHashCount: u64 = 250; @@ -166,16 +172,16 @@ mod tests { type Origin = Origin; type Index = u64; type BlockNumber = u64; - type Call = (); + type Call = Call; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); @@ -183,9 +189,6 @@ mod tests { type SS58Prefix = (); } - type System = frame_system::Module; - type CollectiveFlip = Module; - fn new_test_ext() -> sp_io::TestExternalities { let t = frame_system::GenesisConfig::default().build_storage::().unwrap(); t.into() diff --git a/frame/recovery/src/mock.rs b/frame/recovery/src/mock.rs index 38b5d58ddda54..ee38b0e24cc60 100644 --- a/frame/recovery/src/mock.rs +++ b/frame/recovery/src/mock.rs @@ -19,36 +19,27 @@ use super::*; -use frame_support::{ - impl_outer_origin, impl_outer_dispatch, impl_outer_event, parameter_types, - traits::{OnInitialize, OnFinalize}, -}; +use frame_support::{parameter_types, traits::{OnInitialize, OnFinalize}}; use sp_core::H256; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, testing::Header, }; use crate as recovery; -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} - -impl_outer_event! { - pub enum TestEvent for Test { - system, - pallet_balances, - recovery, - } -} -impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - pallet_balances::Balances, - recovery::Recovery, +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Recovery: recovery::{Module, Call, Storage, Event}, } -} - -#[derive(Clone, Eq, PartialEq)] -pub struct Test; +); parameter_types! { pub const BlockHashCount: u64 = 250; @@ -70,10 +61,10 @@ impl frame_system::Config for Test { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = TestEvent; + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -89,7 +80,7 @@ impl pallet_balances::Config for Test { type MaxLocks = (); type Balance = u128; type DustRemoval = (); - type Event = TestEvent; + type Event = Event; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); @@ -103,7 +94,7 @@ parameter_types! { } impl Config for Test { - type Event = TestEvent; + type Event = Event; type Call = Call; type Currency = Balances; type ConfigDepositBase = ConfigDepositBase; @@ -112,10 +103,6 @@ impl Config for Test { type RecoveryDeposit = RecoveryDeposit; } -pub type Recovery = Module; -pub type System = frame_system::Module; -pub type Balances = pallet_balances::Module; - pub type BalancesCall = pallet_balances::Call; pub type RecoveryCall = super::Call; diff --git a/frame/scheduler/src/lib.rs b/frame/scheduler/src/lib.rs index 9ea6c7603712a..a869fae27d8b3 100644 --- a/frame/scheduler/src/lib.rs +++ b/frame/scheduler/src/lib.rs @@ -721,7 +721,7 @@ mod tests { use super::*; use frame_support::{ - impl_outer_event, impl_outer_origin, impl_outer_dispatch, parameter_types, assert_ok, ord_parameter_types, + parameter_types, assert_ok, ord_parameter_types, assert_noop, assert_err, Hashable, traits::{OnInitialize, OnFinalize, Filter}, weights::constants::RocksDbWeight, @@ -781,24 +781,20 @@ mod tests { } } - impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} - } - - impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - system::System, - logger::Logger, - } - } - - impl_outer_event! { - pub enum Event for Test { - system, - logger, - scheduler, + type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + type Block = frame_system::mocking::MockBlock; + + frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Logger: logger::{Module, Call, Event}, + Scheduler: scheduler::{Module, Call, Storage, Event}, } - } + ); // Scheduler must dispatch with root and no filter, this tests base filter is indeed not used. pub struct BaseFilter; @@ -808,8 +804,6 @@ mod tests { } } - #[derive(Clone, Eq, PartialEq)] - pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = @@ -829,18 +823,18 @@ mod tests { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); type SystemWeightInfo = (); - type SS58Prefix = (); + type SS58Prefix = (); } impl logger::Config for Test { - type Event = (); + type Event = Event; } parameter_types! { pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block; @@ -851,7 +845,7 @@ mod tests { } impl Config for Test { - type Event = (); + type Event = Event; type Origin = Origin; type PalletsOrigin = OriginCaller; type Call = Call; @@ -860,9 +854,6 @@ mod tests { type MaxScheduledPerBlock = MaxScheduledPerBlock; type WeightInfo = (); } - type System = system::Module; - type Logger = logger::Module; - type Scheduler = Module; pub fn new_test_ext() -> sp_io::TestExternalities { let t = system::GenesisConfig::default().build_storage::().unwrap(); diff --git a/frame/scored-pool/src/mock.rs b/frame/scored-pool/src/mock.rs index e3707806e819e..3c4263b813e41 100644 --- a/frame/scored-pool/src/mock.rs +++ b/frame/scored-pool/src/mock.rs @@ -18,21 +18,31 @@ //! Test utilities use super::*; +use crate as pallet_scored_pool; use std::cell::RefCell; -use frame_support::{impl_outer_origin, parameter_types, ord_parameter_types}; +use frame_support::{parameter_types, ord_parameter_types}; use sp_core::H256; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, testing::Header, }; use frame_system::EnsureSignedBy; -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + ScoredPool: pallet_scored_pool::{Module, Call, Storage, Config, Event}, + } +); -#[derive(Clone, Eq, PartialEq)] -pub struct Test; parameter_types! { pub const CandidateDeposit: u64 = 25; pub const Period: u64 = 4; @@ -55,15 +65,15 @@ impl frame_system::Config for Test { type Index = u64; type BlockNumber = u64; type Hash = H256; - type Call = (); + type Call = Call; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -74,7 +84,7 @@ impl frame_system::Config for Test { impl pallet_balances::Config for Test { type MaxLocks = (); type Balance = u64; - type Event = (); + type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; @@ -109,7 +119,7 @@ impl InitializeMembers for TestChangeMembers { } impl Config for Test { - type Event = (); + type Event = Event; type KickOrigin = EnsureSignedBy; type MembershipInitialized = TestChangeMembers; type MembershipChanged = TestChangeMembers; @@ -120,9 +130,6 @@ impl Config for Test { type ScoreOrigin = EnsureSignedBy; } -type System = frame_system::Module; -type Balances = pallet_balances::Module; - pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); pallet_balances::GenesisConfig:: { @@ -136,7 +143,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { (99, 1), ], }.assimilate_storage(&mut t).unwrap(); - GenesisConfig::{ + pallet_scored_pool::GenesisConfig::{ pool: vec![ (5, None), (10, Some(1)), diff --git a/frame/session/src/mock.rs b/frame/session/src/mock.rs index 2923530daf418..73499bf739b87 100644 --- a/frame/session/src/mock.rs +++ b/frame/session/src/mock.rs @@ -19,7 +19,7 @@ use super::*; use std::cell::RefCell; -use frame_support::{impl_outer_origin, parameter_types, BasicExternalities}; +use frame_support::{parameter_types, BasicExternalities}; use sp_core::{crypto::key_types::DUMMY, H256}; use sp_runtime::{ Perbill, impl_opaque_keys, @@ -27,6 +27,9 @@ use sp_runtime::{ testing::{Header, UintAuthorityId}, }; use sp_staking::SessionIndex; +use crate as pallet_session; +#[cfg(feature = "historical")] +use crate::historical as pallet_session_historical; impl_opaque_keys! { pub struct MockSessionKeys { @@ -65,9 +68,33 @@ impl OpaqueKeys for PreUpgradeMockSessionKeys { } } -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +#[cfg(feature = "historical")] +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Session: pallet_session::{Module, Call, Storage, Event, Config}, + Historical: pallet_session_historical::{Module}, + } +); + +#[cfg(not(feature = "historical"))] +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Session: pallet_session::{Module, Call, Storage, Event, Config}, + } +); thread_local! { pub static VALIDATORS: RefCell> = RefCell::new(vec![1, 2, 3]); @@ -189,13 +216,10 @@ pub fn new_test_ext() -> sp_io::TestExternalities { // An additional identity that we use. frame_system::Module::::inc_providers(&69); }); - GenesisConfig:: { keys }.assimilate_storage(&mut t).unwrap(); + pallet_session::GenesisConfig:: { keys }.assimilate_storage(&mut t).unwrap(); sp_io::TestExternalities::new(t) } -#[derive(Clone, Eq, PartialEq)] -pub struct Test; - parameter_types! { pub const MinimumPeriod: u64 = 5; pub const BlockHashCount: u64 = 250; @@ -211,16 +235,16 @@ impl frame_system::Config for Test { type Origin = Origin; type Index = u64; type BlockNumber = u64; - type Call = (); + type Call = Call; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); @@ -249,7 +273,7 @@ impl Config for Test { type ValidatorId = u64; type ValidatorIdOf = ConvertInto; type Keys = MockSessionKeys; - type Event = (); + type Event = Event; type DisabledValidatorsThreshold = DisabledValidatorsThreshold; type NextSessionRotation = (); type WeightInfo = (); @@ -260,6 +284,3 @@ impl crate::historical::Config for Test { type FullIdentification = u64; type FullIdentificationOf = sp_runtime::traits::ConvertInto; } - -pub type System = frame_system::Module; -pub type Session = Module; diff --git a/frame/society/src/mock.rs b/frame/society/src/mock.rs index b7735994ec92c..8c39a0bc3ea59 100644 --- a/frame/society/src/mock.rs +++ b/frame/society/src/mock.rs @@ -18,9 +18,10 @@ //! Test utilities use super::*; +use crate as pallet_society; use frame_support::{ - impl_outer_origin, parameter_types, ord_parameter_types, + parameter_types, ord_parameter_types, traits::{OnInitialize, OnFinalize, TestRandomness}, }; use sp_core::H256; @@ -30,12 +31,21 @@ use sp_runtime::{ }; use frame_system::EnsureSignedBy; -impl_outer_origin! { - pub enum Origin for Test {} -} +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Society: pallet_society::{Module, Call, Storage, Event, Config}, + } +); -#[derive(Clone, Eq, PartialEq)] -pub struct Test; parameter_types! { pub const CandidateDeposit: u64 = 25; pub const WrongSideDeduction: u64 = 2; @@ -65,12 +75,12 @@ impl frame_system::Config for Test { type Index = u64; type BlockNumber = u64; type Hash = H256; - type Call = (); + type Call = Call; type Hashing = BlakeTwo256; type AccountId = u128; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); type PalletInfo = (); @@ -84,7 +94,7 @@ impl frame_system::Config for Test { impl pallet_balances::Config for Test { type MaxLocks = (); type Balance = u64; - type Event = (); + type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; @@ -92,7 +102,7 @@ impl pallet_balances::Config for Test { } impl Config for Test { - type Event = (); + type Event = Event; type Currency = pallet_balances::Module; type Randomness = TestRandomness; type CandidateDeposit = CandidateDeposit; @@ -108,10 +118,6 @@ impl Config for Test { type ModuleId = SocietyModuleId; } -pub type Society = Module; -pub type System = frame_system::Module; -pub type Balances = pallet_balances::Module; - pub struct EnvBuilder { members: Vec, balance: u64, @@ -147,7 +153,7 @@ impl EnvBuilder { pallet_balances::GenesisConfig:: { balances: self.balances, }.assimilate_storage(&mut t).unwrap(); - GenesisConfig::{ + pallet_society::GenesisConfig::{ members: self.members, pot: self.pot, max_members: self.max_members, diff --git a/frame/staking/src/mock.rs b/frame/staking/src/mock.rs index cf1486a9b691c..5c3261414d2bc 100644 --- a/frame/staking/src/mock.rs +++ b/frame/staking/src/mock.rs @@ -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; +type Block = frame_system::mocking::MockBlock; -impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - staking::Staking, - } -} - -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, - balances, - session, - staking, +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Staking: staking::{Module, Call, Config, Storage, Event, ValidateUnsigned}, + Session: pallet_session::{Module, Call, Storage, Event, Config}, } -} +); /// Author of block is always 11 pub struct Author11; @@ -124,10 +115,6 @@ impl FindAuthor 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; type Header = Header; - type Event = MetaEvent; + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; 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; type SessionHandler = (OtherSessionHandler,); - type Event = MetaEvent; + type Event = Event; type ValidatorId = AccountId; type ValidatorIdOf = crate::StashOf; 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::::Nominator(nominated)) ]; } - let _ = GenesisConfig::{ + let _ = staking::GenesisConfig::{ 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; -pub type Balances = pallet_balances::Module; -pub type Session = pallet_session::Module; -pub type Timestamp = pallet_timestamp::Module; -pub type Staking = Module; - fn post_conditions() { check_nominators(); check_exposures(); @@ -1016,9 +997,9 @@ macro_rules! assert_session_era { }; } -pub(crate) fn staking_events() -> Vec> { +pub(crate) fn staking_events() -> Vec> { 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 diff --git a/frame/staking/src/tests.rs b/frame/staking/src/tests.rs index a10c95d0f24d2..1f5e2a48888a5 100644 --- a/frame/staking/src/tests.rs +++ b/frame/staking/src/tests.rs @@ -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 diff --git a/frame/sudo/src/mock.rs b/frame/sudo/src/mock.rs index 6cb418de1325f..91cd03ac4756a 100644 --- a/frame/sudo/src/mock.rs +++ b/frame/sudo/src/mock.rs @@ -18,10 +18,7 @@ //! Test utilities use super::*; -use frame_support::{ - impl_outer_origin, impl_outer_dispatch, impl_outer_event, parameter_types, - weights::Weight, -}; +use frame_support::{parameter_types, weights::Weight}; use sp_core::H256; use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header}; use sp_io; @@ -76,34 +73,20 @@ pub mod logger { } } -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} - -mod test_events { - pub use crate::Event; -} - -impl_outer_event! { - pub enum TestEvent for Test { - frame_system, - sudo, - logger, - } -} - -impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - sudo::Sudo, - logger::Logger, +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Sudo: sudo::{Module, Call, Config, Storage, Event}, + Logger: logger::{Module, Call, Storage, Event}, } -} - -// For testing the pallet, we construct most of a mock runtime. This means -// first constructing a configuration type (`Test`) which `impl`s each of the -// configuration traits of pallets we want to use. -#[derive(Clone, Eq, PartialEq)] -pub struct Test; +); parameter_types! { pub const BlockHashCount: u64 = 250; @@ -131,10 +114,10 @@ impl frame_system::Config for Test { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = TestEvent; + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); @@ -144,20 +127,15 @@ impl frame_system::Config for Test { // Implement the logger module's `Config` on the Test runtime. impl logger::Config for Test { - type Event = TestEvent; + type Event = Event; } // Implement the sudo module's `Config` on the Test runtime. impl Config for Test { - type Event = TestEvent; + type Event = Event; type Call = Call; } -// Assign back to type variables in order to make dispatched calls of these modules later. -pub type Sudo = Module; -pub type Logger = logger::Module; -pub type System = frame_system::Module; - // New types for dispatchable functions. pub type SudoCall = sudo::Call; pub type LoggerCall = logger::Call; @@ -165,7 +143,7 @@ pub type LoggerCall = logger::Call; // Build test environment by setting the root `key` for the Genesis. pub fn new_test_ext(root_key: u64) -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - GenesisConfig::{ + sudo::GenesisConfig::{ key: root_key, }.assimilate_storage(&mut t).unwrap(); t.into() diff --git a/frame/sudo/src/tests.rs b/frame/sudo/src/tests.rs index 1aeb9b57b6165..4d2552b7b88b4 100644 --- a/frame/sudo/src/tests.rs +++ b/frame/sudo/src/tests.rs @@ -19,7 +19,8 @@ use super::*; use mock::{ - Sudo, SudoCall, Origin, Call, Test, new_test_ext, LoggerCall, Logger, System, TestEvent, + Sudo, SudoCall, Origin, Call, Test, new_test_ext, LoggerCall, Logger, System, + Event as TestEvent, }; use frame_support::{assert_ok, assert_noop}; diff --git a/frame/timestamp/src/lib.rs b/frame/timestamp/src/lib.rs index 44f88347c08d3..ae7ba4814694b 100644 --- a/frame/timestamp/src/lib.rs +++ b/frame/timestamp/src/lib.rs @@ -290,9 +290,10 @@ impl UnixTime for Module { #[cfg(test)] mod tests { + use crate as pallet_timestamp; use super::*; - use frame_support::{impl_outer_origin, assert_ok, parameter_types}; + use frame_support::{assert_ok, parameter_types}; use sp_io::TestExternalities; use sp_core::H256; use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header}; @@ -302,12 +303,20 @@ mod tests { TestExternalities::new(t) } - impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} - } + type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + type Block = frame_system::mocking::MockBlock; + + frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent}, + } + ); - #[derive(Clone, Eq, PartialEq)] - pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = @@ -321,16 +330,16 @@ mod tests { type Origin = Origin; type Index = u64; type BlockNumber = u64; - type Call = (); + type Call = Call; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); @@ -346,7 +355,6 @@ mod tests { type MinimumPeriod = MinimumPeriod; type WeightInfo = (); } - type Timestamp = Module; #[test] fn timestamp_works() { diff --git a/frame/tips/src/tests.rs b/frame/tips/src/tests.rs index ae16117d6b177..413e2dd9437e2 100644 --- a/frame/tips/src/tests.rs +++ b/frame/tips/src/tests.rs @@ -19,13 +19,11 @@ #![cfg(test)] +use crate as tips; use super::*; use std::cell::RefCell; -use frame_support::{ - assert_noop, assert_ok, impl_outer_origin, parameter_types, weights::Weight, - impl_outer_event, traits::{Contains} -}; -use sp_runtime::{Permill}; +use frame_support::{assert_noop, assert_ok, parameter_types, weights::Weight, traits::Contains}; +use sp_runtime::Permill; use sp_core::H256; use sp_runtime::{ Perbill, ModuleId, @@ -33,26 +31,22 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup, BadOrigin}, }; -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} - -mod tips { - // Re-export needed for `impl_outer_event!`. - pub use crate::*; -} - -impl_outer_event! { - pub enum Event for Test { - system, - pallet_balances, - pallet_treasury, - tips, +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Treasury: pallet_treasury::{Module, Call, Storage, Config, Event}, + TipsModTestInst: tips::{Module, Call, Storage, Event}, } -} +); -#[derive(Clone, Eq, PartialEq)] -pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub const MaximumBlockWeight: Weight = 1024; @@ -67,7 +61,7 @@ impl frame_system::Config for Test { type Origin = Origin; type Index = u64; type BlockNumber = u64; - type Call = (); + type Call = Call; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account @@ -76,7 +70,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; type OnNewAccount = (); type OnKilledAccount = (); @@ -159,10 +153,6 @@ impl Config for Test { type Event = Event; type WeightInfo = (); } -type System = frame_system::Module; -type Balances = pallet_balances::Module; -type Treasury = pallet_treasury::Module; -type TipsModTestInst = Module; pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 7521fcd80bf0a..5f907fb91b99e 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -600,9 +600,11 @@ impl SignedExtension for ChargeTransactionPayment where #[cfg(test)] mod tests { use super::*; + use crate as pallet_transaction_payment; + use frame_system as system; use codec::Encode; use frame_support::{ - impl_outer_dispatch, impl_outer_origin, impl_outer_event, parameter_types, + parameter_types, weights::{ DispatchClass, DispatchInfo, PostDispatchInfo, GetDispatchInfo, Weight, WeightToFeePolynomial, WeightToFeeCoefficients, WeightToFeeCoefficient, @@ -619,30 +621,23 @@ mod tests { use std::cell::RefCell; use smallvec::smallvec; - const CALL: &::Call = - &Call::Balances(BalancesCall::transfer(2, 69)); - - impl_outer_dispatch! { - pub enum Call for Runtime where origin: Origin { - pallet_balances::Balances, - frame_system::System, - } - } + type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + type Block = frame_system::mocking::MockBlock; - impl_outer_event! { - pub enum Event for Runtime { - system, - pallet_balances, + frame_support::construct_runtime!( + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: system::{Module, Call, Config, Storage, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + TransactionPayment: pallet_transaction_payment::{Module, Storage}, } - } - - #[derive(Clone, PartialEq, Eq, Debug)] - pub struct Runtime; + ); - use frame_system as system; - impl_outer_origin!{ - pub enum Origin for Runtime {} - } + const CALL: &::Call = + &Call::Balances(BalancesCall::transfer(2, 69)); thread_local! { static EXTRINSIC_BASE_WEIGHT: RefCell = RefCell::new(0); @@ -728,10 +723,6 @@ mod tests { type FeeMultiplierUpdate = (); } - type Balances = pallet_balances::Module; - type System = frame_system::Module; - type TransactionPayment = Module; - pub struct ExtBuilder { balance_factor: u64, base_weight: u64, diff --git a/frame/treasury/src/tests.rs b/frame/treasury/src/tests.rs index 177c39eec2446..3c70099843ea8 100644 --- a/frame/treasury/src/tests.rs +++ b/frame/treasury/src/tests.rs @@ -19,13 +19,13 @@ #![cfg(test)] +use crate as treasury; use super::*; use std::cell::RefCell; use frame_support::{ - assert_noop, assert_ok, impl_outer_origin, impl_outer_event, parameter_types, - traits::{OnInitialize} + assert_noop, assert_ok, parameter_types, + traits::OnInitialize, }; -use frame_system::{self as system}; use sp_core::H256; use sp_runtime::{ @@ -34,25 +34,21 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, }; -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} - -mod treasury { - // Re-export needed for `impl_outer_event!`. - pub use super::super::*; -} - -impl_outer_event! { - pub enum Event for Test { - system, - pallet_balances, - treasury, +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Treasury: treasury::{Module, Call, Storage, Config, Event}, } -} +); -#[derive(Clone, Eq, PartialEq)] -pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = @@ -66,7 +62,7 @@ impl frame_system::Config for Test { type Origin = Origin; type Index = u64; type BlockNumber = u64; - type Call = (); + type Call = Call; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account @@ -75,7 +71,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; type OnNewAccount = (); type OnKilledAccount = (); @@ -122,9 +118,6 @@ impl Config for Test { type WeightInfo = (); type SpendFunds = (); } -type System = frame_system::Module; -type Balances = pallet_balances::Module; -type Treasury = Module; pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); @@ -132,7 +125,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { // Total issuance will be 200 with treasury account initialized at ED. balances: vec![(0, 100), (1, 98), (2, 1)], }.assimilate_storage(&mut t).unwrap(); - GenesisConfig::default().assimilate_storage::(&mut t).unwrap(); + treasury::GenesisConfig::default().assimilate_storage::(&mut t).unwrap(); t.into() } @@ -358,7 +351,7 @@ fn genesis_funding_works() { // Total issuance will be 200 with treasury account initialized with 100. balances: vec![(0, 100), (Treasury::account_id(), initial_funding)], }.assimilate_storage(&mut t).unwrap(); - GenesisConfig::default().assimilate_storage::(&mut t).unwrap(); + treasury::GenesisConfig::default().assimilate_storage::(&mut t).unwrap(); let mut t: sp_io::TestExternalities = t.into(); t.execute_with(|| { diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index 556107529e1a2..b14f958bd6f8d 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -22,8 +22,7 @@ use super::*; use frame_support::{ - assert_ok, assert_noop, impl_outer_origin, parameter_types, impl_outer_dispatch, impl_outer_event, - assert_err_ignore_postinfo, + assert_ok, assert_noop, parameter_types, assert_err_ignore_postinfo, weights::{Weight, Pays}, dispatch::{DispatchError, DispatchErrorWithPostInfo, Dispatchable}, traits::Filter, @@ -67,30 +66,22 @@ pub mod example { } } -impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} -} -impl_outer_event! { - pub enum TestEvent for Test { - frame_system, - pallet_balances, - utility, - } -} -impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - frame_system::System, - pallet_balances::Balances, - utility::Utility, - example::Example, +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Utility: utility::{Module, Call, Event}, + Example: example::{Module, Call}, } -} +); -// For testing the pallet, we construct most of a mock runtime. This means -// first constructing a configuration type (`Test`) which `impl`s each of the -// configuration traits of pallets we want to use. -#[derive(Clone, Eq, PartialEq)] -pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = @@ -110,7 +101,7 @@ impl frame_system::Config for Test { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = TestEvent; + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); type PalletInfo = (); @@ -127,7 +118,7 @@ impl pallet_balances::Config for Test { type MaxLocks = (); type Balance = u64; type DustRemoval = (); - type Event = TestEvent; + type Event = Event; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); @@ -156,14 +147,10 @@ impl Filter for TestBaseCallFilter { } } impl Config for Test { - type Event = TestEvent; + type Event = Event; type Call = Call; type WeightInfo = (); } -type System = frame_system::Module; -type Balances = pallet_balances::Module; -type Example = example::Module; -type Utility = Module; type ExampleCall = example::Call; type UtilityCall = crate::Call; @@ -182,11 +169,11 @@ pub fn new_test_ext() -> sp_io::TestExternalities { ext } -fn last_event() -> TestEvent { +fn last_event() -> Event { frame_system::Module::::events().pop().map(|e| e.event).expect("Event expected") } -fn expect_event>(e: E) { +fn expect_event>(e: E) { assert_eq!(last_event(), e.into()); } @@ -324,7 +311,7 @@ fn batch_with_signed_filters() { Call::Balances(pallet_balances::Call::transfer_keep_alive(2, 1)) ]), ); - expect_event(Event::BatchInterrupted(0, DispatchError::BadOrigin)); + expect_event(utility::Event::BatchInterrupted(0, DispatchError::BadOrigin)); }); } @@ -398,7 +385,7 @@ fn batch_handles_weight_refund() { let info = call.get_dispatch_info(); let result = call.dispatch(Origin::signed(1)); assert_ok!(result); - expect_event(Event::BatchInterrupted(1, DispatchError::Other(""))); + expect_event(utility::Event::BatchInterrupted(1, DispatchError::Other(""))); // No weight is refunded assert_eq!(extract_actual_weight(&result, &info), info.weight); @@ -411,7 +398,7 @@ fn batch_handles_weight_refund() { let info = call.get_dispatch_info(); let result = call.dispatch(Origin::signed(1)); assert_ok!(result); - expect_event(Event::BatchInterrupted(1, DispatchError::Other(""))); + expect_event(utility::Event::BatchInterrupted(1, DispatchError::Other(""))); assert_eq!(extract_actual_weight(&result, &info), info.weight - diff * batch_len); // Partial batch completion @@ -422,7 +409,7 @@ fn batch_handles_weight_refund() { let info = call.get_dispatch_info(); let result = call.dispatch(Origin::signed(1)); assert_ok!(result); - expect_event(Event::BatchInterrupted(1, DispatchError::Other(""))); + expect_event(utility::Event::BatchInterrupted(1, DispatchError::Other(""))); assert_eq!( extract_actual_weight(&result, &info), // Real weight is 2 calls at end_weight diff --git a/frame/vesting/src/lib.rs b/frame/vesting/src/lib.rs index 5e20c863c51f3..9cf9166b37c0c 100644 --- a/frame/vesting/src/lib.rs +++ b/frame/vesting/src/lib.rs @@ -389,10 +389,9 @@ impl VestingSchedule for Module where #[cfg(test)] mod tests { use super::*; + use crate as pallet_vesting; - use frame_support::{ - assert_ok, assert_noop, impl_outer_origin, parameter_types, - }; + use frame_support::{assert_ok, assert_noop, parameter_types}; use sp_core::H256; use sp_runtime::{ testing::Header, @@ -400,12 +399,21 @@ mod tests { }; use frame_system::RawOrigin; - impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} - } + type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + type Block = frame_system::mocking::MockBlock; + + frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Vesting: pallet_vesting::{Module, Call, Storage, Event, Config}, + } + ); - #[derive(Clone, Eq, PartialEq)] - pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = @@ -420,15 +428,15 @@ mod tests { type Index = u64; type BlockNumber = u64; type Hash = H256; - type Call = (); + type Call = Call; type Hashing = BlakeTwo256; type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -441,7 +449,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; type DustRemoval = (); - type Event = (); + type Event = Event; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = MaxLocks; @@ -452,16 +460,12 @@ mod tests { pub static ExistentialDeposit: u64 = 0; } impl Config for Test { - type Event = (); + type Event = Event; type Currency = Balances; type BlockNumberToBalance = Identity; type MinVestedTransfer = MinVestedTransfer; type WeightInfo = (); } - type System = frame_system::Module; - type Balances = pallet_balances::Module; - type Vesting = Module; - pub struct ExtBuilder { existential_deposit: u64, @@ -490,7 +494,7 @@ mod tests { (12, 10 * self.existential_deposit) ], }.assimilate_storage(&mut t).unwrap(); - GenesisConfig:: { + pallet_vesting::GenesisConfig:: { vesting: vec![ (1, 0, 10, 5 * self.existential_deposit), (2, 10, 20, 0),