Make pallet use construct_runtime in tests instead of impl_* (#7986)

This commit is contained in:
Guillaume Thiolliere
2021-01-26 15:25:04 +01:00
committed by GitHub
parent 6ae24c91e9
commit b1888395e8
18 changed files with 304 additions and 351 deletions
+1
View File
@@ -4860,6 +4860,7 @@ dependencies = [
"frame-system",
"parity-scale-codec",
"safe-mix",
"serde",
"sp-core",
"sp-io",
"sp-runtime",
@@ -23,6 +23,7 @@ sp-std = { version = "2.0.0", default-features = false, path = "../../primitives
[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"]
@@ -132,6 +132,7 @@ impl<T: Config> Randomness<T::Hash> for Module<T> {
#[cfg(test)]
mod tests {
use crate as pallet_randomness_collective_flip;
use super::*;
use sp_core::H256;
use sp_runtime::{
@@ -139,16 +140,21 @@ mod tests {
traits::{BlakeTwo256, Header as _, IdentityLookup},
};
use frame_system::limits;
use frame_support::{
impl_outer_origin, parameter_types, traits::{Randomness, OnInitialize},
};
use frame_support::{parameter_types, traits::{Randomness, OnInitialize}};
#[derive(Clone, PartialEq, Eq)]
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 where system = frame_system {}
}
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
CollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
}
);
parameter_types! {
pub const BlockHashCount: u64 = 250;
@@ -166,16 +172,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 = ();
@@ -183,9 +189,6 @@ mod tests {
type SS58Prefix = ();
}
type System = frame_system::Module<Test>;
type CollectiveFlip = Module<Test>;
fn new_test_ext() -> sp_io::TestExternalities {
let t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
t.into()
+17 -30
View File
@@ -19,36 +19,27 @@
use super::*;
use frame_support::{
impl_outer_origin, impl_outer_dispatch, impl_outer_event, parameter_types,
traits::{OnInitialize, OnFinalize},
};
use frame_support::{parameter_types, traits::{OnInitialize, OnFinalize}};
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup}, testing::Header,
};
use crate as recovery;
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>;
impl_outer_event! {
pub enum TestEvent for Test {
system<T>,
pallet_balances<T>,
recovery<T>,
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>},
Recovery: recovery::{Module, Call, Storage, Event<T>},
}
}
impl_outer_dispatch! {
pub enum Call for Test where origin: Origin {
pallet_balances::Balances,
recovery::Recovery,
}
}
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
);
parameter_types! {
pub const BlockHashCount: u64 = 250;
@@ -70,10 +61,10 @@ impl frame_system::Config for Test {
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = TestEvent;
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u128>;
type OnNewAccount = ();
type OnKilledAccount = ();
@@ -89,7 +80,7 @@ impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u128;
type DustRemoval = ();
type Event = TestEvent;
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
@@ -103,7 +94,7 @@ parameter_types! {
}
impl Config for Test {
type Event = TestEvent;
type Event = Event;
type Call = Call;
type Currency = Balances;
type ConfigDepositBase = ConfigDepositBase;
@@ -112,10 +103,6 @@ impl Config for Test {
type RecoveryDeposit = RecoveryDeposit;
}
pub type Recovery = Module<Test>;
pub type System = frame_system::Module<Test>;
pub type Balances = pallet_balances::Module<Test>;
pub type BalancesCall = pallet_balances::Call<Test>;
pub type RecoveryCall = super::Call<Test>;
+18 -27
View File
@@ -721,7 +721,7 @@ mod tests {
use super::*;
use frame_support::{
impl_outer_event, impl_outer_origin, impl_outer_dispatch, parameter_types, assert_ok, ord_parameter_types,
parameter_types, assert_ok, ord_parameter_types,
assert_noop, assert_err, Hashable,
traits::{OnInitialize, OnFinalize, Filter},
weights::constants::RocksDbWeight,
@@ -781,24 +781,20 @@ mod tests {
}
}
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>;
impl_outer_dispatch! {
pub enum Call for Test where origin: Origin {
system::System,
logger::Logger,
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Logger: logger::{Module, Call, Event},
Scheduler: scheduler::{Module, Call, Storage, Event<T>},
}
}
impl_outer_event! {
pub enum Event for Test {
system<T>,
logger,
scheduler<T>,
}
}
);
// Scheduler must dispatch with root and no filter, this tests base filter is indeed not used.
pub struct BaseFilter;
@@ -808,8 +804,6 @@ mod tests {
}
}
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
@@ -829,18 +823,18 @@ mod tests {
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 SS58Prefix = ();
}
impl logger::Config for Test {
type Event = ();
type Event = Event;
}
parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * BlockWeights::get().max_block;
@@ -851,7 +845,7 @@ mod tests {
}
impl Config for Test {
type Event = ();
type Event = Event;
type Origin = Origin;
type PalletsOrigin = OriginCaller;
type Call = Call;
@@ -860,9 +854,6 @@ mod tests {
type MaxScheduledPerBlock = MaxScheduledPerBlock;
type WeightInfo = ();
}
type System = system::Module<Test>;
type Logger = logger::Module<Test>;
type Scheduler = Module<Test>;
pub fn new_test_ext() -> sp_io::TestExternalities {
let t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
+22 -15
View File
@@ -18,21 +18,31 @@
//! Test utilities
use super::*;
use crate as pallet_scored_pool;
use std::cell::RefCell;
use frame_support::{impl_outer_origin, parameter_types, ord_parameter_types};
use frame_support::{parameter_types, ord_parameter_types};
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup}, testing::Header,
};
use frame_system::EnsureSignedBy;
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>},
ScoredPool: pallet_scored_pool::{Module, Call, Storage, Config<T>, Event<T>},
}
);
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const CandidateDeposit: u64 = 25;
pub const Period: u64 = 4;
@@ -55,15 +65,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 = ();
@@ -74,7 +84,7 @@ impl frame_system::Config for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type Event = ();
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
@@ -109,7 +119,7 @@ impl InitializeMembers<u64> for TestChangeMembers {
}
impl Config for Test {
type Event = ();
type Event = Event;
type KickOrigin = EnsureSignedBy<KickOrigin, u64>;
type MembershipInitialized = TestChangeMembers;
type MembershipChanged = TestChangeMembers;
@@ -120,9 +130,6 @@ impl Config for Test {
type ScoreOrigin = EnsureSignedBy<ScoreOrigin, u64>;
}
type System = frame_system::Module<Test>;
type Balances = pallet_balances::Module<Test>;
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
pallet_balances::GenesisConfig::<Test> {
@@ -136,7 +143,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
(99, 1),
],
}.assimilate_storage(&mut t).unwrap();
GenesisConfig::<Test>{
pallet_scored_pool::GenesisConfig::<Test>{
pool: vec![
(5, None),
(10, Some(1)),
+36 -15
View File
@@ -19,7 +19,7 @@
use super::*;
use std::cell::RefCell;
use frame_support::{impl_outer_origin, parameter_types, BasicExternalities};
use frame_support::{parameter_types, BasicExternalities};
use sp_core::{crypto::key_types::DUMMY, H256};
use sp_runtime::{
Perbill, impl_opaque_keys,
@@ -27,6 +27,9 @@ use sp_runtime::{
testing::{Header, UintAuthorityId},
};
use sp_staking::SessionIndex;
use crate as pallet_session;
#[cfg(feature = "historical")]
use crate::historical as pallet_session_historical;
impl_opaque_keys! {
pub struct MockSessionKeys {
@@ -65,9 +68,33 @@ impl OpaqueKeys for PreUpgradeMockSessionKeys {
}
}
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>;
#[cfg(feature = "historical")]
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>},
Historical: pallet_session_historical::{Module},
}
);
#[cfg(not(feature = "historical"))]
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>},
}
);
thread_local! {
pub static VALIDATORS: RefCell<Vec<u64>> = RefCell::new(vec![1, 2, 3]);
@@ -189,13 +216,10 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
// An additional identity that we use.
frame_system::Module::<Test>::inc_providers(&69);
});
GenesisConfig::<Test> { keys }.assimilate_storage(&mut t).unwrap();
pallet_session::GenesisConfig::<Test> { keys }.assimilate_storage(&mut t).unwrap();
sp_io::TestExternalities::new(t)
}
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const MinimumPeriod: u64 = 5;
pub const BlockHashCount: u64 = 250;
@@ -211,16 +235,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 = 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 = ();
@@ -249,7 +273,7 @@ impl Config for Test {
type ValidatorId = u64;
type ValidatorIdOf = ConvertInto;
type Keys = MockSessionKeys;
type Event = ();
type Event = Event;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type NextSessionRotation = ();
type WeightInfo = ();
@@ -260,6 +284,3 @@ impl crate::historical::Config for Test {
type FullIdentification = u64;
type FullIdentificationOf = sp_runtime::traits::ConvertInto;
}
pub type System = frame_system::Module<Test>;
pub type Session = Module<Test>;
+21 -15
View File
@@ -18,9 +18,10 @@
//! Test utilities
use super::*;
use crate as pallet_society;
use frame_support::{
impl_outer_origin, parameter_types, ord_parameter_types,
parameter_types, ord_parameter_types,
traits::{OnInitialize, OnFinalize, TestRandomness},
};
use sp_core::H256;
@@ -30,12 +31,21 @@ use sp_runtime::{
};
use frame_system::EnsureSignedBy;
impl_outer_origin! {
pub enum Origin for Test {}
}
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>},
Society: pallet_society::{Module, Call, Storage, Event<T>, Config<T>},
}
);
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const CandidateDeposit: u64 = 25;
pub const WrongSideDeduction: u64 = 2;
@@ -65,12 +75,12 @@ 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 = u128;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = ();
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
@@ -84,7 +94,7 @@ impl frame_system::Config for Test {
impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type Event = ();
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
@@ -92,7 +102,7 @@ impl pallet_balances::Config for Test {
}
impl Config for Test {
type Event = ();
type Event = Event;
type Currency = pallet_balances::Module<Self>;
type Randomness = TestRandomness;
type CandidateDeposit = CandidateDeposit;
@@ -108,10 +118,6 @@ impl Config for Test {
type ModuleId = SocietyModuleId;
}
pub type Society = Module<Test>;
pub type System = frame_system::Module<Test>;
pub type Balances = pallet_balances::Module<Test>;
pub struct EnvBuilder {
members: Vec<u128>,
balance: u64,
@@ -147,7 +153,7 @@ impl EnvBuilder {
pallet_balances::GenesisConfig::<Test> {
balances: self.balances,
}.assimilate_storage(&mut t).unwrap();
GenesisConfig::<Test>{
pallet_society::GenesisConfig::<Test>{
members: self.members,
pot: self.pot,
max_members: self.max_members,
+24 -43
View File
@@ -18,8 +18,9 @@
//! Test utilities
use crate::*;
use crate as staking;
use frame_support::{
assert_ok, impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types,
assert_ok, parameter_types,
traits::{Currency, FindAuthor, Get, OnFinalize, OnInitialize},
weights::{constants::RocksDbWeight, Weight},
IterableStorageMap, StorageDoubleMap, StorageMap, StorageValue,
@@ -87,32 +88,22 @@ pub fn is_disabled(controller: AccountId) -> bool {
SESSION.with(|d| d.borrow().1.contains(&stash))
}
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>;
impl_outer_dispatch! {
pub enum Call for Test where origin: Origin {
staking::Staking,
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},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Staking: staking::{Module, Call, Config<T>, Storage, Event<T>, ValidateUnsigned},
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
}
}
mod staking {
// Re-export needed for `impl_outer_event!`.
pub use super::super::*;
}
use frame_system as system;
use pallet_balances as balances;
use pallet_session as session;
impl_outer_event! {
pub enum MetaEvent for Test {
system<T>,
balances<T>,
session,
staking<T>,
}
}
);
/// Author of block is always 11
pub struct Author11;
@@ -124,10 +115,6 @@ impl FindAuthor<AccountId> for Author11 {
}
}
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
#[derive(Clone, Eq, PartialEq, Debug)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
@@ -158,10 +145,10 @@ impl frame_system::Config for Test {
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = MetaEvent;
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<Balance>;
type OnNewAccount = ();
type OnKilledAccount = ();
@@ -171,7 +158,7 @@ impl frame_system::Config for Test {
impl pallet_balances::Config for Test {
type MaxLocks = MaxLocks;
type Balance = Balance;
type Event = MetaEvent;
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
@@ -191,7 +178,7 @@ impl pallet_session::Config for Test {
type Keys = SessionKeys;
type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
type SessionHandler = (OtherSessionHandler,);
type Event = MetaEvent;
type Event = Event;
type ValidatorId = AccountId;
type ValidatorIdOf = crate::StashOf<Test>;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
@@ -257,7 +244,7 @@ impl Config for Test {
type UnixTime = Timestamp;
type CurrencyToVote = frame_support::traits::SaturatingCurrencyToVote;
type RewardRemainder = RewardRemainderMock;
type Event = MetaEvent;
type Event = Event;
type Slash = ();
type Reward = ();
type SessionsPerEra = SessionsPerEra;
@@ -450,7 +437,7 @@ impl ExtBuilder {
(101, 100, balance_factor * 500, StakerStatus::<AccountId>::Nominator(nominated))
];
}
let _ = GenesisConfig::<Test>{
let _ = staking::GenesisConfig::<Test>{
stakers: stakers,
validator_count: self.validator_count,
minimum_validator_count: self.minimum_validator_count,
@@ -495,12 +482,6 @@ impl ExtBuilder {
}
}
pub type System = frame_system::Module<Test>;
pub type Balances = pallet_balances::Module<Test>;
pub type Session = pallet_session::Module<Test>;
pub type Timestamp = pallet_timestamp::Module<Test>;
pub type Staking = Module<Test>;
fn post_conditions() {
check_nominators();
check_exposures();
@@ -1016,9 +997,9 @@ macro_rules! assert_session_era {
};
}
pub(crate) fn staking_events() -> Vec<Event<Test>> {
pub(crate) fn staking_events() -> Vec<staking::Event<Test>> {
System::events().into_iter().map(|r| r.event).filter_map(|e| {
if let MetaEvent::staking(inner) = e {
if let Event::staking(inner) = e {
Some(inner)
} else {
None
+7 -4
View File
@@ -3181,7 +3181,7 @@ mod offchain_election {
.into_iter()
.map(|r| r.event)
.filter_map(|e| {
if let MetaEvent::staking(inner) = e {
if let mock::Event::staking(inner) = e {
Some(inner)
} else {
None
@@ -3266,7 +3266,7 @@ mod offchain_election {
.into_iter()
.map(|r| r.event)
.filter_map(|e| {
if let MetaEvent::staking(inner) = e {
if let mock::Event::staking(inner) = e {
Some(inner)
} else {
None
@@ -3285,7 +3285,7 @@ mod offchain_election {
.into_iter()
.map(|r| r.event)
.filter_map(|e| {
if let MetaEvent::staking(inner) = e {
if let mock::Event::staking(inner) = e {
Some(inner)
} else {
None
@@ -3322,7 +3322,7 @@ mod offchain_election {
.into_iter()
.map(|r| r.event)
.filter_map(|e| {
if let MetaEvent::staking(inner) = e {
if let mock::Event::staking(inner) = e {
Some(inner)
} else {
None
@@ -3458,6 +3458,7 @@ mod offchain_election {
let call = extrinsic.call;
let inner = match call {
mock::Call::Staking(inner) => inner,
_ => unreachable!(),
};
assert_eq!(
@@ -3501,6 +3502,7 @@ mod offchain_election {
let call = extrinsic.call;
let inner = match call {
mock::Call::Staking(inner) => inner,
_ => unreachable!(),
};
assert_eq!(
@@ -3548,6 +3550,7 @@ mod offchain_election {
let call = extrinsic.call;
let inner = match call {
mock::Call::Staking(inner) => inner,
_ => unreachable!(),
};
// pass this call to ValidateUnsigned
+18 -40
View File
@@ -18,10 +18,7 @@
//! Test utilities
use super::*;
use frame_support::{
impl_outer_origin, impl_outer_dispatch, impl_outer_event, parameter_types,
weights::Weight,
};
use frame_support::{parameter_types, weights::Weight};
use sp_core::H256;
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
use sp_io;
@@ -76,34 +73,20 @@ pub mod logger {
}
}
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>;
mod test_events {
pub use crate::Event;
}
impl_outer_event! {
pub enum TestEvent for Test {
frame_system<T>,
sudo<T>,
logger<T>,
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Sudo: sudo::{Module, Call, Config<T>, Storage, Event<T>},
Logger: logger::{Module, Call, Storage, Event<T>},
}
}
impl_outer_dispatch! {
pub enum Call for Test where origin: Origin {
sudo::Sudo,
logger::Logger,
}
}
// For testing the pallet, we construct most of a mock runtime. This means
// first constructing a configuration type (`Test`) which `impl`s each of the
// configuration traits of pallets we want to use.
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
);
parameter_types! {
pub const BlockHashCount: u64 = 250;
@@ -131,10 +114,10 @@ impl frame_system::Config for Test {
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = TestEvent;
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
@@ -144,20 +127,15 @@ impl frame_system::Config for Test {
// Implement the logger module's `Config` on the Test runtime.
impl logger::Config for Test {
type Event = TestEvent;
type Event = Event;
}
// Implement the sudo module's `Config` on the Test runtime.
impl Config for Test {
type Event = TestEvent;
type Event = Event;
type Call = Call;
}
// Assign back to type variables in order to make dispatched calls of these modules later.
pub type Sudo = Module<Test>;
pub type Logger = logger::Module<Test>;
pub type System = frame_system::Module<Test>;
// New types for dispatchable functions.
pub type SudoCall = sudo::Call<Test>;
pub type LoggerCall = logger::Call<Test>;
@@ -165,7 +143,7 @@ pub type LoggerCall = logger::Call<Test>;
// Build test environment by setting the root `key` for the Genesis.
pub fn new_test_ext(root_key: u64) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
GenesisConfig::<Test>{
sudo::GenesisConfig::<Test>{
key: root_key,
}.assimilate_storage(&mut t).unwrap();
t.into()
+2 -1
View File
@@ -19,7 +19,8 @@
use super::*;
use mock::{
Sudo, SudoCall, Origin, Call, Test, new_test_ext, LoggerCall, Logger, System, TestEvent,
Sudo, SudoCall, Origin, Call, Test, new_test_ext, LoggerCall, Logger, System,
Event as TestEvent,
};
use frame_support::{assert_ok, assert_noop};
+18 -10
View File
@@ -290,9 +290,10 @@ impl<T: Config> UnixTime for Module<T> {
#[cfg(test)]
mod tests {
use crate as pallet_timestamp;
use super::*;
use frame_support::{impl_outer_origin, assert_ok, parameter_types};
use frame_support::{assert_ok, parameter_types};
use sp_io::TestExternalities;
use sp_core::H256;
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
@@ -302,12 +303,20 @@ mod tests {
TestExternalities::new(t)
}
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>},
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
}
);
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
@@ -321,16 +330,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 = ();
@@ -346,7 +355,6 @@ mod tests {
type MinimumPeriod = MinimumPeriod;
type WeightInfo = ();
}
type Timestamp = Module<Test>;
#[test]
fn timestamp_works() {
+18 -28
View File
@@ -19,13 +19,11 @@
#![cfg(test)]
use crate as tips;
use super::*;
use std::cell::RefCell;
use frame_support::{
assert_noop, assert_ok, impl_outer_origin, parameter_types, weights::Weight,
impl_outer_event, traits::{Contains}
};
use sp_runtime::{Permill};
use frame_support::{assert_noop, assert_ok, parameter_types, weights::Weight, traits::Contains};
use sp_runtime::Permill;
use sp_core::H256;
use sp_runtime::{
Perbill, ModuleId,
@@ -33,26 +31,22 @@ use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup, BadOrigin},
};
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>;
mod tips {
// Re-export needed for `impl_outer_event!`.
pub use crate::*;
}
impl_outer_event! {
pub enum Event for Test {
system<T>,
pallet_balances<T>,
pallet_treasury<T>,
tips<T>,
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>},
TipsModTestInst: tips::{Module, Call, Storage, Event<T>},
}
}
);
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: Weight = 1024;
@@ -67,7 +61,7 @@ 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 = BlakeTwo256;
type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account
@@ -76,7 +70,7 @@ impl frame_system::Config for Test {
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
@@ -159,10 +153,6 @@ impl Config for Test {
type Event = Event;
type WeightInfo = ();
}
type System = frame_system::Module<Test>;
type Balances = pallet_balances::Module<Test>;
type Treasury = pallet_treasury::Module<Test>;
type TipsModTestInst = Module<Test>;
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
+18 -27
View File
@@ -600,9 +600,11 @@ impl<T: Config> SignedExtension for ChargeTransactionPayment<T> where
#[cfg(test)]
mod tests {
use super::*;
use crate as pallet_transaction_payment;
use frame_system as system;
use codec::Encode;
use frame_support::{
impl_outer_dispatch, impl_outer_origin, impl_outer_event, parameter_types,
parameter_types,
weights::{
DispatchClass, DispatchInfo, PostDispatchInfo, GetDispatchInfo, Weight,
WeightToFeePolynomial, WeightToFeeCoefficients, WeightToFeeCoefficient,
@@ -619,31 +621,24 @@ mod tests {
use std::cell::RefCell;
use smallvec::smallvec;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;
frame_support::construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: system::{Module, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
TransactionPayment: pallet_transaction_payment::{Module, Storage},
}
);
const CALL: &<Runtime as frame_system::Config>::Call =
&Call::Balances(BalancesCall::transfer(2, 69));
impl_outer_dispatch! {
pub enum Call for Runtime where origin: Origin {
pallet_balances::Balances,
frame_system::System,
}
}
impl_outer_event! {
pub enum Event for Runtime {
system<T>,
pallet_balances<T>,
}
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct Runtime;
use frame_system as system;
impl_outer_origin!{
pub enum Origin for Runtime {}
}
thread_local! {
static EXTRINSIC_BASE_WEIGHT: RefCell<u64> = RefCell::new(0);
}
@@ -728,10 +723,6 @@ mod tests {
type FeeMultiplierUpdate = ();
}
type Balances = pallet_balances::Module<Runtime>;
type System = frame_system::Module<Runtime>;
type TransactionPayment = Module<Runtime>;
pub struct ExtBuilder {
balance_factor: u64,
base_weight: u64,
+19 -26
View File
@@ -19,13 +19,13 @@
#![cfg(test)]
use crate as treasury;
use super::*;
use std::cell::RefCell;
use frame_support::{
assert_noop, assert_ok, impl_outer_origin, impl_outer_event, parameter_types,
traits::{OnInitialize}
assert_noop, assert_ok, parameter_types,
traits::OnInitialize,
};
use frame_system::{self as system};
use sp_core::H256;
use sp_runtime::{
@@ -34,25 +34,21 @@ use sp_runtime::{
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>;
mod treasury {
// Re-export needed for `impl_outer_event!`.
pub use super::super::*;
}
impl_outer_event! {
pub enum Event for Test {
system<T>,
pallet_balances<T>,
treasury<T>,
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: treasury::{Module, Call, Storage, Config, Event<T>},
}
}
);
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
@@ -66,7 +62,7 @@ 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 = BlakeTwo256;
type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account
@@ -75,7 +71,7 @@ impl frame_system::Config for Test {
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
@@ -122,9 +118,6 @@ impl Config for Test {
type WeightInfo = ();
type SpendFunds = ();
}
type System = frame_system::Module<Test>;
type Balances = pallet_balances::Module<Test>;
type Treasury = Module<Test>;
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
@@ -132,7 +125,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
// Total issuance will be 200 with treasury account initialized at ED.
balances: vec![(0, 100), (1, 98), (2, 1)],
}.assimilate_storage(&mut t).unwrap();
GenesisConfig::default().assimilate_storage::<Test, _>(&mut t).unwrap();
treasury::GenesisConfig::default().assimilate_storage::<Test, _>(&mut t).unwrap();
t.into()
}
@@ -358,7 +351,7 @@ fn genesis_funding_works() {
// Total issuance will be 200 with treasury account initialized with 100.
balances: vec![(0, 100), (Treasury::account_id(), initial_funding)],
}.assimilate_storage(&mut t).unwrap();
GenesisConfig::default().assimilate_storage::<Test, _>(&mut t).unwrap();
treasury::GenesisConfig::default().assimilate_storage::<Test, _>(&mut t).unwrap();
let mut t: sp_io::TestExternalities = t.into();
t.execute_with(|| {
+25 -38
View File
@@ -22,8 +22,7 @@
use super::*;
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, parameter_types, impl_outer_dispatch, impl_outer_event,
assert_err_ignore_postinfo,
assert_ok, assert_noop, parameter_types, assert_err_ignore_postinfo,
weights::{Weight, Pays},
dispatch::{DispatchError, DispatchErrorWithPostInfo, Dispatchable},
traits::Filter,
@@ -67,30 +66,22 @@ pub mod example {
}
}
impl_outer_origin! {
pub enum Origin for Test where system = frame_system {}
}
impl_outer_event! {
pub enum TestEvent for Test {
frame_system<T>,
pallet_balances<T>,
utility,
}
}
impl_outer_dispatch! {
pub enum Call for Test where origin: Origin {
frame_system::System,
pallet_balances::Balances,
utility::Utility,
example::Example,
}
}
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>},
Utility: utility::{Module, Call, Event},
Example: example::{Module, Call},
}
);
// For testing the pallet, we construct most of a mock runtime. This means
// first constructing a configuration type (`Test`) which `impl`s each of the
// configuration traits of pallets we want to use.
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
@@ -110,7 +101,7 @@ impl frame_system::Config for Test {
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = TestEvent;
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = ();
@@ -127,7 +118,7 @@ impl pallet_balances::Config for Test {
type MaxLocks = ();
type Balance = u64;
type DustRemoval = ();
type Event = TestEvent;
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
@@ -156,14 +147,10 @@ impl Filter<Call> for TestBaseCallFilter {
}
}
impl Config for Test {
type Event = TestEvent;
type Event = Event;
type Call = Call;
type WeightInfo = ();
}
type System = frame_system::Module<Test>;
type Balances = pallet_balances::Module<Test>;
type Example = example::Module<Test>;
type Utility = Module<Test>;
type ExampleCall = example::Call<Test>;
type UtilityCall = crate::Call<Test>;
@@ -182,11 +169,11 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
ext
}
fn last_event() -> TestEvent {
fn last_event() -> Event {
frame_system::Module::<Test>::events().pop().map(|e| e.event).expect("Event expected")
}
fn expect_event<E: Into<TestEvent>>(e: E) {
fn expect_event<E: Into<Event>>(e: E) {
assert_eq!(last_event(), e.into());
}
@@ -324,7 +311,7 @@ fn batch_with_signed_filters() {
Call::Balances(pallet_balances::Call::transfer_keep_alive(2, 1))
]),
);
expect_event(Event::BatchInterrupted(0, DispatchError::BadOrigin));
expect_event(utility::Event::BatchInterrupted(0, DispatchError::BadOrigin));
});
}
@@ -398,7 +385,7 @@ fn batch_handles_weight_refund() {
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
expect_event(Event::BatchInterrupted(1, DispatchError::Other("")));
expect_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")));
// No weight is refunded
assert_eq!(extract_actual_weight(&result, &info), info.weight);
@@ -411,7 +398,7 @@ fn batch_handles_weight_refund() {
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
expect_event(Event::BatchInterrupted(1, DispatchError::Other("")));
expect_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")));
assert_eq!(extract_actual_weight(&result, &info), info.weight - diff * batch_len);
// Partial batch completion
@@ -422,7 +409,7 @@ fn batch_handles_weight_refund() {
let info = call.get_dispatch_info();
let result = call.dispatch(Origin::signed(1));
assert_ok!(result);
expect_event(Event::BatchInterrupted(1, DispatchError::Other("")));
expect_event(utility::Event::BatchInterrupted(1, DispatchError::Other("")));
assert_eq!(
extract_actual_weight(&result, &info),
// Real weight is 2 calls at end_weight
+22 -18
View File
@@ -389,10 +389,9 @@ impl<T: Config> VestingSchedule<T::AccountId> for Module<T> where
#[cfg(test)]
mod tests {
use super::*;
use crate as pallet_vesting;
use frame_support::{
assert_ok, assert_noop, impl_outer_origin, parameter_types,
};
use frame_support::{assert_ok, assert_noop, parameter_types};
use sp_core::H256;
use sp_runtime::{
testing::Header,
@@ -400,12 +399,21 @@ mod tests {
};
use frame_system::RawOrigin;
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>},
Vesting: pallet_vesting::{Module, Call, Storage, Event<T>, Config<T>},
}
);
#[derive(Clone, Eq, PartialEq)]
pub struct Test;
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
@@ -420,15 +428,15 @@ mod tests {
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 = ();
@@ -441,7 +449,7 @@ mod tests {
impl pallet_balances::Config for Test {
type Balance = u64;
type DustRemoval = ();
type Event = ();
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type MaxLocks = MaxLocks;
@@ -452,16 +460,12 @@ mod tests {
pub static ExistentialDeposit: u64 = 0;
}
impl Config for Test {
type Event = ();
type Event = Event;
type Currency = Balances;
type BlockNumberToBalance = Identity;
type MinVestedTransfer = MinVestedTransfer;
type WeightInfo = ();
}
type System = frame_system::Module<Test>;
type Balances = pallet_balances::Module<Test>;
type Vesting = Module<Test>;
pub struct ExtBuilder {
existential_deposit: u64,
@@ -490,7 +494,7 @@ mod tests {
(12, 10 * self.existential_deposit)
],
}.assimilate_storage(&mut t).unwrap();
GenesisConfig::<Test> {
pallet_vesting::GenesisConfig::<Test> {
vesting: vec![
(1, 0, 10, 5 * self.existential_deposit),
(2, 10, 20, 0),