@@ -30,6 +30,7 @@ use frame_support::traits::StorageMapShim;
30
30
use frame_support:: weights:: { Weight , DispatchInfo , IdentityFee } ;
31
31
use crate :: { GenesisConfig , Module , Config , decl_tests, tests:: CallWithDispatchInfo } ;
32
32
use pallet_transaction_payment:: CurrencyAdapter ;
33
+ use std:: any:: TypeId ;
33
34
34
35
use frame_system as system;
35
36
impl_outer_origin ! {
@@ -47,6 +48,38 @@ impl_outer_event! {
47
48
}
48
49
}
49
50
51
+ /// Provides an implementation of `PalletInfo`.
52
+ ///
53
+ /// Usually this is generated by the `construct_runtime!` macro, but tests typically use `()`.
54
+ /// However the impl for `()` returns the same prefix "test" for all modules, which causes
55
+ /// collisions between pallets with storage items with the same name. For instance in this case
56
+ /// System and Balances both have a storage item called `Account`.
57
+ pub struct PalletInfo ;
58
+
59
+ impl frame_support:: traits:: PalletInfo for PalletInfo {
60
+ fn index < P : ' static > ( ) -> Option < usize > {
61
+ let type_id = TypeId :: of :: < P > ( ) ;
62
+ if type_id == TypeId :: of :: < system:: Pallet < Test > > ( ) {
63
+ return Some ( 0 )
64
+ }
65
+ if type_id == TypeId :: of :: < crate :: Pallet < Test > > ( ) {
66
+ return Some ( 1 )
67
+ }
68
+ None
69
+ }
70
+
71
+ fn name < P : ' static > ( ) -> Option < & ' static str > {
72
+ let type_id = TypeId :: of :: < P > ( ) ;
73
+ if type_id == TypeId :: of :: < system:: Pallet < Test > > ( ) {
74
+ return Some ( "System" )
75
+ }
76
+ if type_id == TypeId :: of :: < crate :: Pallet < Test > > ( ) {
77
+ return Some ( "Balances" )
78
+ }
79
+ None
80
+ }
81
+ }
82
+
50
83
// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
51
84
#[ derive( Clone , PartialEq , Eq , Debug ) ]
52
85
pub struct Test ;
@@ -73,7 +106,7 @@ impl frame_system::Config for Test {
73
106
type Event = Event ;
74
107
type BlockHashCount = BlockHashCount ;
75
108
type Version = ( ) ;
76
- type PalletInfo = ( ) ;
109
+ type PalletInfo = PalletInfo ;
77
110
type AccountData = ( ) ;
78
111
type OnNewAccount = ( ) ;
79
112
type OnKilledAccount = ( ) ;
0 commit comments