Adds ability to provide defaults for types provided by construct_runtime (#14682)

* Adds ability to use defaults for verbatim types

* Adds RuntimeOrigin and PalletInfo in DefaultConfig

* Adds RuntimeEvent in DefaultConfig

* Adds RuntimeEvent in DefaultConfig

* Minor fix

* Minor fix

* Everything in frame_system can now have a default

* Adds docs

* Adds UI Test for no_bounds

* Updates docs

* Adds UI tests for verbatim

* Minor update

* Minor updates

* Minor updates

* Addresses review comments

* Fixes test

* Update frame/support/procedural/src/derive_impl.rs

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

* Minor fix

* Minor

* Fixes build

* Uses runtime_type

* Fixes comment

* Fixes comment

* Fixes test

* Uses no_aggregated_types as an option in derive_impl

* Uses specific imports

* Fmt

* Updates doc

* Update frame/support/procedural/src/derive_impl.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update frame/support/procedural/src/derive_impl.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Addresses review comment

* Addresses review comment

* fmt

* Renames test files

* Adds docs using docify

* Fixes test

* Fixes UI tests

---------

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
gupnik
2023-08-25 13:22:22 +05:30
committed by GitHub
parent 32541bde15
commit 83ae018087
21 changed files with 409 additions and 41 deletions
+21 -7
View File
@@ -205,7 +205,7 @@ pub mod pallet {
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
pub mod config_preludes {
use super::DefaultConfig;
use super::{inject_runtime_type, DefaultConfig};
/// Provides a viable default config that can be used with
/// [`derive_impl`](`frame_support::derive_impl`) to derive a testing pallet config
@@ -232,6 +232,17 @@ pub mod pallet {
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
#[inject_runtime_type]
type RuntimeEvent = ();
#[inject_runtime_type]
type RuntimeOrigin = ();
#[inject_runtime_type]
type RuntimeCall = ();
#[inject_runtime_type]
type PalletInfo = ();
type BaseCallFilter = frame_support::traits::Everything;
type BlockHashCount = frame_support::traits::ConstU64<10>;
type OnSetCode = ();
}
}
@@ -240,6 +251,7 @@ pub mod pallet {
#[pallet::disable_frame_system_supertrait_check]
pub trait Config: 'static + Eq + Clone {
/// The aggregated event type of the runtime.
#[pallet::no_default_bounds]
type RuntimeEvent: Parameter
+ Member
+ From<Event<Self>>
@@ -256,7 +268,7 @@ pub mod pallet {
/// [`frame_support::traits::InsideBoth`], [`frame_support::traits::TheseExcept`] or
/// [`frame_support::traits::EverythingBut`] et al. The default would be
/// [`frame_support::traits::Everything`].
#[pallet::no_default]
#[pallet::no_default_bounds]
type BaseCallFilter: Contains<Self::RuntimeCall>;
/// Block & extrinsics weights: base values and limits.
@@ -268,14 +280,14 @@ pub mod pallet {
type BlockLength: Get<limits::BlockLength>;
/// The `RuntimeOrigin` type used by dispatchable calls.
#[pallet::no_default]
#[pallet::no_default_bounds]
type RuntimeOrigin: Into<Result<RawOrigin<Self::AccountId>, Self::RuntimeOrigin>>
+ From<RawOrigin<Self::AccountId>>
+ Clone
+ OriginTrait<Call = Self::RuntimeCall, AccountId = Self::AccountId>;
/// The aggregated `RuntimeCall` type.
#[pallet::no_default]
#[pallet::no_default_bounds]
type RuntimeCall: Parameter
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
+ Debug
@@ -335,7 +347,7 @@ pub mod pallet {
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
#[pallet::constant]
#[pallet::no_default]
#[pallet::no_default_bounds]
type BlockHashCount: Get<BlockNumberFor<Self>>;
/// The weight of runtime database operations the runtime can invoke.
@@ -350,7 +362,9 @@ pub mod pallet {
///
/// Expects the `PalletInfo` type that is being generated by `construct_runtime!` in the
/// runtime.
#[pallet::no_default]
///
/// For tests it is okay to use `()` as type, however it will provide "useless" data.
#[pallet::no_default_bounds]
type PalletInfo: PalletInfo;
/// Data to be associated with an account (other than nonce/transaction counter, which this
@@ -382,7 +396,7 @@ pub mod pallet {
/// [`Pallet::update_code_in_storage`]).
/// It's unlikely that this needs to be customized, unless you are writing a parachain using
/// `Cumulus`, where the actual code change is deferred.
#[pallet::no_default]
#[pallet::no_default_bounds]
type OnSetCode: SetCode<Self>;
/// The maximum number of consumers allowed on a single account.