mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 17:25:41 +00:00
Make pallets use construct_runtime (#7950)
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: David <dvdplm@gmail.com>
This commit is contained in:
committed by
GitHub
parent
703c263079
commit
48810cd75b
@@ -28,7 +28,7 @@ frame-benchmarking = { version = "2.0.0", default-features = false, path = "../b
|
|||||||
sp-core = { version = "2.0.0", path = "../../primitives/core" }
|
sp-core = { version = "2.0.0", path = "../../primitives/core" }
|
||||||
sp-std = { version = "2.0.0", path = "../../primitives/std" }
|
sp-std = { version = "2.0.0", path = "../../primitives/std" }
|
||||||
sp-io = { version = "2.0.0", path = "../../primitives/io" }
|
sp-io = { version = "2.0.0", path = "../../primitives/io" }
|
||||||
pallet-balances = { version = "2.0.0", default-features = false, path = "../balances" }
|
pallet-balances = { version = "2.0.0", path = "../balances" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
|
|||||||
@@ -1084,30 +1084,28 @@ impl<T: Config> Module<T> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate as pallet_assets;
|
||||||
|
|
||||||
use frame_support::{impl_outer_origin, assert_ok, assert_noop, parameter_types, impl_outer_event};
|
use frame_support::{assert_ok, assert_noop, parameter_types};
|
||||||
use sp_core::H256;
|
use sp_core::H256;
|
||||||
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
|
use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};
|
||||||
use pallet_balances::Error as BalancesError;
|
use pallet_balances::Error as BalancesError;
|
||||||
|
|
||||||
mod pallet_assets {
|
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||||
pub use crate::Event;
|
type Block = frame_system::mocking::MockBlock<Test>;
|
||||||
}
|
|
||||||
|
|
||||||
impl_outer_event! {
|
frame_support::construct_runtime!(
|
||||||
pub enum Event for Test {
|
pub enum Test where
|
||||||
frame_system<T>,
|
Block = Block,
|
||||||
pallet_balances<T>,
|
NodeBlock = Block,
|
||||||
pallet_assets<T>,
|
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||||
|
{
|
||||||
|
System: frame_system::{Module, Call, Config, Storage, Event<T>},
|
||||||
|
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
|
||||||
|
Assets: pallet_assets::{Module, Call, Storage, Event<T>},
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
|
|
||||||
impl_outer_origin! {
|
|
||||||
pub enum Origin for Test where system = frame_system {}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq)]
|
|
||||||
pub struct Test;
|
|
||||||
parameter_types! {
|
parameter_types! {
|
||||||
pub const BlockHashCount: u64 = 250;
|
pub const BlockHashCount: u64 = 250;
|
||||||
}
|
}
|
||||||
@@ -1118,7 +1116,7 @@ mod tests {
|
|||||||
type DbWeight = ();
|
type DbWeight = ();
|
||||||
type Origin = Origin;
|
type Origin = Origin;
|
||||||
type Index = u64;
|
type Index = u64;
|
||||||
type Call = ();
|
type Call = Call;
|
||||||
type BlockNumber = u64;
|
type BlockNumber = u64;
|
||||||
type Hash = H256;
|
type Hash = H256;
|
||||||
type Hashing = BlakeTwo256;
|
type Hashing = BlakeTwo256;
|
||||||
@@ -1128,7 +1126,7 @@ mod tests {
|
|||||||
type Event = Event;
|
type Event = Event;
|
||||||
type BlockHashCount = BlockHashCount;
|
type BlockHashCount = BlockHashCount;
|
||||||
type Version = ();
|
type Version = ();
|
||||||
type PalletInfo = ();
|
type PalletInfo = PalletInfo;
|
||||||
type AccountData = pallet_balances::AccountData<u64>;
|
type AccountData = pallet_balances::AccountData<u64>;
|
||||||
type OnNewAccount = ();
|
type OnNewAccount = ();
|
||||||
type OnKilledAccount = ();
|
type OnKilledAccount = ();
|
||||||
@@ -1171,9 +1169,6 @@ mod tests {
|
|||||||
type MetadataDepositPerByte = MetadataDepositPerByte;
|
type MetadataDepositPerByte = MetadataDepositPerByte;
|
||||||
type WeightInfo = ();
|
type WeightInfo = ();
|
||||||
}
|
}
|
||||||
type System = frame_system::Module<Test>;
|
|
||||||
type Balances = pallet_balances::Module<Test>;
|
|
||||||
type Assets = Module<Test>;
|
|
||||||
|
|
||||||
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
|
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
|
||||||
frame_system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
|
frame_system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
|
||||||
|
|||||||
@@ -965,7 +965,7 @@ mod tests {
|
|||||||
use hex_literal::hex;
|
use hex_literal::hex;
|
||||||
use sp_core::H256;
|
use sp_core::H256;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
traits::{BlakeTwo256, IdentityLookup, Block as BlockT}, testing::Header,
|
traits::{BlakeTwo256, IdentityLookup}, testing::Header,
|
||||||
BuildStorage,
|
BuildStorage,
|
||||||
};
|
};
|
||||||
use crate as collective;
|
use crate as collective;
|
||||||
|
|||||||
@@ -1047,7 +1047,7 @@ mod tests {
|
|||||||
use sp_core::H256;
|
use sp_core::H256;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
testing::Header, BuildStorage, DispatchResult,
|
testing::Header, BuildStorage, DispatchResult,
|
||||||
traits::{BlakeTwo256, IdentityLookup, Block as BlockT},
|
traits::{BlakeTwo256, IdentityLookup},
|
||||||
};
|
};
|
||||||
use crate as elections_phragmen;
|
use crate as elections_phragmen;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ use frame_support::{
|
|||||||
};
|
};
|
||||||
use sp_core::H256;
|
use sp_core::H256;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
BuildStorage, testing::Header, traits::{BlakeTwo256, IdentityLookup, Block as BlockT},
|
BuildStorage, testing::Header, traits::{BlakeTwo256, IdentityLookup},
|
||||||
};
|
};
|
||||||
use crate as elections;
|
use crate as elections;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ use frame_support::{
|
|||||||
};
|
};
|
||||||
use frame_system as system;
|
use frame_system as system;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
traits::{IdentityLookup, Block as BlockT},
|
traits::IdentityLookup,
|
||||||
testing::{Header, UintAuthorityId},
|
testing::{Header, UintAuthorityId},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -302,6 +302,11 @@ pub fn decl_storage(input: TokenStream) -> TokenStream {
|
|||||||
/// The population of the genesis storage depends on the order of modules. So, if one of your
|
/// The population of the genesis storage depends on the order of modules. So, if one of your
|
||||||
/// modules depends on another module, the module that is depended upon needs to come before
|
/// modules depends on another module, the module that is depended upon needs to come before
|
||||||
/// the module depending on it.
|
/// the module depending on it.
|
||||||
|
///
|
||||||
|
/// # Type definitions
|
||||||
|
///
|
||||||
|
/// * The macro generates a type alias for each pallet to their `Module` (or `Pallet`).
|
||||||
|
/// E.g. `type System = frame_system::Module<Runtime>`
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn construct_runtime(input: TokenStream) -> TokenStream {
|
pub fn construct_runtime(input: TokenStream) -> TokenStream {
|
||||||
construct_runtime::construct_runtime(input)
|
construct_runtime::construct_runtime(input)
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ macro_rules! impl_outer_inherent {
|
|||||||
fn check_extrinsics(&self, block: &$block) -> $crate::inherent::CheckInherentsResult {
|
fn check_extrinsics(&self, block: &$block) -> $crate::inherent::CheckInherentsResult {
|
||||||
use $crate::inherent::{ProvideInherent, IsFatalError};
|
use $crate::inherent::{ProvideInherent, IsFatalError};
|
||||||
use $crate::traits::IsSubType;
|
use $crate::traits::IsSubType;
|
||||||
|
use $crate::sp_runtime::traits::Block as _;
|
||||||
|
|
||||||
let mut result = $crate::inherent::CheckInherentsResult::new();
|
let mut result = $crate::inherent::CheckInherentsResult::new();
|
||||||
for xt in block.extrinsics() {
|
for xt in block.extrinsics() {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#![recursion_limit="128"]
|
#![recursion_limit="128"]
|
||||||
|
|
||||||
use sp_runtime::{generic, traits::{BlakeTwo256, Block as _, Verify}, DispatchError};
|
use sp_runtime::{generic, traits::{BlakeTwo256, Verify}, DispatchError};
|
||||||
use sp_core::{H256, sr25519};
|
use sp_core::{H256, sr25519};
|
||||||
use sp_std::cell::RefCell;
|
use sp_std::cell::RefCell;
|
||||||
use frame_support::traits::PalletInfo as _;
|
use frame_support::traits::PalletInfo as _;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#![recursion_limit="128"]
|
#![recursion_limit="128"]
|
||||||
|
|
||||||
use codec::{Codec, EncodeLike, Encode, Decode};
|
use codec::{Codec, EncodeLike, Encode, Decode};
|
||||||
use sp_runtime::{generic, BuildStorage, traits::{BlakeTwo256, Block as _, Verify}};
|
use sp_runtime::{generic, BuildStorage, traits::{BlakeTwo256, Verify}};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
Parameter, traits::Get, parameter_types,
|
Parameter, traits::Get, parameter_types,
|
||||||
metadata::{
|
metadata::{
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use frame_support::sp_runtime::generic;
|
use frame_support::sp_runtime::generic;
|
||||||
use frame_support::sp_runtime::traits::{BlakeTwo256, Block as _, Verify};
|
use frame_support::sp_runtime::traits::{BlakeTwo256, Verify};
|
||||||
use frame_support::codec::{Encode, Decode};
|
use frame_support::codec::{Encode, Decode};
|
||||||
use sp_core::{H256, sr25519};
|
use sp_core::{H256, sr25519};
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use frame_support::{
|
|||||||
dispatch::{UnfilteredDispatchable, Parameter},
|
dispatch::{UnfilteredDispatchable, Parameter},
|
||||||
storage::unhashed,
|
storage::unhashed,
|
||||||
};
|
};
|
||||||
use sp_runtime::{traits::Block as _, DispatchError};
|
use sp_runtime::DispatchError;
|
||||||
use sp_io::{TestExternalities, hashing::{twox_64, twox_128, blake2_128}};
|
use sp_io::{TestExternalities, hashing::{twox_64, twox_128, blake2_128}};
|
||||||
|
|
||||||
pub struct SomeType1;
|
pub struct SomeType1;
|
||||||
|
|||||||
@@ -15,8 +15,6 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use sp_runtime::traits::Block as _;
|
|
||||||
|
|
||||||
pub trait SomeAssociation {
|
pub trait SomeAssociation {
|
||||||
type A: frame_support::dispatch::Parameter + Default;
|
type A: frame_support::dispatch::Parameter + Default;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,6 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
use sp_runtime::traits::Block as _;
|
|
||||||
|
|
||||||
mod pallet_old {
|
mod pallet_old {
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
decl_storage, decl_error, decl_event, decl_module, weights::Weight, traits::Get, Parameter
|
decl_storage, decl_error, decl_event, decl_module, weights::Weight, traits::Get, Parameter
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use frame_support::{
|
|||||||
dispatch::UnfilteredDispatchable,
|
dispatch::UnfilteredDispatchable,
|
||||||
storage::unhashed,
|
storage::unhashed,
|
||||||
};
|
};
|
||||||
use sp_runtime::{traits::Block as _, DispatchError};
|
use sp_runtime::DispatchError;
|
||||||
use sp_io::{TestExternalities, hashing::{twox_64, twox_128, blake2_128}};
|
use sp_io::{TestExternalities, hashing::{twox_64, twox_128, blake2_128}};
|
||||||
|
|
||||||
#[frame_support::pallet]
|
#[frame_support::pallet]
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#![recursion_limit="128"]
|
#![recursion_limit="128"]
|
||||||
|
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use sp_runtime::{generic, traits::{BlakeTwo256, Block as _, Verify}, BuildStorage};
|
use sp_runtime::{generic, traits::{BlakeTwo256, Verify}, BuildStorage};
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
traits::{PALLET_VERSION_STORAGE_KEY_POSTFIX, PalletVersion, OnRuntimeUpgrade, GetPalletVersion},
|
traits::{PALLET_VERSION_STORAGE_KEY_POSTFIX, PalletVersion, OnRuntimeUpgrade, GetPalletVersion},
|
||||||
crate_to_pallet_version, weights::Weight,
|
crate_to_pallet_version, weights::Weight,
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ mod tests {
|
|||||||
use crate as pallet_test;
|
use crate as pallet_test;
|
||||||
|
|
||||||
use frame_support::parameter_types;
|
use frame_support::parameter_types;
|
||||||
use sp_runtime::traits::Block;
|
|
||||||
|
|
||||||
type SignedExtra = (
|
type SignedExtra = (
|
||||||
frame_system::CheckEra<Runtime>,
|
frame_system::CheckEra<Runtime>,
|
||||||
|
|||||||
@@ -112,6 +112,8 @@ mod extensions;
|
|||||||
pub mod weights;
|
pub mod weights;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub mod mocking;
|
||||||
|
|
||||||
|
|
||||||
pub use extensions::{
|
pub use extensions::{
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// This file is part of Substrate.
|
||||||
|
|
||||||
|
// Copyright (C) 2021 Parity Technologies (UK) Ltd.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
//! Provide types to help defining a mock environment when testing pallets.
|
||||||
|
|
||||||
|
use sp_runtime::generic;
|
||||||
|
|
||||||
|
/// An unchecked extrinsic type to be used in tests.
|
||||||
|
pub type MockUncheckedExtrinsic<T, Signature = (), Extra = ()> = generic::UncheckedExtrinsic<
|
||||||
|
<T as crate::Config>::AccountId, <T as crate::Config>::Call, Signature, Extra,
|
||||||
|
>;
|
||||||
|
|
||||||
|
/// An implementation of `sp_runtime::traits::Block` to be used in tests.
|
||||||
|
pub type MockBlock<T> = generic::Block<
|
||||||
|
generic::Header<<T as crate::Config>::BlockNumber, sp_runtime::traits::BlakeTwo256>,
|
||||||
|
MockUncheckedExtrinsic<T>,
|
||||||
|
>;
|
||||||
Reference in New Issue
Block a user