Replace 'Module' with 'Pallet' in construct_runtime macro (#8372)

* Use 'Pallet' struct in construct_runtime.

* Fix genesis and metadata macro.

* Fix 'Pallet' type alias.

* Replace 'Module' with 'Pallet' for all construct_runtime use cases.

* Replace more deprecated 'Module' struct.

* Bring back AllModules and AllPalletsWithSystem type, but deprecate them.

* Replace deprecated 'Module' struct from merge master.

* Minor fix.

* Fix UI tests.

* Revert UI override in derive_no_bound.

* Fix more deprecated 'Module' use from master branch.

* Fix more deprecated 'Module' use from master branch.
This commit is contained in:
Shaun Wang
2021-03-18 21:50:08 +13:00
committed by GitHub
parent 05f24931a9
commit 2e5522444a
157 changed files with 881 additions and 864 deletions
@@ -138,17 +138,17 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module, Call, Event<T>, Origin<T>} = 30,
Module1_1: module1::<Instance1>::{Module, Call, Storage, Event<T>, Origin<T>},
Module2: module2::{Module, Call, Storage, Event, Origin},
Module1_2: module1::<Instance2>::{Module, Call, Storage, Event<T>, Origin<T>},
Module1_3: module1::<Instance3>::{Module, Storage} = 6,
Module1_4: module1::<Instance4>::{Module, Call} = 3,
Module1_5: module1::<Instance5>::{Module, Event<T>},
Module1_6: module1::<Instance6>::{Module, Call, Storage, Event<T>, Origin<T>} = 1,
Module1_7: module1::<Instance7>::{Module, Call, Storage, Event<T>, Origin<T>},
Module1_8: module1::<Instance8>::{Module, Call, Storage, Event<T>, Origin<T>} = 12,
Module1_9: module1::<Instance9>::{Module, Call, Storage, Event<T>, Origin<T>},
System: system::{Pallet, Call, Event<T>, Origin<T>} = 30,
Module1_1: module1::<Instance1>::{Pallet, Call, Storage, Event<T>, Origin<T>},
Module2: module2::{Pallet, Call, Storage, Event, Origin},
Module1_2: module1::<Instance2>::{Pallet, Call, Storage, Event<T>, Origin<T>},
Module1_3: module1::<Instance3>::{Pallet, Storage} = 6,
Module1_4: module1::<Instance4>::{Pallet, Call} = 3,
Module1_5: module1::<Instance5>::{Pallet, Event<T>},
Module1_6: module1::<Instance6>::{Pallet, Call, Storage, Event<T>, Origin<T>} = 1,
Module1_7: module1::<Instance7>::{Pallet, Call, Storage, Event<T>, Origin<T>},
Module1_8: module1::<Instance8>::{Pallet, Call, Storage, Event<T>, Origin<T>} = 12,
Module1_9: module1::<Instance9>::{Pallet, Call, Storage, Event<T>, Origin<T>},
}
);
@@ -1,10 +1,10 @@
error: Module indices are conflicting: Both modules System and Pallet1 are at index 0
error: Pallet indices are conflicting: Both pallets System and Pallet1 are at index 0
--> $DIR/conflicting_index.rs:9:3
|
9 | System: system::{},
| ^^^^^^
error: Module indices are conflicting: Both modules System and Pallet1 are at index 0
error: Pallet indices are conflicting: Both pallets System and Pallet1 are at index 0
--> $DIR/conflicting_index.rs:10:3
|
10 | Pallet1: pallet1::{} = 0,
@@ -1,10 +1,10 @@
error: Module indices are conflicting: Both modules System and Pallet3 are at index 5
error: Pallet indices are conflicting: Both pallets System and Pallet3 are at index 5
--> $DIR/conflicting_index_2.rs:9:3
|
9 | System: system::{} = 5,
| ^^^^^^
error: Module indices are conflicting: Both modules System and Pallet3 are at index 5
error: Pallet indices are conflicting: Both pallets System and Pallet3 are at index 5
--> $DIR/conflicting_index_2.rs:12:3
|
12 | Pallet3: pallet3::{},
@@ -6,9 +6,9 @@ construct_runtime! {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module},
Balance: balances::{Module},
Balance: balances::{Module},
System: system::{Pallet},
Balance: balances::{Pallet},
Balance: balances::{Pallet},
}
}
@@ -1,11 +1,11 @@
error: Two modules with the same name!
error: Two pallets with the same name!
--> $DIR/conflicting_module_name.rs:10:3
|
10 | Balance: balances::{Module},
10 | Balance: balances::{Pallet},
| ^^^^^^^
error: Two modules with the same name!
error: Two pallets with the same name!
--> $DIR/conflicting_module_name.rs:11:3
|
11 | Balance: balances::{Module},
11 | Balance: balances::{Pallet},
| ^^^^^^^
@@ -6,7 +6,7 @@ construct_runtime! {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module},
System: system::{Pallet},
Balance: balances::{Config, Call, Config<T>, Origin<T>},
}
}
@@ -6,7 +6,7 @@ construct_runtime! {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module},
System: system::{Pallet},
Balance: balances::<Instance1>::{Call<T>, Origin<T>},
}
}
@@ -1,4 +1,4 @@
error: `Call` is not allowed to have generics. Only the following modules are allowed to have generics: `Event`, `Origin`, `Config`.
error: `Call` is not allowed to have generics. Only the following pallets are allowed to have generics: `Event`, `Origin`, `Config`.
--> $DIR/generics_in_invalid_module.rs:10:36
|
10 | Balance: balances::<Instance1>::{Call<T>, Origin<T>},
@@ -1,4 +1,4 @@
error: expected one of: `Module`, `Call`, `Storage`, `Event`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`
error: expected one of: `Pallet`, `Call`, `Storage`, `Event`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`
--> $DIR/invalid_module_details_keyword.rs:9:20
|
9 | system: System::{enum},
@@ -6,7 +6,7 @@ construct_runtime! {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module},
System: system::{Pallet},
Balance: balances::{Error},
}
}
@@ -1,4 +1,4 @@
error: expected one of: `Module`, `Call`, `Storage`, `Event`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`
error: expected one of: `Pallet`, `Call`, `Storage`, `Event`, `Config`, `Origin`, `Inherent`, `ValidateUnsigned`
--> $DIR/invalid_module_entry.rs:10:23
|
10 | Balance: balances::{Error},
@@ -6,7 +6,7 @@ construct_runtime! {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module},
System: system::{Pallet},
Balance: balances::<Instance1>::{Event},
}
}
@@ -1,4 +1,4 @@
error: Instantiable module with no generic `Event` cannot be constructed: module `Balance` must have generic `Event`
error: Instantiable pallet with no generic `Event` cannot be constructed: pallet `Balance` must have generic `Event`
--> $DIR/missing_event_generic_on_module_with_instance.rs:10:3
|
10 | Balance: balances::<Instance1>::{Event},
@@ -6,7 +6,7 @@ construct_runtime! {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module},
System: system::{Pallet},
Balance: balances::<Instance1>::{Origin},
}
}
@@ -1,4 +1,4 @@
error: Instantiable module with no generic `Origin` cannot be constructed: module `Balance` must have generic `Origin`
error: Instantiable pallet with no generic `Origin` cannot be constructed: pallet `Balance` must have generic `Origin`
--> $DIR/missing_origin_generic_on_module_with_instance.rs:10:3
|
10 | Balance: balances::<Instance1>::{Origin},
@@ -1,4 +1,4 @@
error: `System` module declaration is missing. Please add this line: `System: frame_system::{Module, Call, Storage, Config, Event<T>},`
error: `System` pallet declaration is missing. Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event<T>},`
--> $DIR/missing_system_module.rs:8:2
|
8 | {
@@ -1,4 +1,4 @@
error: Module index doesn't fit into u8, index is 256
error: Pallet index doesn't fit into u8, index is 256
--> $DIR/more_than_256_modules.rs:10:3
|
10 | Pallet256: pallet256::{},
@@ -264,24 +264,24 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module, Call, Event<T>},
System: system::{Pallet, Call, Event<T>},
Module1_1: module1::<Instance1>::{
Module, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
Pallet, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
},
Module1_2: module1::<Instance2>::{
Module, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
Pallet, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
},
Module2: module2::{Module, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent},
Module2: module2::{Pallet, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent},
Module2_1: module2::<Instance1>::{
Module, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
Pallet, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
},
Module2_2: module2::<Instance2>::{
Module, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
Pallet, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
},
Module2_3: module2::<Instance3>::{
Module, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
Pallet, Call, Storage, Event<T>, Config<T>, Origin<T>, Inherent
},
Module3: module3::{Module, Call},
Module3: module3::{Pallet, Call},
}
);
@@ -177,8 +177,8 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module, Call, Event<T>},
Module: module::{Module, Call, Storage, Config},
System: system::{Pallet, Call, Event<T>},
Module: module::{Pallet, Call, Storage, Config},
}
);
+6 -6
View File
@@ -418,9 +418,9 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Event<T>},
Example: pallet::{Module, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned},
Example2: pallet2::{Module, Call, Event, Config<T>, Storage},
System: frame_system::{Pallet, Call, Event<T>},
Example: pallet::{Pallet, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned},
Example2: pallet2::{Pallet, Call, Event, Config<T>, Storage},
}
);
@@ -559,11 +559,11 @@ fn pallet_hooks_expand() {
TestExternalities::default().execute_with(|| {
frame_system::Pallet::<Runtime>::set_block_number(1);
assert_eq!(AllModules::on_initialize(1), 10);
AllModules::on_finalize(1);
assert_eq!(AllPallets::on_initialize(1), 10);
AllPallets::on_finalize(1);
assert_eq!(pallet::Pallet::<Runtime>::storage_version(), None);
assert_eq!(AllModules::on_runtime_upgrade(), 30);
assert_eq!(AllPallets::on_runtime_upgrade(), 30);
assert_eq!(
pallet::Pallet::<Runtime>::storage_version(),
Some(pallet::Pallet::<Runtime>::current_version()),
@@ -247,10 +247,10 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Event<T>},
System: frame_system::{Pallet, Call, Event<T>},
// NOTE: name Example here is needed in order to have same module prefix
Example: pallet::{Module, Call, Event<T>, Config<T>, Storage},
PalletOld: pallet_old::{Module, Call, Event<T>, Config<T>, Storage},
Example: pallet::{Pallet, Call, Event<T>, Config<T>, Storage},
PalletOld: pallet_old::{Pallet, Call, Event<T>, Config<T>, Storage},
}
);
@@ -259,13 +259,13 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Event<T>},
Example: pallet::{Module, Call, Event<T>, Config<T>, Storage},
PalletOld: pallet_old::{Module, Call, Event<T>, Config<T>, Storage},
Instance2Example: pallet::<Instance2>::{Module, Call, Event<T>, Config<T>, Storage},
PalletOld2: pallet_old::<Instance2>::{Module, Call, Event<T>, Config<T>, Storage},
Instance3Example: pallet::<Instance3>::{Module, Call, Event<T>, Config<T>, Storage},
PalletOld3: pallet_old::<Instance3>::{Module, Call, Event<T>, Config<T>, Storage},
System: frame_system::{Pallet, Call, Event<T>},
Example: pallet::{Pallet, Call, Event<T>, Config<T>, Storage},
PalletOld: pallet_old::{Pallet, Call, Event<T>, Config<T>, Storage},
Instance2Example: pallet::<Instance2>::{Pallet, Call, Event<T>, Config<T>, Storage},
PalletOld2: pallet_old::<Instance2>::{Pallet, Call, Event<T>, Config<T>, Storage},
Instance3Example: pallet::<Instance3>::{Pallet, Call, Event<T>, Config<T>, Storage},
PalletOld3: pallet_old::<Instance3>::{Pallet, Call, Event<T>, Config<T>, Storage},
}
);
@@ -288,13 +288,13 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Event<T>},
Example: pallet::{Module, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned},
System: frame_system::{Pallet, Call, Event<T>},
Example: pallet::{Pallet, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned},
Instance1Example: pallet::<Instance1>::{
Module, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned
Pallet, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned
},
Example2: pallet2::{Module, Call, Event<T>, Config<T>, Storage},
Instance1Example2: pallet2::<Instance1>::{Module, Call, Event<T>, Config<T>, Storage},
Example2: pallet2::{Pallet, Call, Event<T>, Config<T>, Storage},
Instance1Example2: pallet2::<Instance1>::{Pallet, Call, Event<T>, Config<T>, Storage},
}
);
@@ -377,19 +377,19 @@ fn instance_expand() {
#[test]
fn pallet_expand_deposit_event() {
TestExternalities::default().execute_with(|| {
frame_system::Module::<Runtime>::set_block_number(1);
frame_system::Pallet::<Runtime>::set_block_number(1);
pallet::Call::<Runtime>::foo(3).dispatch_bypass_filter(None.into()).unwrap();
assert_eq!(
frame_system::Module::<Runtime>::events()[0].event,
frame_system::Pallet::<Runtime>::events()[0].event,
Event::pallet(pallet::Event::Something(3)),
);
});
TestExternalities::default().execute_with(|| {
frame_system::Module::<Runtime>::set_block_number(1);
frame_system::Pallet::<Runtime>::set_block_number(1);
pallet::Call::<Runtime, pallet::Instance1>::foo(3).dispatch_bypass_filter(None.into()).unwrap();
assert_eq!(
frame_system::Module::<Runtime>::events()[0].event,
frame_system::Pallet::<Runtime>::events()[0].event,
Event::pallet_Instance1(pallet::Event::Something(3)),
);
});
@@ -480,14 +480,14 @@ fn storage_expand() {
#[test]
fn pallet_hooks_expand() {
TestExternalities::default().execute_with(|| {
frame_system::Module::<Runtime>::set_block_number(1);
frame_system::Pallet::<Runtime>::set_block_number(1);
assert_eq!(AllModules::on_initialize(1), 21);
AllModules::on_finalize(1);
assert_eq!(AllPallets::on_initialize(1), 21);
AllPallets::on_finalize(1);
assert_eq!(pallet::Pallet::<Runtime>::storage_version(), None);
assert_eq!(pallet::Pallet::<Runtime, pallet::Instance1>::storage_version(), None);
assert_eq!(AllModules::on_runtime_upgrade(), 61);
assert_eq!(AllPallets::on_runtime_upgrade(), 61);
assert_eq!(
pallet::Pallet::<Runtime>::storage_version(),
Some(pallet::Pallet::<Runtime>::current_version()),
@@ -499,27 +499,27 @@ fn pallet_hooks_expand() {
// The order is indeed reversed due to https://github.com/paritytech/substrate/issues/6280
assert_eq!(
frame_system::Module::<Runtime>::events()[0].event,
frame_system::Pallet::<Runtime>::events()[0].event,
Event::pallet_Instance1(pallet::Event::Something(11)),
);
assert_eq!(
frame_system::Module::<Runtime>::events()[1].event,
frame_system::Pallet::<Runtime>::events()[1].event,
Event::pallet(pallet::Event::Something(10)),
);
assert_eq!(
frame_system::Module::<Runtime>::events()[2].event,
frame_system::Pallet::<Runtime>::events()[2].event,
Event::pallet_Instance1(pallet::Event::Something(21)),
);
assert_eq!(
frame_system::Module::<Runtime>::events()[3].event,
frame_system::Pallet::<Runtime>::events()[3].event,
Event::pallet(pallet::Event::Something(20)),
);
assert_eq!(
frame_system::Module::<Runtime>::events()[4].event,
frame_system::Pallet::<Runtime>::events()[4].event,
Event::pallet_Instance1(pallet::Event::Something(31)),
);
assert_eq!(
frame_system::Module::<Runtime>::events()[5].event,
frame_system::Pallet::<Runtime>::events()[5].event,
Event::pallet(pallet::Event::Something(30)),
);
})
@@ -174,15 +174,15 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Event<T>},
Module1: module1::{Module, Call},
Module2: module2::{Module, Call},
Module2_1: module2::<Instance1>::{Module, Call},
Module2_2: module2::<Instance2>::{Module, Call},
Pallet3: pallet3::{Module, Call},
Pallet4: pallet4::{Module, Call},
Pallet4_1: pallet4::<Instance1>::{Module, Call},
Pallet4_2: pallet4::<Instance2>::{Module, Call},
System: frame_system::{Pallet, Call, Event<T>},
Module1: module1::{Pallet, Call},
Module2: module2::{Pallet, Call},
Module2_1: module2::<Instance1>::{Pallet, Call},
Module2_2: module2::<Instance2>::{Pallet, Call},
Pallet3: pallet3::{Pallet, Call},
Pallet4: pallet4::{Pallet, Call},
Pallet4_1: pallet4::<Instance1>::{Pallet, Call},
Pallet4_2: pallet4::<Instance2>::{Pallet, Call},
}
);
@@ -218,7 +218,7 @@ fn check_pallet_version(pallet: &str) {
#[test]
fn on_runtime_upgrade_sets_the_pallet_versions_in_storage() {
sp_io::TestExternalities::new_empty().execute_with(|| {
AllModules::on_runtime_upgrade();
AllPallets::on_runtime_upgrade();
check_pallet_version("Module1");
check_pallet_version("Module2");
@@ -237,7 +237,7 @@ fn on_runtime_upgrade_overwrites_old_version() {
let key = get_pallet_version_storage_key_for_pallet("Module2");
sp_io::storage::set(&key, &SOME_TEST_VERSION.encode());
AllModules::on_runtime_upgrade();
AllPallets::on_runtime_upgrade();
check_pallet_version("Module1");
check_pallet_version("Module2");
@@ -109,8 +109,8 @@ mod tests {
NodeBlock = TestBlock,
UncheckedExtrinsic = TestUncheckedExtrinsic
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
PalletTest: pallet_test::{Module, Call, Storage, Event<T>, Config, ValidateUnsigned, Inherent},
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
PalletTest: pallet_test::{Pallet, Call, Storage, Event<T>, Config, ValidateUnsigned, Inherent},
}
);