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

Use construct_runtime in tests, remove default PalletInfo impl #2409

Merged
10 commits merged into from
Feb 9, 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
51 changes: 25 additions & 26 deletions runtime/common/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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>},
Vesting: pallet_vesting::{Module, Call, Storage, Config<T>, Event<T>},
Claims: claims::{Module, Call, Storage, Config<T>, Event<T>, 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;
}
Expand All @@ -645,10 +648,10 @@ mod tests {
type AccountId = u64;
type Lookup = IdentityLookup<u64>;
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 @@ -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;
Expand All @@ -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;
Expand All @@ -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<Six, u64>;
type WeightInfo = TestWeightInfo;
}
type System = frame_system::Module<Test>;
type Balances = pallet_balances::Module<Test>;
type Vesting = pallet_vesting::Module<Test>;
type Claims = Module<Test>;

fn alice() -> secp256k1::SecretKey {
secp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap()
Expand All @@ -723,7 +722,7 @@ mod tests {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
// We use default for brevity, but you can configure as desired if needed.
pallet_balances::GenesisConfig::<Test>::default().assimilate_storage(&mut t).unwrap();
GenesisConfig::<Test>{
claims::GenesisConfig::<Test>{
claims: vec![
(eth(&alice()), 100, None, None),
(eth(&dave()), 200, None, Some(StatementKind::Regular)),
Expand Down
58 changes: 22 additions & 36 deletions runtime/common/src/crowdloan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<T>,
pallet_balances<T>,
pallet_treasury<T>,
runtime_common_slots<T>,
runtime_common_crowdloan<T>,
use crate::slots::{self, Registrar};
use crate::crowdloan;

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>},
Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
Slots: slots::{Module, Call, Storage, Event<T>},
Crowdloan: crowdloan::{Module, Call, Storage, Event<T>},
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;
}
Expand All @@ -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;
Expand All @@ -641,7 +633,7 @@ mod tests {
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
Expand Down Expand Up @@ -765,12 +757,6 @@ mod tests {
type RemoveKeysLimit = RemoveKeysLimit;
}

type System = frame_system::Module<Test>;
type Balances = pallet_balances::Module<Test>;
type Slots = slots::Module<Test>;
type Treasury = pallet_treasury::Module<Test>;
type Crowdloan = Module<Test>;
type RandomnessCollectiveFlip = pallet_randomness_collective_flip::Module<Test>;
use pallet_balances::Error as BalancesError;
use slots::Error as SlotsError;

Expand Down
34 changes: 19 additions & 15 deletions runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -83,12 +83,20 @@ mod tests {
};
use primitives::v1::AccountId;

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Test;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

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<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
}
);

parameter_types! {
pub const BlockHashCount: u64 = 250;
Expand All @@ -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<Self::AccountId>;
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<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
Expand All @@ -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;
Expand All @@ -147,7 +155,7 @@ mod tests {
type Currency = pallet_balances::Module<Test>;
type ApproveOrigin = frame_system::EnsureRoot<AccountId>;
type RejectOrigin = frame_system::EnsureRoot<AccountId>;
type Event = ();
type Event = Event;
type OnSlash = ();
type ProposalBond = ();
type ProposalBondMinimum = ();
Expand All @@ -174,10 +182,6 @@ mod tests {
type EventHandler = ();
}

type Treasury = pallet_treasury::Module<Test>;
type Balances = pallet_balances::Module<Test>;
type System = frame_system::Module<Test>;

pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
// We use default for brevity, but you can configure as desired if needed.
Expand Down
26 changes: 15 additions & 11 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,26 @@ impl<T: pallet_session::Config> OneSessionHandler<T::AccountId> 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,
traits::{BlakeTwo256, IdentityLookup, Convert},
Perbill,
};

#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Runtime;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;

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<T>}
}
);

parameter_types! {
pub const BlockHashCount: u64 = 250;
Expand All @@ -220,25 +226,23 @@ 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<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 = ();
}

type System = frame_system::Module<Runtime>;

fn run_with_system_weight<F>(w: Weight, assertions: F) where F: Fn() -> () {
let mut t: sp_io::TestExternalities =
frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap().into();
Expand Down
Loading