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
@@ -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, ());
}
+26 -6
View File
@@ -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 {