Add pallet attribute macro to declare pallets (#6877)

* rename system Config to system Trait.

command used:
```
find frame/ bin/ test-utils/ utils/ -name *.rs -exec sed -i 's/system::Trait>::/system::Config>::/g' {} \;
find frame/ bin/ test-utils/ utils/ -name *.rs -exec sed -i 's/impl frame_system::Trait for /impl frame_system::Config for /g' {} \;
find frame/ bin/ test-utils/ utils/ -name *.rs -exec sed -i 's/impl system::Trait for /impl system::Config for /g' {} \;
```
plus some manual ones especially for frame-support tests and frame-system

* make construct_runtime handle Pallet and Module

pallets can now be implemented on struct named Pallet or Module, both
definition are valid.
This is because next macro will generate only Pallet placeholder.

* introduce pallet attribute macro

currently just with tests, frame_system and other example hasn't been
upgraded

* allow to print some upgrade helper from decl_storage

* Improved error msg, typo.

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Improved error msg, typo.

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Improved error message on unexpected attributes + ui test

* add test for transactional

* various typo

* some tips when spans are lost

* allow pallet to depend on other pallet instances

* make event type metadata consistent with call and constant

* error messages

* ignore doc example

* fix pallet upgrade template

* fixup

* fix doc

* fix indentation

* Apply suggestions code formatting

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* some renames + fix compilation

* remove unsupported genesis config type alias

* merge fixup

* fix ui tests

* additional doc

* implement StorageInstance with new syntax

* fix line width

* fix doc: because pallet doc goes below reexport doc

* Update frame/support/procedural/src/pallet/parse/event.rs

Co-authored-by: Andrew Jones <ascjones@gmail.com>

* Update frame/system/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

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

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* improve doc as suggested

* revert construct_runtime Pallet part.

This revert the changes on construct_runtime. Now construct_runtime is
unchanged and instead pallet macro create a type alias
`type Module<..> = Pallet<..>` to be used by construct_runtime

* refactor with less intricated code

* fix ui test with new image

* fix ui tests

* add minor tests

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Guillaume Thiolliere
2020-12-24 12:33:40 +01:00
committed by GitHub
parent 8e3d8a6a09
commit 6dfad0921b
131 changed files with 9610 additions and 31 deletions
@@ -0,0 +1,764 @@
// This file is part of Substrate.
// Copyright (C) 2020 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::{
weights::{DispatchInfo, DispatchClass, Pays, GetDispatchInfo},
traits::{
GetCallName, OnInitialize, OnFinalize, OnRuntimeUpgrade, GetPalletVersion, OnGenesis,
},
dispatch::{UnfilteredDispatchable, Parameter},
storage::unhashed,
};
use sp_runtime::{traits::Block as _, DispatchError};
use sp_io::{TestExternalities, hashing::{twox_64, twox_128, blake2_128}};
pub struct SomeType1;
impl From<SomeType1> for u64 { fn from(_t: SomeType1) -> Self { 0u64 } }
pub struct SomeType2;
impl From<SomeType2> for u64 { fn from(_t: SomeType2) -> Self { 100u64 } }
pub struct SomeType3;
impl From<SomeType3> for u64 { fn from(_t: SomeType3) -> Self { 0u64 } }
pub struct SomeType4;
impl From<SomeType4> for u64 { fn from(_t: SomeType4) -> Self { 0u64 } }
pub struct SomeType5;
impl From<SomeType5> for u64 { fn from(_t: SomeType5) -> Self { 0u64 } }
pub struct SomeType6;
impl From<SomeType6> for u64 { fn from(_t: SomeType6) -> Self { 0u64 } }
pub struct SomeType7;
impl From<SomeType7> for u64 { fn from(_t: SomeType7) -> Self { 0u64 } }
pub trait SomeAssociation1 { type _1: Parameter; }
impl SomeAssociation1 for u64 { type _1 = u64; }
pub trait SomeAssociation2 { type _2: Parameter; }
impl SomeAssociation2 for u64 { type _2 = u64; }
#[frame_support::pallet]
pub mod pallet {
use super::{
SomeType1, SomeType2, SomeType3, SomeType4, SomeType5, SomeType6, SomeType7,
SomeAssociation1, SomeAssociation2,
};
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
type BalanceOf<T> = <T as Config>::Balance;
#[pallet::config]
pub trait Config: frame_system::Config
where <Self as frame_system::Config>::AccountId: From<SomeType1> + SomeAssociation1,
{
/// Some comment
/// Some comment
#[pallet::constant]
type MyGetParam: Get<u32>;
/// Some comment
/// Some comment
#[pallet::constant]
type MyGetParam2: Get<u32>;
#[pallet::constant]
type MyGetParam3: Get<<Self::AccountId as SomeAssociation1>::_1>;
type Balance: Parameter + Default;
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
}
#[pallet::extra_constants]
impl<T: Config> Pallet<T>
where T::AccountId: From<SomeType1> + SomeAssociation1 + From<SomeType2>,
{
/// Some doc
/// Some doc
fn some_extra() -> T::AccountId { SomeType2.into() }
/// Some doc
fn some_extra_extra() -> T::AccountId { SomeType1.into() }
}
#[pallet::pallet]
#[pallet::generate_store(pub(crate) trait Store)]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
where T::AccountId: From<SomeType2> + From<SomeType1> + SomeAssociation1,
{
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
T::AccountId::from(SomeType1); // Test for where clause
T::AccountId::from(SomeType2); // Test for where clause
Self::deposit_event(Event::Something(10));
10
}
fn on_finalize(_: BlockNumberFor<T>) {
T::AccountId::from(SomeType1); // Test for where clause
T::AccountId::from(SomeType2); // Test for where clause
Self::deposit_event(Event::Something(20));
}
fn on_runtime_upgrade() -> Weight {
T::AccountId::from(SomeType1); // Test for where clause
T::AccountId::from(SomeType2); // Test for where clause
Self::deposit_event(Event::Something(30));
30
}
fn integrity_test() {
T::AccountId::from(SomeType1); // Test for where clause
T::AccountId::from(SomeType2); // Test for where clause
}
}
#[pallet::call]
impl<T: Config> Pallet<T>
where T::AccountId: From<SomeType1> + From<SomeType3> + SomeAssociation1
{
/// Doc comment put in metadata
#[pallet::weight(Weight::from(*_foo))]
fn foo(
origin: OriginFor<T>,
#[pallet::compact] _foo: u32,
_bar: u32,
) -> DispatchResultWithPostInfo {
T::AccountId::from(SomeType1); // Test for where clause
T::AccountId::from(SomeType3); // Test for where clause
let _ = origin;
Self::deposit_event(Event::Something(3));
Ok(().into())
}
/// Doc comment put in metadata
#[pallet::weight(1)]
#[frame_support::transactional]
fn foo_transactional(
_origin: OriginFor<T>,
#[pallet::compact] foo: u32,
) -> DispatchResultWithPostInfo {
Self::deposit_event(Event::Something(0));
if foo != 0 {
Ok(().into())
} else {
Err(Error::<T>::InsufficientProposersBalance.into())
}
}
}
#[pallet::error]
pub enum Error<T> {
/// doc comment put into metadata
InsufficientProposersBalance,
}
#[pallet::event]
#[pallet::metadata(BalanceOf<T> = "Balance", u32 = "Other")]
#[pallet::generate_deposit(fn deposit_event)]
pub enum Event<T: Config> where T::AccountId: SomeAssociation1 + From<SomeType1>{
/// doc comment put in metadata
Proposed(<T as frame_system::Config>::AccountId),
/// doc
Spending(BalanceOf<T>),
Something(u32),
SomethingElse(<T::AccountId as SomeAssociation1>::_1),
}
#[pallet::storage]
pub type ValueWhereClause<T: Config> where T::AccountId: SomeAssociation2 =
StorageValue<_, <T::AccountId as SomeAssociation2>::_2>;
#[pallet::storage]
pub type Value<T> = StorageValue<_, u32>;
#[pallet::type_value]
pub fn MyDefault<T: Config>() -> u16
where T::AccountId: From<SomeType7> + From<SomeType1> + SomeAssociation1
{
T::AccountId::from(SomeType7); // Test where clause works
4u16
}
#[pallet::storage]
pub type Map<T: Config> where T::AccountId: From<SomeType7> =
StorageMap<_, Blake2_128Concat, u8, u16, ValueQuery, MyDefault<T>>;
#[pallet::storage]
pub type Map2<T> = StorageMap<_, Twox64Concat, u16, u32>;
#[pallet::storage]
pub type DoubleMap<T> = StorageDoubleMap<_, Blake2_128Concat, u8, Twox64Concat, u16, u32>;
#[pallet::storage]
pub type DoubleMap2<T> = StorageDoubleMap<_, Twox64Concat, u16, Blake2_128Concat, u32, u64>;
#[pallet::genesis_config]
#[derive(Default)]
pub struct GenesisConfig {
_myfield: u32,
}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig
where T::AccountId: From<SomeType1> + SomeAssociation1 + From<SomeType4>
{
fn build(&self) {
T::AccountId::from(SomeType1); // Test for where clause
T::AccountId::from(SomeType4); // Test for where clause
}
}
#[pallet::origin]
#[derive(EqNoBound, RuntimeDebugNoBound, CloneNoBound, PartialEqNoBound, Encode, Decode)]
pub struct Origin<T>(PhantomData<T>);
#[pallet::validate_unsigned]
impl<T: Config> ValidateUnsigned for Pallet<T>
where T::AccountId: From<SomeType1> + SomeAssociation1 + From<SomeType5> + From<SomeType3>
{
type Call = Call<T>;
fn validate_unsigned(
_source: TransactionSource,
_call: &Self::Call
) -> TransactionValidity {
T::AccountId::from(SomeType1); // Test for where clause
T::AccountId::from(SomeType5); // Test for where clause
Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
}
}
#[pallet::inherent]
impl<T: Config> ProvideInherent for Pallet<T>
where T::AccountId: From<SomeType1> + SomeAssociation1 + From<SomeType6> + From<SomeType3>
{
type Call = Call<T>;
type Error = InherentError;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
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!();
}
}
#[derive(codec::Encode, sp_runtime::RuntimeDebug)]
#[cfg_attr(feature = "std", derive(codec::Decode))]
pub enum InherentError {
}
impl sp_inherents::IsFatalError for InherentError {
fn is_fatal_error(&self) -> bool {
unimplemented!();
}
}
pub const INHERENT_IDENTIFIER: sp_inherents::InherentIdentifier = *b"testpall";
}
// Test that a pallet with non generic event and generic genesis_config is correctly handled
#[frame_support::pallet]
pub mod pallet2 {
use super::{SomeType1, SomeAssociation1};
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config: frame_system::Config
where <Self as frame_system::Config>::AccountId: From<SomeType1> + SomeAssociation1,
{
type Event: From<Event> + IsType<<Self as frame_system::Config>::Event>;
}
#[pallet::pallet]
#[pallet::generate_store(pub(crate) trait Store)]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
where T::AccountId: From<SomeType1> + SomeAssociation1,
{
}
#[pallet::call]
impl<T: Config> Pallet<T>
where T::AccountId: From<SomeType1> + SomeAssociation1,
{
}
#[pallet::event]
pub enum Event {
/// Something
Something(u32),
}
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config>
where T::AccountId: From<SomeType1> + SomeAssociation1,
{
phantom: PhantomData<T>,
}
impl<T: Config> Default for GenesisConfig<T>
where T::AccountId: From<SomeType1> + SomeAssociation1,
{
fn default() -> Self {
GenesisConfig {
phantom: Default::default(),
}
}
}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T>
where T::AccountId: From<SomeType1> + SomeAssociation1,
{
fn build(&self) {}
}
}
frame_support::parameter_types!(
pub const MyGetParam: u32= 10;
pub const MyGetParam2: u32= 11;
pub const MyGetParam3: u32= 12;
pub const BlockHashCount: u32 = 250;
);
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u32;
type Call = Call;
type Hash = sp_runtime::testing::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl pallet::Config for Runtime {
type Event = Event;
type MyGetParam = MyGetParam;
type MyGetParam2 = MyGetParam2;
type MyGetParam3 = MyGetParam3;
type Balance = u64;
}
impl pallet2::Config for Runtime {
type Event = Event;
}
pub type Header = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>;
frame_support::construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Event<T>},
Example: pallet::{Module, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned},
Example2: pallet2::{Module, Call, Event, Config<T>, Storage},
}
);
#[test]
fn transactional_works() {
TestExternalities::default().execute_with(|| {
frame_system::Pallet::<Runtime>::set_block_number(1);
pallet::Call::<Runtime>::foo_transactional(0).dispatch_bypass_filter(None.into())
.err().unwrap();
assert!(frame_system::Pallet::<Runtime>::events().is_empty());
pallet::Call::<Runtime>::foo_transactional(1).dispatch_bypass_filter(None.into()).unwrap();
assert_eq!(
frame_system::Pallet::<Runtime>::events().iter().map(|e| &e.event).collect::<Vec<_>>(),
vec![&Event::pallet(pallet::Event::Something(0))],
);
})
}
#[test]
fn call_expand() {
let call_foo = pallet::Call::<Runtime>::foo(3, 0);
assert_eq!(
call_foo.get_dispatch_info(),
DispatchInfo {
weight: 3,
class: DispatchClass::Normal,
pays_fee: Pays::Yes,
}
);
assert_eq!(call_foo.get_call_name(), "foo");
assert_eq!(
pallet::Call::<Runtime>::get_call_names(),
&["foo", "foo_transactional"],
);
}
#[test]
fn error_expand() {
assert_eq!(
format!("{:?}", pallet::Error::<Runtime>::InsufficientProposersBalance),
String::from("InsufficientProposersBalance"),
);
assert_eq!(
<&'static str>::from(pallet::Error::<Runtime>::InsufficientProposersBalance),
"InsufficientProposersBalance",
);
assert_eq!(
DispatchError::from(pallet::Error::<Runtime>::InsufficientProposersBalance),
DispatchError::Module {
index: 1,
error: 0,
message: Some("InsufficientProposersBalance"),
},
);
}
#[test]
fn instance_expand() {
// Assert same type.
let _: pallet::__InherentHiddenInstance = ();
}
#[test]
fn pallet_expand_deposit_event() {
TestExternalities::default().execute_with(|| {
frame_system::Pallet::<Runtime>::set_block_number(1);
pallet::Call::<Runtime>::foo(3, 0).dispatch_bypass_filter(None.into()).unwrap();
assert_eq!(
frame_system::Pallet::<Runtime>::events()[0].event,
Event::pallet(pallet::Event::Something(3)),
);
})
}
#[test]
fn storage_expand() {
use frame_support::pallet_prelude::*;
use frame_support::StoragePrefixedMap;
fn twox_64_concat(d: &[u8]) -> Vec<u8> {
let mut v = twox_64(d).to_vec();
v.extend_from_slice(d);
v
}
fn blake2_128_concat(d: &[u8]) -> Vec<u8> {
let mut v = blake2_128(d).to_vec();
v.extend_from_slice(d);
v
}
TestExternalities::default().execute_with(|| {
pallet::Value::<Runtime>::put(1);
let k = [twox_128(b"Example"), twox_128(b"Value")].concat();
assert_eq!(unhashed::get::<u32>(&k), Some(1u32));
pallet::Map::<Runtime>::insert(1, 2);
let mut k = [twox_128(b"Example"), twox_128(b"Map")].concat();
k.extend(1u8.using_encoded(blake2_128_concat));
assert_eq!(unhashed::get::<u16>(&k), Some(2u16));
assert_eq!(&k[..32], &<pallet::Map<Runtime>>::final_prefix());
pallet::Map2::<Runtime>::insert(1, 2);
let mut k = [twox_128(b"Example"), twox_128(b"Map2")].concat();
k.extend(1u16.using_encoded(twox_64_concat));
assert_eq!(unhashed::get::<u32>(&k), Some(2u32));
assert_eq!(&k[..32], &<pallet::Map2<Runtime>>::final_prefix());
pallet::DoubleMap::<Runtime>::insert(&1, &2, &3);
let mut k = [twox_128(b"Example"), twox_128(b"DoubleMap")].concat();
k.extend(1u8.using_encoded(blake2_128_concat));
k.extend(2u16.using_encoded(twox_64_concat));
assert_eq!(unhashed::get::<u32>(&k), Some(3u32));
assert_eq!(&k[..32], &<pallet::DoubleMap<Runtime>>::final_prefix());
pallet::DoubleMap2::<Runtime>::insert(&1, &2, &3);
let mut k = [twox_128(b"Example"), twox_128(b"DoubleMap2")].concat();
k.extend(1u16.using_encoded(twox_64_concat));
k.extend(2u32.using_encoded(blake2_128_concat));
assert_eq!(unhashed::get::<u64>(&k), Some(3u64));
assert_eq!(&k[..32], &<pallet::DoubleMap2<Runtime>>::final_prefix());
})
}
#[test]
fn pallet_hooks_expand() {
TestExternalities::default().execute_with(|| {
frame_system::Pallet::<Runtime>::set_block_number(1);
assert_eq!(AllModules::on_initialize(1), 10);
AllModules::on_finalize(1);
assert_eq!(pallet::Pallet::<Runtime>::storage_version(), None);
assert_eq!(AllModules::on_runtime_upgrade(), 30);
assert_eq!(
pallet::Pallet::<Runtime>::storage_version(),
Some(pallet::Pallet::<Runtime>::current_version()),
);
assert_eq!(
frame_system::Pallet::<Runtime>::events()[0].event,
Event::pallet(pallet::Event::Something(10)),
);
assert_eq!(
frame_system::Pallet::<Runtime>::events()[1].event,
Event::pallet(pallet::Event::Something(20)),
);
assert_eq!(
frame_system::Pallet::<Runtime>::events()[2].event,
Event::pallet(pallet::Event::Something(30)),
);
})
}
#[test]
fn pallet_on_genesis() {
TestExternalities::default().execute_with(|| {
assert_eq!(pallet::Pallet::<Runtime>::storage_version(), None);
pallet::Pallet::<Runtime>::on_genesis();
assert_eq!(
pallet::Pallet::<Runtime>::storage_version(),
Some(pallet::Pallet::<Runtime>::current_version()),
);
})
}
#[test]
fn metadata() {
use frame_metadata::*;
use codec::{Decode, Encode};
let expected_pallet_metadata = ModuleMetadata {
index: 1,
name: DecodeDifferent::Decoded("Example".to_string()),
storage: Some(DecodeDifferent::Decoded(StorageMetadata {
prefix: DecodeDifferent::Decoded("Example".to_string()),
entries: DecodeDifferent::Decoded(vec![
StorageEntryMetadata {
name: DecodeDifferent::Decoded("ValueWhereClause".to_string()),
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::Plain(
DecodeDifferent::Decoded(
"<T::AccountId as SomeAssociation2>::_2".to_string()
),
),
default: DecodeDifferent::Decoded(vec![0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
StorageEntryMetadata {
name: DecodeDifferent::Decoded("Value".to_string()),
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::Plain(DecodeDifferent::Decoded("u32".to_string())),
default: DecodeDifferent::Decoded(vec![0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
StorageEntryMetadata {
name: DecodeDifferent::Decoded("Map".to_string()),
modifier: StorageEntryModifier::Default,
ty: StorageEntryType::Map {
key: DecodeDifferent::Decoded("u8".to_string()),
value: DecodeDifferent::Decoded("u16".to_string()),
hasher: StorageHasher::Blake2_128Concat,
unused: false,
},
default: DecodeDifferent::Decoded(vec![4, 0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
StorageEntryMetadata {
name: DecodeDifferent::Decoded("Map2".to_string()),
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::Map {
key: DecodeDifferent::Decoded("u16".to_string()),
value: DecodeDifferent::Decoded("u32".to_string()),
hasher: StorageHasher::Twox64Concat,
unused: false,
},
default: DecodeDifferent::Decoded(vec![0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
StorageEntryMetadata {
name: DecodeDifferent::Decoded("DoubleMap".to_string()),
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::DoubleMap {
value: DecodeDifferent::Decoded("u32".to_string()),
key1: DecodeDifferent::Decoded("u8".to_string()),
key2: DecodeDifferent::Decoded("u16".to_string()),
hasher: StorageHasher::Blake2_128Concat,
key2_hasher: StorageHasher::Twox64Concat,
},
default: DecodeDifferent::Decoded(vec![0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
StorageEntryMetadata {
name: DecodeDifferent::Decoded("DoubleMap2".to_string()),
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::DoubleMap {
value: DecodeDifferent::Decoded("u64".to_string()),
key1: DecodeDifferent::Decoded("u16".to_string()),
key2: DecodeDifferent::Decoded("u32".to_string()),
hasher: StorageHasher::Twox64Concat,
key2_hasher: StorageHasher::Blake2_128Concat,
},
default: DecodeDifferent::Decoded(vec![0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
]),
})),
calls: Some(DecodeDifferent::Decoded(vec![
FunctionMetadata {
name: DecodeDifferent::Decoded("foo".to_string()),
arguments: DecodeDifferent::Decoded(vec![
FunctionArgumentMetadata {
name: DecodeDifferent::Decoded("_foo".to_string()),
ty: DecodeDifferent::Decoded("Compact<u32>".to_string()),
},
FunctionArgumentMetadata {
name: DecodeDifferent::Decoded("_bar".to_string()),
ty: DecodeDifferent::Decoded("u32".to_string()),
}
]),
documentation: DecodeDifferent::Decoded(vec![
" Doc comment put in metadata".to_string(),
]),
},
FunctionMetadata {
name: DecodeDifferent::Decoded("foo_transactional".to_string()),
arguments: DecodeDifferent::Decoded(vec![
FunctionArgumentMetadata {
name: DecodeDifferent::Decoded("foo".to_string()),
ty: DecodeDifferent::Decoded("Compact<u32>".to_string()),
}
]),
documentation: DecodeDifferent::Decoded(vec![
" Doc comment put in metadata".to_string(),
]),
},
])),
event: Some(DecodeDifferent::Decoded(vec![
EventMetadata {
name: DecodeDifferent::Decoded("Proposed".to_string()),
arguments: DecodeDifferent::Decoded(vec!["<T as frame_system::Config>::AccountId".to_string()]),
documentation: DecodeDifferent::Decoded(vec![
" doc comment put in metadata".to_string()
]),
},
EventMetadata {
name: DecodeDifferent::Decoded("Spending".to_string()),
arguments: DecodeDifferent::Decoded(vec!["Balance".to_string()]),
documentation: DecodeDifferent::Decoded(vec![
" doc".to_string()
]),
},
EventMetadata {
name: DecodeDifferent::Decoded("Something".to_string()),
arguments: DecodeDifferent::Decoded(vec!["Other".to_string()]),
documentation: DecodeDifferent::Decoded(vec![]),
},
EventMetadata {
name: DecodeDifferent::Decoded("SomethingElse".to_string()),
arguments: DecodeDifferent::Decoded(vec!["<T::AccountId as SomeAssociation1>::_1".to_string()]),
documentation: DecodeDifferent::Decoded(vec![]),
},
])),
constants: DecodeDifferent::Decoded(vec![
ModuleConstantMetadata {
name: DecodeDifferent::Decoded("MyGetParam".to_string()),
ty: DecodeDifferent::Decoded("u32".to_string()),
value: DecodeDifferent::Decoded(vec![10, 0, 0, 0]),
documentation: DecodeDifferent::Decoded(vec![
" Some comment".to_string(),
" Some comment".to_string(),
]),
},
ModuleConstantMetadata {
name: DecodeDifferent::Decoded("MyGetParam2".to_string()),
ty: DecodeDifferent::Decoded("u32".to_string()),
value: DecodeDifferent::Decoded(vec![11, 0, 0, 0]),
documentation: DecodeDifferent::Decoded(vec![
" Some comment".to_string(),
" Some comment".to_string(),
]),
},
ModuleConstantMetadata {
name: DecodeDifferent::Decoded("MyGetParam3".to_string()),
ty: DecodeDifferent::Decoded("<T::AccountId as SomeAssociation1>::_1".to_string()),
value: DecodeDifferent::Decoded(vec![12, 0, 0, 0, 0, 0, 0, 0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
ModuleConstantMetadata {
name: DecodeDifferent::Decoded("some_extra".to_string()),
ty: DecodeDifferent::Decoded("T::AccountId".to_string()),
value: DecodeDifferent::Decoded(vec![100, 0, 0, 0, 0, 0, 0, 0]),
documentation: DecodeDifferent::Decoded(vec![
" Some doc".to_string(),
" Some doc".to_string(),
]),
},
ModuleConstantMetadata {
name: DecodeDifferent::Decoded("some_extra_extra".to_string()),
ty: DecodeDifferent::Decoded("T::AccountId".to_string()),
value: DecodeDifferent::Decoded(vec![0, 0, 0, 0, 0, 0, 0, 0]),
documentation: DecodeDifferent::Decoded(vec![
" Some doc".to_string(),
]),
},
]),
errors: DecodeDifferent::Decoded(vec![
ErrorMetadata {
name: DecodeDifferent::Decoded("InsufficientProposersBalance".to_string()),
documentation: DecodeDifferent::Decoded(vec![
" doc comment put into metadata".to_string(),
]),
},
]),
};
let metadata = match Runtime::metadata().1 {
RuntimeMetadata::V12(metadata) => metadata,
_ => panic!("metadata has been bump, test needs to be updated"),
};
let modules_metadata = match metadata.modules {
DecodeDifferent::Encode(modules_metadata) => modules_metadata,
_ => unreachable!(),
};
let pallet_metadata = ModuleMetadata::decode(&mut &modules_metadata[1].encode()[..]).unwrap();
pretty_assertions::assert_eq!(pallet_metadata, expected_pallet_metadata);
}
@@ -0,0 +1,298 @@
// This file is part of Substrate.
// Copyright (C) 2020 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 sp_runtime::traits::Block as _;
pub trait SomeAssociation {
type A: frame_support::dispatch::Parameter + Default;
}
impl SomeAssociation for u64 {
type A = u64;
}
mod pallet_old {
use frame_support::{
decl_storage, decl_error, decl_event, decl_module, weights::Weight, traits::Get, Parameter
};
use frame_system::ensure_root;
use super::SomeAssociation;
pub trait Config: frame_system::Config {
type SomeConst: Get<Self::Balance>;
type Balance: Parameter + codec::HasCompact + From<u32> + Into<Weight> + Default
+ SomeAssociation;
type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
}
decl_storage! {
trait Store for Module<T: Config> as Example {
/// Some documentation
Dummy get(fn dummy) config(): Option<T::Balance>;
Bar get(fn bar) config(): map hasher(blake2_128_concat) T::AccountId => T::Balance;
Foo get(fn foo) config(): T::Balance = 3.into();
Double get(fn double): double_map
hasher(blake2_128_concat) u32,
hasher(twox_64_concat) u64
=> <T::Balance as SomeAssociation>::A;
}
}
decl_event!(
pub enum Event<T> where Balance = <T as Config>::Balance {
/// Dummy event, just here so there's a generic type that's used.
Dummy(Balance),
}
);
decl_module! {
pub struct Module<T: Config> for enum Call where origin: T::Origin {
type Error = Error<T>;
fn deposit_event() = default;
const SomeConst: T::Balance = T::SomeConst::get();
#[weight = <T::Balance as Into<Weight>>::into(new_value.clone())]
fn set_dummy(origin, #[compact] new_value: T::Balance) {
ensure_root(origin)?;
<Dummy<T>>::put(&new_value);
Self::deposit_event(RawEvent::Dummy(new_value));
}
fn on_initialize(_n: T::BlockNumber) -> Weight {
<Dummy<T>>::put(T::Balance::from(10));
10
}
fn on_finalize(_n: T::BlockNumber) {
<Dummy<T>>::put(T::Balance::from(11));
}
}
}
decl_error! {
pub enum Error for Module<T: Config> {
/// Some wrong behavior
Wrong,
}
}
}
#[frame_support::pallet]
pub mod pallet {
use super::SomeAssociation;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use frame_system::ensure_root;
#[pallet::config]
pub trait Config: frame_system::Config {
type Balance: Parameter + codec::HasCompact + From<u32> + Into<Weight> + Default
+ MaybeSerializeDeserialize + SomeAssociation;
#[pallet::constant]
type SomeConst: Get<Self::Balance>;
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
}
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<T::BlockNumber> for Pallet<T> {
fn on_initialize(_n: T::BlockNumber) -> Weight {
<Dummy<T>>::put(T::Balance::from(10));
10
}
fn on_finalize(_n: T::BlockNumber) {
<Dummy<T>>::put(T::Balance::from(11));
}
}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(<T::Balance as Into<Weight>>::into(new_value.clone()))]
fn set_dummy(
origin: OriginFor<T>,
#[pallet::compact] new_value: T::Balance
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
<Dummy<T>>::put(&new_value);
Self::deposit_event(Event::Dummy(new_value));
Ok(().into())
}
}
#[pallet::error]
pub enum Error<T> {
/// Some wrong behavior
Wrong,
}
#[pallet::event]
#[pallet::generate_deposit(fn deposit_event)]
#[pallet::metadata(T::Balance = "Balance")]
pub enum Event<T: Config> {
/// Dummy event, just here so there's a generic type that's used.
Dummy(T::Balance),
}
#[pallet::storage]
/// Some documentation
type Dummy<T: Config> = StorageValue<_, T::Balance, OptionQuery>;
#[pallet::storage]
type Bar<T: Config> = StorageMap<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>;
#[pallet::type_value] pub fn OnFooEmpty<T: Config>() -> T::Balance { 3.into() }
#[pallet::storage]
type Foo<T: Config> = StorageValue<_, T::Balance, ValueQuery, OnFooEmpty<T>>;
#[pallet::storage]
type Double<T: Config> = StorageDoubleMap<
_, Blake2_128Concat, u32, Twox64Concat, u64, <T::Balance as SomeAssociation>::A, ValueQuery
>;
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
dummy: Option<T::Balance>,
bar: Vec<(T::AccountId, T::Balance)>,
foo: T::Balance,
}
impl<T: Config> Default for GenesisConfig<T> {
fn default() -> Self {
GenesisConfig {
dummy: Default::default(),
bar: Default::default(),
foo: OnFooEmpty::<T>::get(),
}
}
}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig<T> {
fn build(&self) {
if let Some(dummy) = self.dummy.as_ref() {
<Dummy<T>>::put(dummy);
}
for (k, v) in &self.bar {
<Bar<T>>::insert(k, v);
}
<Foo<T>>::put(&self.foo);
}
}
}
frame_support::parameter_types!(
pub const SomeConst: u64 = 10;
pub const BlockHashCount: u32 = 250;
);
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u32;
type Call = Call;
type Hash = sp_runtime::testing::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl pallet::Config for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type Balance = u64;
}
impl pallet_old::Config for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type Balance = u64;
}
pub type Header = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>;
frame_support::construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Event<T>},
// NOTE: name Example here is needed in order to have same module prefix
Example: pallet::{Module, Call, Event<T>, Config<T>, Storage},
PalletOld: pallet_old::{Module, Call, Event<T>, Config<T>, Storage},
}
);
#[cfg(test)]
mod test {
use super::Runtime;
use super::pallet;
use super::pallet_old;
use codec::{Decode, Encode};
#[test]
fn metadata() {
let metadata = Runtime::metadata();
let modules = match metadata.1 {
frame_metadata::RuntimeMetadata::V12(frame_metadata::RuntimeMetadataV12 {
modules: frame_metadata::DecodeDifferent::Encode(m),
..
}) => m,
_ => unreachable!(),
};
pretty_assertions::assert_eq!(modules[1].storage, modules[2].storage);
pretty_assertions::assert_eq!(modules[1].calls, modules[2].calls);
pretty_assertions::assert_eq!(modules[1].event, modules[2].event);
pretty_assertions::assert_eq!(modules[1].constants, modules[2].constants);
pretty_assertions::assert_eq!(modules[1].errors, modules[2].errors);
}
#[test]
fn types() {
assert_eq!(
pallet_old::Event::<Runtime>::decode(
&mut &pallet::Event::<Runtime>::Dummy(10).encode()[..]
).unwrap(),
pallet_old::Event::<Runtime>::Dummy(10),
);
assert_eq!(
pallet_old::Call::<Runtime>::decode(
&mut &pallet::Call::<Runtime>::set_dummy(10).encode()[..]
).unwrap(),
pallet_old::Call::<Runtime>::set_dummy(10),
);
}
}
@@ -0,0 +1,315 @@
// This file is part of Substrate.
// Copyright (C) 2020 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 sp_runtime::traits::Block as _;
mod pallet_old {
use frame_support::{
decl_storage, decl_error, decl_event, decl_module, weights::Weight, traits::Get, Parameter
};
use frame_system::ensure_root;
pub trait Config<I: Instance = DefaultInstance>: frame_system::Config {
type SomeConst: Get<Self::Balance>;
type Balance: Parameter + codec::HasCompact + From<u32> + Into<Weight> + Default;
type Event: From<Event<Self, I>> + Into<<Self as frame_system::Config>::Event>;
}
decl_storage! {
trait Store for Module<T: Config<I>, I: Instance = DefaultInstance> as Example {
/// Some documentation
Dummy get(fn dummy) config(): Option<T::Balance>;
Bar get(fn bar) config(): map hasher(blake2_128_concat) T::AccountId => T::Balance;
Foo get(fn foo) config(): T::Balance = 3.into();
Double get(fn double):
double_map hasher(blake2_128_concat) u32, hasher(twox_64_concat) u64 => u16;
}
}
decl_event!(
pub enum Event<T, I = DefaultInstance> where Balance = <T as Config<I>>::Balance {
/// Dummy event, just here so there's a generic type that's used.
Dummy(Balance),
}
);
decl_module! {
pub struct Module<T: Config<I>, I: Instance = DefaultInstance> for enum Call
where origin: T::Origin
{
type Error = Error<T, I>;
fn deposit_event() = default;
const SomeConst: T::Balance = T::SomeConst::get();
#[weight = <T::Balance as Into<Weight>>::into(new_value.clone())]
fn set_dummy(origin, #[compact] new_value: T::Balance) {
ensure_root(origin)?;
<Dummy<T, I>>::put(&new_value);
Self::deposit_event(RawEvent::Dummy(new_value));
}
fn on_initialize(_n: T::BlockNumber) -> Weight {
<Dummy<T, I>>::put(T::Balance::from(10));
10
}
fn on_finalize(_n: T::BlockNumber) {
<Dummy<T, I>>::put(T::Balance::from(11));
}
}
}
decl_error! {
pub enum Error for Module<T: Config<I>, I: Instance> {
/// Some wrong behavior
Wrong,
}
}
}
#[frame_support::pallet]
pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use frame_system::ensure_root;
#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config {
type Balance: Parameter + codec::HasCompact + From<u32> + Into<Weight> + Default
+ MaybeSerializeDeserialize;
#[pallet::constant]
type SomeConst: Get<Self::Balance>;
type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;
}
#[pallet::pallet]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<T::BlockNumber> for Pallet<T, I> {
fn on_initialize(_n: T::BlockNumber) -> Weight {
<Dummy<T, I>>::put(T::Balance::from(10));
10
}
fn on_finalize(_n: T::BlockNumber) {
<Dummy<T, I>>::put(T::Balance::from(11));
}
}
#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
#[pallet::weight(<T::Balance as Into<Weight>>::into(new_value.clone()))]
fn set_dummy(
origin: OriginFor<T>,
#[pallet::compact] new_value: T::Balance
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
<Dummy<T, I>>::put(&new_value);
Self::deposit_event(Event::Dummy(new_value));
Ok(().into())
}
}
#[pallet::error]
pub enum Error<T, I = ()> {
/// Some wrong behavior
Wrong,
}
#[pallet::event]
#[pallet::generate_deposit(fn deposit_event)]
#[pallet::metadata(T::Balance = "Balance")]
pub enum Event<T: Config<I>, I: 'static = ()> {
/// Dummy event, just here so there's a generic type that's used.
Dummy(T::Balance),
}
#[pallet::storage]
/// Some documentation
type Dummy<T: Config<I>, I: 'static = ()> = StorageValue<_, T::Balance, OptionQuery>;
#[pallet::storage]
type Bar<T: Config<I>, I: 'static = ()> =
StorageMap<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>;
#[pallet::storage]
type Foo<T: Config<I>, I: 'static = ()> =
StorageValue<_, T::Balance, ValueQuery, OnFooEmpty<T, I>>;
#[pallet::type_value] pub fn OnFooEmpty<T: Config<I>, I: 'static>() -> T::Balance { 3.into() }
#[pallet::storage]
type Double<T, I = ()> = StorageDoubleMap<
_, Blake2_128Concat, u32, Twox64Concat, u64, u16, ValueQuery
>;
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
dummy: Option<T::Balance>,
bar: Vec<(T::AccountId, T::Balance)>,
foo: T::Balance,
}
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
GenesisConfig {
dummy: Default::default(),
bar: Default::default(),
foo: OnFooEmpty::<T, I>::get(),
}
}
}
#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
fn build(&self) {
if let Some(dummy) = self.dummy.as_ref() {
<Dummy<T, I>>::put(dummy);
}
for (k, v) in &self.bar {
<Bar<T, I>>::insert(k, v);
}
<Foo<T, I>>::put(&self.foo);
}
}
}
frame_support::parameter_types!(
pub const SomeConst: u64 = 10;
pub const BlockHashCount: u32 = 250;
);
impl frame_system::Config for Runtime {
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u32;
type Call = Call;
type Hash = sp_runtime::testing::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl pallet::Config for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type Balance = u64;
}
impl pallet::Config<pallet::Instance2> for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type Balance = u64;
}
impl pallet::Config<pallet::Instance3> for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type Balance = u64;
}
impl pallet_old::Config for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type Balance = u64;
}
impl pallet_old::Config<pallet_old::Instance2> for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type Balance = u64;
}
impl pallet_old::Config<pallet_old::Instance3> for Runtime {
type Event = Event;
type SomeConst = SomeConst;
type Balance = u64;
}
pub type Header = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>;
frame_support::construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Event<T>},
Example: pallet::{Module, Call, Event<T>, Config<T>, Storage},
PalletOld: pallet_old::{Module, Call, Event<T>, Config<T>, Storage},
Instance2Example: pallet::<Instance2>::{Module, Call, Event<T>, Config<T>, Storage},
PalletOld2: pallet_old::<Instance2>::{Module, Call, Event<T>, Config<T>, Storage},
Instance3Example: pallet::<Instance3>::{Module, Call, Event<T>, Config<T>, Storage},
PalletOld3: pallet_old::<Instance3>::{Module, Call, Event<T>, Config<T>, Storage},
}
);
#[cfg(test)]
mod test {
use super::Runtime;
use super::pallet;
use super::pallet_old;
use codec::{Decode, Encode};
#[test]
fn metadata() {
let metadata = Runtime::metadata();
let modules = match metadata.1 {
frame_metadata::RuntimeMetadata::V12(frame_metadata::RuntimeMetadataV12 {
modules: frame_metadata::DecodeDifferent::Encode(m),
..
}) => m,
_ => unreachable!(),
};
for i in vec![1, 3, 5].into_iter() {
pretty_assertions::assert_eq!(modules[i].storage, modules[i+1].storage);
pretty_assertions::assert_eq!(modules[i].calls, modules[i+1].calls);
pretty_assertions::assert_eq!(modules[i].event, modules[i+1].event);
pretty_assertions::assert_eq!(modules[i].constants, modules[i+1].constants);
pretty_assertions::assert_eq!(modules[i].errors, modules[i+1].errors);
}
}
#[test]
fn types() {
assert_eq!(
pallet_old::Event::<Runtime>::decode(
&mut &pallet::Event::<Runtime>::Dummy(10).encode()[..]
).unwrap(),
pallet_old::Event::<Runtime>::Dummy(10),
);
assert_eq!(
pallet_old::Call::<Runtime>::decode(
&mut &pallet::Call::<Runtime>::set_dummy(10).encode()[..]
).unwrap(),
pallet_old::Call::<Runtime>::set_dummy(10),
);
}
}
@@ -0,0 +1,708 @@
// This file is part of Substrate.
// Copyright (C) 2020 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::{
weights::{DispatchInfo, DispatchClass, Pays, GetDispatchInfo},
traits::{
GetCallName, GetPalletVersion, OnInitialize, OnFinalize, OnRuntimeUpgrade, OnGenesis,
},
dispatch::UnfilteredDispatchable,
storage::unhashed,
};
use sp_runtime::{traits::Block as _, DispatchError};
use sp_io::{TestExternalities, hashing::{twox_64, twox_128, blake2_128}};
#[frame_support::pallet]
pub mod pallet {
use sp_std::any::TypeId;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
type BalanceOf<T, I> = <T as Config<I>>::Balance;
#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config {
#[pallet::constant]
type MyGetParam: Get<u32>;
type Balance: Parameter + Default;
type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;
}
#[pallet::pallet]
#[pallet::generate_store(pub(crate) trait Store)]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
if TypeId::of::<I>() == TypeId::of::<()>() {
Self::deposit_event(Event::Something(10));
10
} else {
Self::deposit_event(Event::Something(11));
11
}
}
fn on_finalize(_: BlockNumberFor<T>) {
if TypeId::of::<I>() == TypeId::of::<()>() {
Self::deposit_event(Event::Something(20));
} else {
Self::deposit_event(Event::Something(21));
}
}
fn on_runtime_upgrade() -> Weight {
if TypeId::of::<I>() == TypeId::of::<()>() {
Self::deposit_event(Event::Something(30));
30
} else {
Self::deposit_event(Event::Something(31));
31
}
}
fn integrity_test() {
}
}
#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Doc comment put in metadata
#[pallet::weight(Weight::from(*_foo))]
fn foo(origin: OriginFor<T>, #[pallet::compact] _foo: u32) -> DispatchResultWithPostInfo {
let _ = origin;
Self::deposit_event(Event::Something(3));
Ok(().into())
}
/// Doc comment put in metadata
#[pallet::weight(1)]
#[frame_support::transactional]
fn foo_transactional(
origin: OriginFor<T>,
#[pallet::compact] _foo: u32
) -> DispatchResultWithPostInfo {
let _ = origin;
Ok(().into())
}
}
#[pallet::error]
pub enum Error<T, I = ()> {
/// doc comment put into metadata
InsufficientProposersBalance,
}
#[pallet::event]
#[pallet::metadata(BalanceOf<T, I> = "Balance", u32 = "Other")]
#[pallet::generate_deposit(fn deposit_event)]
pub enum Event<T: Config<I>, I: 'static = ()> {
/// doc comment put in metadata
Proposed(<T as frame_system::Config>::AccountId),
/// doc
Spending(BalanceOf<T, I>),
Something(u32),
}
#[pallet::storage]
pub type Value<T, I = ()> = StorageValue<_, u32>;
#[pallet::storage]
pub type Map<T, I = ()> = StorageMap<_, Blake2_128Concat, u8, u16>;
#[pallet::storage]
pub type Map2<T, I = ()> = StorageMap<_, Twox64Concat, u16, u32>;
#[pallet::storage]
pub type DoubleMap<T, I = ()> =
StorageDoubleMap<_, Blake2_128Concat, u8, Twox64Concat, u16, u32>;
#[pallet::storage]
pub type DoubleMap2<T, I = ()> =
StorageDoubleMap<_, Twox64Concat, u16, Blake2_128Concat, u32, u64>;
#[pallet::genesis_config]
#[derive(Default)]
pub struct GenesisConfig {
_myfield: u32,
}
#[pallet::genesis_build]
impl<T: Config<I>, I:'static> GenesisBuild<T, I> for GenesisConfig {
fn build(&self) {}
}
#[pallet::origin]
#[derive(EqNoBound, RuntimeDebugNoBound, CloneNoBound, PartialEqNoBound, Encode, Decode)]
pub struct Origin<T, I = ()>(PhantomData<(T, I)>);
#[pallet::validate_unsigned]
impl<T: Config<I>, I: 'static> ValidateUnsigned for Pallet<T, I> {
type Call = Call<T, I>;
fn validate_unsigned(
_source: TransactionSource,
_call: &Self::Call
) -> TransactionValidity {
Err(TransactionValidityError::Invalid(InvalidTransaction::Call))
}
}
#[pallet::inherent]
impl<T: Config<I>, I: 'static> ProvideInherent for Pallet<T, I> {
type Call = Call<T, I>;
type Error = InherentError;
const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER;
fn create_inherent(_data: &InherentData) -> Option<Self::Call> {
unimplemented!();
}
}
#[derive(codec::Encode, sp_runtime::RuntimeDebug)]
#[cfg_attr(feature = "std", derive(codec::Decode))]
pub enum InherentError {
}
impl sp_inherents::IsFatalError for InherentError {
fn is_fatal_error(&self) -> bool {
unimplemented!();
}
}
pub const INHERENT_IDENTIFIER: sp_inherents::InherentIdentifier = *b"testpall";
}
// Test that a instantiable pallet with a generic genesis_config is correctly handled
#[frame_support::pallet]
pub mod pallet2 {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config {
type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;
}
#[pallet::pallet]
#[pallet::generate_store(pub(crate) trait Store)]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {}
#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {}
#[pallet::event]
pub enum Event<T: Config<I>, I: 'static = ()> {
/// Something
Something(u32),
}
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
phantom: PhantomData<(T, I)>,
}
impl<T: Config<I>, I: 'static> Default for GenesisConfig<T, I> {
fn default() -> Self {
GenesisConfig {
phantom: Default::default(),
}
}
}
#[pallet::genesis_build]
impl<T: Config<I>, I: 'static> GenesisBuild<T, I> for GenesisConfig<T, I> {
fn build(&self) {}
}
}
frame_support::parameter_types!(
pub const MyGetParam: u32= 10;
pub const BlockHashCount: u32 = 250;
);
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = u32;
type Call = Call;
type Hash = sp_runtime::testing::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
impl pallet::Config for Runtime {
type Event = Event;
type MyGetParam= MyGetParam;
type Balance = u64;
}
impl pallet::Config<pallet::Instance1> for Runtime {
type Event = Event;
type MyGetParam= MyGetParam;
type Balance = u64;
}
impl pallet2::Config for Runtime {
type Event = Event;
}
impl pallet2::Config<pallet::Instance1> for Runtime {
type Event = Event;
}
pub type Header = sp_runtime::generic::Header<u32, sp_runtime::traits::BlakeTwo256>;
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>;
frame_support::construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Event<T>},
Example: pallet::{Module, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned},
Instance1Example: pallet::<Instance1>::{
Module, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned
},
Example2: pallet2::{Module, Call, Event<T>, Config<T>, Storage},
Instance1Example2: pallet2::<Instance1>::{Module, Call, Event<T>, Config<T>, Storage},
}
);
#[test]
fn call_expand() {
let call_foo = pallet::Call::<Runtime>::foo(3);
assert_eq!(
call_foo.get_dispatch_info(),
DispatchInfo {
weight: 3,
class: DispatchClass::Normal,
pays_fee: Pays::Yes,
}
);
assert_eq!(call_foo.get_call_name(), "foo");
assert_eq!(
pallet::Call::<Runtime>::get_call_names(),
&["foo", "foo_transactional"],
);
let call_foo = pallet::Call::<Runtime, pallet::Instance1>::foo(3);
assert_eq!(
call_foo.get_dispatch_info(),
DispatchInfo {
weight: 3,
class: DispatchClass::Normal,
pays_fee: Pays::Yes,
}
);
assert_eq!(call_foo.get_call_name(), "foo");
assert_eq!(
pallet::Call::<Runtime, pallet::Instance1>::get_call_names(),
&["foo", "foo_transactional"],
);
}
#[test]
fn error_expand() {
assert_eq!(
format!("{:?}", pallet::Error::<Runtime>::InsufficientProposersBalance),
String::from("InsufficientProposersBalance"),
);
assert_eq!(
<&'static str>::from(pallet::Error::<Runtime>::InsufficientProposersBalance),
"InsufficientProposersBalance",
);
assert_eq!(
DispatchError::from(pallet::Error::<Runtime>::InsufficientProposersBalance),
DispatchError::Module {
index: 1,
error: 0,
message: Some("InsufficientProposersBalance"),
},
);
assert_eq!(
format!("{:?}", pallet::Error::<Runtime, pallet::Instance1>::InsufficientProposersBalance),
String::from("InsufficientProposersBalance"),
);
assert_eq!(
<&'static str>::from(pallet::Error::<Runtime, pallet::Instance1>::InsufficientProposersBalance),
"InsufficientProposersBalance",
);
assert_eq!(
DispatchError::from(pallet::Error::<Runtime, pallet::Instance1>::InsufficientProposersBalance),
DispatchError::Module {
index: 2,
error: 0,
message: Some("InsufficientProposersBalance"),
},
);
}
#[test]
fn instance_expand() {
// assert same type
let _: pallet::__InherentHiddenInstance = ();
}
#[test]
fn pallet_expand_deposit_event() {
TestExternalities::default().execute_with(|| {
frame_system::Module::<Runtime>::set_block_number(1);
pallet::Call::<Runtime>::foo(3).dispatch_bypass_filter(None.into()).unwrap();
assert_eq!(
frame_system::Module::<Runtime>::events()[0].event,
Event::pallet(pallet::Event::Something(3)),
);
});
TestExternalities::default().execute_with(|| {
frame_system::Module::<Runtime>::set_block_number(1);
pallet::Call::<Runtime, pallet::Instance1>::foo(3).dispatch_bypass_filter(None.into()).unwrap();
assert_eq!(
frame_system::Module::<Runtime>::events()[0].event,
Event::pallet_Instance1(pallet::Event::Something(3)),
);
});
}
#[test]
fn storage_expand() {
use frame_support::pallet_prelude::*;
use frame_support::StoragePrefixedMap;
fn twox_64_concat(d: &[u8]) -> Vec<u8> {
let mut v = twox_64(d).to_vec();
v.extend_from_slice(d);
v
}
fn blake2_128_concat(d: &[u8]) -> Vec<u8> {
let mut v = blake2_128(d).to_vec();
v.extend_from_slice(d);
v
}
TestExternalities::default().execute_with(|| {
<pallet::Value<Runtime>>::put(1);
let k = [twox_128(b"Example"), twox_128(b"Value")].concat();
assert_eq!(unhashed::get::<u32>(&k), Some(1u32));
<pallet::Map<Runtime>>::insert(1, 2);
let mut k = [twox_128(b"Example"), twox_128(b"Map")].concat();
k.extend(1u8.using_encoded(blake2_128_concat));
assert_eq!(unhashed::get::<u16>(&k), Some(2u16));
assert_eq!(&k[..32], &<pallet::Map<Runtime>>::final_prefix());
<pallet::Map2<Runtime>>::insert(1, 2);
let mut k = [twox_128(b"Example"), twox_128(b"Map2")].concat();
k.extend(1u16.using_encoded(twox_64_concat));
assert_eq!(unhashed::get::<u32>(&k), Some(2u32));
assert_eq!(&k[..32], &<pallet::Map2<Runtime>>::final_prefix());
<pallet::DoubleMap<Runtime>>::insert(&1, &2, &3);
let mut k = [twox_128(b"Example"), twox_128(b"DoubleMap")].concat();
k.extend(1u8.using_encoded(blake2_128_concat));
k.extend(2u16.using_encoded(twox_64_concat));
assert_eq!(unhashed::get::<u32>(&k), Some(3u32));
assert_eq!(&k[..32], &<pallet::DoubleMap<Runtime>>::final_prefix());
<pallet::DoubleMap2<Runtime>>::insert(&1, &2, &3);
let mut k = [twox_128(b"Example"), twox_128(b"DoubleMap2")].concat();
k.extend(1u16.using_encoded(twox_64_concat));
k.extend(2u32.using_encoded(blake2_128_concat));
assert_eq!(unhashed::get::<u64>(&k), Some(3u64));
assert_eq!(&k[..32], &<pallet::DoubleMap2<Runtime>>::final_prefix());
});
TestExternalities::default().execute_with(|| {
<pallet::Value<Runtime, pallet::Instance1>>::put(1);
let k = [twox_128(b"Instance1Example"), twox_128(b"Value")].concat();
assert_eq!(unhashed::get::<u32>(&k), Some(1u32));
<pallet::Map<Runtime, pallet::Instance1>>::insert(1, 2);
let mut k = [twox_128(b"Instance1Example"), twox_128(b"Map")].concat();
k.extend(1u8.using_encoded(blake2_128_concat));
assert_eq!(unhashed::get::<u16>(&k), Some(2u16));
assert_eq!(&k[..32], &<pallet::Map<Runtime, pallet::Instance1>>::final_prefix());
<pallet::Map2<Runtime, pallet::Instance1>>::insert(1, 2);
let mut k = [twox_128(b"Instance1Example"), twox_128(b"Map2")].concat();
k.extend(1u16.using_encoded(twox_64_concat));
assert_eq!(unhashed::get::<u32>(&k), Some(2u32));
assert_eq!(&k[..32], &<pallet::Map2<Runtime, pallet::Instance1>>::final_prefix());
<pallet::DoubleMap<Runtime, pallet::Instance1>>::insert(&1, &2, &3);
let mut k = [twox_128(b"Instance1Example"), twox_128(b"DoubleMap")].concat();
k.extend(1u8.using_encoded(blake2_128_concat));
k.extend(2u16.using_encoded(twox_64_concat));
assert_eq!(unhashed::get::<u32>(&k), Some(3u32));
assert_eq!(&k[..32], &<pallet::DoubleMap<Runtime, pallet::Instance1>>::final_prefix());
<pallet::DoubleMap2<Runtime, pallet::Instance1>>::insert(&1, &2, &3);
let mut k = [twox_128(b"Instance1Example"), twox_128(b"DoubleMap2")].concat();
k.extend(1u16.using_encoded(twox_64_concat));
k.extend(2u32.using_encoded(blake2_128_concat));
assert_eq!(unhashed::get::<u64>(&k), Some(3u64));
assert_eq!(&k[..32], &<pallet::DoubleMap2<Runtime, pallet::Instance1>>::final_prefix());
});
}
#[test]
fn pallet_hooks_expand() {
TestExternalities::default().execute_with(|| {
frame_system::Module::<Runtime>::set_block_number(1);
assert_eq!(AllModules::on_initialize(1), 21);
AllModules::on_finalize(1);
assert_eq!(pallet::Pallet::<Runtime>::storage_version(), None);
assert_eq!(pallet::Pallet::<Runtime, pallet::Instance1>::storage_version(), None);
assert_eq!(AllModules::on_runtime_upgrade(), 61);
assert_eq!(
pallet::Pallet::<Runtime>::storage_version(),
Some(pallet::Pallet::<Runtime>::current_version()),
);
assert_eq!(
pallet::Pallet::<Runtime, pallet::Instance1>::storage_version(),
Some(pallet::Pallet::<Runtime, pallet::Instance1>::current_version()),
);
// The order is indeed reversed due to https://github.com/paritytech/substrate/issues/6280
assert_eq!(
frame_system::Module::<Runtime>::events()[0].event,
Event::pallet_Instance1(pallet::Event::Something(11)),
);
assert_eq!(
frame_system::Module::<Runtime>::events()[1].event,
Event::pallet(pallet::Event::Something(10)),
);
assert_eq!(
frame_system::Module::<Runtime>::events()[2].event,
Event::pallet_Instance1(pallet::Event::Something(21)),
);
assert_eq!(
frame_system::Module::<Runtime>::events()[3].event,
Event::pallet(pallet::Event::Something(20)),
);
assert_eq!(
frame_system::Module::<Runtime>::events()[4].event,
Event::pallet_Instance1(pallet::Event::Something(31)),
);
assert_eq!(
frame_system::Module::<Runtime>::events()[5].event,
Event::pallet(pallet::Event::Something(30)),
);
})
}
#[test]
fn pallet_on_genesis() {
TestExternalities::default().execute_with(|| {
assert_eq!(pallet::Pallet::<Runtime>::storage_version(), None);
pallet::Pallet::<Runtime>::on_genesis();
assert_eq!(
pallet::Pallet::<Runtime>::storage_version(),
Some(pallet::Pallet::<Runtime>::current_version()),
);
assert_eq!(pallet::Pallet::<Runtime, pallet::Instance1>::storage_version(), None);
pallet::Pallet::<Runtime, pallet::Instance1>::on_genesis();
assert_eq!(
pallet::Pallet::<Runtime, pallet::Instance1>::storage_version(),
Some(pallet::Pallet::<Runtime, pallet::Instance1>::current_version()),
);
})
}
#[test]
fn metadata() {
use frame_metadata::*;
use codec::{Decode, Encode};
let expected_pallet_metadata = ModuleMetadata {
index: 1,
name: DecodeDifferent::Decoded("Example".to_string()),
storage: Some(DecodeDifferent::Decoded(StorageMetadata {
prefix: DecodeDifferent::Decoded("Example".to_string()),
entries: DecodeDifferent::Decoded(vec![
StorageEntryMetadata {
name: DecodeDifferent::Decoded("Value".to_string()),
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::Plain(DecodeDifferent::Decoded("u32".to_string())),
default: DecodeDifferent::Decoded(vec![0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
StorageEntryMetadata {
name: DecodeDifferent::Decoded("Map".to_string()),
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::Map {
key: DecodeDifferent::Decoded("u8".to_string()),
value: DecodeDifferent::Decoded("u16".to_string()),
hasher: StorageHasher::Blake2_128Concat,
unused: false,
},
default: DecodeDifferent::Decoded(vec![0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
StorageEntryMetadata {
name: DecodeDifferent::Decoded("Map2".to_string()),
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::Map {
key: DecodeDifferent::Decoded("u16".to_string()),
value: DecodeDifferent::Decoded("u32".to_string()),
hasher: StorageHasher::Twox64Concat,
unused: false,
},
default: DecodeDifferent::Decoded(vec![0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
StorageEntryMetadata {
name: DecodeDifferent::Decoded("DoubleMap".to_string()),
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::DoubleMap {
value: DecodeDifferent::Decoded("u32".to_string()),
key1: DecodeDifferent::Decoded("u8".to_string()),
key2: DecodeDifferent::Decoded("u16".to_string()),
hasher: StorageHasher::Blake2_128Concat,
key2_hasher: StorageHasher::Twox64Concat,
},
default: DecodeDifferent::Decoded(vec![0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
StorageEntryMetadata {
name: DecodeDifferent::Decoded("DoubleMap2".to_string()),
modifier: StorageEntryModifier::Optional,
ty: StorageEntryType::DoubleMap {
value: DecodeDifferent::Decoded("u64".to_string()),
key1: DecodeDifferent::Decoded("u16".to_string()),
key2: DecodeDifferent::Decoded("u32".to_string()),
hasher: StorageHasher::Twox64Concat,
key2_hasher: StorageHasher::Blake2_128Concat,
},
default: DecodeDifferent::Decoded(vec![0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
]),
})),
calls: Some(DecodeDifferent::Decoded(vec![
FunctionMetadata {
name: DecodeDifferent::Decoded("foo".to_string()),
arguments: DecodeDifferent::Decoded(vec![
FunctionArgumentMetadata {
name: DecodeDifferent::Decoded("_foo".to_string()),
ty: DecodeDifferent::Decoded("Compact<u32>".to_string()),
}
]),
documentation: DecodeDifferent::Decoded(vec![
" Doc comment put in metadata".to_string(),
]),
},
FunctionMetadata {
name: DecodeDifferent::Decoded("foo_transactional".to_string()),
arguments: DecodeDifferent::Decoded(vec![
FunctionArgumentMetadata {
name: DecodeDifferent::Decoded("_foo".to_string()),
ty: DecodeDifferent::Decoded("Compact<u32>".to_string()),
}
]),
documentation: DecodeDifferent::Decoded(vec![
" Doc comment put in metadata".to_string(),
]),
},
])),
event: Some(DecodeDifferent::Decoded(vec![
EventMetadata {
name: DecodeDifferent::Decoded("Proposed".to_string()),
arguments: DecodeDifferent::Decoded(vec!["<T as frame_system::Config>::AccountId".to_string()]),
documentation: DecodeDifferent::Decoded(vec![
" doc comment put in metadata".to_string()
]),
},
EventMetadata {
name: DecodeDifferent::Decoded("Spending".to_string()),
arguments: DecodeDifferent::Decoded(vec!["Balance".to_string()]),
documentation: DecodeDifferent::Decoded(vec![
" doc".to_string()
]),
},
EventMetadata {
name: DecodeDifferent::Decoded("Something".to_string()),
arguments: DecodeDifferent::Decoded(vec!["Other".to_string()]),
documentation: DecodeDifferent::Decoded(vec![]),
},
])),
constants: DecodeDifferent::Decoded(vec![
ModuleConstantMetadata {
name: DecodeDifferent::Decoded("MyGetParam".to_string()),
ty: DecodeDifferent::Decoded("u32".to_string()),
value: DecodeDifferent::Decoded(vec![10, 0, 0, 0]),
documentation: DecodeDifferent::Decoded(vec![]),
},
]),
errors: DecodeDifferent::Decoded(vec![
ErrorMetadata {
name: DecodeDifferent::Decoded("InsufficientProposersBalance".to_string()),
documentation: DecodeDifferent::Decoded(vec![
" doc comment put into metadata".to_string(),
]),
},
]),
};
let mut expected_pallet_instance1_metadata = expected_pallet_metadata.clone();
expected_pallet_instance1_metadata.name = DecodeDifferent::Decoded("Instance1Example".to_string());
expected_pallet_instance1_metadata.index = 2;
match expected_pallet_instance1_metadata.storage {
Some(DecodeDifferent::Decoded(ref mut storage_meta)) => {
storage_meta.prefix = DecodeDifferent::Decoded("Instance1Example".to_string());
},
_ => unreachable!(),
}
let metadata = match Runtime::metadata().1 {
RuntimeMetadata::V12(metadata) => metadata,
_ => panic!("metadata has been bump, test needs to be updated"),
};
let modules_metadata = match metadata.modules {
DecodeDifferent::Encode(modules_metadata) => modules_metadata,
_ => unreachable!(),
};
let pallet_metadata = ModuleMetadata::decode(&mut &modules_metadata[1].encode()[..]).unwrap();
let pallet_instance1_metadata =
ModuleMetadata::decode(&mut &modules_metadata[2].encode()[..]).unwrap();
pretty_assertions::assert_eq!(pallet_metadata, expected_pallet_metadata);
pretty_assertions::assert_eq!(pallet_instance1_metadata, expected_pallet_instance1_metadata);
}
@@ -0,0 +1,26 @@
// This file is part of Substrate.
// Copyright (C) 2020 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)]
#[test]
fn pallet_ui() {
// As trybuild is using `cargo check`, we don't need the real WASM binaries.
std::env::set_var("SKIP_WASM_BUILD", "1");
let t = trybuild::TestCases::new();
t.compile_fail("tests/pallet_ui/*.rs");
}
@@ -0,0 +1,6 @@
#[frame_support::pallet [foo]]
mod foo {
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet macro call: expected no attributes, e.g. macro call must be just `#[frame_support::pallet]` or `#[pallet]`
--> $DIR/attr_non_empty.rs:1:26
|
1 | #[frame_support::pallet [foo]]
| ^^^
@@ -0,0 +1,27 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar: codec::Codec;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
Ok(().into())
}
}
}
fn main() {
}
@@ -0,0 +1,28 @@
error[E0369]: binary operation `==` cannot be applied to type `&<T as pallet::Config>::Bar`
--> $DIR/call_argument_invalid_bound.rs:20:37
|
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^
|
help: consider further restricting this bound
|
1 | #[frame_support::pallet] + std::cmp::PartialEq
| ^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `<T as pallet::Config>::Bar: Clone` is not satisfied
--> $DIR/call_argument_invalid_bound.rs:20:37
|
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
= note: required by `clone`
error[E0277]: `<T as pallet::Config>::Bar` doesn't implement `std::fmt::Debug`
--> $DIR/call_argument_invalid_bound.rs:20:37
|
20 | fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
| ^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
= help: the trait `std::fmt::Debug` is not implemented for `<T as pallet::Config>::Bar`
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&<T as pallet::Config>::Bar`
= note: required for the cast to the object type `dyn std::fmt::Debug`
@@ -0,0 +1,27 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
fn foo(origin: OriginFor<T>, bar: T::Bar) -> DispatchResultWithPostInfo {
Ok(().into())
}
}
}
fn main() {
}
@@ -0,0 +1,11 @@
error[E0277]: the trait bound `pallet::Call<T>: Decode` is not satisfied
--> $DIR/call_argument_invalid_bound_2.rs:17:12
|
17 | #[pallet::call]
| ^^^^ the trait `Decode` is not implemented for `pallet::Call<T>`
error[E0277]: the trait bound `pallet::Call<T>: pallet::_::_parity_scale_codec::Encode` is not satisfied
--> $DIR/call_argument_invalid_bound_2.rs:17:12
|
17 | #[pallet::call]
| ^^^^ the trait `pallet::_::_parity_scale_codec::Encode` is not implemented for `pallet::Call<T>`
@@ -0,0 +1,29 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
use codec::{Encode, Decode};
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[derive(Encode, Decode)]
struct Bar;
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
Ok(().into())
}
}
}
fn main() {
}
@@ -0,0 +1,26 @@
error[E0369]: binary operation `==` cannot be applied to type `&Bar`
--> $DIR/call_argument_invalid_bound_3.rs:22:37
|
22 | fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
| ^^^
|
= note: an implementation of `std::cmp::PartialEq` might be missing for `&Bar`
error[E0277]: the trait bound `Bar: Clone` is not satisfied
--> $DIR/call_argument_invalid_bound_3.rs:22:37
|
22 | fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
| ^^^ the trait `Clone` is not implemented for `Bar`
|
= note: required by `clone`
error[E0277]: `Bar` doesn't implement `std::fmt::Debug`
--> $DIR/call_argument_invalid_bound_3.rs:22:37
|
22 | fn foo(origin: OriginFor<T>, bar: Bar) -> DispatchResultWithPostInfo {
| ^^^ `Bar` cannot be formatted using `{:?}`
|
= help: the trait `std::fmt::Debug` is not implemented for `Bar`
= note: add `#[derive(Debug)]` or manually implement `std::fmt::Debug`
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&Bar`
= note: required for the cast to the object type `dyn std::fmt::Debug`
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
const Foo: u8 = 3u8;
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::call, only method accepted
--> $DIR/call_invalid_const.rs:17:3
|
17 | const Foo: u8 = 3u8;
| ^^^^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
fn foo(origin: u8) {}
}
}
fn main() {
}
@@ -0,0 +1,11 @@
error: Invalid type: expected `OriginFor<T>`
--> $DIR/call_invalid_origin_type.rs:17:18
|
17 | fn foo(origin: u8) {}
| ^^
error: expected `OriginFor`
--> $DIR/call_invalid_origin_type.rs:17:18
|
17 | fn foo(origin: u8) {}
| ^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, DispatchResultWithPostInfo};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::call, require weight attribute i.e. `#[pallet::weight = $expr]`
--> $DIR/call_missing_weight.rs:17:3
|
17 | fn foo(origin: OriginFor<T>) -> DispatchResultWithPostInfo {}
| ^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
fn foo() {}
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::call, must have at least origin arg
--> $DIR/call_no_origin.rs:17:3
|
17 | fn foo() {}
| ^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {
fn foo(origin: OriginFor<T>) {}
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::call, require return type DispatchResultWithPostInfo
--> $DIR/call_no_return.rs:17:3
|
17 | fn foo(origin: OriginFor<T>) {}
| ^^
@@ -0,0 +1,28 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
use frame_support::pallet_prelude::StorageValue;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
#[pallet::generate_store(trait Store)]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue<_, u8>;
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid duplicated attribute
--> $DIR/duplicate_call_attr.rs:23:12
|
23 | #[pallet::call]
| ^^^^
@@ -0,0 +1,26 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
use frame_support::pallet_prelude::StorageValue;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
#[pallet::generate_store(trait Store)]
#[pallet::generate_store(trait Store)]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue<_, u8>;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::pallet, multiple argument pallet::generate_store found
--> $DIR/duplicate_store_attr.rs:12:33
|
12 | #[pallet::generate_store(trait Store)]
| ^^^^^
@@ -0,0 +1,25 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::error]
pub enum Error<T> {
U8(u8),
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::error, unexpected fields, must be `Unit`
--> $DIR/error_no_fieldless.rs:20:5
|
20 | U8(u8),
| ^^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::error]
pub struct Foo;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::error, expected item enum
--> $DIR/error_wrong_item.rs:19:2
|
19 | pub struct Foo;
| ^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::error]
pub enum Foo<T> {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: expected `Error`
--> $DIR/error_wrong_item_name.rs:19:11
|
19 | pub enum Foo<T> {}
| ^^^
@@ -0,0 +1,28 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, IsType};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar;
type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub enum Event<T: Config> {
B { b: T::Bar },
}
}
fn main() {
}
@@ -0,0 +1,28 @@
error[E0277]: `<T as pallet::Config>::Bar` doesn't implement `std::fmt::Debug`
--> $DIR/event_field_not_member.rs:23:7
|
23 | B { b: T::Bar },
| ^ `<T as pallet::Config>::Bar` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
= help: the trait `std::fmt::Debug` is not implemented for `<T as pallet::Config>::Bar`
= note: required because of the requirements on the impl of `std::fmt::Debug` for `&<T as pallet::Config>::Bar`
= note: required for the cast to the object type `dyn std::fmt::Debug`
error[E0369]: binary operation `==` cannot be applied to type `&<T as pallet::Config>::Bar`
--> $DIR/event_field_not_member.rs:23:7
|
23 | B { b: T::Bar },
| ^
|
help: consider further restricting this bound
|
22 | pub enum Event<T: Config + std::cmp::PartialEq> {
| ^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `<T as pallet::Config>::Bar: Clone` is not satisfied
--> $DIR/event_field_not_member.rs:23:7
|
23 | B { b: T::Bar },
| ^ the trait `Clone` is not implemented for `<T as pallet::Config>::Bar`
|
= note: required by `clone`
@@ -0,0 +1,27 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub enum Event<T: Config> {
B { b: T::Bar },
}
}
fn main() {
}
@@ -0,0 +1,7 @@
error: Invalid usage of Event, `Config` contains no associated type `Event`, but enum `Event` is declared (in use of `#[pallet::event]`). An Event associated type must be declare on trait `Config`.
--> $DIR/event_not_in_trait.rs:1:1
|
1 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -0,0 +1,28 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar;
type Event;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub enum Event<T: Config> {
B { b: T::Bar },
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid `type Event`, associated type `Event` is reserved and must bound: `IsType<<Self as frame_system::Config>::Event>`
--> $DIR/event_type_invalid_bound.rs:9:3
|
9 | type Event;
| ^^^^
@@ -0,0 +1,28 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, IsType};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
type Bar;
type Event: IsType<<Self as frame_system::Config>::Event>;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub enum Event<T: Config> {
B { b: T::Bar },
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid `type Event`, associated type `Event` is reserved and must bound: `From<Event>` or `From<Event<Self>>` or `From<Event<Self, I>>`
--> $DIR/event_type_invalid_bound_2.rs:9:3
|
9 | type Event: IsType<<Self as frame_system::Config>::Event>;
| ^^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub struct Foo;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::event, expected item enum
--> $DIR/event_wrong_item.rs:19:2
|
19 | pub struct Foo;
| ^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::event]
pub enum Foo {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: expected `Event`
--> $DIR/event_wrong_item_name.rs:19:11
|
19 | pub enum Foo {}
| ^^^
@@ -0,0 +1,26 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, GenesisBuild};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::genesis_config]
pub struct GenesisConfig;
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {}
}
fn main() {
}
@@ -0,0 +1,10 @@
error[E0277]: the trait bound `pallet::GenesisConfig: std::default::Default` is not satisfied
--> $DIR/genesis_default_not_satisfied.rs:22:18
|
22 | impl<T: Config> GenesisBuild<T> for GenesisConfig {}
| ^^^^^^^^^^^^^^^ the trait `std::default::Default` is not implemented for `pallet::GenesisConfig`
|
::: $WORKSPACE/frame/support/src/traits.rs
|
| pub trait GenesisBuild<T, I=()>: Default + MaybeSerializeDeserialize {
| ------- required by this bound in `GenesisBuild`
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: `#[pallet::genesis_config]` and `#[pallet::genesis_build]` attributes must be either both used or both not used, instead genesis_config is unused and genesis_build is used
--> $DIR/genesis_inconsistent_build_config.rs:2:1
|
2 | mod pallet {
| ^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::genesis_build]
impl GenesisBuild for GenesisConfig {}
}
fn main() {
}
@@ -0,0 +1,13 @@
error: Invalid genesis builder: expected `GenesisBuild<T>` or `GenesisBuild<T, I>`
--> $DIR/genesis_invalid_generic.rs:19:7
|
19 | impl GenesisBuild for GenesisConfig {}
| ^^^^^^^^^^^^
error: expected `<`
--> $DIR/genesis_invalid_generic.rs:1:1
|
1 | #[frame_support::pallet]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::genesis_build]
impl Foo {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::genesis_build, expected impl<..> GenesisBuild<..> for GenesisConfig<..>
--> $DIR/genesis_wrong_name.rs:19:2
|
19 | impl Foo {}
| ^^^^
@@ -0,0 +1,19 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, PhantomData};
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error[E0107]: wrong number of type arguments: expected 1, found 0
--> $DIR/hooks_invalid_item.rs:12:18
|
12 | impl<T: Config> Hooks for Pallet<T> {}
| ^^^^^ expected 1 type argument
@@ -0,0 +1,20 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,29 @@
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:16:7
|
16 | impl<T: Config> Pallet<T> {}
| ^
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:16:18
|
16 | impl<T: Config> Pallet<T> {}
| ^^^^^^
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:10:20
|
10 | pub struct Pallet<T>(core::marker::PhantomData<T>);
| ^
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:13:47
|
13 | impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
| ^^^^^^
error: Invalid generic declaration, trait is defined with instance but generic use none
--> $DIR/inconsistent_instance_1.rs:13:7
|
13 | impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
| ^
@@ -0,0 +1,20 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T, I = ()>(core::marker::PhantomData<(T, I)>);
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {}
#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {}
}
fn main() {
}
@@ -0,0 +1,29 @@
error: Invalid generic declaration, trait is defined without instance but generic use some
--> $DIR/inconsistent_instance_2.rs:16:7
|
16 | impl<T: Config<I>, I: 'static> Pallet<T, I> {}
| ^
error: Invalid generic declaration, trait is defined without instance but generic use some
--> $DIR/inconsistent_instance_2.rs:16:33
|
16 | impl<T: Config<I>, I: 'static> Pallet<T, I> {}
| ^^^^^^
error: Invalid generic declaration, trait is defined without instance but generic use some
--> $DIR/inconsistent_instance_2.rs:10:20
|
10 | pub struct Pallet<T, I = ()>(core::marker::PhantomData<(T, I)>);
| ^
error: Invalid generic declaration, trait is defined without instance but generic use some
--> $DIR/inconsistent_instance_2.rs:13:62
|
13 | impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {}
| ^^^^^^
error: Invalid generic declaration, trait is defined without instance but generic use some
--> $DIR/inconsistent_instance_2.rs:13:7
|
13 | impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {}
| ^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, ProvideInherent};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::inherent]
impl<T: Config> ProvideInherent for Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,10 @@
error[E0046]: not all trait items implemented, missing: `Call`, `Error`, `INHERENT_IDENTIFIER`, `create_inherent`
--> $DIR/inherent_check_inner_span.rs:19:2
|
19 | impl<T: Config> ProvideInherent for Pallet<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Call`, `Error`, `INHERENT_IDENTIFIER`, `create_inherent` in implementation
|
= help: implement the missing item: `type Call = Type;`
= help: implement the missing item: `type Error = Type;`
= help: implement the missing item: `const INHERENT_IDENTIFIER: [u8; 8] = value;`
= help: implement the missing item: `fn create_inherent(_: &InherentData) -> std::option::Option<<Self as ProvideInherent>::Call> { todo!() }`
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::inherent]
impl Foo {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::inherent, expected impl<..> ProvideInherent for Pallet<..>
--> $DIR/inherent_invalid_item.rs:19:2
|
19 | impl Foo {}
| ^^^^
@@ -0,0 +1,5 @@
#[frame_support::pallet]
mod foo;
fn main() {
}
@@ -0,0 +1,13 @@
error[E0658]: non-inline modules in proc macro input are unstable
--> $DIR/mod_not_inlined.rs:2:1
|
2 | mod foo;
| ^^^^^^^^
|
= note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information
error: Invalid pallet definition, expected mod to be inlined.
--> $DIR/mod_not_inlined.rs:2:1
|
2 | mod foo;
| ^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo;
}
fn main() {
}
@@ -0,0 +1,13 @@
error: free type alias without body
--> $DIR/storage_incomplete_item.rs:19:2
|
19 | type Foo;
| ^^^^^^^^-
| |
| help: provide a definition for the type: `= <type>;`
error[E0433]: failed to resolve: use of undeclared crate or module `pallet`
--> $DIR/storage_incomplete_item.rs:18:4
|
18 | #[pallet::storage]
| ^^^^^^ use of undeclared crate or module `pallet`
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue<u8, u8>;
}
fn main() {
}
@@ -0,0 +1,11 @@
error: Invalid use of `#[pallet::storage]`, the type first generic argument must be `_`, the final argument is automatically set by macro.
--> $DIR/storage_invalid_first_generic.rs:19:29
|
19 | type Foo<T> = StorageValue<u8, u8>;
| ^^
error: expected `_`
--> $DIR/storage_invalid_first_generic.rs:19:29
|
19 | type Foo<T> = StorageValue<u8, u8>;
| ^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = u8;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::storage, expected ident: `StorageValue` or `StorageMap` or `StorageDoubleMap` in order to expand metadata, found `u8`
--> $DIR/storage_not_storage_type.rs:19:16
|
19 | type Foo<T> = u8;
| ^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: pallet::storage unexpected number of generic argument, expected at least 2 args, found none
--> $DIR/storage_value_no_generic.rs:19:16
|
19 | type Foo<T> = StorageValue;
| ^^^^^^^^^^^^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
impl Foo {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::storage, expected item type
--> $DIR/storage_wrong_item.rs:19:2
|
19 | impl Foo {}
| ^^^^
@@ -0,0 +1,25 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
use frame_support::pallet_prelude::StorageValue;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
#[pallet::generate_store(pub trait Store)]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue<_, u8>;
}
fn main() {
}
@@ -0,0 +1,8 @@
error[E0446]: private type `_GeneratedPrefixForStorageFoo<T>` in public interface
--> $DIR/store_trait_leak_private.rs:11:37
|
11 | #[pallet::generate_store(pub trait Store)]
| ^^^^^ can't leak private type
...
21 | type Foo<T> = StorageValue<_, u8>;
| - `_GeneratedPrefixForStorageFoo<T>` declared as private
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
#[pallet::constant]
type U;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,11 @@
error: Invalid usage of `#[pallet::constant]`, syntax must be `type $SomeIdent: Get<$SomeType>;`
--> $DIR/trait_constant_invalid_bound.rs:9:3
|
9 | type U;
| ^^^^
error: expected `:`
--> $DIR/trait_constant_invalid_bound.rs:9:9
|
9 | type U;
| ^
@@ -0,0 +1,23 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {
#[pallet::constant]
const U: u8 = 3;
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::constant in pallet::config, expected type trait item
--> $DIR/trait_invalid_item.rs:9:3
|
9 | const U: u8 = 3;
| ^^^^^
@@ -0,0 +1,21 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config {
}
#[pallet::pallet]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::trait, expected explicit `frame_system::Config` as supertrait, found none. (try `pub trait Config: frame_system::Config { ...` or `pub trait Config<I: 'static>: frame_system::Config { ...`). To disable this check, use `#[pallet::disable_frame_system_supertrait_check]`
--> $DIR/trait_no_supertrait.rs:7:2
|
7 | pub trait Config {
| ^^^
@@ -0,0 +1,25 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, PhantomData};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::type_value] fn Foo() -> u32 {
// Just wrong code to see span
u32::new()
}
}
fn main() {
}
@@ -0,0 +1,5 @@
error[E0599]: no function or associated item named `new` found for type `u32` in the current scope
--> $DIR/type_value_error_in_block.rs:20:8
|
20 | u32::new()
| ^^^ function or associated item not found in `u32`
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, PhantomData};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::type_value] struct Foo;
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::type_value, expected item fn
--> $DIR/type_value_invalid_item.rs:18:24
|
18 | #[pallet::type_value] struct Foo;
| ^^^^^^
@@ -0,0 +1,22 @@
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::{Hooks, PhantomData};
use frame_system::pallet_prelude::BlockNumberFor;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::type_value] fn Foo() {}
}
fn main() {
}
@@ -0,0 +1,5 @@
error: Invalid pallet::type_value, expected return type
--> $DIR/type_value_no_return.rs:18:24
|
18 | #[pallet::type_value] fn Foo() {}
| ^^
@@ -27,22 +27,17 @@ use frame_support::{
};
use sp_core::{H256, sr25519};
mod system;
/// A version that we will check for in the tests
const SOME_TEST_VERSION: PalletVersion = PalletVersion { major: 3000, minor: 30, patch: 13 };
/// Checks that `on_runtime_upgrade` sets the latest pallet version when being called without
/// being provided by the user.
mod module1 {
use super::*;
pub trait Config: system::Config {}
pub trait Config: frame_system::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call where
origin: <T as system::Config>::Origin,
system = system,
origin: <T as frame_system::Config>::Origin,
{}
}
}
@@ -52,12 +47,11 @@ mod module1 {
mod module2 {
use super::*;
pub trait Config<I=DefaultInstance>: system::Config {}
pub trait Config<I=DefaultInstance>: frame_system::Config {}
frame_support::decl_module! {
pub struct Module<T: Config<I>, I: Instance=DefaultInstance> for enum Call where
origin: <T as system::Config>::Origin,
system = system
origin: <T as frame_system::Config>::Origin,
{
fn on_runtime_upgrade() -> Weight {
assert_eq!(crate_to_pallet_version!(), Self::current_version());
@@ -82,26 +76,95 @@ mod module2 {
}
}
#[frame_support::pallet]
mod pallet3 {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config: frame_system::Config {
}
#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_runtime_upgrade() -> Weight {
return 3;
}
}
#[pallet::call]
impl<T: Config> Pallet<T> {
}
}
#[frame_support::pallet]
mod pallet4 {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config<I: 'static = ()>: frame_system::Config {
}
#[pallet::pallet]
pub struct Pallet<T, I=()>(PhantomData<(T, I)>);
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
fn on_runtime_upgrade() -> Weight {
return 3;
}
}
#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
}
}
impl module1::Config for Runtime {}
impl module2::Config for Runtime {}
impl module2::Config<module2::Instance1> for Runtime {}
impl module2::Config<module2::Instance2> for Runtime {}
impl pallet3::Config for Runtime {}
impl pallet4::Config for Runtime {}
impl pallet4::Config<pallet4::Instance1> for Runtime {}
impl pallet4::Config<pallet4::Instance2> for Runtime {}
pub type Signature = sr25519::Signature;
pub type AccountId = <Signature as Verify>::Signer;
pub type BlockNumber = u64;
pub type Index = u64;
impl system::Config for Runtime {
type BaseCallFilter= ();
type Hash = H256;
frame_support::parameter_types!(
pub const BlockHashCount: u32 = 250;
);
impl frame_system::Config for Runtime {
type BaseCallFilter = ();
type Origin = Origin;
type Index = u64;
type BlockNumber = BlockNumber;
type AccountId = AccountId;
type Event = Event;
type PalletInfo = PalletInfo;
type Call = Call;
type Hash = H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type BlockHashCount = BlockHashCount;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
}
frame_support::construct_runtime!(
@@ -110,11 +173,15 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module, Call, Event<T>},
System: frame_system::{Module, Call, Event<T>},
Module1: module1::{Module, Call},
Module2: module2::{Module, Call},
Module2_1: module2::<Instance1>::{Module, Call},
Module2_2: module2::<Instance2>::{Module, Call},
Pallet3: pallet3::{Module, Call},
Pallet4: pallet4::{Module, Call},
Pallet4_1: pallet4::<Instance1>::{Module, Call},
Pallet4_2: pallet4::<Instance2>::{Module, Call},
}
);
@@ -156,6 +223,10 @@ fn on_runtime_upgrade_sets_the_pallet_versions_in_storage() {
check_pallet_version("Module2");
check_pallet_version("Module2_1");
check_pallet_version("Module2_2");
check_pallet_version("Pallet3");
check_pallet_version("Pallet4");
check_pallet_version("Pallet4_1");
check_pallet_version("Pallet4_2");
});
}
@@ -171,6 +242,10 @@ fn on_runtime_upgrade_overwrites_old_version() {
check_pallet_version("Module2");
check_pallet_version("Module2_1");
check_pallet_version("Module2_2");
check_pallet_version("Pallet3");
check_pallet_version("Pallet4");
check_pallet_version("Pallet4_1");
check_pallet_version("Pallet4_2");
});
}
@@ -183,6 +258,10 @@ fn genesis_init_puts_pallet_version_into_storage() {
check_pallet_version("Module2");
check_pallet_version("Module2_1");
check_pallet_version("Module2_2");
check_pallet_version("Pallet3");
check_pallet_version("Pallet4");
check_pallet_version("Pallet4_1");
check_pallet_version("Pallet4_2");
let system_version = System::storage_version().expect("System version should be set");
assert_eq!(System::current_version(), system_version);