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:
Andrew Jones
2021-01-25 15:56:07 +00:00
committed by GitHub
parent 681f8408ce
commit ee85121c57
5 changed files with 109 additions and 139 deletions
+17 -33
View File
@@ -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))
]
);
});