Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Use construct_runtime for some more pallet #7974

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 21 additions & 14 deletions frame/atomic-swap/src/tests.rs
Original file line number Diff line number Diff line change
@@ -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<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

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>},
AtomicSwap: pallet_atomic_swap::{Module, Call, Event<T>},
}
);

#[derive(Clone, Eq, Debug, PartialEq)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
Expand All @@ -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<Self::AccountId>;
type Header = Header;
type Event = ();
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
Expand All @@ -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 = ();
Expand All @@ -61,13 +71,10 @@ parameter_types! {
pub const ExpireDuration: u64 = 100;
}
impl Config for Test {
type Event = ();
type Event = Event;
type SwapAction = BalanceSwapAction<u64, Balances>;
type ProofLimit = ProofLimit;
}
type System = frame_system::Module<Test>;
type Balances = pallet_balances::Module<Test>;
type AtomicSwap = Module<Test>;

const A: u64 = 1;
const B: u64 = 2;
Expand Down
35 changes: 20 additions & 15 deletions frame/aura/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

// 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<T>},
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Aura: pallet_aura::{Module, Call, Storage, Config<T>, Inherent},
}
);

parameter_types! {
pub const BlockHashCount: u64 = 250;
Expand All @@ -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<Self::AccountId>;
type Header = Header;
type Event = ();
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
Expand All @@ -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<u64>) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
GenesisConfig::<Test>{
pallet_aura::GenesisConfig::<Test>{
authorities: authorities.into_iter().map(|a| UintAuthorityId(a).to_public_key()).collect(),
}.assimilate_storage(&mut t).unwrap();
t.into()
}

pub type Aura = Module<Test>;
36 changes: 22 additions & 14 deletions frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl<T: Config> pallet_session::OneSessionHandler<T::AccountId> for Module<T> {

#[cfg(test)]
mod tests {
use crate as pallet_authority_discovery;
use super::*;
use sp_authority_discovery::AuthorityPair;
use sp_application_crypto::Pair;
Expand All @@ -124,12 +125,23 @@ mod tests {
testing::{Header, UintAuthorityId}, traits::{ConvertInto, IdentityLookup, OpaqueKeys},
Perbill, KeyTypeId,
};
use frame_support::{impl_outer_origin, parameter_types};

type AuthorityDiscovery = Module<Test>;
use frame_support::parameter_types;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
AuthorityDiscovery: pallet_authority_discovery::{Module, Call, Config},
}
);

#[derive(Clone, Eq, PartialEq)]
pub struct Test;
impl Config for Test {}

parameter_types! {
Expand All @@ -141,7 +153,7 @@ mod tests {
type Keys = UintAuthorityId;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type SessionHandler = TestSessionHandler;
type Event = ();
type Event = Event;
type ValidatorId = AuthorityId;
type ValidatorIdOf = ConvertInto;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
Expand Down Expand Up @@ -173,27 +185,23 @@ 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<Self::AccountId>;
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 = ();
}

impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
}

pub struct TestSessionHandler;
impl pallet_session::SessionHandler<AuthorityId> for TestSessionHandler {
const KEY_TYPE_IDS: &'static [KeyTypeId] = &[key_types::DUMMY];
Expand Down Expand Up @@ -247,7 +255,7 @@ mod tests {
.build_storage::<Test>()
.unwrap();

GenesisConfig {
pallet_authority_discovery::GenesisConfig {
keys: vec![],
}
.assimilate_storage::<Test>(&mut t)
Expand Down
1 change: 1 addition & 0 deletions frame/authorship/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
29 changes: 17 additions & 12 deletions frame/authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,19 +396,27 @@ impl<T: Config> ProvideInherent for Module<T> {

#[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<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

#[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<T>},
Authorship: pallet_authorship::{Module, Call, Storage, Inherent},
}
);

parameter_types! {
pub const BlockHashCount: u64 = 250;
Expand All @@ -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<Self::AccountId>;
type Header = Header;
type Event = ();
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
Expand All @@ -452,9 +460,6 @@ mod tests {
type EventHandler = ();
}

type System = frame_system::Module<Test>;
type Authorship = Module<Test>;

const TEST_ID: ConsensusEngineId = [1, 2, 3, 4];

pub struct AuthorGiven;
Expand Down