Emit error when construct_runtime imports a non-existent pallet part (#8949)

* Emit error when construct_runtime imports a non-existent Call part

* Reword and display pallet name when emitting part not found error

* Migrate decl_outer_dispatch to a proc macro

* Rename calls.rs to call.rs

* Create new construct_runtime_v2 macro

* Add UI test for importing non-existent call part in construct_runtime

* Emit error when construct_runtime imports a non-existent Config part

* Emit error when construct_runtime imports a non-existent Event part

* Migrate decl_outer_inherent to a proc macro

* Emit error when construct_runtime imports a non-existent Inherent part

* Migrate decl_outer_validate_unsigned to a proc macro

* Emit error when construct_runtime imports a non-existent ValidateUnsigned part

* impl for old macro

* fix line width

* add doc

* hide macroes and use unique counter everywhere

* Remove construct_runtime_v2

* Encapsulate pallet part check macros in a module

* Fix macro definitions in dummy part checker

* Tag ProvideInherent impl with #[pallet::inherent] properly for authorship pallet

* Remove Call part from pallets that do not define it

* Add Call part unit tests

* Remove undefined Call part import from offences pallet

* Add tests for expand_outer_inherent

* Remove Call part from pallets that do not define them

* Remove Call part imports from pallets that do not have it defined

* Remove Call part import of the offences pallet from grandpa pallet mocks

* Update frame/support/test/tests/pallet.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Remove Call part imports for pallets that do not define them

* Move inherent tests to inherent_expand

* Add unit tests for expand_outer_validate_unsigned

* Add newline at the end of file

* fix ui test

* Small prayer to RNGsus for fixing CI

* Remove Call part from construct_runtime for randomness collective flip pallet

* Remove Call part import for randomness collective flip pallet

* Summon Laplace's demon instead of praying to RNGsus

* Update test expectations

* fix ui test and make sure it's flaky

* Revert "fix ui test and make sure it's flaky"

This reverts commit 362b6881389c911ef8d9ef85d71c9463f5694b20.

* Comment out test instead of putting it in conditional compilation

* Update UI test expectations

* Update UI test expectations

* Emit error when construct_runtime imports a non-existent Origin part

Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Denis P <denis.pisarev@parity.io>
This commit is contained in:
Keith Yeung
2021-06-15 20:44:22 -07:00
committed by GitHub
parent 7dd38e3aec
commit 58e837fcd3
47 changed files with 1934 additions and 197 deletions
@@ -0,0 +1,145 @@
// This file is part of Substrate.
// Copyright (C) 2021 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 crate::construct_runtime::Pallet;
use proc_macro2::TokenStream;
use quote::quote;
use syn::Ident;
pub fn expand_outer_dispatch(
runtime: &Ident,
pallet_decls: &[Pallet],
scrate: &TokenStream,
) -> TokenStream {
let mut variant_defs = TokenStream::new();
let mut variant_patterns = Vec::new();
let mut query_call_part_macros = Vec::new();
let mut pallet_names = Vec::new();
let pallets_with_call = pallet_decls
.iter()
.filter(|decl| decl.exists_part("Call"));
for pallet_declaration in pallets_with_call {
let name = &pallet_declaration.name;
let path = &pallet_declaration.path;
let index = pallet_declaration.index;
variant_defs.extend(quote!(#[codec(index = #index)] #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ),));
variant_patterns.push(quote!(Call::#name(call)));
pallet_names.push(name);
query_call_part_macros.push(quote! {
#path::__substrate_call_check::is_call_part_defined!(#name);
});
}
quote! {
#( #query_call_part_macros )*
#[derive(
Clone, PartialEq, Eq,
#scrate::codec::Encode,
#scrate::codec::Decode,
#scrate::RuntimeDebug,
)]
pub enum Call {
#variant_defs
}
impl #scrate::dispatch::GetDispatchInfo for Call {
fn get_dispatch_info(&self) -> #scrate::dispatch::DispatchInfo {
match self {
#( #variant_patterns => call.get_dispatch_info(), )*
}
}
}
impl #scrate::dispatch::GetCallMetadata for Call {
fn get_call_metadata(&self) -> #scrate::dispatch::CallMetadata {
use #scrate::dispatch::GetCallName;
match self {
#(
#variant_patterns => {
let function_name = call.get_call_name();
let pallet_name = stringify!(#pallet_names);
#scrate::dispatch::CallMetadata { function_name, pallet_name }
}
)*
}
}
fn get_module_names() -> &'static [&'static str] {
&[#(
stringify!(#pallet_names),
)*]
}
fn get_call_names(module: &str) -> &'static [&'static str] {
use #scrate::dispatch::{Callable, GetCallName};
match module {
#(
stringify!(#pallet_names) =>
<<#pallet_names as Callable<#runtime>>::Call
as GetCallName>::get_call_names(),
)*
_ => unreachable!(),
}
}
}
impl #scrate::dispatch::Dispatchable for Call {
type Origin = Origin;
type Config = Call;
type Info = #scrate::weights::DispatchInfo;
type PostInfo = #scrate::weights::PostDispatchInfo;
fn dispatch(self, origin: Origin) -> #scrate::dispatch::DispatchResultWithPostInfo {
if !<Self::Origin as #scrate::traits::OriginTrait>::filter_call(&origin, &self) {
return #scrate::sp_std::result::Result::Err(#scrate::dispatch::DispatchError::BadOrigin.into());
}
#scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(self, origin)
}
}
impl #scrate::traits::UnfilteredDispatchable for Call {
type Origin = Origin;
fn dispatch_bypass_filter(self, origin: Origin) -> #scrate::dispatch::DispatchResultWithPostInfo {
match self {
#(
#variant_patterns =>
#scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(call, origin),
)*
}
}
}
#(
impl #scrate::traits::IsSubType<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for Call {
#[allow(unreachable_patterns)]
fn is_sub_type(&self) -> Option<&#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> {
match self {
#variant_patterns => Some(call),
// May be unreachable
_ => None,
}
}
}
impl From<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for Call {
fn from(call: #scrate::dispatch::CallableCallFor<#pallet_names, #runtime>) -> Self {
#variant_patterns
}
}
)*
}
}
@@ -29,21 +29,31 @@ pub fn expand_outer_config(
let mut types = TokenStream::new();
let mut fields = TokenStream::new();
let mut build_storage_calls = TokenStream::new();
let mut query_genesis_config_part_macros = Vec::new();
for decl in pallet_decls {
if let Some(pallet_entry) = decl.find_part("Config") {
let config = format_ident!("{}Config", decl.name);
let pallet_name = &decl.name.to_string().to_snake_case();
let field_name = &Ident::new(pallet_name, decl.name.span());
let path = &decl.path;
let pallet_name = &decl.name;
let config = format_ident!("{}Config", pallet_name);
let field_name = &Ident::new(
&pallet_name.to_string().to_snake_case(),
decl.name.span(),
);
let part_is_generic = !pallet_entry.generics.params.is_empty();
types.extend(expand_config_types(runtime, decl, &config, part_is_generic));
fields.extend(quote!(pub #field_name: #config,));
build_storage_calls.extend(expand_config_build_storage_call(scrate, runtime, decl, &field_name));
query_genesis_config_part_macros.push(quote! {
#path::__substrate_genesis_config_check::is_genesis_config_defined!(#pallet_name);
});
}
}
quote!{
quote! {
#( #query_genesis_config_part_macros )*
#types
#[cfg(any(feature = "std", test))]
@@ -27,10 +27,12 @@ pub fn expand_outer_event(
) -> syn::Result<TokenStream> {
let mut event_variants = TokenStream::new();
let mut event_conversions = TokenStream::new();
let mut query_event_part_macros = Vec::new();
for pallet_decl in pallet_decls {
if let Some(pallet_entry) = pallet_decl.find_part("Event") {
let path = &pallet_decl.path;
let pallet_name = &pallet_decl.name;
let index = pallet_decl.index;
let instance = pallet_decl.instance.as_ref();
let generics = &pallet_entry.generics;
@@ -39,9 +41,9 @@ pub fn expand_outer_event(
let msg = format!(
"Instantiable pallet with no generic `Event` cannot \
be constructed: pallet `{}` must have generic `Event`",
pallet_decl.name,
pallet_name,
);
return Err(syn::Error::new(pallet_decl.name.span(), msg));
return Err(syn::Error::new(pallet_name.span(), msg));
}
let part_is_generic = !generics.params.is_empty();
@@ -54,10 +56,15 @@ pub fn expand_outer_event(
event_variants.extend(expand_event_variant(runtime, pallet_decl, index, instance, generics));
event_conversions.extend(expand_event_conversion(scrate, pallet_decl, &pallet_event));
query_event_part_macros.push(quote! {
#path::__substrate_event_check::is_event_part_defined!(#pallet_name);
});
}
}
Ok(quote!{
Ok(quote! {
#( #query_event_part_macros )*
#[derive(
Clone, PartialEq, Eq,
#scrate::codec::Encode,
@@ -0,0 +1,204 @@
// This file is part of Substrate.
// Copyright (C) 2021 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 crate::construct_runtime::Pallet;
use proc_macro2::TokenStream;
use quote::quote;
use syn::{Ident, TypePath};
pub fn expand_outer_inherent(
runtime: &Ident,
block: &TypePath,
unchecked_extrinsic: &TypePath,
pallet_decls: &[Pallet],
scrate: &TokenStream,
) -> TokenStream {
let mut pallet_names = Vec::new();
let mut query_inherent_part_macros = Vec::new();
for pallet_decl in pallet_decls {
if pallet_decl.exists_part("Inherent") {
let name = &pallet_decl.name;
let path = &pallet_decl.path;
pallet_names.push(name);
query_inherent_part_macros.push(quote! {
#path::__substrate_inherent_check::is_inherent_part_defined!(#name);
});
}
}
quote! {
#( #query_inherent_part_macros )*
trait InherentDataExt {
fn create_extrinsics(&self) ->
#scrate::inherent::Vec<<#block as #scrate::inherent::BlockT>::Extrinsic>;
fn check_extrinsics(&self, block: &#block) -> #scrate::inherent::CheckInherentsResult;
}
impl InherentDataExt for #scrate::inherent::InherentData {
fn create_extrinsics(&self) ->
#scrate::inherent::Vec<<#block as #scrate::inherent::BlockT>::Extrinsic>
{
use #scrate::inherent::ProvideInherent;
let mut inherents = Vec::new();
#(
if let Some(inherent) = #pallet_names::create_inherent(self) {
let inherent = <#unchecked_extrinsic as #scrate::inherent::Extrinsic>::new(
inherent.into(),
None,
).expect("Runtime UncheckedExtrinsic is not Opaque, so it has to return \
`Some`; qed");
inherents.push(inherent);
}
)*
inherents
}
fn check_extrinsics(&self, block: &#block) -> #scrate::inherent::CheckInherentsResult {
use #scrate::inherent::{ProvideInherent, IsFatalError};
use #scrate::traits::{IsSubType, ExtrinsicCall};
use #scrate::sp_runtime::traits::Block as _;
let mut result = #scrate::inherent::CheckInherentsResult::new();
for xt in block.extrinsics() {
// Inherents are before any other extrinsics.
// And signed extrinsics are not inherents.
if #scrate::inherent::Extrinsic::is_signed(xt).unwrap_or(false) {
break
}
let mut is_inherent = false;
#({
let call = <#unchecked_extrinsic as ExtrinsicCall>::call(xt);
if let Some(call) = IsSubType::<_>::is_sub_type(call) {
if #pallet_names::is_inherent(call) {
is_inherent = true;
if let Err(e) = #pallet_names::check_inherent(call, self) {
result.put_error(
#pallet_names::INHERENT_IDENTIFIER, &e
).expect("There is only one fatal error; qed");
if e.is_fatal_error() {
return result;
}
}
}
}
})*
// Inherents are before any other extrinsics.
// No module marked it as inherent thus it is not.
if !is_inherent {
break
}
}
#(
match #pallet_names::is_inherent_required(self) {
Ok(Some(e)) => {
let found = block.extrinsics().iter().any(|xt| {
let is_signed = #scrate::inherent::Extrinsic::is_signed(xt)
.unwrap_or(false);
if !is_signed {
let call = <
#unchecked_extrinsic as ExtrinsicCall
>::call(xt);
if let Some(call) = IsSubType::<_>::is_sub_type(call) {
#pallet_names::is_inherent(&call)
} else {
false
}
} else {
// Signed extrinsics are not inherents.
false
}
});
if !found {
result.put_error(
#pallet_names::INHERENT_IDENTIFIER, &e
).expect("There is only one fatal error; qed");
if e.is_fatal_error() {
return result;
}
}
},
Ok(None) => (),
Err(e) => {
result.put_error(
#pallet_names::INHERENT_IDENTIFIER, &e
).expect("There is only one fatal error; qed");
if e.is_fatal_error() {
return result;
}
},
}
)*
result
}
}
impl #scrate::traits::EnsureInherentsAreFirst<#block> for #runtime {
fn ensure_inherents_are_first(block: &#block) -> Result<(), u32> {
use #scrate::inherent::ProvideInherent;
use #scrate::traits::{IsSubType, ExtrinsicCall};
use #scrate::sp_runtime::traits::Block as _;
let mut first_signed_observed = false;
for (i, xt) in block.extrinsics().iter().enumerate() {
let is_signed = #scrate::inherent::Extrinsic::is_signed(xt).unwrap_or(false);
let is_inherent = if is_signed {
// Signed extrinsics are not inherents.
false
} else {
let mut is_inherent = false;
#({
let call = <#unchecked_extrinsic as ExtrinsicCall>::call(xt);
if let Some(call) = IsSubType::<_>::is_sub_type(call) {
if #pallet_names::is_inherent(&call) {
is_inherent = true;
}
}
})*
is_inherent
};
if !is_inherent {
first_signed_observed = true;
}
if first_signed_observed && is_inherent {
return Err(i as u32)
}
}
Ok(())
}
}
}
}
@@ -15,12 +15,18 @@
// See the License for the specific language governing permissions and
// limitations under the License
mod call;
mod config;
mod event;
mod inherent;
mod metadata;
mod origin;
mod unsigned;
pub use call::expand_outer_dispatch;
pub use config::expand_outer_config;
pub use event::expand_outer_event;
pub use inherent::expand_outer_inherent;
pub use metadata::expand_runtime_metadata;
pub use origin::expand_outer_origin;
pub use unsigned::expand_outer_validate_unsigned;
@@ -36,20 +36,23 @@ pub fn expand_outer_origin(
let mut caller_variants = TokenStream::new();
let mut pallet_conversions = TokenStream::new();
let mut query_origin_part_macros = Vec::new();
for pallet_decl in pallets.iter().filter(|pallet| pallet.name != SYSTEM_PALLET_NAME) {
if let Some(pallet_entry) = pallet_decl.find_part("Origin") {
let instance = pallet_decl.instance.as_ref();
let index = pallet_decl.index;
let generics = &pallet_entry.generics;
let name = &pallet_decl.name;
let path = &pallet_decl.path;
if instance.is_some() && generics.params.is_empty() {
let msg = format!(
"Instantiable pallet with no generic `Origin` cannot \
be constructed: pallet `{}` must have generic `Origin`",
pallet_decl.name
name
);
return Err(syn::Error::new(pallet_decl.name.span(), msg));
return Err(syn::Error::new(name.span(), msg));
}
caller_variants.extend(
@@ -58,13 +61,18 @@ pub fn expand_outer_origin(
pallet_conversions.extend(
expand_origin_pallet_conversions(scrate, runtime, pallet_decl, instance, generics),
);
query_origin_part_macros.push(quote! {
#path::__substrate_origin_check::is_origin_part_defined!(#name);
});
}
}
let system_path = &system_pallet.path;
let system_index = system_pallet.index;
Ok(quote!{
Ok(quote! {
#( #query_origin_part_macros )*
// WARNING: All instance must hold the filter `frame_system::Config::BaseCallFilter`, except
// when caller is system Root. One can use `OriginTrait::reset_filter` to do so.
#[derive(Clone)]
@@ -0,0 +1,72 @@
// This file is part of Substrate.
// Copyright (C) 2021 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 crate::construct_runtime::Pallet;
use proc_macro2::TokenStream;
use quote::quote;
use syn::Ident;
pub fn expand_outer_validate_unsigned(
runtime: &Ident,
pallet_decls: &[Pallet],
scrate: &TokenStream,
) -> TokenStream {
let mut pallet_names = Vec::new();
let mut query_validate_unsigned_part_macros = Vec::new();
for pallet_decl in pallet_decls {
if pallet_decl.exists_part("ValidateUnsigned") {
let name = &pallet_decl.name;
let path = &pallet_decl.path;
pallet_names.push(name);
query_validate_unsigned_part_macros.push(quote! {
#path::__substrate_validate_unsigned_check::is_validate_unsigned_part_defined!(#name);
});
}
}
quote! {
#( #query_validate_unsigned_part_macros )*
impl #scrate::unsigned::ValidateUnsigned for #runtime {
type Call = Call;
fn pre_dispatch(call: &Self::Call) -> Result<(), #scrate::unsigned::TransactionValidityError> {
#[allow(unreachable_patterns)]
match call {
#( Call::#pallet_names(inner_call) => #pallet_names::pre_dispatch(inner_call), )*
// pre-dispatch should not stop inherent extrinsics, validation should prevent
// including arbitrary (non-inherent) extrinsics to blocks.
_ => Ok(()),
}
}
fn validate_unsigned(
#[allow(unused_variables)]
source: #scrate::unsigned::TransactionSource,
call: &Self::Call,
) -> #scrate::unsigned::TransactionValidity {
#[allow(unreachable_patterns)]
match call {
#( Call::#pallet_names(inner_call) => #pallet_names::validate_unsigned(source, inner_call), )*
_ => #scrate::unsigned::UnknownTransaction::NoUnsignedValidator.into(),
}
}
}
}
}
@@ -145,17 +145,17 @@ fn construct_runtime_parsed(definition: RuntimeDefinition) -> Result<TokenStream
let all_pallets = decl_all_pallets(&name, pallets.iter());
let pallet_to_index = decl_pallet_runtime_setup(&pallets, &scrate);
let dispatch = decl_outer_dispatch(&name, pallets.iter(), &scrate);
let dispatch = expand::expand_outer_dispatch(&name, &pallets, &scrate);
let metadata = expand::expand_runtime_metadata(&name, &pallets, &scrate, &unchecked_extrinsic);
let outer_config = expand::expand_outer_config(&name, &pallets, &scrate);
let inherent = decl_outer_inherent(
let inherent = expand::expand_outer_inherent(
&name,
&block,
&unchecked_extrinsic,
pallets.iter(),
&pallets,
&scrate,
);
let validate_unsigned = decl_validate_unsigned(&name, pallets.iter(), &scrate);
let validate_unsigned = expand::expand_outer_validate_unsigned(&name, &pallets, &scrate);
let integrity_test = decl_integrity_test(&scrate);
let res = quote!(
@@ -200,73 +200,6 @@ fn construct_runtime_parsed(definition: RuntimeDefinition) -> Result<TokenStream
Ok(res)
}
fn decl_validate_unsigned<'a>(
runtime: &'a Ident,
pallet_declarations: impl Iterator<Item = &'a Pallet>,
scrate: &'a TokenStream2,
) -> TokenStream2 {
let pallets_tokens = pallet_declarations
.filter(|pallet_declaration| pallet_declaration.exists_part("ValidateUnsigned"))
.map(|pallet_declaration| &pallet_declaration.name);
quote!(
#scrate::impl_outer_validate_unsigned!(
impl ValidateUnsigned for #runtime {
#( #pallets_tokens )*
}
);
)
}
fn decl_outer_inherent<'a>(
runtime: &'a Ident,
block: &'a syn::TypePath,
unchecked_extrinsic: &'a syn::TypePath,
pallet_declarations: impl Iterator<Item = &'a Pallet>,
scrate: &'a TokenStream2,
) -> TokenStream2 {
let pallets_tokens = pallet_declarations.filter_map(|pallet_declaration| {
let maybe_config_part = pallet_declaration.find_part("Inherent");
maybe_config_part.map(|_| {
let name = &pallet_declaration.name;
quote!(#name,)
})
});
quote!(
#scrate::impl_outer_inherent!(
impl Inherents where
Block = #block,
UncheckedExtrinsic = #unchecked_extrinsic,
Runtime = #runtime,
{
#(#pallets_tokens)*
}
);
)
}
fn decl_outer_dispatch<'a>(
runtime: &'a Ident,
pallet_declarations: impl Iterator<Item = &'a Pallet>,
scrate: &'a TokenStream2,
) -> TokenStream2 {
let pallets_tokens = pallet_declarations
.filter(|pallet_declaration| pallet_declaration.exists_part("Call"))
.map(|pallet_declaration| {
let pallet = &pallet_declaration.path.inner.segments.last().unwrap();
let name = &pallet_declaration.name;
let index = pallet_declaration.index;
quote!(#[codec(index = #index)] #pallet::#name)
});
quote!(
#scrate::impl_outer_dispatch! {
pub enum Call for #runtime where origin: Origin {
#(#pallets_tokens,)*
}
}
)
}
fn decl_all_pallets<'a>(
runtime: &'a Ident,
pallet_declarations: impl Iterator<Item = &'a Pallet>,
@@ -0,0 +1,104 @@
use proc_macro::TokenStream;
use crate::COUNTER;
pub fn generate_dummy_part_checker(input: TokenStream) -> TokenStream {
if !input.is_empty() {
return syn::Error::new(proc_macro2::Span::call_site(), "No arguments expected")
.to_compile_error().into()
}
let count = COUNTER.with(|counter| counter.borrow_mut().inc());
let genesis_config_macro_ident = syn::Ident::new(
&format!("__is_genesis_config_defined_{}", count),
proc_macro2::Span::call_site(),
);
let event_macro_ident = syn::Ident::new(
&format!("__is_event_part_defined_{}", count),
proc_macro2::Span::call_site(),
);
let inherent_macro_ident = syn::Ident::new(
&format!("__is_inherent_part_defined_{}", count),
proc_macro2::Span::call_site(),
);
let validate_unsigned_macro_ident = syn::Ident::new(
&format!("__is_validate_unsigned_part_defined_{}", count),
proc_macro2::Span::call_site(),
);
let call_macro_ident = syn::Ident::new(
&format!("__is_call_part_defined_{}", count),
proc_macro2::Span::call_site(),
);
let origin_macro_ident = syn::Ident::new(
&format!("__is_origin_part_defined_{}", count),
proc_macro2::Span::call_site(),
);
quote::quote!(
#[doc(hidden)]
pub mod __substrate_genesis_config_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #genesis_config_macro_ident {
($pallet_name:ident) => {};
}
#[doc(hidden)]
pub use #genesis_config_macro_ident as is_genesis_config_defined;
}
#[doc(hidden)]
pub mod __substrate_event_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #event_macro_ident {
($pallet_name:ident) => {};
}
#[doc(hidden)]
pub use #event_macro_ident as is_event_part_defined;
}
#[doc(hidden)]
pub mod __substrate_inherent_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #inherent_macro_ident {
($pallet_name:ident) => {};
}
#[doc(hidden)]
pub use #inherent_macro_ident as is_inherent_part_defined;
}
#[doc(hidden)]
pub mod __substrate_validate_unsigned_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #validate_unsigned_macro_ident {
($pallet_name:ident) => {};
}
#[doc(hidden)]
pub use #validate_unsigned_macro_ident as is_validate_unsigned_part_defined;
}
#[doc(hidden)]
pub mod __substrate_call_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #call_macro_ident {
($pallet_name:ident) => {};
}
#[doc(hidden)]
pub use #call_macro_ident as is_call_part_defined;
}
#[doc(hidden)]
pub mod __substrate_origin_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #origin_macro_ident {
($pallet_name:ident) => {};
}
#[doc(hidden)]
pub use #origin_macro_ident as is_origin_part_defined;
}
).into()
}
@@ -29,9 +29,29 @@ mod clone_no_bound;
mod partial_eq_no_bound;
mod default_no_bound;
mod key_prefix;
mod dummy_part_checker;
pub(crate) use storage::INHERENT_INSTANCE_NAME;
use proc_macro::TokenStream;
use std::cell::RefCell;
thread_local! {
/// A global counter, can be used to generate a relatively unique identifier.
static COUNTER: RefCell<Counter> = RefCell::new(Counter(0));
}
/// Counter to generate a relatively unique identifier for macros querying for the existence of
/// pallet parts. This is necessary because declarative macros gets hoisted to the crate root,
/// which shares the namespace with other pallets containing the very same query macros.
struct Counter(u64);
impl Counter {
fn inc(&mut self) -> u64 {
let ret = self.0;
self.0 += 1;
ret
}
}
/// Declares strongly-typed wrappers around codec-compatible types in storage.
///
@@ -453,3 +473,9 @@ pub(crate) const NUMBER_OF_INSTANCE: u8 = 16;
pub fn impl_key_prefix_for_tuples(input: TokenStream) -> TokenStream {
key_prefix::impl_key_prefix_for_tuples(input).unwrap_or_else(syn::Error::into_compile_error).into()
}
/// Internal macro use by frame_support to generate dummy part checker for old pallet declaration
#[proc_macro]
pub fn __generate_dummy_part_checker(input: TokenStream) -> TokenStream {
dummy_part_checker::generate_dummy_part_checker(input)
}
@@ -17,6 +17,7 @@
use crate::pallet::Def;
use frame_support_procedural_tools::clean_type_string;
use crate::COUNTER;
use syn::spanned::Spanned;
/// * Generate enum call and implement various trait on it.
@@ -31,7 +32,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
(span, where_clause, methods, docs)
}
None => (def.pallet_struct.attr_span, None, Vec::new(), Vec::new()),
None => (def.item.span(), None, Vec::new(), Vec::new()),
};
let frame_support = &def.frame_support;
let frame_system = &def.frame_system;
@@ -89,7 +90,37 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
&docs[..]
};
let maybe_compile_error = if def.call.is_none() {
quote::quote!{
compile_error!(concat!(
"`",
stringify!($pallet_name),
"` does not have #[pallet::call] defined, perhaps you should remove `Call` from \
construct_runtime?",
));
}
} else {
proc_macro2::TokenStream::new()
};
let count = COUNTER.with(|counter| counter.borrow_mut().inc());
let macro_ident = syn::Ident::new(&format!("__is_call_part_defined_{}", count), span);
quote::quote_spanned!(span =>
#[doc(hidden)]
pub mod __substrate_call_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #macro_ident {
($pallet_name:ident) => {
#maybe_compile_error
};
}
#[doc(hidden)]
pub use #macro_ident as is_call_part_defined;
}
#( #[doc = #docs] )*
#[derive(
#frame_support::RuntimeDebugNoBound,
@@ -16,15 +16,44 @@
// limitations under the License.
use crate::pallet::{Def, parse::helper::get_doc_literals};
use crate::COUNTER;
use syn::{spanned::Spanned, Ident};
/// * Add __Ignore variant on Event
/// * Impl various trait on Event including metadata
/// * if deposit_event is defined, implement deposit_event on module.
pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {
let event = if let Some(event) = &def.event {
event
let count = COUNTER.with(|counter| counter.borrow_mut().inc());
let (event, macro_ident) = if let Some(event) = &def.event {
let ident = Ident::new(&format!("__is_event_part_defined_{}", count), event.attr_span);
(event, ident)
} else {
return Default::default()
let macro_ident = Ident::new(
&format!("__is_event_part_defined_{}", count),
def.item.span(),
);
return quote::quote! {
#[doc(hidden)]
pub mod __substrate_event_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #macro_ident {
($pallet_name:ident) => {
compile_error!(concat!(
"`",
stringify!($pallet_name),
"` does not have #[pallet::event] defined, perhaps you should \
remove `Event` from construct_runtime?",
));
}
}
#[doc(hidden)]
pub use #macro_ident as is_event_part_defined;
}
};
};
let event_where_clause = &event.where_clause;
@@ -130,6 +159,18 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {
};
quote::quote_spanned!(event.attr_span =>
#[doc(hidden)]
pub mod __substrate_event_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #macro_ident {
($pallet_name:ident) => {};
}
#[doc(hidden)]
pub use #macro_ident as is_event_part_defined;
}
#deposit_event
impl<#event_impl_gen> From<#event_ident<#event_use_gen>> for () #event_where_clause {
@@ -16,13 +16,45 @@
// limitations under the License.
use crate::pallet::{Def, parse::helper::get_doc_literals};
use crate::COUNTER;
use syn::{Ident, spanned::Spanned};
/// * add various derive trait on GenesisConfig struct.
pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream {
let genesis_config = if let Some(genesis_config) = &def.genesis_config {
genesis_config
let count = COUNTER.with(|counter| counter.borrow_mut().inc());
let (genesis_config, macro_ident) = if let Some(genesis_config) = &def.genesis_config {
let ident = Ident::new(
&format!("__is_genesis_config_defined_{}", count),
genesis_config.genesis_config.span(),
);
(genesis_config, ident)
} else {
return Default::default()
let macro_ident = Ident::new(
&format!("__is_genesis_config_defined_{}", count),
def.item.span(),
);
return quote::quote! {
#[doc(hidden)]
pub mod __substrate_genesis_config_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #macro_ident {
($pallet_name:ident) => {
compile_error!(concat!(
"`",
stringify!($pallet_name),
"` does not have #[pallet::genesis_config] defined, perhaps you should \
remove `Config` from construct_runtime?",
));
}
}
#[doc(hidden)]
pub use #macro_ident as is_genesis_config_defined;
}
};
};
let frame_support = &def.frame_support;
@@ -57,5 +89,17 @@ pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream {
_ => unreachable!("Checked by genesis_config parser"),
}
Default::default()
quote::quote! {
#[doc(hidden)]
pub mod __substrate_genesis_config_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #macro_ident {
($pallet_name:ident) => {};
}
#[doc(hidden)]
pub use #macro_ident as is_genesis_config_defined;
}
}
}
@@ -0,0 +1,56 @@
// This file is part of Substrate.
// Copyright (C) 2021 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 crate::pallet::Def;
use proc_macro2::TokenStream;
use quote::quote;
use crate::COUNTER;
use syn::{Ident, spanned::Spanned};
pub fn expand_inherents(def: &mut Def) -> TokenStream {
let count = COUNTER.with(|counter| counter.borrow_mut().inc());
let macro_ident = Ident::new(&format!("__is_inherent_part_defined_{}", count), def.item.span());
let maybe_compile_error = if def.inherent.is_none() {
quote! {
compile_error!(concat!(
"`",
stringify!($pallet_name),
"` does not have #[pallet::inherent] defined, perhaps you should \
remove `Inherent` from construct_runtime?",
));
}
} else {
TokenStream::new()
};
quote! {
#[doc(hidden)]
pub mod __substrate_inherent_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #macro_ident {
($pallet_name:ident) => {
#maybe_compile_error
}
}
#[doc(hidden)]
pub use #macro_ident as is_inherent_part_defined;
}
}
}
@@ -24,10 +24,13 @@ mod event;
mod storage;
mod hooks;
mod store_trait;
mod inherent;
mod instances;
mod genesis_build;
mod genesis_config;
mod type_value;
mod origin;
mod validate_unsigned;
use crate::pallet::{Def, parse::helper::get_doc_literals};
use quote::ToTokens;
@@ -54,12 +57,15 @@ pub fn expand(mut def: Def) -> proc_macro2::TokenStream {
let error = error::expand_error(&mut def);
let event = event::expand_event(&mut def);
let storages = storage::expand_storages(&mut def);
let inherents = inherent::expand_inherents(&mut def);
let instances = instances::expand_instances(&mut def);
let store_trait = store_trait::expand_store_trait(&mut def);
let hooks = hooks::expand_hooks(&mut def);
let genesis_build = genesis_build::expand_genesis_build(&mut def);
let genesis_config = genesis_config::expand_genesis_config(&mut def);
let type_values = type_value::expand_type_values(&mut def);
let origins = origin::expand_origins(&mut def);
let validate_unsigned = validate_unsigned::expand_validate_unsigned(&mut def);
if get_doc_literals(&def.item.attrs).is_empty() {
def.item.attrs.push(syn::parse_quote!(
@@ -80,12 +86,15 @@ pub fn expand(mut def: Def) -> proc_macro2::TokenStream {
#error
#event
#storages
#inherents
#instances
#store_trait
#hooks
#genesis_build
#genesis_config
#type_values
#origins
#validate_unsigned
);
def.item.content.as_mut().expect("This is checked by parsing").1
@@ -0,0 +1,55 @@
// This file is part of Substrate.
// Copyright (C) 2020-2021 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 crate::{pallet::Def, COUNTER};
use proc_macro2::TokenStream;
use quote::quote;
use syn::{Ident, spanned::Spanned};
pub fn expand_origins(def: &mut Def) -> TokenStream {
let count = COUNTER.with(|counter| counter.borrow_mut().inc());
let macro_ident = Ident::new(&format!("__is_origin_part_defined_{}", count), def.item.span());
let maybe_compile_error = if def.origin.is_none() {
quote! {
compile_error!(concat!(
"`",
stringify!($pallet_name),
"` does not have #[pallet::origin] defined, perhaps you should \
remove `Origin` from construct_runtime?",
));
}
} else {
TokenStream::new()
};
quote! {
#[doc(hidden)]
pub mod __substrate_origin_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #macro_ident {
($pallet_name:ident) => {
#maybe_compile_error
}
}
#[doc(hidden)]
pub use #macro_ident as is_origin_part_defined;
}
}
}
@@ -0,0 +1,56 @@
// This file is part of Substrate.
// Copyright (C) 2020-2021 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 crate::pallet::Def;
use proc_macro2::TokenStream;
use quote::quote;
use crate::COUNTER;
use syn::{Ident, spanned::Spanned};
pub fn expand_validate_unsigned(def: &mut Def) -> TokenStream {
let count = COUNTER.with(|counter| counter.borrow_mut().inc());
let macro_ident = Ident::new(&format!("__is_validate_unsigned_part_defined_{}", count), def.item.span());
let maybe_compile_error = if def.validate_unsigned.is_none() {
quote! {
compile_error!(concat!(
"`",
stringify!($pallet_name),
"` does not have #[pallet::validate_unsigned] defined, perhaps you should \
remove `ValidateUnsigned` from construct_runtime?",
));
}
} else {
TokenStream::new()
};
quote! {
#[doc(hidden)]
pub mod __substrate_validate_unsigned_check {
#[macro_export]
#[doc(hidden)]
macro_rules! #macro_ident {
($pallet_name:ident) => {
#maybe_compile_error
}
}
#[doc(hidden)]
pub use #macro_ident as is_validate_unsigned_part_defined;
}
}
}
+2
View File
@@ -2159,6 +2159,8 @@ macro_rules! decl_module {
<$error_type as $crate::dispatch::ModuleErrorMetadata>::metadata()
}
}
$crate::__generate_dummy_part_checker!();
}
}
+4 -1
View File
@@ -501,9 +501,12 @@ pub fn debug(data: &impl sp_std::fmt::Debug) {
#[doc(inline)]
pub use frame_support_procedural::{
decl_storage, construct_runtime, transactional, RuntimeDebugNoBound
decl_storage, construct_runtime, transactional, RuntimeDebugNoBound,
};
#[doc(hidden)]
pub use frame_support_procedural::__generate_dummy_part_checker;
/// Derive [`Clone`] but do not bound any generic.
///
/// This is useful for type generic over runtime:
@@ -172,6 +172,22 @@ pub mod module3 {
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
Err(Error::<T>::Something.into())
}
#[weight = 0]
pub fn aux_1(_origin, #[compact] _data: u32) -> frame_support::dispatch::DispatchResult {
unreachable!()
}
#[weight = 0]
pub fn aux_2(_origin, _data: i32, #[compact] _data2: u32) -> frame_support::dispatch::DispatchResult {
unreachable!()
}
#[weight = 0]
fn aux_3(_origin, _data: i32, _data2: String) -> frame_support::dispatch::DispatchResult {
unreachable!()
}
#[weight = 3]
fn aux_4(_origin) -> frame_support::dispatch::DispatchResult { unreachable!() }
#[weight = (5, frame_support::weights::DispatchClass::Operational)]
fn operational(_origin) { unreachable!() }
}
}
@@ -465,6 +481,100 @@ fn call_codec() {
assert_eq!(Call::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(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(1, 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(32, "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::{DispatchInfo, GetDispatchInfo},
weights::{DispatchClass, Pays},
};
// operational.
assert_eq!(
module3::Call::<Runtime>::operational().get_dispatch_info(),
DispatchInfo { weight: 5, class: DispatchClass::Operational, pays_fee: Pays::Yes },
);
// custom basic
assert_eq!(
module3::Call::<Runtime>::aux_4().get_dispatch_info(),
DispatchInfo { weight: 3, class: DispatchClass::Normal, pays_fee: Pays::Yes },
);
}
#[test]
fn call_name() {
use frame_support::dispatch::GetCallName;
let name = module3::Call::<Runtime>::aux_4().get_call_name();
assert_eq!("aux_4", name);
}
#[test]
fn call_metadata() {
use frame_support::dispatch::{CallMetadata, GetCallMetadata};
let call = Call::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::dispatch::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::dispatch::GetCallMetadata;
let module_names = Call::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 = Call::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 = Call::from(subcall.unwrap().clone());
assert_eq!(from, call);
}
#[test]
fn test_metadata() {
use frame_metadata::*;
@@ -601,6 +711,54 @@ fn test_metadata() {
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
name: DecodeDifferent::Encode("aux_1"),
arguments: DecodeDifferent::Encode(&[
FunctionArgumentMetadata {
name: DecodeDifferent::Encode("_data"),
ty: DecodeDifferent::Encode("Compact<u32>"),
},
]),
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
name: DecodeDifferent::Encode("aux_2"),
arguments: DecodeDifferent::Encode(&[
FunctionArgumentMetadata {
name: DecodeDifferent::Encode("_data"),
ty: DecodeDifferent::Encode("i32"),
},
FunctionArgumentMetadata {
name: DecodeDifferent::Encode("_data2"),
ty: DecodeDifferent::Encode("Compact<u32>"),
},
]),
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
name: DecodeDifferent::Encode("aux_3"),
arguments: DecodeDifferent::Encode(&[
FunctionArgumentMetadata {
name: DecodeDifferent::Encode("_data"),
ty: DecodeDifferent::Encode("i32"),
},
FunctionArgumentMetadata {
name: DecodeDifferent::Encode("_data2"),
ty: DecodeDifferent::Encode("String"),
},
]),
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
name: DecodeDifferent::Encode("aux_4"),
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[]),
},
FunctionMetadata {
name: DecodeDifferent::Encode("operational"),
arguments: DecodeDifferent::Encode(&[]),
documentation: DecodeDifferent::Encode(&[]),
},
]))),
event: Some(DecodeDifferent::Encode(FnEncode(|| &[
EventMetadata {
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, Call},
}
}
fn main() {}
@@ -0,0 +1,49 @@
error: `Pallet` does not have #[pallet::call] defined, perhaps you should remove `Call` from construct_runtime?
--> $DIR/undefined_call_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_call_part.rs:28:11
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_call_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_call_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, Event},
}
}
fn main() {}
@@ -0,0 +1,101 @@
error: `Pallet` does not have #[pallet::event] defined, perhaps you should remove `Event` from construct_runtime?
--> $DIR/undefined_event_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_event_part.rs:28:11
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: could not find `Event` in `pallet`
--> $DIR/undefined_event_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ could not find `Event` in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0412]: cannot find type `Event` in module `pallet`
--> $DIR/undefined_event_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::Event;
|
error[E0412]: cannot find type `Event` in module `pallet`
--> $DIR/undefined_event_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
|
1 | use crate::Event;
|
1 | use frame_system::Event;
|
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_event_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_event_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, Config},
}
}
fn main() {}
@@ -0,0 +1,67 @@
error: `Pallet` does not have #[pallet::genesis_config] defined, perhaps you should remove `Config` from construct_runtime?
--> $DIR/undefined_genesis_config_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_genesis_config_part.rs:28:17
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_genesis_config_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0412]: cannot find type `GenesisConfig` in module `pallet`
--> $DIR/undefined_genesis_config_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
|
1 | use frame_system::GenesisConfig;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_genesis_config_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, Inherent},
}
}
fn main() {}
@@ -0,0 +1,49 @@
error: `Pallet` does not have #[pallet::inherent] defined, perhaps you should remove `Inherent` from construct_runtime?
--> $DIR/undefined_inherent_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_inherent_part.rs:28:11
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_inherent_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_inherent_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, Origin},
}
}
fn main() {}
@@ -0,0 +1,87 @@
error: `Pallet` does not have #[pallet::origin] defined, perhaps you should remove `Origin` from construct_runtime?
--> $DIR/undefined_origin_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_origin_part.rs:28:11
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_origin_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0412]: cannot find type `Origin` in module `pallet`
--> $DIR/undefined_origin_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this type alias
|
1 | use frame_system::Origin;
|
error[E0412]: cannot find type `Origin` in module `pallet`
--> $DIR/undefined_origin_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `pallet`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
|
1 | use crate::Origin;
|
1 | use frame_system::Origin;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_origin_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`
@@ -0,0 +1,33 @@
use frame_support::construct_runtime;
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_core::sr25519;
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
}
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, Call, Signature, ()>;
impl pallet::Config for Runtime {}
construct_runtime! {
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Call, Storage, Config, Event<T>},
Pallet: pallet::{Pallet, ValidateUnsigned},
}
}
fn main() {}
@@ -0,0 +1,49 @@
error: `Pallet` does not have #[pallet::validate_unsigned] defined, perhaps you should remove `ValidateUnsigned` from construct_runtime?
--> $DIR/undefined_validate_unsigned_part.rs:5:1
|
5 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
...
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_validate_unsigned_part.rs:28:11
|
28 | System: system::{Pallet, Call, Storage, Config, Event<T>},
| ^^^^^^ use of undeclared crate or module `system`
error[E0433]: failed to resolve: use of undeclared crate or module `system`
--> $DIR/undefined_validate_unsigned_part.rs:22:1
|
22 | / construct_runtime! {
23 | | pub enum Runtime where
24 | | Block = Block,
25 | | NodeBlock = Block,
... |
30 | | }
31 | | }
| |_^ not found in `system`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
1 | use frame_system::RawOrigin;
|
error[E0277]: the trait bound `Runtime: frame_system::Config` is not satisfied
--> $DIR/undefined_validate_unsigned_part.rs:20:6
|
8 | pub trait Config: frame_system::Config {}
| -------------------- required by this bound in `pallet::Config`
...
20 | impl pallet::Config for Runtime {}
| ^^^^^^^^^^^^^^ the trait `frame_system::Config` is not implemented for `Runtime`
+175 -5
View File
@@ -304,10 +304,13 @@ pub mod pallet {
type Call = Call<T>;
fn validate_unsigned(
_source: TransactionSource,
_call: &Self::Call
call: &Self::Call
) -> TransactionValidity {
T::AccountId::from(SomeType1); // Test for where clause
T::AccountId::from(SomeType5); // Test for where clause
if matches!(call, Call::foo_transactional(_)) {
return Ok(ValidTransaction::default());
}
Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
}
}
@@ -324,22 +327,40 @@ pub mod pallet {
fn create_inherent(_data: &InherentData) -> Option<Self::Call> {
T::AccountId::from(SomeType1); // Test for where clause
T::AccountId::from(SomeType6); // Test for where clause
unimplemented!();
Some(Call::foo_no_post_info())
}
fn is_inherent(_call: &Self::Call) -> bool {
unimplemented!();
fn is_inherent(call: &Self::Call) -> bool {
matches!(call, Call::foo_no_post_info() | Call::foo(..))
}
fn check_inherent(call: &Self::Call, _: &InherentData) -> Result<(), Self::Error> {
match call {
Call::foo_no_post_info() => Ok(()),
Call::foo(0, 0) => Err(InherentError::Fatal),
Call::foo(..) => Ok(()),
_ => unreachable!("other calls are not inherents"),
}
}
fn is_inherent_required(d: &InherentData) -> Result<Option<Self::Error>, Self::Error> {
match d.get_data::<bool>(b"required") {
Ok(Some(true)) => Ok(Some(InherentError::Fatal)),
Ok(Some(false)) | Ok(None) => Ok(None),
Err(_) => unreachable!("should not happen in tests"),
}
}
}
#[derive(codec::Encode, sp_runtime::RuntimeDebug)]
#[cfg_attr(feature = "std", derive(codec::Decode))]
pub enum InherentError {
Fatal,
}
impl frame_support::inherent::IsFatalError for InherentError {
fn is_fatal_error(&self) -> bool {
unimplemented!();
matches!(self, InherentError::Fatal)
}
}
@@ -538,6 +559,155 @@ fn instance_expand() {
let _: pallet::__InherentHiddenInstance = ();
}
#[test]
fn inherent_expand() {
use frame_support::{
inherent::{BlockT, InherentData},
traits::EnsureInherentsAreFirst,
};
use sp_core::Hasher;
use sp_runtime::{traits::{BlakeTwo256, Header}, Digest};
let inherents = InherentData::new().create_extrinsics();
let expected = vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: None },
];
assert_eq!(expected, inherents);
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(1, 0)), signature: None },
],
);
assert!(InherentData::new().check_extrinsics(&block).ok());
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(0, 0)), signature: None },
],
);
assert!(InherentData::new().check_extrinsics(&block).fatal_error());
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_transactional(0)), signature: None },
],
);
let mut inherent = InherentData::new();
inherent.put_data(*b"required", &true).unwrap();
assert!(inherent.check_extrinsics(&block).fatal_error());
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: Some((1, (), ())) },
],
);
let mut inherent = InherentData::new();
inherent.put_data(*b"required", &true).unwrap();
assert!(inherent.check_extrinsics(&block).fatal_error());
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(1, 1)), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_transactional(0)), signature: None },
],
);
assert!(Runtime::ensure_inherents_are_first(&block).is_ok());
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(1, 1)), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_transactional(0)), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: None },
],
);
assert_eq!(Runtime::ensure_inherents_are_first(&block).err().unwrap(), 2);
let block = Block::new(
Header::new(
1,
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
BlakeTwo256::hash(b"test"),
Digest::default(),
),
vec![
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(1, 1)), signature: None },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo(1, 0)), signature: Some((1, (), ())) },
UncheckedExtrinsic { function: Call::Example(pallet::Call::foo_no_post_info()), signature: None },
],
);
assert_eq!(Runtime::ensure_inherents_are_first(&block).err().unwrap(), 2);
}
#[test]
fn validate_unsigned_expand() {
use frame_support::pallet_prelude::{
InvalidTransaction, TransactionSource, TransactionValidityError, ValidTransaction, ValidateUnsigned,
};
let call = pallet::Call::<Runtime>::foo_no_post_info();
let validity = pallet::Pallet::validate_unsigned(TransactionSource::Local, &call).unwrap_err();
assert_eq!(validity, TransactionValidityError::Invalid(InvalidTransaction::Call));
let call = pallet::Call::<Runtime>::foo_transactional(0);
let validity = pallet::Pallet::validate_unsigned(TransactionSource::External, &call).unwrap();
assert_eq!(validity, ValidTransaction::default());
}
#[test]
fn trait_store_expand() {
TestExternalities::default().execute_with(|| {
@@ -306,8 +306,8 @@ frame_support::construct_runtime!(
Instance1Example: pallet::<Instance1>::{
Pallet, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned
},
Example2: pallet2::{Pallet, Call, Event<T>, Config<T>, Storage},
Instance1Example2: pallet2::<Instance1>::{Pallet, Call, Event<T>, Config<T>, Storage},
Example2: pallet2::{Pallet, Event<T>, Config<T>, Storage},
Instance1Example2: pallet2::<Instance1>::{Pallet, Event<T>, Config<T>, Storage},
}
);
@@ -1,27 +1,28 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, StorageNMap, Twox64Concat, NMapKey};
use frame_system::pallet_prelude::BlockNumberFor;
// #[frame_support::pallet]
// mod pallet {
// use frame_support::pallet_prelude::{Hooks, StorageNMap, Twox64Concat, NMapKey};
// use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
// #[pallet::config]
// pub trait Config: frame_system::Config {}
#[pallet::pallet]
#[pallet::generate_storage_info]
pub struct Pallet<T>(core::marker::PhantomData<T>);
// #[pallet::pallet]
// #[pallet::generate_storage_info]
// pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
// #[pallet::hooks]
// impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
// #[pallet::call]
// impl<T: Config> Pallet<T> {}
#[derive(codec::Encode, codec::Decode)]
struct Bar;
// #[derive(codec::Encode, codec::Decode)]
// struct Bar;
#[pallet::storage]
type Foo<T> = StorageNMap<_, NMapKey<Twox64Concat, Bar>, u32>;
}
// #[pallet::storage]
// type Foo<T> = StorageNMap<_, NMapKey<Twox64Concat, Bar>, u32>;
// }
fn main() {
compile_error!("Temporarily disabled due to test flakiness");
}
@@ -1,9 +1,5 @@
error[E0277]: the trait bound `Bar: MaxEncodedLen` is not satisfied
--> $DIR/storage_info_unsatisfied_nmap.rs:10:12
error: Temporarily disabled due to test flakiness
--> $DIR/storage_info_unsatisfied_nmap.rs:27:2
|
10 | #[pallet::generate_storage_info]
| ^^^^^^^^^^^^^^^^^^^^^ the trait `MaxEncodedLen` is not implemented for `Bar`
|
= note: required because of the requirements on the impl of `KeyGeneratorMaxEncodedLen` for `NMapKey<frame_support::Twox64Concat, Bar>`
= note: required because of the requirements on the impl of `StorageInfoTrait` for `frame_support::pallet_prelude::StorageNMap<_GeneratedPrefixForStorageFoo<T>, NMapKey<frame_support::Twox64Concat, Bar>, u32>`
= note: required by `storage_info`
27 | compile_error!("Temporarily disabled due to test flakiness");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^