diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index ead9135aaa19f..50beb8607d61d 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -995,7 +995,7 @@ mod tests { type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index d566975e2e7a9..057e9f181c7af 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -1074,7 +1074,7 @@ mod tests { type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); diff --git a/frame/elections/src/mock.rs b/frame/elections/src/mock.rs index b386542b2b3db..7c9bc9bfaf8b0 100644 --- a/frame/elections/src/mock.rs +++ b/frame/elections/src/mock.rs @@ -52,7 +52,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; type OnNewAccount = (); type OnKilledAccount = (); diff --git a/frame/offences/benchmarking/src/mock.rs b/frame/offences/benchmarking/src/mock.rs index 5d6d13aa30913..e4ec32d0bc3bf 100644 --- a/frame/offences/benchmarking/src/mock.rs +++ b/frame/offences/benchmarking/src/mock.rs @@ -58,7 +58,7 @@ impl frame_system::Config for Test { type Event = Event; type BlockHashCount = (); type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); diff --git a/frame/society/src/mock.rs b/frame/society/src/mock.rs index 8c39a0bc3ea59..4b1bb21dd18db 100644 --- a/frame/society/src/mock.rs +++ b/frame/society/src/mock.rs @@ -83,7 +83,7 @@ impl frame_system::Config for Test { type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type OnNewAccount = (); type OnKilledAccount = (); type AccountData = pallet_balances::AccountData; diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index 03cda0e4d40e0..7927ccd014bd5 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -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 { } @@ -2562,13 +2562,32 @@ mod tests { } } + impl PalletInfo for TraitImpl { + fn index() -> Option { + let type_id = sp_std::any::TypeId::of::

(); + if type_id == sp_std::any::TypeId::of::() { + return Some(0) + } + + None + } + fn name() -> Option<&'static str> { + let type_id = sp_std::any::TypeId::of::

(); + if type_id == sp_std::any::TypeId::of::() { + 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 = (); } diff --git a/frame/support/src/event.rs b/frame/support/src/event.rs index 39baee29bc0cd..eb666b6f028ab 100644 --- a/frame/support/src/event.rs +++ b/frame/support/src/event.rs @@ -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 = (); } diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 951e12c9c7d4a..940e70852af52 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -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() -> Option { + unimplemented!("PanicPalletInfo mustn't be triggered by tests"); + } + fn name() -> 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 = (); } diff --git a/frame/support/src/metadata.rs b/frame/support/src/metadata.rs index a60481933701b..2edaba1cb47e9 100644 --- a/frame/support/src/metadata.rs +++ b/frame/support/src/metadata.rs @@ -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() -> Option { unimplemented!() } +///# fn name() -> 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() -> Option { + let type_id = sp_std::any::TypeId::of::

(); + if type_id == sp_std::any::TypeId::of::>() { + return Some(0) + } + if type_id == sp_std::any::TypeId::of::() { + return Some(1) + } + if type_id == sp_std::any::TypeId::of::() { + return Some(2) + } + + None + } + fn name() -> Option<&'static str> { + let type_id = sp_std::any::TypeId::of::

(); + if type_id == sp_std::any::TypeId::of::>() { + return Some("System") + } + if type_id == sp_std::any::TypeId::of::() { + return Some("EventModule") + } + if type_id == sp_std::any::TypeId::of::() { + 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; } diff --git a/frame/support/src/storage/generator/mod.rs b/frame/support/src/storage/generator/mod.rs index a9e5665c544d2..fc2a21ff72517 100644 --- a/frame/support/src/storage/generator/mod.rs +++ b/frame/support/src/storage/generator/mod.rs @@ -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 = (); } diff --git a/frame/support/src/weights.rs b/frame/support/src/weights.rs index 32dc9e1f2529f..abd54994bc9e8 100644 --- a/frame/support/src/weights.rs +++ b/frame/support/src/weights.rs @@ -841,7 +841,7 @@ mod tests { type BlockNumber = u32; type Balance = u32; type DbWeight = DbWeight; - type PalletInfo = (); + type PalletInfo = crate::tests::PanicPalletInfo; } decl_module! { diff --git a/frame/support/test/src/lib.rs b/frame/support/test/src/lib.rs index d837056fe6ab6..4b1510bf81f4d 100644 --- a/frame/support/test/src/lib.rs +++ b/frame/support/test/src/lib.rs @@ -41,3 +41,15 @@ frame_support::decl_module! { /// Some test module pub struct Module for enum Call where origin: T::Origin, system=self {} } + +/// A PalletInfo implementation which just panics. +pub struct PanicPalletInfo; + +impl frame_support::traits::PalletInfo for PanicPalletInfo { + fn index() -> Option { + unimplemented!("PanicPalletInfo mustn't be triggered by tests"); + } + fn name() -> Option<&'static str> { + unimplemented!("PanicPalletInfo mustn't be triggered by tests"); + } +} diff --git a/frame/support/test/tests/decl_storage.rs b/frame/support/test/tests/decl_storage.rs index 99697393785fe..a2690b1379db5 100644 --- a/frame/support/test/tests/decl_storage.rs +++ b/frame/support/test/tests/decl_storage.rs @@ -84,7 +84,7 @@ mod tests { impl frame_support_test::Config for TraitImpl { type Origin = u32; type BlockNumber = u32; - type PalletInfo = (); + type PalletInfo = frame_support_test::PanicPalletInfo; type DbWeight = (); } @@ -441,7 +441,7 @@ mod test2 { impl frame_support_test::Config for TraitImpl { type Origin = u32; type BlockNumber = u32; - type PalletInfo = (); + type PalletInfo = frame_support_test::PanicPalletInfo; type DbWeight = (); } @@ -469,7 +469,7 @@ mod test3 { impl frame_support_test::Config for TraitImpl { type Origin = u32; type BlockNumber = u32; - type PalletInfo = (); + type PalletInfo = frame_support_test::PanicPalletInfo; type DbWeight = (); } @@ -514,7 +514,7 @@ mod test_append_and_len { impl frame_support_test::Config for Test { type Origin = u32; type BlockNumber = u32; - type PalletInfo = (); + type PalletInfo = frame_support_test::PanicPalletInfo; type DbWeight = (); } diff --git a/frame/support/test/tests/genesisconfig.rs b/frame/support/test/tests/genesisconfig.rs index dd98fca8c9538..a30b021d13e51 100644 --- a/frame/support/test/tests/genesisconfig.rs +++ b/frame/support/test/tests/genesisconfig.rs @@ -32,7 +32,7 @@ struct Test; impl frame_support_test::Config for Test { type BlockNumber = u32; type Origin = (); - type PalletInfo = (); + type PalletInfo = frame_support_test::PanicPalletInfo; type DbWeight = (); } diff --git a/frame/support/test/tests/instance.rs b/frame/support/test/tests/instance.rs index dc6c41564a753..f7d79b7d4bf6e 100644 --- a/frame/support/test/tests/instance.rs +++ b/frame/support/test/tests/instance.rs @@ -253,7 +253,7 @@ impl system::Config for Runtime { type BlockNumber = BlockNumber; type AccountId = AccountId; type Event = Event; - type PalletInfo = (); + type PalletInfo = PalletInfo; type Call = Call; type DbWeight = (); } diff --git a/frame/support/test/tests/issue2219.rs b/frame/support/test/tests/issue2219.rs index adabb2d597928..4eacca9daca01 100644 --- a/frame/support/test/tests/issue2219.rs +++ b/frame/support/test/tests/issue2219.rs @@ -164,7 +164,7 @@ impl system::Config for Runtime { type BlockNumber = BlockNumber; type AccountId = AccountId; type Event = Event; - type PalletInfo = (); + type PalletInfo = PalletInfo; type Call = Call; type DbWeight = (); } diff --git a/frame/support/test/tests/pallet_with_name_trait_is_valid.rs b/frame/support/test/tests/pallet_with_name_trait_is_valid.rs index 6247e46c85f01..b09beb04cd17c 100644 --- a/frame/support/test/tests/pallet_with_name_trait_is_valid.rs +++ b/frame/support/test/tests/pallet_with_name_trait_is_valid.rs @@ -135,7 +135,7 @@ mod tests { type BlockWeights = (); type BlockLength = (); type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); diff --git a/frame/support/test/tests/storage_transaction.rs b/frame/support/test/tests/storage_transaction.rs index ee6ce5869e176..b518c60e957c6 100644 --- a/frame/support/test/tests/storage_transaction.rs +++ b/frame/support/test/tests/storage_transaction.rs @@ -53,7 +53,7 @@ struct Runtime; impl frame_support_test::Config for Runtime { type Origin = u32; type BlockNumber = u32; - type PalletInfo = (); + type PalletInfo = frame_support_test::PanicPalletInfo; type DbWeight = (); } diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 5f907fb91b99e..c460fcba3a597 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -681,7 +681,7 @@ mod tests { type Event = Event; type BlockHashCount = BlockHashCount; type Version = (); - type PalletInfo = (); + type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); diff --git a/frame/utility/src/tests.rs b/frame/utility/src/tests.rs index b14f958bd6f8d..af31bbe96cbc4 100644 --- a/frame/utility/src/tests.rs +++ b/frame/utility/src/tests.rs @@ -104,7 +104,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; type OnNewAccount = (); type OnKilledAccount = (); diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index d7d7ccd31b713..b349d1266b031 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -433,6 +433,37 @@ impl From> for Event { } } +impl frame_support::traits::PalletInfo for Runtime { + fn index() -> Option { + let type_id = sp_std::any::TypeId::of::

(); + if type_id == sp_std::any::TypeId::of::>() { + return Some(0) + } + if type_id == sp_std::any::TypeId::of::>() { + return Some(1) + } + if type_id == sp_std::any::TypeId::of::>() { + return Some(2) + } + + None + } + fn name() -> Option<&'static str> { + let type_id = sp_std::any::TypeId::of::

(); + if type_id == sp_std::any::TypeId::of::>() { + return Some("System") + } + if type_id == sp_std::any::TypeId::of::>() { + return Some("Timestamp") + } + if type_id == sp_std::any::TypeId::of::>() { + return Some("Babe") + } + + None + } +} + parameter_types! { pub const BlockHashCount: BlockNumber = 2400; pub const MinimumPeriod: u64 = 5; @@ -463,7 +494,7 @@ impl frame_system::Config for Runtime { type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); - type PalletInfo = (); + type PalletInfo = Self; type AccountData = (); type OnNewAccount = (); type OnKilledAccount = ();