feat: Rebrand Polkadot/Substrate references to PezkuwiChain
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.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
[package]
|
||||
name = "pezpallet-tx-pause"
|
||||
version = "9.0.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license = "Apache-2.0"
|
||||
homepage.workspace = true
|
||||
repository.workspace = true
|
||||
description = "FRAME transaction pause pallet"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[dependencies]
|
||||
codec = { features = ["derive"], workspace = true }
|
||||
docify = { workspace = true }
|
||||
frame = { workspace = true, features = ["runtime"] }
|
||||
scale-info = { features = ["derive"], workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
pezpallet-balances = { workspace = true, default-features = true }
|
||||
pezpallet-proxy = { workspace = true, default-features = true }
|
||||
pezpallet-utility = { workspace = true, default-features = true }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = ["codec/std", "frame/std", "scale-info/std"]
|
||||
runtime-benchmarks = [
|
||||
"frame/runtime-benchmarks",
|
||||
"pezpallet-balances/runtime-benchmarks",
|
||||
"pezpallet-proxy/runtime-benchmarks",
|
||||
"pezpallet-utility/runtime-benchmarks",
|
||||
]
|
||||
try-runtime = [
|
||||
"frame/try-runtime",
|
||||
"pezpallet-balances/try-runtime",
|
||||
"pezpallet-proxy/try-runtime",
|
||||
"pezpallet-utility/try-runtime",
|
||||
]
|
||||
@@ -0,0 +1,60 @@
|
||||
// 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.
|
||||
|
||||
#![cfg(feature = "runtime-benchmarks")]
|
||||
|
||||
use super::{Pallet as TxPause, *};
|
||||
use alloc::vec;
|
||||
use frame::benchmarking::prelude::*;
|
||||
|
||||
#[benchmarks]
|
||||
mod benchmarks {
|
||||
use super::*;
|
||||
|
||||
#[benchmark]
|
||||
fn pause() {
|
||||
let origin = T::PauseOrigin::try_successful_origin()
|
||||
.expect("Tx-pause pallet is not usable without pause origin");
|
||||
let full_name = name::<T>();
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, full_name.clone());
|
||||
|
||||
assert!(PausedCalls::<T>::get(full_name).is_some());
|
||||
}
|
||||
|
||||
#[benchmark]
|
||||
fn unpause() {
|
||||
let unpause_origin = T::UnpauseOrigin::try_successful_origin()
|
||||
.expect("Tx-pause pallet is not usable without pause origin");
|
||||
let full_name = name::<T>();
|
||||
TxPause::<T>::do_pause(full_name.clone()).unwrap();
|
||||
|
||||
#[extrinsic_call]
|
||||
_(unpause_origin as T::RuntimeOrigin, full_name.clone());
|
||||
|
||||
assert!(PausedCalls::<T>::get(full_name).is_none());
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(TxPause, crate::mock::new_test_ext(), crate::mock::Test);
|
||||
}
|
||||
|
||||
/// Longest possible name.
|
||||
fn name<T: Config>() -> RuntimeCallNameOf<T> {
|
||||
let max_len = T::MaxNameLen::get() as usize;
|
||||
(vec![1; max_len].try_into().unwrap(), vec![1; max_len].try_into().unwrap())
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
// 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.
|
||||
|
||||
//! # Transaction Pause
|
||||
//!
|
||||
//! Allows dynamic, chain-state-based pausing and unpausing of specific extrinsics via call filters.
|
||||
//!
|
||||
//! ## Pallet API
|
||||
//!
|
||||
//! See the [`pallet`] module for more information about the interfaces this pallet exposes,
|
||||
//! including its configuration trait, dispatchables, storage items, events, and errors.
|
||||
//!
|
||||
//! ## Overview
|
||||
//!
|
||||
//! A dynamic call filter that can be controlled with extrinsics.
|
||||
//!
|
||||
//! Pausing an extrinsic means that the extrinsic CANNOT be called again until it is unpaused.
|
||||
//! The exception is calls that use `dispatch_bypass_filter`, typically only with the root origin.
|
||||
//!
|
||||
//! ### Primary Features
|
||||
//!
|
||||
//! - Calls that should never be paused can be added to a whitelist.
|
||||
//! - Separate origins are configurable for pausing and pausing.
|
||||
//! - Pausing is triggered using the string representation of the call.
|
||||
//! - Pauses can target a single extrinsic or an entire pallet.
|
||||
//! - Pauses can target future extrinsics or pallets.
|
||||
//!
|
||||
//! ### Example
|
||||
//!
|
||||
//! Configuration of call filters:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! impl pezframe_system::Config for Runtime {
|
||||
//! // …
|
||||
//! type BaseCallFilter = InsideBoth<DefaultFilter, TxPause>;
|
||||
//! // …
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! Pause specific all:
|
||||
#![doc = docify::embed!("src/tests.rs", can_pause_specific_call)]
|
||||
//!
|
||||
//! Unpause specific all:
|
||||
#![doc = docify::embed!("src/tests.rs", can_unpause_specific_call)]
|
||||
//!
|
||||
//! Pause all calls in a pallet:
|
||||
#![doc = docify::embed!("src/tests.rs", can_pause_all_calls_in_pallet_except_on_whitelist)]
|
||||
//!
|
||||
//! ## Low Level / Implementation Details
|
||||
//!
|
||||
//! ### Use Cost
|
||||
//!
|
||||
//! A storage map (`PausedCalls`) is used to store currently paused calls.
|
||||
//! Using the call filter will require a db read of that storage on each extrinsic.
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![deny(rustdoc::broken_intra_doc_links)]
|
||||
|
||||
mod benchmarking;
|
||||
pub mod mock;
|
||||
mod tests;
|
||||
pub mod weights;
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use frame::{
|
||||
prelude::*,
|
||||
traits::{TransactionPause, TransactionPauseError},
|
||||
};
|
||||
pub use pallet::*;
|
||||
pub use weights::*;
|
||||
|
||||
/// The stringy name of a pallet from [`GetCallMetadata`] for [`Config::RuntimeCall`] variants.
|
||||
pub type PalletNameOf<T> = BoundedVec<u8, <T as Config>::MaxNameLen>;
|
||||
|
||||
/// The stringy name of a call (within a pallet) from [`GetCallMetadata`] for
|
||||
/// [`Config::RuntimeCall`] variants.
|
||||
pub type PalletCallNameOf<T> = BoundedVec<u8, <T as Config>::MaxNameLen>;
|
||||
|
||||
/// A fully specified pallet ([`PalletNameOf`]) and optional call ([`PalletCallNameOf`])
|
||||
/// to partially or fully specify an item a variant of a [`Config::RuntimeCall`].
|
||||
pub type RuntimeCallNameOf<T> = (PalletNameOf<T>, PalletCallNameOf<T>);
|
||||
|
||||
#[frame::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: pezframe_system::Config {
|
||||
/// The overarching event type.
|
||||
#[allow(deprecated)]
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as pezframe_system::Config>::RuntimeEvent>;
|
||||
|
||||
/// The overarching call type.
|
||||
type RuntimeCall: Parameter
|
||||
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
|
||||
+ GetDispatchInfo
|
||||
+ GetCallMetadata
|
||||
+ From<pezframe_system::Call<Self>>
|
||||
+ IsSubType<Call<Self>>
|
||||
+ IsType<<Self as pezframe_system::Config>::RuntimeCall>;
|
||||
|
||||
/// The only origin that can pause calls.
|
||||
type PauseOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// The only origin that can un-pause calls.
|
||||
type UnpauseOrigin: EnsureOrigin<Self::RuntimeOrigin>;
|
||||
|
||||
/// Contains all calls that cannot be paused.
|
||||
///
|
||||
/// The `TxMode` pallet cannot pause its own calls, and does not need to be explicitly
|
||||
/// added here.
|
||||
type WhitelistedCalls: Contains<RuntimeCallNameOf<Self>>;
|
||||
|
||||
/// Maximum length for pallet name and call name SCALE encoded string names.
|
||||
///
|
||||
/// TOO LONG NAMES WILL BE TREATED AS PAUSED.
|
||||
#[pallet::constant]
|
||||
type MaxNameLen: Get<u32>;
|
||||
|
||||
// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
}
|
||||
|
||||
/// The set of calls that are explicitly paused.
|
||||
#[pallet::storage]
|
||||
pub type PausedCalls<T: Config> =
|
||||
StorageMap<_, Blake2_128Concat, RuntimeCallNameOf<T>, (), OptionQuery>;
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
/// The call is paused.
|
||||
IsPaused,
|
||||
|
||||
/// The call is unpaused.
|
||||
IsUnpaused,
|
||||
|
||||
/// The call is whitelisted and cannot be paused.
|
||||
Unpausable,
|
||||
|
||||
// The pallet or call does not exist in the runtime.
|
||||
NotFound,
|
||||
}
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// This pallet, or a specific call is now paused.
|
||||
CallPaused { full_name: RuntimeCallNameOf<T> },
|
||||
/// This pallet, or a specific call is now unpaused.
|
||||
CallUnpaused { full_name: RuntimeCallNameOf<T> },
|
||||
}
|
||||
|
||||
/// Configure the initial state of this pallet in the genesis block.
|
||||
#[pallet::genesis_config]
|
||||
#[derive(DefaultNoBound)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
/// Initially paused calls.
|
||||
pub paused: Vec<RuntimeCallNameOf<T>>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
|
||||
fn build(&self) {
|
||||
for call in &self.paused {
|
||||
Pallet::<T>::ensure_can_pause(&call).expect("Genesis data is known good; qed");
|
||||
PausedCalls::<T>::insert(&call, ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Pause a call.
|
||||
///
|
||||
/// Can only be called by [`Config::PauseOrigin`].
|
||||
/// Emits an [`Event::CallPaused`] event on success.
|
||||
#[pallet::call_index(0)]
|
||||
#[pallet::weight(T::WeightInfo::pause())]
|
||||
pub fn pause(origin: OriginFor<T>, full_name: RuntimeCallNameOf<T>) -> DispatchResult {
|
||||
T::PauseOrigin::ensure_origin(origin)?;
|
||||
|
||||
Self::do_pause(full_name).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Un-pause a call.
|
||||
///
|
||||
/// Can only be called by [`Config::UnpauseOrigin`].
|
||||
/// Emits an [`Event::CallUnpaused`] event on success.
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight(T::WeightInfo::unpause())]
|
||||
pub fn unpause(origin: OriginFor<T>, ident: RuntimeCallNameOf<T>) -> DispatchResult {
|
||||
T::UnpauseOrigin::ensure_origin(origin)?;
|
||||
|
||||
Self::do_unpause(ident).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
pub(crate) fn do_pause(ident: RuntimeCallNameOf<T>) -> Result<(), Error<T>> {
|
||||
Self::ensure_can_pause(&ident)?;
|
||||
PausedCalls::<T>::insert(&ident, ());
|
||||
Self::deposit_event(Event::CallPaused { full_name: ident });
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn do_unpause(ident: RuntimeCallNameOf<T>) -> Result<(), Error<T>> {
|
||||
Self::ensure_can_unpause(&ident)?;
|
||||
PausedCalls::<T>::remove(&ident);
|
||||
Self::deposit_event(Event::CallUnpaused { full_name: ident });
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Return whether this call is paused.
|
||||
pub fn is_paused(full_name: &RuntimeCallNameOf<T>) -> bool {
|
||||
if T::WhitelistedCalls::contains(full_name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
<PausedCalls<T>>::contains_key(full_name)
|
||||
}
|
||||
|
||||
/// Same as [`Self::is_paused`] but for inputs unbound by max-encoded-len.
|
||||
pub fn is_paused_unbound(pallet: Vec<u8>, call: Vec<u8>) -> bool {
|
||||
let pallet = PalletNameOf::<T>::try_from(pallet);
|
||||
let call = PalletCallNameOf::<T>::try_from(call);
|
||||
|
||||
match (pallet, call) {
|
||||
(Ok(pallet), Ok(call)) => Self::is_paused(&(pallet, call)),
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Ensure that this call can be paused.
|
||||
pub fn ensure_can_pause(full_name: &RuntimeCallNameOf<T>) -> Result<(), Error<T>> {
|
||||
// SAFETY: The `TxPause` pallet can never pause itself.
|
||||
if full_name.0.as_slice() == <Self as PalletInfoAccess>::name().as_bytes() {
|
||||
return Err(Error::<T>::Unpausable);
|
||||
}
|
||||
|
||||
if T::WhitelistedCalls::contains(&full_name) {
|
||||
return Err(Error::<T>::Unpausable);
|
||||
}
|
||||
if Self::is_paused(&full_name) {
|
||||
return Err(Error::<T>::IsPaused);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Ensure that this call can be un-paused.
|
||||
pub fn ensure_can_unpause(full_name: &RuntimeCallNameOf<T>) -> Result<(), Error<T>> {
|
||||
if Self::is_paused(&full_name) {
|
||||
// SAFETY: Everything that is paused, can be un-paused.
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::IsUnpaused)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: pallet::Config> Contains<<T as pezframe_system::Config>::RuntimeCall> for Pallet<T>
|
||||
where
|
||||
<T as pezframe_system::Config>::RuntimeCall: GetCallMetadata,
|
||||
{
|
||||
/// Return whether the call is allowed to be dispatched.
|
||||
fn contains(call: &<T as pezframe_system::Config>::RuntimeCall) -> bool {
|
||||
let CallMetadata { pezpallet_name, function_name } = call.get_call_metadata();
|
||||
!Pallet::<T>::is_paused_unbound(pezpallet_name.into(), function_name.into())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> TransactionPause for Pallet<T> {
|
||||
type CallIdentifier = RuntimeCallNameOf<T>;
|
||||
|
||||
fn is_paused(full_name: Self::CallIdentifier) -> bool {
|
||||
Self::is_paused(&full_name)
|
||||
}
|
||||
|
||||
fn can_pause(full_name: Self::CallIdentifier) -> bool {
|
||||
Self::ensure_can_pause(&full_name).is_ok()
|
||||
}
|
||||
|
||||
fn pause(full_name: Self::CallIdentifier) -> Result<(), TransactionPauseError> {
|
||||
Self::do_pause(full_name).map_err(Into::into)
|
||||
}
|
||||
|
||||
fn unpause(full_name: Self::CallIdentifier) -> Result<(), TransactionPauseError> {
|
||||
Self::do_unpause(full_name).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> From<Error<T>> for TransactionPauseError {
|
||||
fn from(err: Error<T>) -> Self {
|
||||
match err {
|
||||
Error::<T>::NotFound => Self::NotFound,
|
||||
Error::<T>::Unpausable => Self::Unpausable,
|
||||
Error::<T>::IsPaused => Self::AlreadyPaused,
|
||||
Error::<T>::IsUnpaused => Self::AlreadyUnpaused,
|
||||
_ => Self::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
// 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.
|
||||
|
||||
//! Tests and test utilities for transaction pause pallet.
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use super::*;
|
||||
use crate as pezpallet_tx_pause;
|
||||
use frame::testing_prelude::*;
|
||||
|
||||
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
|
||||
impl pezframe_system::Config for Test {
|
||||
type BaseCallFilter = InsideBoth<Everything, TxPause>;
|
||||
type Block = Block;
|
||||
type AccountData = pezpallet_balances::AccountData<u64>;
|
||||
}
|
||||
|
||||
#[derive_impl(pezpallet_balances::config_preludes::TestDefaultConfig)]
|
||||
impl pezpallet_balances::Config for Test {
|
||||
type AccountStore = System;
|
||||
}
|
||||
|
||||
impl pezpallet_utility::Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type PalletsOrigin = OriginCaller;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
/// Mocked proxies to check that tx-pause also works with the proxy pallet.
|
||||
#[derive(
|
||||
Copy,
|
||||
Clone,
|
||||
Eq,
|
||||
PartialEq,
|
||||
Ord,
|
||||
PartialOrd,
|
||||
Encode,
|
||||
Decode,
|
||||
DecodeWithMemTracking,
|
||||
RuntimeDebug,
|
||||
MaxEncodedLen,
|
||||
scale_info::TypeInfo,
|
||||
)]
|
||||
pub enum ProxyType {
|
||||
Any,
|
||||
JustTransfer,
|
||||
JustUtility,
|
||||
}
|
||||
|
||||
impl Default for ProxyType {
|
||||
fn default() -> Self {
|
||||
Self::Any
|
||||
}
|
||||
}
|
||||
|
||||
impl InstanceFilter<RuntimeCall> for ProxyType {
|
||||
fn filter(&self, c: &RuntimeCall) -> bool {
|
||||
match self {
|
||||
ProxyType::Any => true,
|
||||
ProxyType::JustTransfer => {
|
||||
matches!(
|
||||
c,
|
||||
RuntimeCall::Balances(pezpallet_balances::Call::transfer_allow_death { .. })
|
||||
)
|
||||
},
|
||||
ProxyType::JustUtility => matches!(c, RuntimeCall::Utility { .. }),
|
||||
}
|
||||
}
|
||||
fn is_superset(&self, o: &Self) -> bool {
|
||||
self == &ProxyType::Any || self == o
|
||||
}
|
||||
}
|
||||
|
||||
impl pezpallet_proxy::Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Currency = Balances;
|
||||
type ProxyType = ProxyType;
|
||||
type ProxyDepositBase = ConstU64<1>;
|
||||
type ProxyDepositFactor = ConstU64<1>;
|
||||
type MaxProxies = ConstU32<4>;
|
||||
type WeightInfo = ();
|
||||
type CallHasher = BlakeTwo256;
|
||||
type MaxPending = ConstU32<2>;
|
||||
type AnnouncementDepositBase = ConstU64<1>;
|
||||
type AnnouncementDepositFactor = ConstU64<1>;
|
||||
type BlockNumberProvider = pezframe_system::Pallet<Test>;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MaxNameLen: u32 = 50;
|
||||
}
|
||||
|
||||
ord_parameter_types! {
|
||||
pub const PauseOrigin: u64 = 1;
|
||||
pub const UnpauseOrigin: u64 = 2;
|
||||
}
|
||||
|
||||
/// Calls that are never allowed to be paused.
|
||||
pub struct WhitelistedCalls;
|
||||
impl Contains<RuntimeCallNameOf<Test>> for WhitelistedCalls {
|
||||
fn contains(full_name: &RuntimeCallNameOf<Test>) -> bool {
|
||||
match (full_name.0.as_slice(), full_name.1.as_slice()) {
|
||||
(b"Balances", b"transfer_keep_alive") => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config for Test {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type PauseOrigin = EnsureSignedBy<PauseOrigin, Self::AccountId>;
|
||||
type UnpauseOrigin = EnsureSignedBy<UnpauseOrigin, Self::AccountId>;
|
||||
type WhitelistedCalls = WhitelistedCalls;
|
||||
type MaxNameLen = MaxNameLen;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
type Block = pezframe_system::mocking::MockBlock<Test>;
|
||||
|
||||
construct_runtime!(
|
||||
pub enum Test
|
||||
{
|
||||
System: pezframe_system,
|
||||
Balances: pezpallet_balances,
|
||||
Utility: pezpallet_utility,
|
||||
Proxy: pezpallet_proxy,
|
||||
TxPause: pezpallet_tx_pause,
|
||||
}
|
||||
);
|
||||
|
||||
pub fn new_test_ext() -> TestExternalities {
|
||||
let mut t = pezframe_system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
|
||||
pezpallet_balances::GenesisConfig::<Test> {
|
||||
// The 0 account is NOT a special origin. The rest may be:
|
||||
balances: vec![(0, 1234), (1, 5678), (2, 5678), (3, 5678), (4, 5678)],
|
||||
..Default::default()
|
||||
}
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
|
||||
pezpallet_tx_pause::GenesisConfig::<Test> { paused: vec![] }
|
||||
.assimilate_storage(&mut t)
|
||||
.unwrap();
|
||||
|
||||
let mut ext = TestExternalities::new(t);
|
||||
ext.execute_with(|| {
|
||||
System::set_block_number(1);
|
||||
});
|
||||
ext
|
||||
}
|
||||
|
||||
pub fn next_block() {
|
||||
TxPause::on_finalize(System::block_number());
|
||||
Balances::on_finalize(System::block_number());
|
||||
System::on_finalize(System::block_number());
|
||||
System::set_block_number(System::block_number() + 1);
|
||||
System::on_initialize(System::block_number());
|
||||
Balances::on_initialize(System::block_number());
|
||||
TxPause::on_initialize(System::block_number());
|
||||
}
|
||||
|
||||
pub fn run_to(n: u64) {
|
||||
while System::block_number() < n {
|
||||
next_block();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
// 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.
|
||||
|
||||
#![cfg(test)]
|
||||
|
||||
use super::*;
|
||||
use crate::mock::{RuntimeCall, *};
|
||||
use frame::testing_prelude::*;
|
||||
// GENERAL SUCCESS/POSITIVE TESTS ---------------------
|
||||
|
||||
#[docify::export]
|
||||
#[test]
|
||||
fn can_pause_specific_call() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(call_transfer(1, 1).dispatch(RuntimeOrigin::signed(0)));
|
||||
|
||||
assert_ok!(TxPause::pause(
|
||||
RuntimeOrigin::signed(mock::PauseOrigin::get()),
|
||||
full_name::<Test>(b"Balances", b"transfer_allow_death")
|
||||
));
|
||||
|
||||
assert_err!(
|
||||
call_transfer(2, 1).dispatch(RuntimeOrigin::signed(2)),
|
||||
pezframe_system::Error::<Test>::CallFiltered
|
||||
);
|
||||
assert_ok!(call_transfer_keep_alive(3, 1).dispatch(RuntimeOrigin::signed(3)));
|
||||
});
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
#[test]
|
||||
fn can_pause_all_calls_in_pallet_except_on_whitelist() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(call_transfer(1, 1).dispatch(RuntimeOrigin::signed(0)));
|
||||
|
||||
let batch_call =
|
||||
RuntimeCall::Utility(pezpallet_utility::Call::batch { calls: vec![call_transfer(1, 1)] });
|
||||
assert_ok!(batch_call.clone().dispatch(RuntimeOrigin::signed(0)));
|
||||
|
||||
assert_ok!(TxPause::pause(
|
||||
RuntimeOrigin::signed(mock::PauseOrigin::get()),
|
||||
full_name::<Test>(b"Utility", b"batch")
|
||||
),);
|
||||
|
||||
assert_err!(
|
||||
batch_call.clone().dispatch(RuntimeOrigin::signed(0)),
|
||||
pezframe_system::Error::<Test>::CallFiltered
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[docify::export]
|
||||
#[test]
|
||||
fn can_unpause_specific_call() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(TxPause::pause(
|
||||
RuntimeOrigin::signed(mock::PauseOrigin::get()),
|
||||
full_name::<Test>(b"Balances", b"transfer_allow_death"),
|
||||
));
|
||||
assert_err!(
|
||||
call_transfer(2, 1).dispatch(RuntimeOrigin::signed(2)),
|
||||
pezframe_system::Error::<Test>::CallFiltered
|
||||
);
|
||||
|
||||
assert_ok!(TxPause::unpause(
|
||||
RuntimeOrigin::signed(mock::UnpauseOrigin::get()),
|
||||
full_name::<Test>(b"Balances", b"transfer_allow_death"),
|
||||
));
|
||||
assert_ok!(call_transfer(4, 1).dispatch(RuntimeOrigin::signed(0)));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_filter_balance_in_batch_when_paused() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let batch_call =
|
||||
RuntimeCall::Utility(pezpallet_utility::Call::batch { calls: vec![call_transfer(1, 1)] });
|
||||
|
||||
assert_ok!(TxPause::pause(
|
||||
RuntimeOrigin::signed(mock::PauseOrigin::get()),
|
||||
full_name::<Test>(b"Balances", b"transfer_allow_death"),
|
||||
));
|
||||
|
||||
assert_ok!(batch_call.clone().dispatch(RuntimeOrigin::signed(0)));
|
||||
System::assert_last_event(
|
||||
pezpallet_utility::Event::BatchInterrupted {
|
||||
index: 0,
|
||||
error: pezframe_system::Error::<Test>::CallFiltered.into(),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_filter_balance_in_proxy_when_paused() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(TxPause::pause(
|
||||
RuntimeOrigin::signed(mock::PauseOrigin::get()),
|
||||
full_name::<Test>(b"Balances", b"transfer_allow_death"),
|
||||
));
|
||||
|
||||
assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 2, ProxyType::JustTransfer, 0));
|
||||
|
||||
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, Box::new(call_transfer(1, 1))));
|
||||
System::assert_last_event(
|
||||
pezpallet_proxy::Event::ProxyExecuted {
|
||||
result: DispatchError::from(pezframe_system::Error::<Test>::CallFiltered).into(),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// GENERAL FAIL/NEGATIVE TESTS ---------------------
|
||||
|
||||
#[test]
|
||||
fn fails_to_pause_self() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
TxPause::pause(
|
||||
RuntimeOrigin::signed(mock::PauseOrigin::get()),
|
||||
full_name::<Test>(b"TxPause", b"pause"),
|
||||
),
|
||||
Error::<Test>::Unpausable
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fails_to_pause_unpausable_call_when_other_call_is_paused() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(call_transfer(1, 1).dispatch(RuntimeOrigin::signed(0)));
|
||||
|
||||
let batch_call =
|
||||
RuntimeCall::Utility(pezpallet_utility::Call::batch { calls: vec![call_transfer(1, 1)] });
|
||||
assert_ok!(batch_call.clone().dispatch(RuntimeOrigin::signed(0)));
|
||||
|
||||
assert_ok!(TxPause::pause(
|
||||
RuntimeOrigin::signed(mock::PauseOrigin::get()),
|
||||
full_name::<Test>(b"Balances", b"transfer_allow_death"),
|
||||
));
|
||||
|
||||
assert_ok!(call_transfer_keep_alive(3, 1).dispatch(RuntimeOrigin::signed(3)));
|
||||
assert_err!(
|
||||
call_transfer(2, 1).dispatch(RuntimeOrigin::signed(0)),
|
||||
pezframe_system::Error::<Test>::CallFiltered
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fails_to_pause_unpausable_call() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
TxPause::pause(
|
||||
RuntimeOrigin::signed(mock::PauseOrigin::get()),
|
||||
full_name::<Test>(b"Balances", b"transfer_keep_alive"),
|
||||
),
|
||||
Error::<Test>::Unpausable
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fails_to_pause_already_paused_pallet() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_ok!(TxPause::pause(
|
||||
RuntimeOrigin::signed(mock::PauseOrigin::get()),
|
||||
full_name::<Test>(b"Balances", b"transfer_allow_death"),
|
||||
));
|
||||
|
||||
assert_noop!(
|
||||
TxPause::pause(
|
||||
RuntimeOrigin::signed(mock::PauseOrigin::get()),
|
||||
full_name::<Test>(b"Balances", b"transfer_allow_death"),
|
||||
),
|
||||
Error::<Test>::IsPaused
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fails_to_unpause_not_paused_pallet() {
|
||||
new_test_ext().execute_with(|| {
|
||||
assert_noop!(
|
||||
TxPause::unpause(
|
||||
RuntimeOrigin::signed(mock::UnpauseOrigin::get()),
|
||||
full_name::<Test>(b"Balances", b"transfer_keep_alive"),
|
||||
),
|
||||
Error::<Test>::IsUnpaused
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn call_transfer(dest: u64, value: u64) -> RuntimeCall {
|
||||
RuntimeCall::Balances(pezpallet_balances::Call::transfer_allow_death { dest, value })
|
||||
}
|
||||
|
||||
pub fn call_transfer_keep_alive(dest: u64, value: u64) -> RuntimeCall {
|
||||
RuntimeCall::Balances(pezpallet_balances::Call::transfer_keep_alive { dest, value })
|
||||
}
|
||||
|
||||
pub fn full_name<T: Config>(pezpallet_name: &[u8], call_name: &[u8]) -> RuntimeCallNameOf<T> {
|
||||
<RuntimeCallNameOf<T>>::from((
|
||||
pezpallet_name.to_vec().try_into().unwrap(),
|
||||
call_name.to_vec().try_into().unwrap(),
|
||||
))
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
// 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.
|
||||
|
||||
// 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.
|
||||
|
||||
//! Autogenerated weights for `pezpallet_tx_pause`
|
||||
//!
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE BIZINIKIWI BENCHMARK CLI VERSION 32.0.0
|
||||
//! DATE: 2025-02-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
|
||||
//! WORST CASE MAP SIZE: `1000000`
|
||||
//! HOSTNAME: `4563561839a5`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz`
|
||||
//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024`
|
||||
|
||||
// Executed Command:
|
||||
// frame-omni-bencher
|
||||
// v1
|
||||
// benchmark
|
||||
// pallet
|
||||
// --extrinsic=*
|
||||
// --runtime=target/production/wbuild/kitchensink-runtime/kitchensink_runtime.wasm
|
||||
// --pallet=pezpallet_tx_pause
|
||||
// --header=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/HEADER-APACHE2
|
||||
// --output=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/pezframe/tx-pause/src/weights.rs
|
||||
// --wasm-execution=compiled
|
||||
// --steps=50
|
||||
// --repeat=20
|
||||
// --heap-pages=4096
|
||||
// --template=bizinikiwi/.maintain/frame-weight-template.hbs
|
||||
// --no-storage-info
|
||||
// --no-min-squares
|
||||
// --no-median-slopes
|
||||
// --genesis-builder-policy=none
|
||||
// --exclude-pallets=pezpallet_xcm,pezpallet_xcm_benchmarks::fungible,pezpallet_xcm_benchmarks::generic,pezpallet_nomination_pools,pezpallet_remark,pezpallet_transaction_storage,pezpallet_election_provider_multi_block,pezpallet_election_provider_multi_block::signed,pezpallet_election_provider_multi_block::unsigned,pezpallet_election_provider_multi_block::verifier
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
#![allow(missing_docs)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
use frame::weights_prelude::*;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
/// Weight functions needed for `pezpallet_tx_pause`.
|
||||
pub trait WeightInfo {
|
||||
fn pause() -> Weight;
|
||||
fn unpause() -> Weight;
|
||||
}
|
||||
|
||||
/// Weights for `pezpallet_tx_pause` using the Bizinikiwi node and recommended hardware.
|
||||
pub struct BizinikiwiWeight<T>(PhantomData<T>);
|
||||
impl<T: pezframe_system::Config> WeightInfo for BizinikiwiWeight<T> {
|
||||
/// Storage: `TxPause::PausedCalls` (r:1 w:1)
|
||||
/// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`)
|
||||
fn pause() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `3997`
|
||||
// Minimum execution time: 9_771_000 picoseconds.
|
||||
Weight::from_parts(10_141_000, 3997)
|
||||
.saturating_add(T::DbWeight::get().reads(1_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: `TxPause::PausedCalls` (r:1 w:1)
|
||||
/// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`)
|
||||
fn unpause() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `3997`
|
||||
// Minimum execution time: 12_192_000 picoseconds.
|
||||
Weight::from_parts(12_554_000, 3997)
|
||||
.saturating_add(T::DbWeight::get().reads(1_u64))
|
||||
.saturating_add(T::DbWeight::get().writes(1_u64))
|
||||
}
|
||||
}
|
||||
|
||||
// For backwards compatibility and tests.
|
||||
impl WeightInfo for () {
|
||||
/// Storage: `TxPause::PausedCalls` (r:1 w:1)
|
||||
/// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`)
|
||||
fn pause() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `3997`
|
||||
// Minimum execution time: 9_771_000 picoseconds.
|
||||
Weight::from_parts(10_141_000, 3997)
|
||||
.saturating_add(RocksDbWeight::get().reads(1_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
}
|
||||
/// Storage: `TxPause::PausedCalls` (r:1 w:1)
|
||||
/// Proof: `TxPause::PausedCalls` (`max_values`: None, `max_size`: Some(532), added: 3007, mode: `MaxEncodedLen`)
|
||||
fn unpause() -> Weight {
|
||||
// Proof Size summary in bytes:
|
||||
// Measured: `0`
|
||||
// Estimated: `3997`
|
||||
// Minimum execution time: 12_192_000 picoseconds.
|
||||
Weight::from_parts(12_554_000, 3997)
|
||||
.saturating_add(RocksDbWeight::get().reads(1_u64))
|
||||
.saturating_add(RocksDbWeight::get().writes(1_u64))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user