mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 10:31:04 +00:00
Migrate some more pallets to construct_runtime (#7975)
* WIP converting balances tests to construct_runtime * Converting balances tests_local to construct_runtime * Fix up system and balances Events * Use static Call instance in tests * Migrate indices to construct_runtime * Migrate babe test to construct_runtime * Update frame/indices/src/mock.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/babe/src/mock.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Update frame/babe/src/mock.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Remove redundant import Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -19,20 +19,6 @@
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CallWithDispatchInfo;
|
||||
impl sp_runtime::traits::Dispatchable for CallWithDispatchInfo {
|
||||
type Origin = ();
|
||||
type Config = ();
|
||||
type Info = frame_support::weights::DispatchInfo;
|
||||
type PostInfo = frame_support::weights::PostDispatchInfo;
|
||||
|
||||
fn dispatch(self, _origin: Self::Origin)
|
||||
-> sp_runtime::DispatchResultWithInfo<Self::PostInfo> {
|
||||
panic!("Do not use dummy implementation for dispatch.");
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! decl_tests {
|
||||
($test:ty, $ext_builder:ty, $existential_deposit:expr) => {
|
||||
@@ -52,10 +38,8 @@ macro_rules! decl_tests {
|
||||
const ID_1: LockIdentifier = *b"1 ";
|
||||
const ID_2: LockIdentifier = *b"2 ";
|
||||
|
||||
pub type System = frame_system::Module<$test>;
|
||||
pub type Balances = Module<$test>;
|
||||
|
||||
pub const CALL: &<$test as frame_system::Config>::Call = &$crate::tests::CallWithDispatchInfo;
|
||||
pub const CALL: &<$test as frame_system::Config>::Call =
|
||||
&Call::Balances(pallet_balances::Call::transfer(0, 0));
|
||||
|
||||
/// create a transaction info struct from weight. Handy to avoid building the whole struct.
|
||||
pub fn info_from_weight(w: Weight) -> DispatchInfo {
|
||||
@@ -485,7 +469,7 @@ macro_rules! decl_tests {
|
||||
assert_ok!(Balances::repatriate_reserved(&1, &2, 41, Status::Free), 0);
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
Event::balances(RawEvent::ReserveRepatriated(1, 2, 41, Status::Free)),
|
||||
Event::pallet_balances(RawEvent::ReserveRepatriated(1, 2, 41, Status::Free)),
|
||||
);
|
||||
assert_eq!(Balances::reserved_balance(1), 69);
|
||||
assert_eq!(Balances::free_balance(1), 0);
|
||||
@@ -626,7 +610,7 @@ macro_rules! decl_tests {
|
||||
fn cannot_set_genesis_value_below_ed() {
|
||||
($existential_deposit).with(|v| *v.borrow_mut() = 11);
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<$test>().unwrap();
|
||||
let _ = GenesisConfig::<$test> {
|
||||
let _ = pallet_balances::GenesisConfig::<$test> {
|
||||
balances: vec![(1, 10)],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
}
|
||||
@@ -635,7 +619,7 @@ macro_rules! decl_tests {
|
||||
#[should_panic = "duplicate balances in genesis."]
|
||||
fn cannot_set_genesis_value_twice() {
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<$test>().unwrap();
|
||||
let _ = GenesisConfig::<$test> {
|
||||
let _ = pallet_balances::GenesisConfig::<$test> {
|
||||
balances: vec![(1, 10), (2, 20), (1, 15)],
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
}
|
||||
@@ -704,7 +688,7 @@ macro_rules! decl_tests {
|
||||
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
Event::balances(RawEvent::Reserved(1, 10)),
|
||||
Event::pallet_balances(RawEvent::Reserved(1, 10)),
|
||||
);
|
||||
|
||||
System::set_block_number(3);
|
||||
@@ -712,7 +696,7 @@ macro_rules! decl_tests {
|
||||
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
Event::balances(RawEvent::Unreserved(1, 5)),
|
||||
Event::pallet_balances(RawEvent::Unreserved(1, 5)),
|
||||
);
|
||||
|
||||
System::set_block_number(4);
|
||||
@@ -721,7 +705,7 @@ macro_rules! decl_tests {
|
||||
// should only unreserve 5
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
Event::balances(RawEvent::Unreserved(1, 5)),
|
||||
Event::pallet_balances(RawEvent::Unreserved(1, 5)),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -737,9 +721,9 @@ macro_rules! decl_tests {
|
||||
assert_eq!(
|
||||
events(),
|
||||
[
|
||||
Event::system(system::Event::NewAccount(1)),
|
||||
Event::balances(RawEvent::Endowed(1, 100)),
|
||||
Event::balances(RawEvent::BalanceSet(1, 100, 0)),
|
||||
Event::frame_system(system::Event::NewAccount(1)),
|
||||
Event::pallet_balances(RawEvent::Endowed(1, 100)),
|
||||
Event::pallet_balances(RawEvent::BalanceSet(1, 100, 0)),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -748,8 +732,8 @@ macro_rules! decl_tests {
|
||||
assert_eq!(
|
||||
events(),
|
||||
[
|
||||
Event::balances(RawEvent::DustLost(1, 99)),
|
||||
Event::system(system::Event::KilledAccount(1))
|
||||
Event::pallet_balances(RawEvent::DustLost(1, 99)),
|
||||
Event::frame_system(system::Event::KilledAccount(1))
|
||||
]
|
||||
);
|
||||
});
|
||||
@@ -766,9 +750,9 @@ macro_rules! decl_tests {
|
||||
assert_eq!(
|
||||
events(),
|
||||
[
|
||||
Event::system(system::Event::NewAccount(1)),
|
||||
Event::balances(RawEvent::Endowed(1, 100)),
|
||||
Event::balances(RawEvent::BalanceSet(1, 100, 0)),
|
||||
Event::frame_system(system::Event::NewAccount(1)),
|
||||
Event::pallet_balances(RawEvent::Endowed(1, 100)),
|
||||
Event::pallet_balances(RawEvent::BalanceSet(1, 100, 0)),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -777,7 +761,7 @@ macro_rules! decl_tests {
|
||||
assert_eq!(
|
||||
events(),
|
||||
[
|
||||
Event::system(system::Event::KilledAccount(1))
|
||||
Event::frame_system(system::Event::KilledAccount(1))
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -25,30 +25,27 @@ use sp_runtime::{
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_io;
|
||||
use frame_support::{impl_outer_origin, impl_outer_event, parameter_types};
|
||||
use frame_support::parameter_types;
|
||||
use frame_support::weights::{Weight, DispatchInfo, IdentityFee};
|
||||
use pallet_transaction_payment::CurrencyAdapter;
|
||||
use crate::{GenesisConfig, Module, Config, decl_tests, tests::CallWithDispatchInfo};
|
||||
use crate::{
|
||||
self as pallet_balances,
|
||||
Module, Config, decl_tests,
|
||||
};
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
|
||||
use frame_system as system;
|
||||
impl_outer_origin!{
|
||||
pub enum Origin for Test {}
|
||||
}
|
||||
|
||||
mod balances {
|
||||
pub use crate::Event;
|
||||
}
|
||||
|
||||
impl_outer_event! {
|
||||
pub enum Event for Test {
|
||||
system<T>,
|
||||
balances<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>},
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Test;
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
@@ -63,7 +60,7 @@ impl frame_system::Config for Test {
|
||||
type Origin = Origin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Call = CallWithDispatchInfo;
|
||||
type Call = Call;
|
||||
type Hash = H256;
|
||||
type Hashing = ::sp_runtime::traits::BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
@@ -72,7 +69,7 @@ impl frame_system::Config for Test {
|
||||
type Event = Event;
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type Version = ();
|
||||
type PalletInfo = ();
|
||||
type PalletInfo = PalletInfo;
|
||||
type AccountData = super::AccountData<u64>;
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
@@ -94,7 +91,7 @@ impl Config for Test {
|
||||
type DustRemoval = ();
|
||||
type Event = Event;
|
||||
type ExistentialDeposit = ExistentialDeposit;
|
||||
type AccountStore = system::Module<Test>;
|
||||
type AccountStore = frame_system::Pallet<Test>;
|
||||
type MaxLocks = ();
|
||||
type WeightInfo = ();
|
||||
}
|
||||
@@ -126,7 +123,7 @@ impl ExtBuilder {
|
||||
pub fn build(self) -> sp_io::TestExternalities {
|
||||
self.set_associated_consts();
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
GenesisConfig::<Test> {
|
||||
pallet_balances::GenesisConfig::<Test> {
|
||||
balances: if self.monied {
|
||||
vec![
|
||||
(1, 10 * self.existential_deposit),
|
||||
|
||||
@@ -25,31 +25,29 @@ use sp_runtime::{
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_io;
|
||||
use frame_support::{impl_outer_origin, impl_outer_event, parameter_types};
|
||||
use frame_support::parameter_types;
|
||||
use frame_support::traits::StorageMapShim;
|
||||
use frame_support::weights::{Weight, DispatchInfo, IdentityFee};
|
||||
use crate::{GenesisConfig, Module, Config, decl_tests, tests::CallWithDispatchInfo};
|
||||
use crate::{
|
||||
self as pallet_balances,
|
||||
Module, Config, decl_tests,
|
||||
};
|
||||
use pallet_transaction_payment::CurrencyAdapter;
|
||||
|
||||
use frame_system as system;
|
||||
impl_outer_origin!{
|
||||
pub enum Origin for Test {}
|
||||
}
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
|
||||
mod balances {
|
||||
pub use crate::Event;
|
||||
}
|
||||
|
||||
impl_outer_event! {
|
||||
pub enum Event for Test {
|
||||
system<T>,
|
||||
balances<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>},
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Test;
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub BlockWeights: frame_system::limits::BlockWeights =
|
||||
@@ -64,7 +62,7 @@ impl frame_system::Config for Test {
|
||||
type Origin = Origin;
|
||||
type Index = u64;
|
||||
type BlockNumber = u64;
|
||||
type Call = CallWithDispatchInfo;
|
||||
type Call = Call;
|
||||
type Hash = H256;
|
||||
type Hashing = ::sp_runtime::traits::BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
@@ -73,7 +71,7 @@ impl frame_system::Config for Test {
|
||||
type Event = Event;
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type Version = ();
|
||||
type PalletInfo = ();
|
||||
type PalletInfo = PalletInfo;
|
||||
type AccountData = ();
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
@@ -137,7 +135,7 @@ impl ExtBuilder {
|
||||
pub fn build(self) -> sp_io::TestExternalities {
|
||||
self.set_associated_consts();
|
||||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
GenesisConfig::<Test> {
|
||||
pallet_balances::GenesisConfig::<Test> {
|
||||
balances: if self.monied {
|
||||
vec![
|
||||
(1, 10 * self.existential_deposit),
|
||||
@@ -170,9 +168,9 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
|
||||
assert_eq!(
|
||||
events(),
|
||||
[
|
||||
Event::system(system::Event::NewAccount(1)),
|
||||
Event::balances(RawEvent::Endowed(1, 100)),
|
||||
Event::balances(RawEvent::BalanceSet(1, 100, 0)),
|
||||
Event::frame_system(frame_system::Event::NewAccount(1)),
|
||||
Event::pallet_balances(RawEvent::Endowed(1, 100)),
|
||||
Event::pallet_balances(RawEvent::BalanceSet(1, 100, 0)),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -186,8 +184,8 @@ fn emit_events_with_no_existential_deposit_suicide_with_dust() {
|
||||
assert_eq!(
|
||||
events(),
|
||||
[
|
||||
Event::balances(RawEvent::DustLost(1, 1)),
|
||||
Event::system(system::Event::KilledAccount(1))
|
||||
Event::pallet_balances(RawEvent::DustLost(1, 1)),
|
||||
Event::frame_system(frame_system::Event::KilledAccount(1))
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user