1c0e57d984
This commit systematically rebrands various references from Parity Technologies' Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk. Key changes include: - Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks. - Modified internal documentation and code comments to reflect PezkuwiChain naming and structure. - Replaced direct references to with or specific paths within the for XCM, Pezkuwi, and other modules. - Cleaned up deprecated issue and PR references in various and files, particularly in and modules. - Adjusted image and logo URLs in documentation to point to PezkuwiChain assets. - Removed or rephrased comments related to external Polkadot/Substrate PRs and issues. This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
257 lines
6.9 KiB
Rust
257 lines
6.9 KiB
Rust
// This file is part of Bizinikiwi.
|
|
|
|
// Copyright (C) Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
//! RuntimeOrigin tests for construct_runtime macro
|
|
|
|
#![recursion_limit = "128"]
|
|
|
|
use pezframe_support::{
|
|
derive_impl,
|
|
traits::{Contains, OriginTrait},
|
|
};
|
|
use pezsp_runtime::{generic, traits::BlakeTwo256};
|
|
|
|
mod nested {
|
|
#[pezframe_support::pallet(dev_mode)]
|
|
pub mod module {
|
|
use pezframe_support::pezpallet_prelude::*;
|
|
use pezframe_system::pezpallet_prelude::*;
|
|
|
|
#[pallet::pallet]
|
|
pub struct Pallet<T>(_);
|
|
|
|
#[pallet::config]
|
|
pub trait Config: pezframe_system::Config {
|
|
#[allow(deprecated)]
|
|
type RuntimeEvent: From<Event<Self>>
|
|
+ IsType<<Self as pezframe_system::Config>::RuntimeEvent>;
|
|
}
|
|
|
|
#[pallet::call]
|
|
impl<T: Config> Pallet<T> {
|
|
pub fn fail(_origin: OriginFor<T>) -> DispatchResult {
|
|
Err(Error::<T>::Something.into())
|
|
}
|
|
}
|
|
|
|
#[pallet::origin]
|
|
#[derive(
|
|
Clone,
|
|
PartialEq,
|
|
Eq,
|
|
RuntimeDebug,
|
|
Encode,
|
|
Decode,
|
|
DecodeWithMemTracking,
|
|
MaxEncodedLen,
|
|
TypeInfo,
|
|
)]
|
|
pub struct Origin;
|
|
|
|
#[pallet::event]
|
|
pub enum Event<T> {
|
|
A,
|
|
}
|
|
|
|
#[pallet::error]
|
|
pub enum Error<T> {
|
|
Something,
|
|
}
|
|
|
|
#[pallet::genesis_config]
|
|
#[derive(pezframe_support::DefaultNoBound)]
|
|
pub struct GenesisConfig<T: Config> {
|
|
#[serde(skip)]
|
|
pub _config: core::marker::PhantomData<T>,
|
|
}
|
|
|
|
#[pallet::genesis_build]
|
|
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
|
fn build(&self) {}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[pezframe_support::pallet(dev_mode)]
|
|
pub mod module {
|
|
use pezframe_support::pezpallet_prelude::*;
|
|
use pezframe_system::pezpallet_prelude::*;
|
|
|
|
#[pallet::pallet]
|
|
pub struct Pallet<T>(_);
|
|
|
|
#[pallet::config]
|
|
pub trait Config: pezframe_system::Config {
|
|
#[allow(deprecated)]
|
|
type RuntimeEvent: From<Event<Self>> + IsType<<Self as pezframe_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,
|
|
DecodeWithMemTracking,
|
|
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(pezframe_support::DefaultNoBound)]
|
|
pub struct GenesisConfig<T: Config> {
|
|
#[serde(skip)]
|
|
pub _config: core::marker::PhantomData<T>,
|
|
}
|
|
|
|
#[pallet::genesis_build]
|
|
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
|
fn build(&self) {}
|
|
}
|
|
}
|
|
|
|
pub struct BaseCallFilter;
|
|
impl Contains<RuntimeCall> for BaseCallFilter {
|
|
fn contains(c: &RuntimeCall) -> bool {
|
|
match c {
|
|
RuntimeCall::NestedModule(_) => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
}
|
|
|
|
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>;
|
|
|
|
pezframe_support::construct_runtime!(
|
|
pub enum RuntimeOriginTest
|
|
{
|
|
System: pezframe_system,
|
|
NestedModule: nested::module,
|
|
Module: module,
|
|
}
|
|
);
|
|
|
|
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
|
impl pezframe_system::Config for RuntimeOriginTest {
|
|
type BaseCallFilter = BaseCallFilter;
|
|
type Block = Block;
|
|
type RuntimeOrigin = RuntimeOrigin;
|
|
type RuntimeCall = RuntimeCall;
|
|
type RuntimeEvent = RuntimeEvent;
|
|
type PalletInfo = PalletInfo;
|
|
type OnSetCode = ();
|
|
}
|
|
|
|
impl nested::module::Config for RuntimeOriginTest {
|
|
type RuntimeEvent = RuntimeEvent;
|
|
}
|
|
impl module::Config for RuntimeOriginTest {
|
|
type RuntimeEvent = RuntimeEvent;
|
|
}
|
|
|
|
#[test]
|
|
fn origin_default_filter() {
|
|
let accepted_call = nested::module::Call::fail {}.into();
|
|
let rejected_call = module::Call::fail {}.into();
|
|
|
|
assert_eq!(RuntimeOrigin::root().filter_call(&accepted_call), true);
|
|
assert_eq!(RuntimeOrigin::root().filter_call(&rejected_call), true);
|
|
assert_eq!(RuntimeOrigin::none().filter_call(&accepted_call), true);
|
|
assert_eq!(RuntimeOrigin::none().filter_call(&rejected_call), false);
|
|
assert_eq!(RuntimeOrigin::signed(0).filter_call(&accepted_call), true);
|
|
assert_eq!(RuntimeOrigin::signed(0).filter_call(&rejected_call), false);
|
|
assert_eq!(RuntimeOrigin::from(Some(0)).filter_call(&accepted_call), true);
|
|
assert_eq!(RuntimeOrigin::from(Some(0)).filter_call(&rejected_call), false);
|
|
assert_eq!(RuntimeOrigin::from(None).filter_call(&accepted_call), true);
|
|
assert_eq!(RuntimeOrigin::from(None).filter_call(&rejected_call), false);
|
|
assert_eq!(RuntimeOrigin::from(nested::module::Origin).filter_call(&accepted_call), true);
|
|
assert_eq!(RuntimeOrigin::from(nested::module::Origin).filter_call(&rejected_call), false);
|
|
|
|
let mut origin = RuntimeOrigin::from(Some(0));
|
|
origin.add_filter(|c| matches!(c, RuntimeCall::Module(_)));
|
|
assert_eq!(origin.filter_call(&accepted_call), false);
|
|
assert_eq!(origin.filter_call(&rejected_call), false);
|
|
|
|
// 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(pezframe_support_test::RawOrigin::Root)));
|
|
|
|
// Root origin bypass all filter.
|
|
assert_eq!(origin.filter_call(&accepted_call), true);
|
|
assert_eq!(origin.filter_call(&rejected_call), true);
|
|
|
|
origin.set_caller_from(RuntimeOrigin::from(Some(0)));
|
|
|
|
// Back to another signed origin, the filtered are now effective again
|
|
assert_eq!(origin.filter_call(&accepted_call), true);
|
|
assert_eq!(origin.filter_call(&rejected_call), false);
|
|
|
|
origin.set_caller_from(RuntimeOrigin::root());
|
|
origin.reset_filter();
|
|
|
|
// Root origin bypass all filter, even when they are reset.
|
|
assert_eq!(origin.filter_call(&accepted_call), true);
|
|
assert_eq!(origin.filter_call(&rejected_call), true);
|
|
}
|