mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 05:17:58 +00:00
Construct Runtime v2 (#1378)
Moved from https://github.com/paritytech/substrate/pull/14788 ---- Fixes https://github.com/paritytech/polkadot-sdk/issues/232 This PR introduces outer-macro approach for `construct_runtime` as discussed in the linked issue. It looks like the following: ```rust #[frame_support::runtime] mod runtime { #[runtime::runtime] #[runtime::derive( RuntimeCall, RuntimeEvent, RuntimeError, RuntimeOrigin, RuntimeFreezeReason, RuntimeHoldReason, RuntimeSlashReason, RuntimeLockId, RuntimeTask, )] pub struct Runtime; #[runtime::pallet_index(0)] pub type System = frame_system; #[runtime::pallet_index(1)] pub type Timestamp = pallet_timestamp; #[runtime::pallet_index(2)] pub type Aura = pallet_aura; #[runtime::pallet_index(3)] pub type Grandpa = pallet_grandpa; #[runtime::pallet_index(4)] pub type Balances = pallet_balances; #[runtime::pallet_index(5)] pub type TransactionPayment = pallet_transaction_payment; #[runtime::pallet_index(6)] pub type Sudo = pallet_sudo; // Include the custom logic from the pallet-template in the runtime. #[runtime::pallet_index(7)] pub type TemplateModule = pallet_template; } ``` ## Features - `#[runtime::runtime]` attached to a struct defines the main runtime - `#[runtime::derive]` attached to this struct defines the types generated by runtime - `#[runtime::pallet_index]` must be attached to a pallet to define its index - `#[runtime::disable_call]` can be optionally attached to a pallet to disable its calls - `#[runtime::disable_unsigned]` can be optionally attached to a pallet to disable unsigned calls - A pallet instance can be defined as `TemplateModule: pallet_template<Instance>` - An optional attribute can be defined as `#[frame_support::runtime(legacy_ordering)]` to ensure that the order of hooks is same as the order of pallets (and not based on the pallet_index). This is to support legacy runtimes and should be avoided for new ones. ## Todo - [x] Update the latest syntax in kitchensink and tests - [x] Update UI tests - [x] Docs ## Extension - Abstract away the Executive similar to https://github.com/paritytech/substrate/pull/14742 - Optionally avoid the need to specify all runtime types (TBD) --------- Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com> Co-authored-by: Nikhil Gupta <>
This commit is contained in:
@@ -24,7 +24,7 @@ sp-api = { path = "../../../primitives/api", default-features = false }
|
||||
sp-arithmetic = { path = "../../../primitives/arithmetic", default-features = false }
|
||||
sp-io = { path = "../../../primitives/io", default-features = false }
|
||||
sp-state-machine = { path = "../../../primitives/state-machine", optional = true }
|
||||
frame-support = { path = "..", default-features = false }
|
||||
frame-support = { path = "..", default-features = false, features = ["experimental"] }
|
||||
frame-benchmarking = { path = "../../benchmarking", default-features = false }
|
||||
sp-runtime = { path = "../../../primitives/runtime", default-features = false }
|
||||
sp-core = { path = "../../../primitives/core", default-features = false }
|
||||
|
||||
+189
-93
@@ -30,7 +30,7 @@ use scale_info::TypeInfo;
|
||||
use sp_core::{sr25519, ConstU64};
|
||||
use sp_runtime::{
|
||||
generic,
|
||||
traits::{BlakeTwo256, Verify},
|
||||
traits::{BlakeTwo256, ValidateUnsigned, Verify},
|
||||
DispatchError, ModuleError,
|
||||
};
|
||||
use sp_version::RuntimeVersion;
|
||||
@@ -176,6 +176,17 @@ mod nested {
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {}
|
||||
}
|
||||
|
||||
#[pallet::validate_unsigned]
|
||||
impl<T: Config> ValidateUnsigned for Pallet<T> {
|
||||
type Call = Call<T>;
|
||||
fn validate_unsigned(
|
||||
_source: TransactionSource,
|
||||
_call: &Self::Call,
|
||||
) -> TransactionValidity {
|
||||
Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,6 +258,20 @@ pub mod module3 {
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {}
|
||||
}
|
||||
|
||||
#[pallet::storage]
|
||||
pub type Storage<T> = StorageValue<_, u32>;
|
||||
|
||||
#[pallet::validate_unsigned]
|
||||
impl<T: Config> ValidateUnsigned for Pallet<T> {
|
||||
type Call = Call<T>;
|
||||
fn validate_unsigned(
|
||||
_source: TransactionSource,
|
||||
_call: &Self::Call,
|
||||
) -> TransactionValidity {
|
||||
Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type BlockNumber = u64;
|
||||
@@ -256,24 +281,64 @@ pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, RuntimeCall, Signature, ()>;
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
|
||||
frame_support::construct_runtime!(
|
||||
pub struct Runtime
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Event<T>, Origin<T>} = 30,
|
||||
Module1_1: module1::<Instance1>::{Pallet, Call, Storage, Event<T>, Origin<T>},
|
||||
Module2: module2::{Pallet, Call, Storage, Event<T>, Origin},
|
||||
Module1_2: module1::<Instance2>::{Pallet, Call, Storage, Event<T>, Origin<T>},
|
||||
NestedModule3: nested::module3::{Pallet, Call, Config<T>, Storage, Event<T>, Origin},
|
||||
Module3: self::module3::{Pallet, Call, Config<T>, Storage, Event<T>, Origin<T>},
|
||||
Module1_3: module1::<Instance3>::{Pallet, Storage, Event<T> } = 6,
|
||||
Module1_4: module1::<Instance4>::{Pallet, Call, Event<T> } = 3,
|
||||
Module1_5: module1::<Instance5>::{Pallet, Event<T>},
|
||||
Module1_6: module1::<Instance6>::{Pallet, Call, Storage, Event<T>, Origin<T>} = 1,
|
||||
Module1_7: module1::<Instance7>::{Pallet, Call, Storage, Event<T>, Origin<T>},
|
||||
Module1_8: module1::<Instance8>::{Pallet, Call, Storage, Event<T>, Origin<T>} = 12,
|
||||
Module1_9: module1::<Instance9>::{Pallet, Call, Storage, Event<T>, Origin<T>},
|
||||
}
|
||||
);
|
||||
#[frame_support::runtime]
|
||||
mod runtime {
|
||||
#[runtime::runtime]
|
||||
#[runtime::derive(
|
||||
RuntimeCall,
|
||||
RuntimeEvent,
|
||||
RuntimeError,
|
||||
RuntimeOrigin,
|
||||
RuntimeFreezeReason,
|
||||
RuntimeHoldReason,
|
||||
RuntimeSlashReason,
|
||||
RuntimeLockId,
|
||||
RuntimeTask
|
||||
)]
|
||||
pub struct Runtime;
|
||||
|
||||
#[runtime::pallet_index(30)]
|
||||
pub type System = frame_system + Pallet + Call + Event<T> + Origin<T>;
|
||||
|
||||
#[runtime::pallet_index(31)]
|
||||
pub type Module1_1 = module1<Instance1>;
|
||||
|
||||
#[runtime::pallet_index(32)]
|
||||
pub type Module2 = module2;
|
||||
|
||||
#[runtime::pallet_index(33)]
|
||||
pub type Module1_2 = module1<Instance2>;
|
||||
|
||||
#[runtime::pallet_index(34)]
|
||||
pub type NestedModule3 = nested::module3;
|
||||
|
||||
#[runtime::pallet_index(35)]
|
||||
#[runtime::disable_unsigned]
|
||||
pub type Module3 = self::module3;
|
||||
|
||||
#[runtime::pallet_index(6)]
|
||||
#[runtime::disable_call]
|
||||
pub type Module1_3 = module1<Instance3>;
|
||||
|
||||
#[runtime::pallet_index(3)]
|
||||
pub type Module1_4 = module1<Instance4>;
|
||||
|
||||
#[runtime::pallet_index(4)]
|
||||
#[runtime::disable_call]
|
||||
pub type Module1_5 = module1<Instance5>;
|
||||
|
||||
#[runtime::pallet_index(1)]
|
||||
pub type Module1_6 = module1<Instance6>;
|
||||
|
||||
#[runtime::pallet_index(2)]
|
||||
pub type Module1_7 = module1<Instance7>;
|
||||
|
||||
#[runtime::pallet_index(12)]
|
||||
pub type Module1_8 = module1<Instance8>;
|
||||
|
||||
#[runtime::pallet_index(13)]
|
||||
pub type Module1_9 = module1<Instance9>;
|
||||
}
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
|
||||
impl frame_system::Config for Runtime {
|
||||
@@ -605,17 +670,17 @@ fn get_module_names() {
|
||||
let module_names = RuntimeCall::get_module_names();
|
||||
assert_eq!(
|
||||
[
|
||||
"Module1_6",
|
||||
"Module1_7",
|
||||
"Module1_4",
|
||||
"Module1_8",
|
||||
"Module1_9",
|
||||
"System",
|
||||
"Module1_1",
|
||||
"Module2",
|
||||
"Module1_2",
|
||||
"NestedModule3",
|
||||
"Module3",
|
||||
"Module1_4",
|
||||
"Module1_6",
|
||||
"Module1_7",
|
||||
"Module1_8",
|
||||
"Module1_9",
|
||||
],
|
||||
module_names
|
||||
);
|
||||
@@ -636,9 +701,13 @@ fn call_subtype_conversion() {
|
||||
|
||||
#[test]
|
||||
fn test_metadata() {
|
||||
use frame_metadata::{v14::*, *};
|
||||
use frame_metadata::{
|
||||
v14::{StorageEntryType::Plain, *},
|
||||
*,
|
||||
};
|
||||
use scale_info::meta_type;
|
||||
use sp_core::Encode;
|
||||
use sp_metadata_ir::StorageEntryModifierIR::Optional;
|
||||
|
||||
fn maybe_docs(doc: Vec<&'static str>) -> Vec<&'static str> {
|
||||
if cfg!(feature = "no-metadata-docs") {
|
||||
@@ -649,6 +718,69 @@ fn test_metadata() {
|
||||
}
|
||||
|
||||
let pallets = vec![
|
||||
PalletMetadata {
|
||||
name: "Module1_6",
|
||||
storage:None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance6>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance6>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance6>>().into()),
|
||||
index: 1,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_7",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance7>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance7>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance7>>().into()),
|
||||
index: 2,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_4",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance4>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance4>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance4>>().into()),
|
||||
index: 3,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_5",
|
||||
storage: None,
|
||||
calls: None,
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance5>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance5>>().into()),
|
||||
index: 4,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_3",
|
||||
storage: None,
|
||||
calls: None,
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance3>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance3>>().into()),
|
||||
index: 6,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_8",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance8>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance8>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance8>>().into()),
|
||||
index: 12,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_9",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance9>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance9>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance9>>().into()),
|
||||
index: 13,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "System",
|
||||
storage: None,
|
||||
@@ -703,7 +835,7 @@ fn test_metadata() {
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_1",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module1_1", entries: vec![] }),
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance1>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance1>>().into()),
|
||||
constants: vec![],
|
||||
@@ -712,7 +844,7 @@ fn test_metadata() {
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module2",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module2", entries: vec![] }),
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module2::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<module2::Event<Runtime>>().into()),
|
||||
constants: vec![],
|
||||
@@ -721,7 +853,7 @@ fn test_metadata() {
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_2",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module1_2", entries: vec![] }),
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance2>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance2>>().into()),
|
||||
constants: vec![],
|
||||
@@ -730,7 +862,7 @@ fn test_metadata() {
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "NestedModule3",
|
||||
storage: Some(PalletStorageMetadata { prefix: "NestedModule3", entries: vec![] }),
|
||||
storage: None,
|
||||
calls: Some(meta_type::<nested::module3::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<nested::module3::Event<Runtime>>().into()),
|
||||
constants: vec![],
|
||||
@@ -739,76 +871,24 @@ fn test_metadata() {
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module3",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module3", entries: vec![] }),
|
||||
storage: Some(PalletStorageMetadata {
|
||||
prefix: "Module3",
|
||||
entries: vec![
|
||||
StorageEntryMetadata {
|
||||
name: "Storage",
|
||||
modifier: Optional.into(),
|
||||
ty: Plain(meta_type::<u32>().into()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
]
|
||||
}),
|
||||
calls: Some(meta_type::<module3::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<module3::Event<Runtime>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module3::Error<Runtime>>().into()),
|
||||
index: 35,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_3",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module1_3", entries: vec![] }),
|
||||
calls: None,
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance3>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance3>>().into()),
|
||||
index: 6,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_4",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance4>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance4>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance4>>().into()),
|
||||
index: 3,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_5",
|
||||
storage: None,
|
||||
calls: None,
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance5>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance5>>().into()),
|
||||
index: 4,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_6",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module1_6", entries: vec![] }),
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance6>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance6>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance6>>().into()),
|
||||
index: 1,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_7",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module1_7", entries: vec![] }),
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance7>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance7>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance7>>().into()),
|
||||
index: 2,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_8",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module1_8", entries: vec![] }),
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance8>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance8>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance8>>().into()),
|
||||
index: 12,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_9",
|
||||
storage: Some(PalletStorageMetadata { prefix: "Module1_9", entries: vec![] }),
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance9>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance9>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance9>>().into()),
|
||||
index: 13,
|
||||
},
|
||||
];
|
||||
|
||||
let extrinsic = ExtrinsicMetadata {
|
||||
@@ -895,3 +975,19 @@ fn pallet_in_runtime_is_correct() {
|
||||
assert_eq!(PalletInfo::module_name::<Module1_9>().unwrap(), "module1");
|
||||
assert!(PalletInfo::crate_version::<Module1_9>().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validate_unsigned() {
|
||||
use frame_support::pallet_prelude::*;
|
||||
|
||||
let call = RuntimeCall::NestedModule3(nested::module3::Call::fail {});
|
||||
let validity = Runtime::validate_unsigned(TransactionSource::Local, &call).unwrap_err();
|
||||
assert_eq!(validity, TransactionValidityError::Invalid(InvalidTransaction::Call));
|
||||
|
||||
let call = RuntimeCall::Module3(module3::Call::fail {});
|
||||
let validity = Runtime::validate_unsigned(TransactionSource::Local, &call).unwrap_err();
|
||||
assert_eq!(
|
||||
validity,
|
||||
TransactionValidityError::Unknown(UnknownTransaction::NoUnsignedValidator)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,993 @@
|
||||
// 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.
|
||||
|
||||
//! General tests for construct_runtime macro, test for:
|
||||
//! * error declared with decl_error works
|
||||
//! * integrity test is generated
|
||||
|
||||
#![recursion_limit = "128"]
|
||||
|
||||
use codec::MaxEncodedLen;
|
||||
use frame_support::{
|
||||
derive_impl, parameter_types, traits::PalletInfo as _, weights::RuntimeDbWeight,
|
||||
};
|
||||
use frame_system::limits::{BlockLength, BlockWeights};
|
||||
use scale_info::TypeInfo;
|
||||
use sp_core::{sr25519, ConstU64};
|
||||
use sp_runtime::{
|
||||
generic,
|
||||
traits::{BlakeTwo256, ValidateUnsigned, Verify},
|
||||
DispatchError, ModuleError,
|
||||
};
|
||||
use sp_version::RuntimeVersion;
|
||||
|
||||
parameter_types! {
|
||||
pub static IntegrityTestExec: u32 = 0;
|
||||
}
|
||||
|
||||
#[frame_support::pallet(dev_mode)]
|
||||
mod module1 {
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T, I = ()>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config<I: 'static = ()>: frame_system::Config {
|
||||
type RuntimeEvent: From<Event<Self, I>>
|
||||
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
pub fn fail(_origin: OriginFor<T>) -> DispatchResult {
|
||||
Err(Error::<T, I>::Something.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::origin]
|
||||
#[derive(Clone, PartialEq, Eq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)]
|
||||
#[scale_info(skip_type_params(I))]
|
||||
pub struct Origin<T, I = ()>(pub PhantomData<(T, I)>);
|
||||
|
||||
#[pallet::event]
|
||||
pub enum Event<T: Config<I>, I: 'static = ()> {
|
||||
A(<T as frame_system::Config>::AccountId),
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T, I = ()> {
|
||||
Something,
|
||||
}
|
||||
}
|
||||
|
||||
#[frame_support::pallet(dev_mode)]
|
||||
mod module2 {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn integrity_test() {
|
||||
IntegrityTestExec::mutate(|i| *i += 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
pub fn fail(_origin: OriginFor<T>) -> DispatchResult {
|
||||
Err(Error::<T>::Something.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::origin]
|
||||
#[derive(Clone, PartialEq, Eq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)]
|
||||
pub struct Origin;
|
||||
|
||||
#[pallet::event]
|
||||
pub enum Event<T> {
|
||||
A,
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
Something,
|
||||
}
|
||||
}
|
||||
|
||||
mod nested {
|
||||
use super::*;
|
||||
|
||||
#[frame_support::pallet(dev_mode)]
|
||||
pub mod module3 {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
type RuntimeEvent: From<Event<Self>>
|
||||
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
}
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn integrity_test() {
|
||||
IntegrityTestExec::mutate(|i| *i += 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
pub fn fail(_origin: OriginFor<T>) -> DispatchResult {
|
||||
Err(Error::<T>::Something.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::origin]
|
||||
#[derive(Clone, PartialEq, Eq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)]
|
||||
pub struct Origin;
|
||||
|
||||
#[pallet::event]
|
||||
pub enum Event<T> {
|
||||
A,
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
Something,
|
||||
}
|
||||
|
||||
#[pallet::genesis_config]
|
||||
#[derive(frame_support::DefaultNoBound)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
#[serde(skip)]
|
||||
pub _config: sp_std::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {}
|
||||
}
|
||||
|
||||
#[pallet::validate_unsigned]
|
||||
impl<T: Config> ValidateUnsigned for Pallet<T> {
|
||||
type Call = Call<T>;
|
||||
fn validate_unsigned(
|
||||
_source: TransactionSource,
|
||||
_call: &Self::Call,
|
||||
) -> TransactionValidity {
|
||||
Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[frame_support::pallet(dev_mode)]
|
||||
pub mod module3 {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
pub fn fail(_origin: OriginFor<T>) -> DispatchResult {
|
||||
Err(Error::<T>::Something.into())
|
||||
}
|
||||
pub fn aux_1(_origin: OriginFor<T>, #[pallet::compact] _data: u32) -> DispatchResult {
|
||||
unreachable!()
|
||||
}
|
||||
pub fn aux_2(
|
||||
_origin: OriginFor<T>,
|
||||
_data: i32,
|
||||
#[pallet::compact] _data2: u32,
|
||||
) -> DispatchResult {
|
||||
unreachable!()
|
||||
}
|
||||
#[pallet::weight(0)]
|
||||
pub fn aux_3(_origin: OriginFor<T>, _data: i32, _data2: String) -> DispatchResult {
|
||||
unreachable!()
|
||||
}
|
||||
#[pallet::weight(3)]
|
||||
pub fn aux_4(_origin: OriginFor<T>) -> DispatchResult {
|
||||
unreachable!()
|
||||
}
|
||||
#[pallet::weight((5, DispatchClass::Operational))]
|
||||
pub fn operational(_origin: OriginFor<T>) -> DispatchResult {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::origin]
|
||||
#[derive(Clone, PartialEq, Eq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)]
|
||||
pub struct Origin<T>(pub PhantomData<T>);
|
||||
|
||||
#[pallet::event]
|
||||
pub enum Event<T> {
|
||||
A,
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
Something,
|
||||
}
|
||||
|
||||
#[pallet::genesis_config]
|
||||
#[derive(frame_support::DefaultNoBound)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
#[serde(skip)]
|
||||
pub _config: sp_std::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {}
|
||||
}
|
||||
|
||||
#[pallet::storage]
|
||||
pub type Storage<T> = StorageValue<_, u32>;
|
||||
|
||||
#[pallet::validate_unsigned]
|
||||
impl<T: Config> ValidateUnsigned for Pallet<T> {
|
||||
type Call = Call<T>;
|
||||
fn validate_unsigned(
|
||||
_source: TransactionSource,
|
||||
_call: &Self::Call,
|
||||
) -> TransactionValidity {
|
||||
Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type BlockNumber = u64;
|
||||
pub type Signature = sr25519::Signature;
|
||||
pub type AccountId = <Signature as Verify>::Signer;
|
||||
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
|
||||
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, RuntimeCall, Signature, ()>;
|
||||
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
|
||||
|
||||
#[frame_support::runtime(legacy_ordering)]
|
||||
mod runtime {
|
||||
#[runtime::runtime]
|
||||
#[runtime::derive(
|
||||
RuntimeCall,
|
||||
RuntimeEvent,
|
||||
RuntimeError,
|
||||
RuntimeOrigin,
|
||||
RuntimeFreezeReason,
|
||||
RuntimeHoldReason,
|
||||
RuntimeSlashReason,
|
||||
RuntimeLockId,
|
||||
RuntimeTask
|
||||
)]
|
||||
pub struct Runtime;
|
||||
|
||||
#[runtime::pallet_index(30)]
|
||||
pub type System = frame_system + Pallet + Call + Event<T> + Origin<T>;
|
||||
|
||||
#[runtime::pallet_index(31)]
|
||||
pub type Module1_1 = module1<Instance1>;
|
||||
|
||||
#[runtime::pallet_index(32)]
|
||||
pub type Module2 = module2;
|
||||
|
||||
#[runtime::pallet_index(33)]
|
||||
pub type Module1_2 = module1<Instance2>;
|
||||
|
||||
#[runtime::pallet_index(34)]
|
||||
pub type NestedModule3 = nested::module3;
|
||||
|
||||
#[runtime::pallet_index(35)]
|
||||
#[runtime::disable_unsigned]
|
||||
pub type Module3 = self::module3;
|
||||
|
||||
#[runtime::pallet_index(6)]
|
||||
#[runtime::disable_call]
|
||||
pub type Module1_3 = module1<Instance3>;
|
||||
|
||||
#[runtime::pallet_index(3)]
|
||||
pub type Module1_4 = module1<Instance4>;
|
||||
|
||||
#[runtime::pallet_index(4)]
|
||||
#[runtime::disable_call]
|
||||
pub type Module1_5 = module1<Instance5>;
|
||||
|
||||
#[runtime::pallet_index(1)]
|
||||
pub type Module1_6 = module1<Instance6>;
|
||||
|
||||
#[runtime::pallet_index(2)]
|
||||
pub type Module1_7 = module1<Instance7>;
|
||||
|
||||
#[runtime::pallet_index(12)]
|
||||
pub type Module1_8 = module1<Instance8>;
|
||||
|
||||
#[runtime::pallet_index(13)]
|
||||
pub type Module1_9 = module1<Instance9>;
|
||||
}
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
|
||||
impl frame_system::Config for Runtime {
|
||||
type AccountId = AccountId;
|
||||
type Lookup = sp_runtime::traits::IdentityLookup<AccountId>;
|
||||
type BaseCallFilter = frame_support::traits::Everything;
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type PalletInfo = PalletInfo;
|
||||
type OnSetCode = ();
|
||||
type Block = Block;
|
||||
type BlockHashCount = ConstU64<10>;
|
||||
}
|
||||
|
||||
impl module1::Config<module1::Instance1> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
impl module1::Config<module1::Instance2> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
impl module1::Config<module1::Instance3> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
impl module1::Config<module1::Instance4> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
impl module1::Config<module1::Instance5> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
impl module1::Config<module1::Instance6> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
impl module1::Config<module1::Instance7> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
impl module1::Config<module1::Instance8> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
impl module1::Config<module1::Instance9> for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
impl module2::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
impl nested::module3::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
impl module3::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
}
|
||||
|
||||
fn test_pub() -> AccountId {
|
||||
AccountId::from_raw([0; 32])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn check_modules_error_type() {
|
||||
sp_io::TestExternalities::default().execute_with(|| {
|
||||
assert_eq!(
|
||||
Module1_1::fail(frame_system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module(ModuleError {
|
||||
index: 31,
|
||||
error: [0; 4],
|
||||
message: Some("Something")
|
||||
})),
|
||||
);
|
||||
assert_eq!(
|
||||
Module2::fail(frame_system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module(ModuleError {
|
||||
index: 32,
|
||||
error: [0; 4],
|
||||
message: Some("Something")
|
||||
})),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_2::fail(frame_system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module(ModuleError {
|
||||
index: 33,
|
||||
error: [0; 4],
|
||||
message: Some("Something")
|
||||
})),
|
||||
);
|
||||
assert_eq!(
|
||||
NestedModule3::fail(frame_system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module(ModuleError {
|
||||
index: 34,
|
||||
error: [0; 4],
|
||||
message: Some("Something")
|
||||
})),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_3::fail(frame_system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module(ModuleError {
|
||||
index: 6,
|
||||
error: [0; 4],
|
||||
message: Some("Something")
|
||||
})),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_4::fail(frame_system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module(ModuleError {
|
||||
index: 3,
|
||||
error: [0; 4],
|
||||
message: Some("Something")
|
||||
})),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_5::fail(frame_system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module(ModuleError {
|
||||
index: 4,
|
||||
error: [0; 4],
|
||||
message: Some("Something")
|
||||
})),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_6::fail(frame_system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module(ModuleError {
|
||||
index: 1,
|
||||
error: [0; 4],
|
||||
message: Some("Something")
|
||||
})),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_7::fail(frame_system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module(ModuleError {
|
||||
index: 2,
|
||||
error: [0; 4],
|
||||
message: Some("Something")
|
||||
})),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_8::fail(frame_system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module(ModuleError {
|
||||
index: 12,
|
||||
error: [0; 4],
|
||||
message: Some("Something")
|
||||
})),
|
||||
);
|
||||
assert_eq!(
|
||||
Module1_9::fail(frame_system::Origin::<Runtime>::Root.into()),
|
||||
Err(DispatchError::Module(ModuleError {
|
||||
index: 13,
|
||||
error: [0; 4],
|
||||
message: Some("Something")
|
||||
})),
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn integrity_test_works() {
|
||||
__construct_runtime_integrity_test::runtime_integrity_tests();
|
||||
assert_eq!(IntegrityTestExec::get(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn origin_codec() {
|
||||
use codec::Encode;
|
||||
|
||||
let origin = OriginCaller::system(frame_system::RawOrigin::None);
|
||||
assert_eq!(origin.encode()[0], 30);
|
||||
|
||||
let origin = OriginCaller::Module1_1(module1::Origin(Default::default()));
|
||||
assert_eq!(origin.encode()[0], 31);
|
||||
|
||||
let origin = OriginCaller::Module2(module2::Origin);
|
||||
assert_eq!(origin.encode()[0], 32);
|
||||
|
||||
let origin = OriginCaller::Module1_2(module1::Origin(Default::default()));
|
||||
assert_eq!(origin.encode()[0], 33);
|
||||
|
||||
let origin = OriginCaller::NestedModule3(nested::module3::Origin);
|
||||
assert_eq!(origin.encode()[0], 34);
|
||||
|
||||
let origin = OriginCaller::Module3(module3::Origin(Default::default()));
|
||||
assert_eq!(origin.encode()[0], 35);
|
||||
|
||||
let origin = OriginCaller::Module1_6(module1::Origin(Default::default()));
|
||||
assert_eq!(origin.encode()[0], 1);
|
||||
|
||||
let origin = OriginCaller::Module1_7(module1::Origin(Default::default()));
|
||||
assert_eq!(origin.encode()[0], 2);
|
||||
|
||||
let origin = OriginCaller::Module1_8(module1::Origin(Default::default()));
|
||||
assert_eq!(origin.encode()[0], 12);
|
||||
|
||||
let origin = OriginCaller::Module1_9(module1::Origin(Default::default()));
|
||||
assert_eq!(origin.encode()[0], 13);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn event_codec() {
|
||||
use codec::Encode;
|
||||
|
||||
let event =
|
||||
frame_system::Event::<Runtime>::ExtrinsicSuccess { dispatch_info: Default::default() };
|
||||
assert_eq!(RuntimeEvent::from(event).encode()[0], 30);
|
||||
|
||||
let event = module1::Event::<Runtime, module1::Instance1>::A(test_pub());
|
||||
assert_eq!(RuntimeEvent::from(event).encode()[0], 31);
|
||||
|
||||
let event = module2::Event::A;
|
||||
assert_eq!(RuntimeEvent::from(event).encode()[0], 32);
|
||||
|
||||
let event = module1::Event::<Runtime, module1::Instance2>::A(test_pub());
|
||||
assert_eq!(RuntimeEvent::from(event).encode()[0], 33);
|
||||
|
||||
let event = nested::module3::Event::A;
|
||||
assert_eq!(RuntimeEvent::from(event).encode()[0], 34);
|
||||
|
||||
let event = module3::Event::A;
|
||||
assert_eq!(RuntimeEvent::from(event).encode()[0], 35);
|
||||
|
||||
let event = module1::Event::<Runtime, module1::Instance5>::A(test_pub());
|
||||
assert_eq!(RuntimeEvent::from(event).encode()[0], 4);
|
||||
|
||||
let event = module1::Event::<Runtime, module1::Instance6>::A(test_pub());
|
||||
assert_eq!(RuntimeEvent::from(event).encode()[0], 1);
|
||||
|
||||
let event = module1::Event::<Runtime, module1::Instance7>::A(test_pub());
|
||||
assert_eq!(RuntimeEvent::from(event).encode()[0], 2);
|
||||
|
||||
let event = module1::Event::<Runtime, module1::Instance8>::A(test_pub());
|
||||
assert_eq!(RuntimeEvent::from(event).encode()[0], 12);
|
||||
|
||||
let event = module1::Event::<Runtime, module1::Instance9>::A(test_pub());
|
||||
assert_eq!(RuntimeEvent::from(event).encode()[0], 13);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_codec() {
|
||||
use codec::Encode;
|
||||
assert_eq!(RuntimeCall::System(frame_system::Call::remark { remark: vec![1] }).encode()[0], 30);
|
||||
assert_eq!(RuntimeCall::Module1_1(module1::Call::fail {}).encode()[0], 31);
|
||||
assert_eq!(RuntimeCall::Module2(module2::Call::fail {}).encode()[0], 32);
|
||||
assert_eq!(RuntimeCall::Module1_2(module1::Call::fail {}).encode()[0], 33);
|
||||
assert_eq!(RuntimeCall::NestedModule3(nested::module3::Call::fail {}).encode()[0], 34);
|
||||
assert_eq!(RuntimeCall::Module3(module3::Call::fail {}).encode()[0], 35);
|
||||
assert_eq!(RuntimeCall::Module1_4(module1::Call::fail {}).encode()[0], 3);
|
||||
assert_eq!(RuntimeCall::Module1_6(module1::Call::fail {}).encode()[0], 1);
|
||||
assert_eq!(RuntimeCall::Module1_7(module1::Call::fail {}).encode()[0], 2);
|
||||
assert_eq!(RuntimeCall::Module1_8(module1::Call::fail {}).encode()[0], 12);
|
||||
assert_eq!(RuntimeCall::Module1_9(module1::Call::fail {}).encode()[0], 13);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_compact_attr() {
|
||||
use codec::Encode;
|
||||
let call: module3::Call<Runtime> = module3::Call::aux_1 { data: 1 };
|
||||
let encoded = call.encode();
|
||||
assert_eq!(2, encoded.len());
|
||||
assert_eq!(vec![1, 4], encoded);
|
||||
|
||||
let call: module3::Call<Runtime> = module3::Call::aux_2 { data: 1, data2: 2 };
|
||||
let encoded = call.encode();
|
||||
assert_eq!(6, encoded.len());
|
||||
assert_eq!(vec![2, 1, 0, 0, 0, 8], encoded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_encode_is_correct_and_decode_works() {
|
||||
use codec::{Decode, Encode};
|
||||
let call: module3::Call<Runtime> = module3::Call::fail {};
|
||||
let encoded = call.encode();
|
||||
assert_eq!(vec![0], encoded);
|
||||
let decoded = module3::Call::<Runtime>::decode(&mut &encoded[..]).unwrap();
|
||||
assert_eq!(decoded, call);
|
||||
|
||||
let call: module3::Call<Runtime> = module3::Call::aux_3 { data: 32, data2: "hello".into() };
|
||||
let encoded = call.encode();
|
||||
assert_eq!(vec![3, 32, 0, 0, 0, 20, 104, 101, 108, 108, 111], encoded);
|
||||
let decoded = module3::Call::<Runtime>::decode(&mut &encoded[..]).unwrap();
|
||||
assert_eq!(decoded, call);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_weight_should_attach_to_call_enum() {
|
||||
use frame_support::{
|
||||
dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays},
|
||||
weights::Weight,
|
||||
};
|
||||
// operational.
|
||||
assert_eq!(
|
||||
module3::Call::<Runtime>::operational {}.get_dispatch_info(),
|
||||
DispatchInfo {
|
||||
weight: Weight::from_parts(5, 0),
|
||||
class: DispatchClass::Operational,
|
||||
pays_fee: Pays::Yes
|
||||
},
|
||||
);
|
||||
// custom basic
|
||||
assert_eq!(
|
||||
module3::Call::<Runtime>::aux_4 {}.get_dispatch_info(),
|
||||
DispatchInfo {
|
||||
weight: Weight::from_parts(3, 0),
|
||||
class: DispatchClass::Normal,
|
||||
pays_fee: Pays::Yes
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_name() {
|
||||
use frame_support::traits::GetCallName;
|
||||
let name = module3::Call::<Runtime>::aux_4 {}.get_call_name();
|
||||
assert_eq!("aux_4", name);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_metadata() {
|
||||
use frame_support::traits::{CallMetadata, GetCallMetadata};
|
||||
let call = RuntimeCall::Module3(module3::Call::<Runtime>::aux_4 {});
|
||||
let metadata = call.get_call_metadata();
|
||||
let expected = CallMetadata { function_name: "aux_4".into(), pallet_name: "Module3".into() };
|
||||
assert_eq!(metadata, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_call_names() {
|
||||
use frame_support::traits::GetCallName;
|
||||
let call_names = module3::Call::<Runtime>::get_call_names();
|
||||
assert_eq!(["fail", "aux_1", "aux_2", "aux_3", "aux_4", "operational"], call_names);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_module_names() {
|
||||
use frame_support::traits::GetCallMetadata;
|
||||
let module_names = RuntimeCall::get_module_names();
|
||||
assert_eq!(
|
||||
[
|
||||
"System",
|
||||
"Module1_1",
|
||||
"Module2",
|
||||
"Module1_2",
|
||||
"NestedModule3",
|
||||
"Module3",
|
||||
"Module1_4",
|
||||
"Module1_6",
|
||||
"Module1_7",
|
||||
"Module1_8",
|
||||
"Module1_9",
|
||||
],
|
||||
module_names
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_subtype_conversion() {
|
||||
use frame_support::{dispatch::CallableCallFor, traits::IsSubType};
|
||||
let call = RuntimeCall::Module3(module3::Call::<Runtime>::fail {});
|
||||
let subcall: Option<&CallableCallFor<Module3, Runtime>> = call.is_sub_type();
|
||||
let subcall_none: Option<&CallableCallFor<Module2, Runtime>> = call.is_sub_type();
|
||||
assert_eq!(Some(&module3::Call::<Runtime>::fail {}), subcall);
|
||||
assert_eq!(None, subcall_none);
|
||||
|
||||
let from = RuntimeCall::from(subcall.unwrap().clone());
|
||||
assert_eq!(from, call);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_metadata() {
|
||||
use frame_metadata::{
|
||||
v14::{StorageEntryType::Plain, *},
|
||||
*,
|
||||
};
|
||||
use scale_info::meta_type;
|
||||
use sp_core::Encode;
|
||||
use sp_metadata_ir::StorageEntryModifierIR::Optional;
|
||||
|
||||
fn maybe_docs(doc: Vec<&'static str>) -> Vec<&'static str> {
|
||||
if cfg!(feature = "no-metadata-docs") {
|
||||
vec![]
|
||||
} else {
|
||||
doc
|
||||
}
|
||||
}
|
||||
|
||||
let pallets = vec![
|
||||
PalletMetadata {
|
||||
name: "System",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<frame_system::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<frame_system::Event<Runtime>>().into()),
|
||||
constants: vec![
|
||||
PalletConstantMetadata {
|
||||
name: "BlockWeights",
|
||||
ty: meta_type::<BlockWeights>(),
|
||||
value: BlockWeights::default().encode(),
|
||||
docs: maybe_docs(vec![" Block & extrinsics weights: base values and limits."]),
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "BlockLength",
|
||||
ty: meta_type::<BlockLength>(),
|
||||
value: BlockLength::default().encode(),
|
||||
docs: maybe_docs(vec![" The maximum length of a block (in bytes)."]),
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "BlockHashCount",
|
||||
ty: meta_type::<u64>(),
|
||||
value: 10u64.encode(),
|
||||
docs: maybe_docs(vec![" Maximum number of block number to block hash mappings to keep (oldest pruned first)."]),
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "DbWeight",
|
||||
ty: meta_type::<RuntimeDbWeight>(),
|
||||
value: RuntimeDbWeight::default().encode(),
|
||||
docs: maybe_docs(vec![" The weight of runtime database operations the runtime can invoke.",]),
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "Version",
|
||||
ty: meta_type::<RuntimeVersion>(),
|
||||
value: RuntimeVersion::default().encode(),
|
||||
docs: maybe_docs(vec![ " Get the chain's current version."]),
|
||||
},
|
||||
PalletConstantMetadata {
|
||||
name: "SS58Prefix",
|
||||
ty: meta_type::<u16>(),
|
||||
value: 0u16.encode(),
|
||||
docs: maybe_docs(vec![
|
||||
" The designated SS58 prefix of this chain.",
|
||||
"",
|
||||
" This replaces the \"ss58Format\" property declared in the chain spec. Reason is",
|
||||
" that the runtime should know about the prefix in order to make use of it as",
|
||||
" an identifier of the chain.",
|
||||
]),
|
||||
},
|
||||
],
|
||||
error: Some(meta_type::<frame_system::Error<Runtime>>().into()),
|
||||
index: 30,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_1",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance1>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance1>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime>>().into()),
|
||||
index: 31,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module2",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module2::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<module2::Event<Runtime>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module2::Error<Runtime>>().into()),
|
||||
index: 32,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_2",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance2>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance2>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance2>>().into()),
|
||||
index: 33,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "NestedModule3",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<nested::module3::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<nested::module3::Event<Runtime>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<nested::module3::Error<Runtime>>().into()),
|
||||
index: 34,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module3",
|
||||
storage: Some(PalletStorageMetadata {
|
||||
prefix: "Module3",
|
||||
entries: vec![
|
||||
StorageEntryMetadata {
|
||||
name: "Storage",
|
||||
modifier: Optional.into(),
|
||||
ty: Plain(meta_type::<u32>().into()),
|
||||
default: vec![0],
|
||||
docs: vec![],
|
||||
},
|
||||
]
|
||||
}),
|
||||
calls: Some(meta_type::<module3::Call<Runtime>>().into()),
|
||||
event: Some(meta_type::<module3::Event<Runtime>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module3::Error<Runtime>>().into()),
|
||||
index: 35,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_3",
|
||||
storage: None,
|
||||
calls: None,
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance3>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance3>>().into()),
|
||||
index: 6,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_4",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance4>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance4>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance4>>().into()),
|
||||
index: 3,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_5",
|
||||
storage: None,
|
||||
calls: None,
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance5>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance5>>().into()),
|
||||
index: 4,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_6",
|
||||
storage:None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance6>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance6>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance6>>().into()),
|
||||
index: 1,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_7",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance7>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance7>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance7>>().into()),
|
||||
index: 2,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_8",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance8>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance8>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance8>>().into()),
|
||||
index: 12,
|
||||
},
|
||||
PalletMetadata {
|
||||
name: "Module1_9",
|
||||
storage: None,
|
||||
calls: Some(meta_type::<module1::Call<Runtime, module1::Instance9>>().into()),
|
||||
event: Some(meta_type::<module1::Event<Runtime, module1::Instance9>>().into()),
|
||||
constants: vec![],
|
||||
error: Some(meta_type::<module1::Error<Runtime, module1::Instance9>>().into()),
|
||||
index: 13,
|
||||
},
|
||||
];
|
||||
|
||||
let extrinsic = ExtrinsicMetadata {
|
||||
ty: meta_type::<UncheckedExtrinsic>(),
|
||||
version: 4,
|
||||
signed_extensions: vec![SignedExtensionMetadata {
|
||||
identifier: "UnitTransactionExtension",
|
||||
ty: meta_type::<()>(),
|
||||
additional_signed: meta_type::<()>(),
|
||||
}],
|
||||
};
|
||||
|
||||
let expected_metadata: RuntimeMetadataPrefixed =
|
||||
RuntimeMetadataLastVersion::new(pallets, extrinsic, meta_type::<Runtime>()).into();
|
||||
let actual_metadata = Runtime::metadata();
|
||||
|
||||
pretty_assertions::assert_eq!(actual_metadata, expected_metadata);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pallet_in_runtime_is_correct() {
|
||||
assert_eq!(PalletInfo::index::<System>().unwrap(), 30);
|
||||
assert_eq!(PalletInfo::name::<System>().unwrap(), "System");
|
||||
assert_eq!(PalletInfo::module_name::<System>().unwrap(), "frame_system");
|
||||
assert!(PalletInfo::crate_version::<System>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<Module1_1>().unwrap(), 31);
|
||||
assert_eq!(PalletInfo::name::<Module1_1>().unwrap(), "Module1_1");
|
||||
assert_eq!(PalletInfo::module_name::<Module1_1>().unwrap(), "module1");
|
||||
assert!(PalletInfo::crate_version::<Module1_1>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<Module2>().unwrap(), 32);
|
||||
assert_eq!(PalletInfo::name::<Module2>().unwrap(), "Module2");
|
||||
assert_eq!(PalletInfo::module_name::<Module2>().unwrap(), "module2");
|
||||
assert!(PalletInfo::crate_version::<Module2>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<Module1_2>().unwrap(), 33);
|
||||
assert_eq!(PalletInfo::name::<Module1_2>().unwrap(), "Module1_2");
|
||||
assert_eq!(PalletInfo::module_name::<Module1_2>().unwrap(), "module1");
|
||||
assert!(PalletInfo::crate_version::<Module1_2>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<NestedModule3>().unwrap(), 34);
|
||||
assert_eq!(PalletInfo::name::<NestedModule3>().unwrap(), "NestedModule3");
|
||||
assert_eq!(PalletInfo::module_name::<NestedModule3>().unwrap(), "nested::module3");
|
||||
assert!(PalletInfo::crate_version::<NestedModule3>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<Module3>().unwrap(), 35);
|
||||
assert_eq!(PalletInfo::name::<Module3>().unwrap(), "Module3");
|
||||
assert_eq!(PalletInfo::module_name::<Module3>().unwrap(), "self::module3");
|
||||
assert!(PalletInfo::crate_version::<Module3>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<Module1_3>().unwrap(), 6);
|
||||
assert_eq!(PalletInfo::name::<Module1_3>().unwrap(), "Module1_3");
|
||||
assert_eq!(PalletInfo::module_name::<Module1_3>().unwrap(), "module1");
|
||||
assert!(PalletInfo::crate_version::<Module1_3>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<Module1_4>().unwrap(), 3);
|
||||
assert_eq!(PalletInfo::name::<Module1_4>().unwrap(), "Module1_4");
|
||||
assert_eq!(PalletInfo::module_name::<Module1_4>().unwrap(), "module1");
|
||||
assert!(PalletInfo::crate_version::<Module1_4>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<Module1_5>().unwrap(), 4);
|
||||
assert_eq!(PalletInfo::name::<Module1_5>().unwrap(), "Module1_5");
|
||||
assert_eq!(PalletInfo::module_name::<Module1_5>().unwrap(), "module1");
|
||||
assert!(PalletInfo::crate_version::<Module1_5>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<Module1_6>().unwrap(), 1);
|
||||
assert_eq!(PalletInfo::name::<Module1_6>().unwrap(), "Module1_6");
|
||||
assert_eq!(PalletInfo::module_name::<Module1_6>().unwrap(), "module1");
|
||||
assert!(PalletInfo::crate_version::<Module1_6>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<Module1_7>().unwrap(), 2);
|
||||
assert_eq!(PalletInfo::name::<Module1_7>().unwrap(), "Module1_7");
|
||||
assert_eq!(PalletInfo::module_name::<Module1_7>().unwrap(), "module1");
|
||||
assert!(PalletInfo::crate_version::<Module1_7>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<Module1_8>().unwrap(), 12);
|
||||
assert_eq!(PalletInfo::name::<Module1_8>().unwrap(), "Module1_8");
|
||||
assert_eq!(PalletInfo::module_name::<Module1_8>().unwrap(), "module1");
|
||||
assert!(PalletInfo::crate_version::<Module1_8>().is_some());
|
||||
|
||||
assert_eq!(PalletInfo::index::<Module1_9>().unwrap(), 13);
|
||||
assert_eq!(PalletInfo::name::<Module1_9>().unwrap(), "Module1_9");
|
||||
assert_eq!(PalletInfo::module_name::<Module1_9>().unwrap(), "module1");
|
||||
assert!(PalletInfo::crate_version::<Module1_9>().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_validate_unsigned() {
|
||||
use frame_support::pallet_prelude::*;
|
||||
|
||||
let call = RuntimeCall::NestedModule3(nested::module3::Call::fail {});
|
||||
let validity = Runtime::validate_unsigned(TransactionSource::Local, &call).unwrap_err();
|
||||
assert_eq!(validity, TransactionValidityError::Invalid(InvalidTransaction::Call));
|
||||
|
||||
let call = RuntimeCall::Module3(module3::Call::fail {});
|
||||
let validity = Runtime::validate_unsigned(TransactionSource::Local, &call).unwrap_err();
|
||||
assert_eq!(
|
||||
validity,
|
||||
TransactionValidityError::Unknown(UnknownTransaction::NoUnsignedValidator)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// 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.
|
||||
|
||||
#[rustversion::attr(not(stable), ignore)]
|
||||
#[cfg(not(feature = "disable-ui-tests"))]
|
||||
#[test]
|
||||
fn ui() {
|
||||
// Only run the ui tests when `RUN_UI_TESTS` is set.
|
||||
if std::env::var("RUN_UI_TESTS").is_err() {
|
||||
return
|
||||
}
|
||||
|
||||
// As trybuild is using `cargo check`, we don't need the real WASM binaries.
|
||||
std::env::set_var("SKIP_WASM_BUILD", "1");
|
||||
|
||||
// Deny all warnings since we emit warnings as part of a Runtime's UI.
|
||||
std::env::set_var("RUSTFLAGS", "--deny warnings");
|
||||
|
||||
let t = trybuild::TestCases::new();
|
||||
t.compile_fail("tests/runtime_ui/*.rs");
|
||||
t.pass("tests/runtime_ui/pass/*.rs");
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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.
|
||||
|
||||
#[frame_support::runtime]
|
||||
fn construct_runtime() {}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: expected `mod`
|
||||
--> tests/runtime_ui/can_only_be_attached_to_mod.rs:19:1
|
||||
|
|
||||
19 | fn construct_runtime() {}
|
||||
| ^^
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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.
|
||||
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
}
|
||||
|
||||
#[frame_support::runtime]
|
||||
mod runtime {
|
||||
#[runtime::runtime]
|
||||
#[runtime::derive(RuntimeCall)]
|
||||
pub struct Runtime;
|
||||
|
||||
#[runtime::pallet_index(0)]
|
||||
pub type System = frame_system;
|
||||
|
||||
#[runtime::pallet_index(0)]
|
||||
pub type Pallet = pallet;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,11 @@
|
||||
error: Pallet indices are conflicting: Both pallets System and Pallet are at index 0
|
||||
--> tests/runtime_ui/conflicting_pallet_index.rs:37:14
|
||||
|
|
||||
37 | pub type System = frame_system;
|
||||
| ^^^^^^
|
||||
|
||||
error: Pallet indices are conflicting: Both pallets System and Pallet are at index 0
|
||||
--> tests/runtime_ui/conflicting_pallet_index.rs:40:14
|
||||
|
|
||||
40 | pub type Pallet = pallet;
|
||||
| ^^^^^^
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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.
|
||||
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
}
|
||||
|
||||
#[frame_support::runtime]
|
||||
mod runtime {
|
||||
#[runtime::runtime]
|
||||
#[runtime::derive(RuntimeCall)]
|
||||
pub struct Runtime;
|
||||
|
||||
#[runtime::pallet_index(0)]
|
||||
pub type System = frame_system;
|
||||
|
||||
#[runtime::pallet_index(1)]
|
||||
pub type System = pallet;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,11 @@
|
||||
error: Two pallets with the same name!
|
||||
--> tests/runtime_ui/conflicting_pallet_name.rs:37:14
|
||||
|
|
||||
37 | pub type System = frame_system;
|
||||
| ^^^^^^
|
||||
|
||||
error: Two pallets with the same name!
|
||||
--> tests/runtime_ui/conflicting_pallet_name.rs:40:14
|
||||
|
|
||||
40 | pub type System = pallet;
|
||||
| ^^^^^^
|
||||
@@ -0,0 +1,23 @@
|
||||
// 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.
|
||||
|
||||
#[frame_support::runtime(dummy)]
|
||||
mod runtime {
|
||||
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Invalid runtime macro call: unexpected attribute. Macro call must be bare, such as `#[frame_support::runtime]` or `#[runtime]`, or must specify the `legacy_ordering` attribute, such as `#[frame_support::runtime(legacy_ordering)]` or #[runtime(legacy_ordering)].
|
||||
--> tests/runtime_ui/invalid_attribute.rs:18:26
|
||||
|
|
||||
18 | #[frame_support::runtime(dummy)]
|
||||
| ^^^^^
|
||||
@@ -0,0 +1,28 @@
|
||||
// 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.
|
||||
|
||||
#[frame_support::runtime]
|
||||
mod runtime {
|
||||
#[runtime::runtime]
|
||||
#[runtime::derive(RuntimeCall)]
|
||||
pub struct Runtime;
|
||||
|
||||
#[runtime::pallet_index("0")]
|
||||
pub type System = frame_system;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: expected integer literal
|
||||
--> tests/runtime_ui/invalid_pallet_index.rs:24:29
|
||||
|
|
||||
24 | #[runtime::pallet_index("0")]
|
||||
| ^^^
|
||||
@@ -0,0 +1,25 @@
|
||||
// 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.
|
||||
|
||||
#[frame_support::runtime]
|
||||
mod runtime {
|
||||
#[runtime::runtime]
|
||||
#[runtime::derive(RuntimeInfo)]
|
||||
pub struct Runtime;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: expected one of: `RuntimeCall`, `RuntimeEvent`, `RuntimeError`, `RuntimeOrigin`, `RuntimeFreezeReason`, `RuntimeHoldReason`, `RuntimeSlashReason`, `RuntimeLockId`, `RuntimeTask`
|
||||
--> tests/runtime_ui/invalid_runtime_type_derive.rs:21:23
|
||||
|
|
||||
21 | #[runtime::derive(RuntimeInfo)]
|
||||
| ^^^^^^^^^^^
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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.
|
||||
|
||||
#[frame_support::runtime]
|
||||
mod runtime {}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Missing Runtime. Please add a struct inside the module and annotate it with `#[runtime::runtime]`
|
||||
--> tests/runtime_ui/missing_runtime.rs:19:1
|
||||
|
|
||||
19 | mod runtime {}
|
||||
| ^^^
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
|
||||
#[frame_support::runtime]
|
||||
mod runtime {
|
||||
#[runtime::runtime]
|
||||
pub struct Runtime;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Missing Runtime Types. Please annotate the runtime struct with `#[runtime::derive]`
|
||||
--> tests/runtime_ui/missing_runtime_types_derive.rs:19:1
|
||||
|
|
||||
19 | mod runtime {
|
||||
| ^^^
|
||||
@@ -0,0 +1,25 @@
|
||||
// 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.
|
||||
|
||||
#[frame_support::runtime]
|
||||
mod runtime {
|
||||
#[runtime::runtime]
|
||||
#[runtime::derive(RuntimeCall)]
|
||||
pub struct Runtime;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: `System` pallet declaration is missing. Please add this line: `pub type System = frame_system;`
|
||||
--> tests/runtime_ui/missing_system_pallet.rs:19:5
|
||||
|
|
||||
19 | mod runtime {
|
||||
| ^^^^^^^
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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 frame_support::derive_impl;
|
||||
|
||||
pub type Block = frame_system::mocking::MockBlock<Runtime>;
|
||||
|
||||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
|
||||
impl frame_system::Config for Runtime {
|
||||
type Block = Block;
|
||||
}
|
||||
|
||||
#[frame_support::runtime]
|
||||
mod runtime {
|
||||
#[runtime::runtime]
|
||||
#[runtime::derive(RuntimeCall, RuntimeEvent, RuntimeOrigin, RuntimeError, RuntimeTask)]
|
||||
pub struct Runtime;
|
||||
|
||||
#[runtime::pallet_index(0)]
|
||||
pub type System = frame_system;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
|
||||
#[frame_support::runtime]
|
||||
mod runtime {
|
||||
#[runtime::runtime]
|
||||
pub enum Runtime {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Invalid runtime::runtime, expected struct definition
|
||||
--> tests/runtime_ui/runtime_struct.rs:21:5
|
||||
|
|
||||
21 | pub enum Runtime {}
|
||||
| ^^^
|
||||
Reference in New Issue
Block a user