Unverified Commit 6a19ab14 authored by Andrew Jones's avatar Andrew Jones Committed by GitHub
Browse files

Use construct_runtime in tests, remove default PalletInfo impl (#2409)



* Claims

* Crowdloan

* Runtime common

* Parachains registrar

* Impls

* Purchase

* Slots

* parachains runtime mock

* Use MockGenesisConfig in tests

* Update runtime/common/src/claims.rs

Co-authored-by: thiolliere's avatarGuillaume Thiolliere <gui.thiolliere@gmail.com>

Co-authored-by: thiolliere's avatarGuillaume Thiolliere <gui.thiolliere@gmail.com>
parent 57eb9d10
Pipeline #123595 passed with stages
in 29 minutes and 38 seconds
......@@ -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;
}
......@@ -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 = ();
......@@ -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<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()
......@@ -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)),
......
......@@ -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<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;
}
......@@ -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<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
......@@ -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;
......
......@@ -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<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;
......@@ -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 = ();
......@@ -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<Test>;
type ApproveOrigin = frame_system::EnsureRoot<AccountId>;
type RejectOrigin = frame_system::EnsureRoot<AccountId>;
type Event = ();
type Event = Event;
type OnSlash = ();
type ProposalBond = ();
type ProposalBondMinimum = ();
......@@ -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.
......
......@@ -188,7 +188,7 @@ 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,
......@@ -196,12 +196,18 @@ mod multiplier_tests {
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;
......@@ -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<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 = ();
......@@ -237,8 +243,6 @@ mod multiplier_tests {
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();
......
......@@ -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<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>},
Parachains: paras::{Module, Origin, Call, Storage, Config<T>},
Inclusion: inclusion::{Module, Call, Storage, Event<T>},
Registrar: paras_registrar::{Module, Call, Storage},
Staking: pallet_staking::{Module, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
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<u64>;
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<u128>;
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<Period, Offset>;
type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
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<Test>;
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<Test>;
type Parachains = paras::Module<Test>;
type Inclusion = inclusion::Module<Test>;
type System = frame_system::Module<Test>;
type Registrar = Module<Test>;
type Session = pallet_session::Module<Test>;
type Staking = pallet_staking::Module<Test>;
type Initializer = initializer::Module<Test>;
fn new_test_ext() -> TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
......
......@@ -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<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>},
Purchase: purchase::{Module, Call, Storage, Event<T>},
}
}
);
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<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 = ();
......@@ -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<ValidityOrigin, AccountId>;
......@@ -499,11 +500,6 @@ mod tests {
type MaxUnlocked = MaxUnlocked;
}
type System = frame_system::Module<Test>;
type Balances = pallet_balances::Module<Test>;
type Vesting = pallet_vesting::Module<Test>;
type Purchase = Module<Test>;
// 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 {
......
......@@ -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<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>},
Slots: slots::{Module, Call, Storage, Event<T>},
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 {