mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 19:11:04 +00:00
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:
@@ -830,6 +830,21 @@ pub mod pallet_prelude {
|
||||
};
|
||||
pub use codec::{Decode, Encode, MaxEncodedLen};
|
||||
pub use frame_support::pallet_macros::*;
|
||||
/// The optional attribute `#[inject_runtime_type]` can be attached to `RuntimeCall`,
|
||||
/// `RuntimeEvent`, `RuntimeOrigin` or `PalletInfo` in an impl statement that has
|
||||
/// `#[register_default_impl]` attached to indicate that this item is generated by
|
||||
/// `construct_runtime`.
|
||||
///
|
||||
/// Attaching this attribute to such an item ensures that the combined impl generated via
|
||||
/// [`#[derive_impl(..)]`](`macro@super::derive_impl`) will use the correct type
|
||||
/// auto-generated by `construct_runtime!`.
|
||||
#[doc = docify::embed!("src/tests/inject_runtime_type.rs", derive_impl_works_with_runtime_type_injection)]
|
||||
///
|
||||
/// However, if `no_aggregated_types` is specified while using
|
||||
/// `[`#[derive_impl(..)]`](`macro@super::derive_impl`)`, then these items are attached
|
||||
/// verbatim to the combined impl.
|
||||
#[doc = docify::embed!("src/tests/inject_runtime_type.rs", derive_impl_works_with_no_aggregated_types)]
|
||||
pub use frame_support_procedural::inject_runtime_type;
|
||||
pub use frame_support_procedural::register_default_impl;
|
||||
pub use scale_info::TypeInfo;
|
||||
pub use sp_inherents::MakeFatalError;
|
||||
@@ -2176,8 +2191,8 @@ pub mod pallet_macros {
|
||||
call_index, compact, composite_enum, config, constant,
|
||||
disable_frame_system_supertrait_check, error, event, extra_constants, generate_deposit,
|
||||
generate_store, genesis_build, genesis_config, getter, hooks, import_section, inherent,
|
||||
no_default, origin, pallet_section, storage, storage_prefix, storage_version, type_value,
|
||||
unbounded, validate_unsigned, weight, whitelist_storage,
|
||||
no_default, no_default_bounds, origin, pallet_section, storage, storage_prefix,
|
||||
storage_version, type_value, unbounded, validate_unsigned, weight, whitelist_storage,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use super::{Config, Runtime};
|
||||
use crate::{derive_impl, pallet_prelude::inject_runtime_type};
|
||||
use static_assertions::assert_type_eq_all;
|
||||
|
||||
#[docify::export]
|
||||
#[test]
|
||||
fn derive_impl_works_with_runtime_type_injection() {
|
||||
assert_type_eq_all!(<Runtime as Config>::RuntimeOrigin, super::RuntimeOrigin);
|
||||
assert_type_eq_all!(<Runtime as Config>::RuntimeCall, super::RuntimeCall);
|
||||
assert_type_eq_all!(<Runtime as Config>::PalletInfo, super::PalletInfo);
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
#[test]
|
||||
fn derive_impl_works_with_no_aggregated_types() {
|
||||
struct DummyRuntime;
|
||||
|
||||
#[derive_impl(
|
||||
super::frame_system::config_preludes::TestDefaultConfig as super::frame_system::DefaultConfig,
|
||||
no_aggregated_types
|
||||
)]
|
||||
impl Config for DummyRuntime {
|
||||
type Block = super::Block;
|
||||
type AccountId = super::AccountId;
|
||||
type PalletInfo = super::PalletInfo;
|
||||
}
|
||||
|
||||
assert_type_eq_all!(<DummyRuntime as Config>::RuntimeOrigin, ());
|
||||
assert_type_eq_all!(<DummyRuntime as Config>::RuntimeCall, ());
|
||||
}
|
||||
@@ -25,6 +25,7 @@ use sp_runtime::{generic, traits::BlakeTwo256, BuildStorage};
|
||||
|
||||
pub use self::frame_system::{pallet_prelude::*, Config, Pallet};
|
||||
|
||||
mod inject_runtime_type;
|
||||
mod storage_alias;
|
||||
|
||||
#[pallet]
|
||||
@@ -34,17 +35,40 @@ pub mod frame_system {
|
||||
pub use crate::dispatch::RawOrigin;
|
||||
use crate::pallet_prelude::*;
|
||||
|
||||
pub mod config_preludes {
|
||||
use super::{inject_runtime_type, DefaultConfig};
|
||||
pub struct TestDefaultConfig;
|
||||
|
||||
#[crate::register_default_impl(TestDefaultConfig)]
|
||||
impl DefaultConfig for TestDefaultConfig {
|
||||
type AccountId = u64;
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
#[inject_runtime_type]
|
||||
type RuntimeOrigin = ();
|
||||
#[inject_runtime_type]
|
||||
type RuntimeCall = ();
|
||||
#[inject_runtime_type]
|
||||
type PalletInfo = ();
|
||||
type DbWeight = ();
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
#[pallet::config(with_default)]
|
||||
#[pallet::disable_frame_system_supertrait_check]
|
||||
pub trait Config: 'static {
|
||||
#[pallet::no_default]
|
||||
type Block: Parameter + sp_runtime::traits::Block;
|
||||
type AccountId;
|
||||
#[pallet::no_default_bounds]
|
||||
type BaseCallFilter: crate::traits::Contains<Self::RuntimeCall>;
|
||||
#[pallet::no_default_bounds]
|
||||
type RuntimeOrigin;
|
||||
#[pallet::no_default_bounds]
|
||||
type RuntimeCall;
|
||||
#[pallet::no_default_bounds]
|
||||
type PalletInfo: crate::traits::PalletInfo;
|
||||
type DbWeight: Get<crate::weights::RuntimeDbWeight>;
|
||||
}
|
||||
@@ -168,14 +192,10 @@ crate::construct_runtime!(
|
||||
}
|
||||
);
|
||||
|
||||
#[crate::derive_impl(self::frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
|
||||
impl Config for Runtime {
|
||||
type Block = Block;
|
||||
type AccountId = AccountId;
|
||||
type BaseCallFilter = crate::traits::Everything;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type PalletInfo = PalletInfo;
|
||||
type DbWeight = ();
|
||||
}
|
||||
|
||||
fn new_test_ext() -> TestExternalities {
|
||||
|
||||
Reference in New Issue
Block a user