diff --git a/runtime/common/src/claims.rs b/runtime/common/src/claims.rs index 6500b6039ea1..17570e830b7e 100644 --- a/runtime/common/src/claims.rs +++ b/runtime/common/src/claims.rs @@ -607,27 +607,30 @@ mod tests { // or public keys. `u64` is used as the `AccountId` and no `Signature`s are required. use sp_runtime::{traits::{BlakeTwo256, IdentityLookup, Identity}, testing::Header}; use frame_support::{ - impl_outer_origin, impl_outer_dispatch, assert_ok, assert_err, assert_noop, parameter_types, + assert_ok, assert_err, assert_noop, parameter_types, ord_parameter_types, weights::{Pays, GetDispatchInfo}, traits::ExistenceRequirement, dispatch::DispatchError::BadOrigin, }; use pallet_balances; - use super::Call as ClaimsCall; - - impl_outer_origin! { - pub enum Origin for Test {} - } - - impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - claims::Claims, + use crate::claims; + use claims::Call as ClaimsCall; + + 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, Config, Event}, + Claims: claims::{Module, Call, Storage, Config, Event, ValidateUnsigned}, } - } - // For testing the module, we construct most of a mock runtime. This means - // first constructing a configuration type (`Test`) which `impl`s each of the - // configuration traits of modules we want to use. - #[derive(Clone, Eq, PartialEq)] - pub struct Test; + ); + parameter_types! { pub const BlockHashCount: u32 = 250; } @@ -645,10 +648,10 @@ 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 = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -662,7 +665,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; - type Event = (); + type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; @@ -675,7 +678,7 @@ mod tests { } impl pallet_vesting::Config for Test { - type Event = (); + type Event = Event; type Currency = Balances; type BlockNumberToBalance = Identity; type MinVestedTransfer = MinVestedTransfer; @@ -690,16 +693,12 @@ mod tests { } impl Config for Test { - type Event = (); + type Event = Event; type VestingSchedule = Vesting; type Prefix = Prefix; type MoveClaimOrigin = frame_system::EnsureSignedBy; type WeightInfo = TestWeightInfo; } - type System = frame_system::Module; - type Balances = pallet_balances::Module; - type Vesting = pallet_vesting::Module; - type Claims = Module; fn alice() -> secp256k1::SecretKey { secp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap() @@ -723,7 +722,7 @@ mod tests { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); // We use default for brevity, but you can configure as desired if needed. pallet_balances::GenesisConfig::::default().assimilate_storage(&mut t).unwrap(); - GenesisConfig::{ + claims::GenesisConfig::{ claims: vec![ (eth(&alice()), 100, None, None), (eth(&dave()), 200, None, Some(StatementKind::Regular)), diff --git a/runtime/common/src/crowdloan.rs b/runtime/common/src/crowdloan.rs index ff7c7a6f04a2..56dc0d967c8f 100644 --- a/runtime/common/src/crowdloan.rs +++ b/runtime/common/src/crowdloan.rs @@ -580,7 +580,7 @@ mod tests { use std::{collections::HashMap, cell::RefCell}; use frame_support::{ - impl_outer_origin, impl_outer_event, assert_ok, assert_noop, parameter_types, + assert_ok, assert_noop, parameter_types, traits::{OnInitialize, OnFinalize}, }; use sp_core::H256; @@ -591,35 +591,27 @@ mod tests { Permill, testing::Header, traits::{BlakeTwo256, IdentityLookup}, }; - use crate::slots::Registrar; - - impl_outer_origin! { - pub enum Origin for Test {} - } - - mod runtime_common_slots { - pub use crate::slots::Event; - } - - mod runtime_common_crowdloan { - pub use crate::crowdloan::Event; - } - - impl_outer_event! { - pub enum Event for Test { - frame_system, - pallet_balances, - pallet_treasury, - runtime_common_slots, - runtime_common_crowdloan, + use crate::slots::{self, Registrar}; + use crate::crowdloan; + + 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}, + Slots: slots::{Module, Call, Storage, Event}, + Crowdloan: crowdloan::{Module, Call, Storage, Event}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage}, } - } + ); - // For testing the module, we construct most of a mock runtime. This means - // first constructing a configuration type (`Test`) which `impl`s each of the - // configuration traits of modules we want to use. - #[derive(Clone, Eq, PartialEq)] - pub struct Test; parameter_types! { pub const BlockHashCount: u32 = 250; } @@ -630,7 +622,7 @@ mod tests { type BlockLength = (); type DbWeight = (); type Origin = Origin; - type Call = (); + type Call = Call; type Index = u64; type BlockNumber = u64; type Hash = H256; @@ -641,7 +633,7 @@ mod tests { type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -765,12 +757,6 @@ mod tests { type RemoveKeysLimit = RemoveKeysLimit; } - type System = frame_system::Module; - type Balances = pallet_balances::Module; - type Slots = slots::Module; - type Treasury = pallet_treasury::Module; - type Crowdloan = Module; - type RandomnessCollectiveFlip = pallet_randomness_collective_flip::Module; use pallet_balances::Error as BalancesError; use slots::Error as SlotsError; diff --git a/runtime/common/src/impls.rs b/runtime/common/src/impls.rs index 66ebb7cd9e64..22d889df0acd 100644 --- a/runtime/common/src/impls.rs +++ b/runtime/common/src/impls.rs @@ -73,7 +73,7 @@ where mod tests { use super::*; use frame_system::limits; - use frame_support::{impl_outer_origin, parameter_types, weights::DispatchClass}; + use frame_support::{parameter_types, weights::DispatchClass}; use frame_support::traits::FindAuthor; use sp_core::H256; use sp_runtime::{ @@ -83,12 +83,20 @@ mod tests { }; use primitives::v1::AccountId; - #[derive(Clone, PartialEq, Eq, Debug)] - pub struct Test; + type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + type Block = frame_system::mocking::MockBlock; - impl_outer_origin!{ - pub enum Origin for Test {} - } + 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}, + } + ); parameter_types! { pub const BlockHashCount: u64 = 250; @@ -109,19 +117,19 @@ mod tests { type Origin = Origin; type Index = u64; type BlockNumber = u64; - type Call = (); + type Call = Call; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type BlockLength = BlockLength; type BlockWeights = BlockWeights; type DbWeight = (); type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -131,7 +139,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; - type Event = (); + type Event = Event; type DustRemoval = (); type ExistentialDeposit = (); type AccountStore = System; @@ -147,7 +155,7 @@ mod tests { type Currency = pallet_balances::Module; type ApproveOrigin = frame_system::EnsureRoot; type RejectOrigin = frame_system::EnsureRoot; - type Event = (); + type Event = Event; type OnSlash = (); type ProposalBond = (); type ProposalBondMinimum = (); @@ -174,10 +182,6 @@ mod tests { type EventHandler = (); } - type Treasury = pallet_treasury::Module; - type Balances = pallet_balances::Module; - type System = frame_system::Module; - pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); // We use default for brevity, but you can configure as desired if needed. diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 31cad65133a5..2f62eb956606 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -188,7 +188,7 @@ impl OneSessionHandler for AssignmentSe #[cfg(test)] mod multiplier_tests { use super::*; - use frame_support::{impl_outer_origin, parameter_types, weights::Weight}; + use frame_support::{parameter_types, weights::Weight}; use sp_core::H256; use sp_runtime::{ testing::Header, @@ -196,12 +196,18 @@ mod multiplier_tests { Perbill, }; - #[derive(Clone, PartialEq, Eq, Debug)] - pub struct Runtime; + type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + type Block = frame_system::mocking::MockBlock; - impl_outer_origin!{ - pub enum Origin for Runtime {} - } + frame_support::construct_runtime!( + pub enum Runtime where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event} + } + ); parameter_types! { pub const BlockHashCount: u64 = 250; @@ -220,16 +226,16 @@ mod multiplier_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 = (); @@ -237,8 +243,6 @@ mod multiplier_tests { type SS58Prefix = (); } - type System = frame_system::Module; - fn run_with_system_weight(w: Weight, assertions: F) where F: Fn() -> () { let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default().build_storage::().unwrap().into(); diff --git a/runtime/common/src/paras_registrar.rs b/runtime/common/src/paras_registrar.rs index 30f966d71912..e9e3c3c234b7 100644 --- a/runtime/common/src/paras_registrar.rs +++ b/runtime/common/src/paras_registrar.rs @@ -267,25 +267,32 @@ mod tests { use frame_system::limits; use frame_support::{ traits::{Randomness, OnInitialize, OnFinalize}, - impl_outer_origin, impl_outer_dispatch, assert_ok, parameter_types, + assert_ok, parameter_types, }; use keyring::Sr25519Keyring; use runtime_parachains::{initializer, configuration, inclusion, session_info, scheduler, dmp, ump, hrmp}; use frame_support::traits::OneSessionHandler; - - impl_outer_origin! { - pub enum Origin for Test { - runtime_parachains, - } - } - - impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - paras::Parachains, - registrar::Registrar, - staking::Staking, + use crate::paras_registrar; + + 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}, + Parachains: paras::{Module, Origin, Call, Storage, Config}, + Inclusion: inclusion::{Module, Call, Storage, Event}, + Registrar: paras_registrar::{Module, Call, Storage}, + Staking: pallet_staking::{Module, Call, Config, Storage, Event, ValidateUnsigned}, + Session: pallet_session::{Module, Call, Storage, Event, Config}, + Initializer: initializer::{Module, Call, Storage}, } - } + ); pallet_staking_reward_curve::build! { const REWARD_CURVE: PiecewiseLinear<'static> = curve!( @@ -298,8 +305,6 @@ mod tests { ); } - #[derive(Clone, Eq, PartialEq)] - pub struct Test; const NORMAL_RATIO: Perbill = Perbill::from_percent(75); parameter_types! { pub const BlockHashCount: u32 = 250; @@ -320,13 +325,13 @@ mod tests { type AccountId = u64; type Lookup = IdentityLookup; type Header = Header; - type Event = (); + type Event = Event; type BlockHashCount = BlockHashCount; type DbWeight = (); type BlockWeights = BlockWeights; type BlockLength = BlockLength; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -348,7 +353,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u128; type DustRemoval = (); - type Event = (); + type Event = Event; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type MaxLocks = (); @@ -377,7 +382,7 @@ mod tests { type ShouldEndSession = pallet_session::PeriodicSessions; type NextSessionRotation = pallet_session::PeriodicSessions; type SessionHandler = pallet_session::TestSessionHandler; - type Event = (); + type Event = Event; type ValidatorId = u64; type ValidatorIdOf = (); type DisabledValidatorsThreshold = DisabledValidatorsThreshold; @@ -398,7 +403,7 @@ mod tests { impl pallet_staking::Config for Test { type RewardRemainder = (); type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote; - type Event = (); + type Event = Event; type Currency = pallet_balances::Module; type Slash = (); type Reward = (); @@ -482,7 +487,7 @@ mod tests { } impl inclusion::Config for Test { - type Event = (); + type Event = Event; type RewardValidators = TestRewardValidators; } @@ -540,15 +545,6 @@ mod tests { type ParathreadDeposit = ParathreadDeposit; } - type Balances = pallet_balances::Module; - type Parachains = paras::Module; - type Inclusion = inclusion::Module; - type System = frame_system::Module; - type Registrar = Module; - type Session = pallet_session::Module; - type Staking = pallet_staking::Module; - type Initializer = initializer::Module; - fn new_test_ext() -> TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); diff --git a/runtime/common/src/purchase.rs b/runtime/common/src/purchase.rs index 3d73405fbb43..e90f31696afd 100644 --- a/runtime/common/src/purchase.rs +++ b/runtime/common/src/purchase.rs @@ -398,30 +398,31 @@ mod tests { testing::Header }; use frame_support::{ - impl_outer_origin, impl_outer_dispatch, assert_ok, assert_noop, parameter_types, + assert_ok, assert_noop, parameter_types, ord_parameter_types, dispatch::DispatchError::BadOrigin, }; use frame_support::traits::Currency; use pallet_balances::Error as BalancesError; - - impl_outer_origin! { - pub enum Origin for Test {} - } - - impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - purchase::Purchase, - vesting::Vesting, + use crate::purchase; + + 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, Config, Event}, + Purchase: purchase::{Module, Call, Storage, Event}, } - } + ); type AccountId = AccountId32; - // For testing the module, we construct most of a mock runtime. This means - // first constructing a configuration type (`Test`) which `impl`s each of the - // configuration traits of modules we want to use. - #[derive(Clone, Eq, PartialEq)] - pub struct Test; parameter_types! { pub const BlockHashCount: u32 = 250; } @@ -439,10 +440,10 @@ mod tests { type AccountId = AccountId; 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 = (); @@ -456,7 +457,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; - type Event = (); + type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; @@ -469,7 +470,7 @@ mod tests { } impl pallet_vesting::Config for Test { - type Event = (); + type Event = Event; type Currency = Balances; type BlockNumberToBalance = Identity; type MinVestedTransfer = MinVestedTransfer; @@ -489,7 +490,7 @@ mod tests { } impl Config for Test { - type Event = (); + type Event = Event; type Currency = Balances; type VestingSchedule = Vesting; type ValidityOrigin = frame_system::EnsureSignedBy; @@ -499,11 +500,6 @@ mod tests { type MaxUnlocked = MaxUnlocked; } - type System = frame_system::Module; - type Balances = pallet_balances::Module; - type Vesting = pallet_vesting::Module; - type Purchase = Module; - // This function basically just builds a genesis storage key/value store according to // our desired mockup. It also executes our `setup` function which sets up this pallet for use. pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/runtime/common/src/slots.rs b/runtime/common/src/slots.rs index 6c0f25dc2d0e..122c010b2afb 100644 --- a/runtime/common/src/slots.rs +++ b/runtime/common/src/slots.rs @@ -944,21 +944,29 @@ mod tests { use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, Hash, IdentityLookup}; use frame_support::{ - impl_outer_origin, parameter_types, assert_ok, assert_noop, + parameter_types, assert_ok, assert_noop, traits::{OnInitialize, OnFinalize} }; use pallet_balances; use primitives::v1::{BlockNumber, Header, Id as ParaId}; + use crate::slots; + + 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}, + Slots: slots::{Module, Call, Storage, Event}, + RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage}, + } + ); - impl_outer_origin! { - pub enum Origin for Test {} - } - - // For testing the module, we construct most of a mock runtime. This means - // first constructing a configuration type (`Test`) which `impl`s each of the - // configuration traits of modules we want to use. - #[derive(Clone, Eq, PartialEq)] - pub struct Test; parameter_types! { pub const BlockHashCount: u32 = 250; } @@ -968,7 +976,7 @@ mod tests { type BlockLength = (); type DbWeight = (); type Origin = Origin; - type Call = (); + type Call = Call; type Index = u64; type BlockNumber = BlockNumber; type Hash = H256; @@ -976,10 +984,10 @@ 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 = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); @@ -993,7 +1001,7 @@ mod tests { impl pallet_balances::Config for Test { type Balance = u64; - type Event = (); + type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; @@ -1066,7 +1074,7 @@ mod tests { } impl Config for Test { - type Event = (); + type Event = Event; type Currency = Balances; type Parachains = TestParachains; type LeasePeriod = LeasePeriod; @@ -1074,11 +1082,6 @@ mod tests { type Randomness = RandomnessCollectiveFlip; } - type System = frame_system::Module; - type Balances = pallet_balances::Module; - type Slots = Module; - type RandomnessCollectiveFlip = pallet_randomness_collective_flip::Module; - // This function basically just builds a genesis storage key/value store according to // our desired mock up. fn new_test_ext() -> sp_io::TestExternalities { diff --git a/runtime/parachains/src/dmp.rs b/runtime/parachains/src/dmp.rs index 7930beeeb60d..8a615ae36a43 100644 --- a/runtime/parachains/src/dmp.rs +++ b/runtime/parachains/src/dmp.rs @@ -232,7 +232,7 @@ mod tests { use frame_support::StorageValue; use frame_support::traits::{OnFinalize, OnInitialize}; use parity_scale_codec::Encode; - use crate::mock::{Configuration, new_test_ext, System, Dmp, GenesisConfig as MockGenesisConfig}; + use crate::mock::{Configuration, new_test_ext, System, Dmp, MockGenesisConfig}; pub(crate) fn run_to_block(to: BlockNumber, new_session: Option>) { while System::block_number() < to { diff --git a/runtime/parachains/src/hrmp.rs b/runtime/parachains/src/hrmp.rs index c7db967dd5ed..e56fe2a19852 100644 --- a/runtime/parachains/src/hrmp.rs +++ b/runtime/parachains/src/hrmp.rs @@ -1124,7 +1124,7 @@ impl Module { mod tests { use super::*; use crate::mock::{ - new_test_ext, Test, Configuration, Paras, Hrmp, System, GenesisConfig as MockGenesisConfig, + new_test_ext, Test, Configuration, Paras, Hrmp, System, MockGenesisConfig, }; use frame_support::{assert_err, traits::Currency as _}; use primitives::v1::BlockNumber; @@ -1198,7 +1198,7 @@ mod tests { } impl GenesisConfigBuilder { - fn build(self) -> crate::mock::GenesisConfig { + fn build(self) -> crate::mock::MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; config.hrmp_channel_max_capacity = self.hrmp_channel_max_capacity; diff --git a/runtime/parachains/src/inclusion.rs b/runtime/parachains/src/inclusion.rs index 68a0b6f01f1e..d6d88b187f65 100644 --- a/runtime/parachains/src/inclusion.rs +++ b/runtime/parachains/src/inclusion.rs @@ -907,7 +907,7 @@ mod tests { use sc_keystore::LocalKeystore; use crate::mock::{ new_test_ext, Configuration, Paras, System, Inclusion, - GenesisConfig as MockGenesisConfig, Test, + MockGenesisConfig, Test, }; use crate::initializer::SessionChangeNotification; use crate::configuration::HostConfiguration; diff --git a/runtime/parachains/src/inclusion_inherent.rs b/runtime/parachains/src/inclusion_inherent.rs index cc121ed3563a..12012e4e6f97 100644 --- a/runtime/parachains/src/inclusion_inherent.rs +++ b/runtime/parachains/src/inclusion_inherent.rs @@ -225,7 +225,7 @@ mod tests { use super::*; use crate::mock::{ - new_test_ext, System, GenesisConfig as MockGenesisConfig, Test + new_test_ext, System, MockGenesisConfig, Test }; mod limit_backed_candidates { @@ -278,7 +278,7 @@ mod tests { use super::*; use crate::mock::{ - new_test_ext, System, GenesisConfig as MockGenesisConfig, Test + new_test_ext, System, MockGenesisConfig, Test }; use frame_support::traits::UnfilteredDispatchable; diff --git a/runtime/parachains/src/mock.rs b/runtime/parachains/src/mock.rs index b219a70a2df1..edaea92d2270 100644 --- a/runtime/parachains/src/mock.rs +++ b/runtime/parachains/src/mock.rs @@ -22,38 +22,36 @@ use sp_runtime::traits::{ BlakeTwo256, IdentityLookup, }; use primitives::v1::{AuthorityDiscoveryId, Balance, BlockNumber, Header, ValidatorIndex}; -use frame_support::{ - impl_outer_origin, impl_outer_dispatch, impl_outer_event, parameter_types, - traits::Randomness as RandomnessT, -}; +use frame_support::{parameter_types, traits::Randomness as RandomnessT}; use std::cell::RefCell; use std::collections::HashMap; -use crate::inclusion; -use crate as parachains; - -/// A test runtime struct. -#[derive(Clone, Eq, PartialEq)] -pub struct Test; - -impl_outer_origin! { - pub enum Origin for Test { - parachains - } -} - -impl_outer_dispatch! { - pub enum Call for Test where origin: Origin { - initializer::Initializer, - } -} +use crate::{ + inclusion, scheduler, dmp, ump, hrmp, session_info, paras, configuration, + initializer, +}; -impl_outer_event! { - pub enum TestEvent for Test { - frame_system, - pallet_balances, - inclusion, +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}, + Paras: paras::{Module, Origin, Call, Storage, Config}, + Configuration: configuration::{Module, Call, Storage, Config}, + Inclusion: inclusion::{Module, Call, Storage, Event}, + Scheduler: scheduler::{Module, Call, Storage}, + Initializer: initializer::{Module, Call, Storage}, + Dmp: dmp::{Module, Call, Storage}, + Ump: ump::{Module, Call, Storage}, + Hrmp: hrmp::{Module, Call, Storage}, + SessionInfo: session_info::{Module, Call, Storage}, } -} +); pub struct TestRandomness; @@ -83,10 +81,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 = (); @@ -101,7 +99,7 @@ parameter_types! { impl pallet_balances::Config for Test { type MaxLocks = (); type Balance = Balance; - type Event = TestEvent; + type Event = Event; type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; @@ -132,7 +130,7 @@ impl crate::hrmp::Config for Test { impl crate::scheduler::Config for Test { } impl crate::inclusion::Config for Test { - type Event = TestEvent; + type Event = Event; type RewardValidators = TestRewardValidators; } @@ -183,37 +181,8 @@ impl inclusion::RewardValidators for TestRewardValidators { } } -pub type System = frame_system::Module; - -/// Mocked initializer. -pub type Initializer = crate::initializer::Module; - -/// Mocked configuration. -pub type Configuration = crate::configuration::Module; - -/// Mocked paras. -pub type Paras = crate::paras::Module; - -/// Mocked DMP -pub type Dmp = crate::dmp::Module; - -/// Mocked UMP -pub type Ump = crate::ump::Module; - -/// Mocked HRMP -pub type Hrmp = crate::hrmp::Module; - -/// Mocked scheduler. -pub type Scheduler = crate::scheduler::Module; - -/// Mocked inclusion module. -pub type Inclusion = crate::inclusion::Module; - -/// Mocked session info module. -pub type SessionInfo = crate::session_info::Module; - /// Create a new set of test externalities. -pub fn new_test_ext(state: GenesisConfig) -> TestExternalities { +pub fn new_test_ext(state: MockGenesisConfig) -> TestExternalities { BACKING_REWARDS.with(|r| r.borrow_mut().clear()); AVAILABILITY_REWARDS.with(|r| r.borrow_mut().clear()); @@ -225,7 +194,7 @@ pub fn new_test_ext(state: GenesisConfig) -> TestExternalities { } #[derive(Default)] -pub struct GenesisConfig { +pub struct MockGenesisConfig { pub system: frame_system::GenesisConfig, pub configuration: crate::configuration::GenesisConfig, pub paras: crate::paras::GenesisConfig, diff --git a/runtime/parachains/src/paras.rs b/runtime/parachains/src/paras.rs index 0e1b968ac4e0..bc137db3ada6 100644 --- a/runtime/parachains/src/paras.rs +++ b/runtime/parachains/src/paras.rs @@ -837,7 +837,7 @@ mod tests { use primitives::v1::BlockNumber; use frame_support::traits::{OnFinalize, OnInitialize}; - use crate::mock::{new_test_ext, Paras, System, GenesisConfig as MockGenesisConfig}; + use crate::mock::{new_test_ext, Paras, System, MockGenesisConfig}; use crate::configuration::HostConfiguration; fn run_to_block(to: BlockNumber, new_session: Option>) { diff --git a/runtime/parachains/src/scheduler.rs b/runtime/parachains/src/scheduler.rs index f21f6646d4cf..f8e46cffd017 100644 --- a/runtime/parachains/src/scheduler.rs +++ b/runtime/parachains/src/scheduler.rs @@ -739,7 +739,7 @@ mod tests { use frame_support::traits::{OnFinalize, OnInitialize}; use keyring::Sr25519Keyring; - use crate::mock::{new_test_ext, Configuration, Paras, System, Scheduler, GenesisConfig as MockGenesisConfig}; + use crate::mock::{new_test_ext, Configuration, Paras, System, Scheduler, MockGenesisConfig}; use crate::initializer::SessionChangeNotification; use crate::configuration::HostConfiguration; use crate::paras::ParaGenesisArgs; diff --git a/runtime/parachains/src/session_info.rs b/runtime/parachains/src/session_info.rs index 89c4b03c98bf..12facbea05d9 100644 --- a/runtime/parachains/src/session_info.rs +++ b/runtime/parachains/src/session_info.rs @@ -165,7 +165,7 @@ impl OneSessionHandler for Mod mod tests { use super::*; use crate::mock::{ - new_test_ext, Configuration, SessionInfo, System, GenesisConfig as MockGenesisConfig, + new_test_ext, Configuration, SessionInfo, System, MockGenesisConfig, Origin, }; use crate::initializer::SessionChangeNotification; diff --git a/runtime/parachains/src/ump.rs b/runtime/parachains/src/ump.rs index 35c0188c5b5f..3728382a3723 100644 --- a/runtime/parachains/src/ump.rs +++ b/runtime/parachains/src/ump.rs @@ -661,7 +661,7 @@ pub(crate) mod mock_sink { mod tests { use super::*; use super::mock_sink::Probe; - use crate::mock::{Configuration, Ump, new_test_ext, GenesisConfig as MockGenesisConfig}; + use crate::mock::{Configuration, Ump, new_test_ext, MockGenesisConfig}; use frame_support::IterableStorageMap; use std::collections::HashSet; @@ -686,7 +686,7 @@ mod tests { } impl GenesisConfigBuilder { - fn build(self) -> crate::mock::GenesisConfig { + fn build(self) -> crate::mock::MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config;