frame-support-test: migrate tests from decl_* macros to the new pallet macros (#12445)

* frame-support: migrate some tests from decl macros to new pallet attribute macros

* Remove useless type alias

* Remove useless type alias

* frame-support-test: migrate old decl_macros to new pallet attribute macros

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix features

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Remove deprecated stuff

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update UI tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix UI test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Fix test

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update UI tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: parity-processbot <>
This commit is contained in:
Qinxuan Chen
2023-05-09 17:22:55 +08:00
committed by GitHub
parent 1d42bdf664
commit dcc0858f67
41 changed files with 1139 additions and 2988 deletions
+120 -110
View File
@@ -19,119 +19,123 @@
#![recursion_limit = "128"]
use codec::MaxEncodedLen;
use frame_support::traits::{Contains, OriginTrait};
use scale_info::TypeInfo;
use sp_core::{sr25519, H256};
use sp_runtime::{generic, traits::BlakeTwo256};
mod system;
mod nested {
use super::*;
#[frame_support::pallet(dev_mode)]
pub mod module {
use self::frame_system::pallet_prelude::*;
use frame_support::pallet_prelude::*;
use frame_support_test as frame_system;
use super::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
pub trait Config: system::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call
where origin: <T as system::Config>::RuntimeOrigin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
Err(Error::<T>::Something.into())
}
}
#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
#[derive(
Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen,
)]
pub struct Origin;
frame_support::decl_event! {
pub enum Event {
A,
}
}
frame_support::decl_error! {
pub enum Error for Module<T: Config> {
Something
}
}
frame_support::decl_storage! {
trait Store for Module<T: Config> as Module {}
add_extra_genesis {
build(|_config| {})
}
}
}
}
pub mod module {
use super::*;
pub trait Config: system::Config {}
frame_support::decl_module! {
pub struct Module<T: Config> for enum Call
where origin: <T as system::Config>::RuntimeOrigin, system=system
{
#[weight = 0]
pub fn fail(_origin) -> frame_support::dispatch::DispatchResult {
#[pallet::call]
impl<T: Config> Pallet<T> {
pub fn fail(_origin: OriginFor<T>) -> DispatchResult {
Err(Error::<T>::Something.into())
}
#[weight = 0]
pub fn aux_1(_origin, #[compact] _data: u32) -> frame_support::dispatch::DispatchResult {
unreachable!()
}
#[weight = 0]
pub fn aux_2(_origin, _data: i32, #[compact] _data2: u32) -> frame_support::dispatch::DispatchResult {
unreachable!()
}
#[weight = 0]
fn aux_3(_origin, _data: i32, _data2: String) -> frame_support::dispatch::DispatchResult {
unreachable!()
}
#[weight = 3]
fn aux_4(_origin) -> frame_support::dispatch::DispatchResult { unreachable!() }
#[weight = (5, frame_support::dispatch::DispatchClass::Operational)]
fn operational(_origin) { unreachable!() }
}
}
#[derive(
Clone, PartialEq, Eq, Debug, codec::Encode, codec::Decode, TypeInfo, MaxEncodedLen,
)]
pub struct Origin<T>(pub core::marker::PhantomData<T>);
#[pallet::origin]
#[derive(Clone, PartialEq, Eq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub struct Origin;
frame_support::decl_event! {
pub enum Event {
#[pallet::event]
pub enum Event<T> {
A,
}
}
frame_support::decl_error! {
pub enum Error for Module<T: Config> {
Something
#[pallet::error]
pub enum Error<T> {
Something,
}
}
frame_support::decl_storage! {
trait Store for Module<T: Config> as Module {}
add_extra_genesis {
build(|_config| {})
#[pallet::genesis_config]
#[derive(Default)]
pub struct GenesisConfig {}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {}
}
}
}
impl nested::module::Config for RuntimeOriginTest {}
impl module::Config for RuntimeOriginTest {}
#[frame_support::pallet(dev_mode)]
pub mod module {
use self::frame_system::pallet_prelude::*;
use frame_support::pallet_prelude::*;
use frame_support_test as frame_system;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
#[pallet::call]
impl<T: Config> Pallet<T> {
pub fn fail(_origin: OriginFor<T>) -> DispatchResult {
Err(Error::<T>::Something.into())
}
pub fn aux_1(_origin: OriginFor<T>, #[pallet::compact] _data: u32) -> DispatchResult {
unreachable!()
}
pub fn aux_2(
_origin: OriginFor<T>,
_data: i32,
#[pallet::compact] _data2: u32,
) -> DispatchResult {
unreachable!()
}
#[pallet::weight(0)]
pub fn aux_3(_origin: OriginFor<T>, _data: i32, _data2: String) -> DispatchResult {
unreachable!()
}
#[pallet::weight(3)]
pub fn aux_4(_origin: OriginFor<T>) -> DispatchResult {
unreachable!()
}
#[pallet::weight((5, DispatchClass::Operational))]
pub fn operational(_origin: OriginFor<T>) -> DispatchResult {
unreachable!()
}
}
#[pallet::origin]
#[derive(Clone, PartialEq, Eq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub struct Origin<T>(pub PhantomData<T>);
#[pallet::event]
pub enum Event<T> {
A,
}
#[pallet::error]
pub enum Error<T> {
Something,
}
#[pallet::genesis_config]
#[derive(Default)]
pub struct GenesisConfig {}
#[pallet::genesis_build]
impl<T: Config> GenesisBuild<T> for GenesisConfig {
fn build(&self) {}
}
}
pub struct BaseCallFilter;
impl Contains<RuntimeCall> for BaseCallFilter {
@@ -143,17 +147,11 @@ impl Contains<RuntimeCall> for BaseCallFilter {
}
}
impl system::Config for RuntimeOriginTest {
type BaseCallFilter = BaseCallFilter;
type Hash = H256;
type RuntimeOrigin = RuntimeOrigin;
type BlockNumber = BlockNumber;
type AccountId = u32;
type RuntimeEvent = RuntimeEvent;
type PalletInfo = PalletInfo;
type RuntimeCall = RuntimeCall;
type DbWeight = ();
}
pub type BlockNumber = u32;
pub type AccountId = u32;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, RuntimeCall, (), ()>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
frame_support::construct_runtime!(
pub enum RuntimeOriginTest where
@@ -161,17 +159,29 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet, Event<T>, Origin<T>},
NestedModule: nested::module::{Pallet, Origin, Call},
Module: module::{Pallet, Origin<T>, Call},
System: frame_support_test,
NestedModule: nested::module,
Module: module,
}
);
pub type Signature = sr25519::Signature;
pub type BlockNumber = u64;
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<u32, RuntimeCall, Signature, ()>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
impl frame_support_test::Config for RuntimeOriginTest {
type BlockNumber = BlockNumber;
type AccountId = AccountId;
type BaseCallFilter = BaseCallFilter;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type PalletInfo = PalletInfo;
type DbWeight = ();
}
impl nested::module::Config for RuntimeOriginTest {
type RuntimeEvent = RuntimeEvent;
}
impl module::Config for RuntimeOriginTest {
type RuntimeEvent = RuntimeEvent;
}
#[test]
fn origin_default_filter() {
@@ -199,7 +209,7 @@ fn origin_default_filter() {
// Now test for root origin and filters:
let mut origin = RuntimeOrigin::from(Some(0));
origin.set_caller_from(RuntimeOrigin::root());
assert!(matches!(origin.caller, OriginCaller::system(system::RawOrigin::Root)));
assert!(matches!(origin.caller, OriginCaller::system(frame_support_test::RawOrigin::Root)));
// Root origin bypass all filter.
assert_eq!(origin.filter_call(&accepted_call), true);