Automatic pallet parts in construct_runtime (#9681)

* implement automatic parts

* ui tests

* rename

* remove unnecessary exclude

* better doc

* better doc

* fix genesis config

* fix UI tests

* fix UI test

* Revert "fix UI test"

This reverts commit a910351c0b24cfe42195cfd97d83a416640e3259.

* implemented used_parts

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* doc + fmt

* Update frame/support/procedural/src/construct_runtime/parse.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* add doc in the macro

* remove yet some more parts

* fix ui test

* more determnistic error message + fix ui tests

* fix ui test

* Apply suggestions from code review

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* do refactor + fix ui tests

* fmt

* fix test

* fix test

* fix ui test

* Apply suggestions from code review

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* refactor

* remove even more part in node-runtime

* fix test

* Add flow chart for the construct_runtime! execution flow

* Fix typo

* Ignore snippets that don't contain code

* Refactor some code in expand_after

* Rename expand_after to match_and_insert

* cargo fmt

* Fix rename

* Remove frame_support argument to construct_runtime_parts

* Make use of tt-call to simplify intermediate expansions

* cargo fmt

* Update match_and_insert documentation

* Reset cursor to 0 when no matching patterns are found

* Reorder struct fields on MatchAndInsertDef

* Add test for dependency renames and fix frame-support import

* Add more doc comments

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

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Guillaume Thiolliere
2021-10-31 14:55:10 +01:00
committed by GitHub
parent 0214fde9a6
commit 4292e18e50
31 changed files with 1340 additions and 223 deletions
+29 -6
View File
@@ -509,6 +509,18 @@ pub mod pallet3 {
pub struct Pallet<T>(_);
}
#[frame_support::pallet]
pub mod pallet4 {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
frame_support::parameter_types!(
pub const MyGetParam: u32 = 10;
pub const MyGetParam2: u32 = 11;
@@ -553,6 +565,8 @@ impl pallet2::Config for Runtime {
type Event = Event;
}
impl pallet4::Config for Runtime {}
pub type Header = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>;
@@ -563,12 +577,21 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Call, Event<T>},
Example: pallet::{Pallet, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned},
Example2: pallet2::{Pallet, Call, Event, Config<T>, Storage},
// Exclude part `Storage` in order not to check its metadata in tests.
System: frame_system exclude_parts { Pallet, Storage },
Example: pallet,
Example2: pallet2 exclude_parts { Call },
Example4: pallet4 use_parts { Call },
}
);
// Test that the part `Call` is excluded from Example2 and included in Example4.
fn _ensure_call_is_correctly_excluded_and_included(call: Call) {
match call {
Call::System(_) | Call::Example(_) | Call::Example4(_) => (),
}
}
#[test]
fn transactional_works() {
TestExternalities::default().execute_with(|| {
@@ -995,8 +1018,8 @@ fn migrate_from_pallet_version_to_storage_version() {
AllPalletsWithSystem,
>(&db_weight);
// 3 pallets, 2 writes and every write costs 5 weight.
assert_eq!(3 * 2 * 5, weight);
// 4 pallets, 2 writes and every write costs 5 weight.
assert_eq!(4 * 2 * 5, weight);
// All pallet versions should be removed
assert!(sp_io::storage::get(&pallet_version_key(Example::name())).is_none());
@@ -1268,7 +1291,7 @@ fn metadata() {
},
],
}),
calls: Some(meta_type::<pallet2::Call<Runtime>>().into()),
calls: None,
event: Some(PalletEventMetadata { ty: meta_type::<pallet2::Event>() }),
constants: vec![],
error: None,