diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 32159c6936..9d29777fd5 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -4351,6 +4351,7 @@ dependencies = [ "frame-system", "impl-trait-for-tuples 0.2.0", "parity-scale-codec", + "serde", "sp-authorship", "sp-core", "sp-inherents", diff --git a/substrate/frame/atomic-swap/src/tests.rs b/substrate/frame/atomic-swap/src/tests.rs index 19f5fc1dff..977b17f871 100644 --- a/substrate/frame/atomic-swap/src/tests.rs +++ b/substrate/frame/atomic-swap/src/tests.rs @@ -1,20 +1,30 @@ #![cfg(test)] use super::*; +use crate as pallet_atomic_swap; -use frame_support::{impl_outer_origin, parameter_types}; +use frame_support::parameter_types; use sp_core::H256; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, }; -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}, + AtomicSwap: pallet_atomic_swap::{Module, Call, Event}, + } +); -#[derive(Clone, Eq, Debug, PartialEq)] -pub struct Test; parameter_types! { pub const BlockHashCount: u64 = 250; pub BlockWeights: frame_system::limits::BlockWeights = @@ -29,15 +39,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 = (); @@ -51,7 +61,7 @@ impl pallet_balances::Config for Test { type MaxLocks = (); type Balance = u64; type DustRemoval = (); - type Event = (); + type Event = Event; type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); @@ -61,13 +71,10 @@ parameter_types! { pub const ExpireDuration: u64 = 100; } impl Config for Test { - type Event = (); + type Event = Event; type SwapAction = BalanceSwapAction; type ProofLimit = ProofLimit; } -type System = frame_system::Module; -type Balances = pallet_balances::Module; -type AtomicSwap = Module; const A: u64 = 1; const B: u64 = 2; diff --git a/substrate/frame/aura/src/mock.rs b/substrate/frame/aura/src/mock.rs index 69e914a23a..c7c439393d 100644 --- a/substrate/frame/aura/src/mock.rs +++ b/substrate/frame/aura/src/mock.rs @@ -19,23 +19,30 @@ #![cfg(test)] -use crate::{Config, Module, GenesisConfig}; +use crate as pallet_aura; use sp_consensus_aura::ed25519::AuthorityId; use sp_runtime::{ traits::IdentityLookup, testing::{Header, UintAuthorityId}, }; -use frame_support::{impl_outer_origin, parameter_types}; +use frame_support::parameter_types; use sp_io; use sp_core::H256; -impl_outer_origin!{ - pub enum Origin for Test where system = frame_system {} -} +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlock; -// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. -#[derive(Clone, PartialEq, Eq, Debug)] -pub struct Test; +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}, + Aura: pallet_aura::{Module, Call, Storage, Config, Inherent}, + } +); parameter_types! { pub const BlockHashCount: u64 = 250; @@ -52,16 +59,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 = ::sp_runtime::traits::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 = (); @@ -76,16 +83,14 @@ impl pallet_timestamp::Config for Test { type WeightInfo = (); } -impl Config for Test { +impl pallet_aura::Config for Test { type AuthorityId = AuthorityId; } pub fn new_test_ext(authorities: Vec) -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - GenesisConfig::{ + pallet_aura::GenesisConfig::{ authorities: authorities.into_iter().map(|a| UintAuthorityId(a).to_public_key()).collect(), }.assimilate_storage(&mut t).unwrap(); t.into() } - -pub type Aura = Module; diff --git a/substrate/frame/authority-discovery/src/lib.rs b/substrate/frame/authority-discovery/src/lib.rs index 9a7c209887..219219b995 100644 --- a/substrate/frame/authority-discovery/src/lib.rs +++ b/substrate/frame/authority-discovery/src/lib.rs @@ -115,6 +115,7 @@ impl pallet_session::OneSessionHandler for Module { #[cfg(test)] mod tests { + use crate as pallet_authority_discovery; use super::*; use sp_authority_discovery::AuthorityPair; use sp_application_crypto::Pair; @@ -124,12 +125,23 @@ mod tests { testing::{Header, UintAuthorityId}, traits::{ConvertInto, IdentityLookup, OpaqueKeys}, Perbill, KeyTypeId, }; - use frame_support::{impl_outer_origin, parameter_types}; + use frame_support::parameter_types; - type AuthorityDiscovery = Module; + 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}, + Session: pallet_session::{Module, Call, Storage, Event, Config}, + AuthorityDiscovery: pallet_authority_discovery::{Module, Call, Config}, + } + ); - #[derive(Clone, Eq, PartialEq)] - pub struct Test; impl Config for Test {} parameter_types! { @@ -141,7 +153,7 @@ mod tests { type Keys = UintAuthorityId; type ShouldEndSession = pallet_session::PeriodicSessions; type SessionHandler = TestSessionHandler; - type Event = (); + type Event = Event; type ValidatorId = AuthorityId; type ValidatorIdOf = ConvertInto; type DisabledValidatorsThreshold = DisabledValidatorsThreshold; @@ -173,16 +185,16 @@ mod tests { type Origin = Origin; type Index = u64; type BlockNumber = BlockNumber; - type Call = (); + type Call = Call; type Hash = H256; type Hashing = ::sp_runtime::traits::BlakeTwo256; type AccountId = AuthorityId; 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 = (); @@ -190,10 +202,6 @@ mod tests { type SS58Prefix = (); } - impl_outer_origin! { - pub enum Origin for Test where system = frame_system {} - } - pub struct TestSessionHandler; impl pallet_session::SessionHandler for TestSessionHandler { const KEY_TYPE_IDS: &'static [KeyTypeId] = &[key_types::DUMMY]; @@ -247,7 +255,7 @@ mod tests { .build_storage::() .unwrap(); - GenesisConfig { + pallet_authority_discovery::GenesisConfig { keys: vec![], } .assimilate_storage::(&mut t) diff --git a/substrate/frame/authorship/Cargo.toml b/substrate/frame/authorship/Cargo.toml index d957fb9094..64e3fb12b0 100644 --- a/substrate/frame/authorship/Cargo.toml +++ b/substrate/frame/authorship/Cargo.toml @@ -25,6 +25,7 @@ impl-trait-for-tuples = "0.2.0" [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/substrate/frame/authorship/src/lib.rs b/substrate/frame/authorship/src/lib.rs index d31d686625..3d89ab24d0 100644 --- a/substrate/frame/authorship/src/lib.rs +++ b/substrate/frame/authorship/src/lib.rs @@ -396,19 +396,27 @@ impl ProvideInherent for Module { #[cfg(test)] mod tests { + use crate as pallet_authorship; use super::*; use sp_core::H256; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, testing::Header, generic::DigestItem, }; - use frame_support::{parameter_types, impl_outer_origin, ConsensusEngineId}; + use frame_support::{parameter_types, ConsensusEngineId}; - impl_outer_origin!{ - pub enum Origin for Test where system = frame_system {} - } + type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; + type Block = frame_system::mocking::MockBlock; - #[derive(Clone, Eq, PartialEq)] - pub struct Test; + frame_support::construct_runtime!( + pub enum Test where + Block = Block, + NodeBlock = Block, + UncheckedExtrinsic = UncheckedExtrinsic, + { + System: frame_system::{Module, Call, Config, Storage, Event}, + Authorship: pallet_authorship::{Module, Call, Storage, Inherent}, + } + ); parameter_types! { pub const BlockHashCount: u64 = 250; @@ -424,16 +432,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 = (); @@ -452,9 +460,6 @@ mod tests { type EventHandler = (); } - type System = frame_system::Module; - type Authorship = Module; - const TEST_ID: ConsensusEngineId = [1, 2, 3, 4]; pub struct AuthorGiven;