Replace last usages of <() as PalletInfo> in substrate (#8080)

* replace last occurences

* Update frame/support/src/traits.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/support/test/src/lib.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* fix dispatch test

* move PanicPalletInfo to tests module

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Guillaume Thiolliere
2021-02-09 16:28:34 +01:00
committed by GitHub
parent 1ee71e54e5
commit 9fbbecc195
21 changed files with 137 additions and 28 deletions
+21 -2
View File
@@ -2409,7 +2409,7 @@ mod tests {
use crate::weights::{DispatchInfo, DispatchClass, Pays, RuntimeDbWeight};
use crate::traits::{
CallMetadata, GetCallMetadata, GetCallName, OnInitialize, OnFinalize, OnRuntimeUpgrade,
IntegrityTest, Get,
IntegrityTest, Get, PalletInfo,
};
pub trait Config: system::Config + Sized where Self::AccountId: From<u32> { }
@@ -2562,13 +2562,32 @@ mod tests {
}
}
impl PalletInfo for TraitImpl {
fn index<P: 'static>() -> Option<usize> {
let type_id = sp_std::any::TypeId::of::<P>();
if type_id == sp_std::any::TypeId::of::<Test>() {
return Some(0)
}
None
}
fn name<P: 'static>() -> Option<&'static str> {
let type_id = sp_std::any::TypeId::of::<P>();
if type_id == sp_std::any::TypeId::of::<Test>() {
return Some("Test")
}
None
}
}
impl system::Config for TraitImpl {
type Origin = OuterOrigin;
type AccountId = u32;
type Call = OuterCall;
type BaseCallFilter = ();
type BlockNumber = u32;
type PalletInfo = ();
type PalletInfo = Self;
type DbWeight = ();
}
+3 -3
View File
@@ -729,7 +729,7 @@ mod tests {
impl system::Config for TestRuntime {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
type PalletInfo = crate::tests::PanicPalletInfo;
type DbWeight = ();
}
@@ -744,14 +744,14 @@ mod tests {
impl system_renamed::Config for TestRuntime2 {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
type PalletInfo = crate::tests::PanicPalletInfo;
type DbWeight = ();
}
impl system::Config for TestRuntime2 {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
type PalletInfo = crate::tests::PanicPalletInfo;
type DbWeight = ();
}
+14 -2
View File
@@ -571,7 +571,7 @@ macro_rules! assert_ok {
pub use serde::{Serialize, Deserialize};
#[cfg(test)]
mod tests {
pub mod tests {
use super::*;
use codec::{Codec, EncodeLike};
use frame_metadata::{
@@ -581,6 +581,18 @@ mod tests {
use sp_std::{marker::PhantomData, result};
use sp_io::TestExternalities;
/// A PalletInfo implementation which just panics.
pub struct PanicPalletInfo;
impl crate::traits::PalletInfo for PanicPalletInfo {
fn index<P: 'static>() -> Option<usize> {
unimplemented!("PanicPalletInfo mustn't be triggered by tests");
}
fn name<P: 'static>() -> Option<&'static str> {
unimplemented!("PanicPalletInfo mustn't be triggered by tests");
}
}
pub trait Config: 'static {
type BlockNumber: Codec + EncodeLike + Default;
type Origin;
@@ -625,7 +637,7 @@ mod tests {
impl Config for Test {
type BlockNumber = u32;
type Origin = u32;
type PalletInfo = ();
type PalletInfo = PanicPalletInfo;
type DbWeight = ();
}
+37 -2
View File
@@ -43,10 +43,14 @@ pub use frame_metadata::{
///# }
///# use module0 as module1;
///# use module0 as module2;
///# impl frame_support::traits::PalletInfo for Runtime {
///# fn index<P: 'static>() -> Option<usize> { unimplemented!() }
///# fn name<P: 'static>() -> Option<&'static str> { unimplemented!() }
///# }
///# impl module0::Config for Runtime {
///# type Origin = u32;
///# type BlockNumber = u32;
///# type PalletInfo = ();
///# type PalletInfo = Self;
///# type DbWeight = ();
///# }
///#
@@ -414,6 +418,37 @@ mod tests {
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct TestRuntime;
impl crate::traits::PalletInfo for TestRuntime {
fn index<P: 'static>() -> Option<usize> {
let type_id = sp_std::any::TypeId::of::<P>();
if type_id == sp_std::any::TypeId::of::<system::Module<TestRuntime>>() {
return Some(0)
}
if type_id == sp_std::any::TypeId::of::<EventModule>() {
return Some(1)
}
if type_id == sp_std::any::TypeId::of::<EventModule2>() {
return Some(2)
}
None
}
fn name<P: 'static>() -> Option<&'static str> {
let type_id = sp_std::any::TypeId::of::<P>();
if type_id == sp_std::any::TypeId::of::<system::Module<TestRuntime>>() {
return Some("System")
}
if type_id == sp_std::any::TypeId::of::<EventModule>() {
return Some("EventModule")
}
if type_id == sp_std::any::TypeId::of::<EventModule2>() {
return Some("EventModule2")
}
None
}
}
impl_outer_event! {
pub enum TestEvent for TestRuntime {
system,
@@ -451,7 +486,7 @@ mod tests {
type AccountId = u32;
type BlockNumber = u32;
type SomeValue = SystemValue;
type PalletInfo = ();
type PalletInfo = Self;
type DbWeight = ();
type Call = Call;
}
@@ -52,7 +52,7 @@ mod tests {
impl Config for Runtime {
type Origin = u32;
type BlockNumber = u32;
type PalletInfo = ();
type PalletInfo = crate::tests::PanicPalletInfo;
type DbWeight = ();
}
+1 -1
View File
@@ -841,7 +841,7 @@ mod tests {
type BlockNumber = u32;
type Balance = u32;
type DbWeight = DbWeight;
type PalletInfo = ();
type PalletInfo = crate::tests::PanicPalletInfo;
}
decl_module! {