mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 06:15:41 +00:00
add frame_system::DefaultConfig to individual pallet DefaultConfigs (#14453)
* add frame_system::DefaultConfig to individual pallet DefaultConfigs * Fixes tests * Minor fix * ".git/.scripts/commands/fmt/fmt.sh" * Adds UI Tests --------- Co-authored-by: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Co-authored-by: command-bot <>
This commit is contained in:
@@ -49,24 +49,33 @@ Consequently, a runtime that wants to include this pallet must implement this tr
|
||||
);
|
||||
|
||||
// we only emit `DefaultConfig` if there are trait items, so an empty `DefaultConfig` is
|
||||
// impossible consequently
|
||||
if config.default_sub_trait.len() > 0 {
|
||||
let trait_items = &config.default_sub_trait;
|
||||
quote!(
|
||||
/// Based on [`Config`]. Auto-generated by
|
||||
/// [`#[pallet::config(with_default)]`](`frame_support::pallet_macros::config`).
|
||||
/// Can be used in tandem with
|
||||
/// [`#[register_default_config]`](`frame_support::register_default_config`) and
|
||||
/// [`#[derive_impl]`](`frame_support::derive_impl`) to derive test config traits
|
||||
/// based on existing pallet config traits in a safe and developer-friendly way.
|
||||
///
|
||||
/// See [here](`frame_support::pallet_macros::config`) for more information and caveats about
|
||||
/// the auto-generated `DefaultConfig` trait and how it is generated.
|
||||
pub trait DefaultConfig {
|
||||
#(#trait_items)*
|
||||
}
|
||||
)
|
||||
} else {
|
||||
Default::default()
|
||||
// impossible consequently.
|
||||
match &config.default_sub_trait {
|
||||
Some(default_sub_trait) if default_sub_trait.items.len() > 0 => {
|
||||
let trait_items = &default_sub_trait.items;
|
||||
|
||||
let type_param_bounds = if default_sub_trait.has_system {
|
||||
let system = &def.frame_system;
|
||||
quote::quote!(: #system::DefaultConfig)
|
||||
} else {
|
||||
quote::quote!()
|
||||
};
|
||||
|
||||
quote!(
|
||||
/// Based on [`Config`]. Auto-generated by
|
||||
/// [`#[pallet::config(with_default)]`](`frame_support::pallet_macros::config`).
|
||||
/// Can be used in tandem with
|
||||
/// [`#[register_default_config]`](`frame_support::register_default_config`) and
|
||||
/// [`#[derive_impl]`](`frame_support::derive_impl`) to derive test config traits
|
||||
/// based on existing pallet config traits in a safe and developer-friendly way.
|
||||
///
|
||||
/// See [here](`frame_support::pallet_macros::config`) for more information and caveats about
|
||||
/// the auto-generated `DefaultConfig` trait and how it is generated.
|
||||
pub trait DefaultConfig #type_param_bounds {
|
||||
#(#trait_items)*
|
||||
}
|
||||
)
|
||||
},
|
||||
_ => Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,12 @@ mod keyword {
|
||||
syn::custom_keyword!(constant);
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DefaultTrait {
|
||||
pub items: Vec<syn::TraitItem>,
|
||||
pub has_system: bool,
|
||||
}
|
||||
|
||||
/// Input definition for the pallet config.
|
||||
pub struct ConfigDef {
|
||||
/// The index of item in pallet module.
|
||||
@@ -58,8 +64,8 @@ pub struct ConfigDef {
|
||||
///
|
||||
/// Contains default sub-trait items (instantiated by `#[pallet::config(with_default)]`).
|
||||
/// Vec will be empty if `#[pallet::config(with_default)]` is not specified or if there are
|
||||
/// no trait items
|
||||
pub default_sub_trait: Vec<syn::TraitItem>,
|
||||
/// no trait items.
|
||||
pub default_sub_trait: Option<DefaultTrait>,
|
||||
}
|
||||
|
||||
/// Input definition for a constant in pallet config.
|
||||
@@ -339,9 +345,21 @@ impl ConfigDef {
|
||||
false
|
||||
};
|
||||
|
||||
let has_frame_system_supertrait = item.supertraits.iter().any(|s| {
|
||||
syn::parse2::<ConfigBoundParse>(s.to_token_stream())
|
||||
.map_or(false, |b| b.0 == *frame_system)
|
||||
});
|
||||
|
||||
let mut has_event_type = false;
|
||||
let mut consts_metadata = vec![];
|
||||
let mut default_sub_trait = vec![];
|
||||
let mut default_sub_trait = if enable_default {
|
||||
Some(DefaultTrait {
|
||||
items: Default::default(),
|
||||
has_system: has_frame_system_supertrait,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
for trait_item in &mut item.items {
|
||||
let is_event = check_event_type(frame_system, trait_item, has_instance)?;
|
||||
has_event_type = has_event_type || is_event;
|
||||
@@ -382,13 +400,18 @@ impl ConfigDef {
|
||||
"Duplicate #[pallet::no_default] attribute not allowed.",
|
||||
))
|
||||
}
|
||||
|
||||
already_no_default = true;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if !already_no_default && !is_event && enable_default {
|
||||
default_sub_trait.push(trait_item.clone());
|
||||
default_sub_trait
|
||||
.as_mut()
|
||||
.expect("is 'Some(_)' if 'enable_default'; qed")
|
||||
.items
|
||||
.push(trait_item.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,11 +419,6 @@ impl ConfigDef {
|
||||
helper::take_first_item_pallet_attr(&mut item.attrs)?;
|
||||
let disable_system_supertrait_check = attr.is_some();
|
||||
|
||||
let has_frame_system_supertrait = item.supertraits.iter().any(|s| {
|
||||
syn::parse2::<ConfigBoundParse>(s.to_token_stream())
|
||||
.map_or(false, |b| b.0 == *frame_system)
|
||||
});
|
||||
|
||||
if !has_frame_system_supertrait && !disable_system_supertrait_check {
|
||||
let found = if item.supertraits.is_empty() {
|
||||
"none".to_string()
|
||||
|
||||
Reference in New Issue
Block a user