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:
2025-12-14 00:04:10 +03:00
parent 286de54384
commit 1c0e57d984
9084 changed files with 997839 additions and 997557 deletions
+61
View File
@@ -0,0 +1,61 @@
[package]
name = "pezpallet-parameters"
description = "Pallet to store and configure parameters."
repository.workspace = true
license = "Apache-2.0"
version = "0.1.0"
authors = [
"Acala Developers",
"Kurdistan Tech Institute <info@pezkuwichain.io>",
"Parity Technologies <admin@parity.io>",
]
edition.workspace = true
[dependencies]
codec = { features = ["max-encoded-len"], workspace = true }
docify = { workspace = true }
paste = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
serde = { features = [
"derive",
], optional = true, workspace = true, default-features = true }
pezframe-benchmarking = { optional = true, workspace = true }
pezframe-support = { features = ["experimental"], workspace = true }
pezframe-system = { workspace = true }
pezsp-core = { workspace = true }
pezsp-runtime = { workspace = true }
[dev-dependencies]
pezpallet-balances = { workspace = true, default-features = true }
pezpallet-example-basic = { workspace = true, default-features = true }
pezsp-io = { workspace = true, default-features = true }
[features]
default = ["std"]
std = [
"codec/std",
"pezframe-benchmarking?/std",
"pezframe-support/std",
"pezframe-system/std",
"scale-info/std",
"serde",
"pezsp-core/std",
"pezsp-runtime/std",
]
runtime-benchmarks = [
"pezframe-benchmarking/runtime-benchmarks",
"pezframe-support/runtime-benchmarks",
"pezframe-system/runtime-benchmarks",
"pezpallet-balances/runtime-benchmarks",
"pezpallet-example-basic/runtime-benchmarks",
"pezsp-io/runtime-benchmarks",
"pezsp-runtime/runtime-benchmarks",
]
try-runtime = [
"pezframe-support/try-runtime",
"pezframe-system/try-runtime",
"pezpallet-balances/try-runtime",
"pezpallet-example-basic/try-runtime",
"pezsp-runtime/try-runtime",
]
@@ -0,0 +1,51 @@
// 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.
//! Parameters pallet benchmarking.
#![cfg(feature = "runtime-benchmarks")]
use super::*;
#[cfg(test)]
use crate::Pallet as Parameters;
use pezframe_benchmarking::v2::*;
#[benchmarks(where T::RuntimeParameters: Default)]
mod benchmarks {
use super::*;
#[benchmark]
fn set_parameter() -> Result<(), BenchmarkError> {
let kv = T::RuntimeParameters::default();
let k = kv.clone().into_parts().0;
let origin =
T::AdminOrigin::try_successful_origin(&k).map_err(|_| BenchmarkError::Weightless)?;
#[extrinsic_call]
_(origin as T::RuntimeOrigin, kv);
Ok(())
}
impl_benchmark_test_suite! {
Parameters,
crate::tests::mock::new_test_ext(),
crate::tests::mock::Runtime,
}
}
+271
View File
@@ -0,0 +1,271 @@
// 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_attr(not(feature = "std"), no_std)]
#![deny(missing_docs)]
// Need to enable this one since we document feature-gated stuff.
#![allow(rustdoc::broken_intra_doc_links)]
//! # **⚠️ WARNING ⚠️**
//!
//! <br>
//! <b>THIS CRATE IS NOT AUDITED AND SHOULD NOT BE USED IN PRODUCTION.</b>
//! <br>
//!
//! # Parameters
//!
//! Allows to update configuration parameters at runtime.
//!
//! ## Pallet API
//!
//! This pallet exposes two APIs; one *inbound* side to update parameters, and one *outbound* side
//! to access said parameters. Parameters themselves are defined in the runtime config and will be
//! aggregated into an enum. Each parameter is addressed by a `key` and can have a default value.
//! This is not done by the pallet but through the [`pezframe_support::dynamic_params::dynamic_params`]
//! macro or alternatives.
//!
//! Note that this is incurring one storage read per access. This should not be a problem in most
//! cases but must be considered in weight-restrained code.
//!
//! ### Inbound
//!
//! The inbound side solely consists of the [`Pallet::set_parameter`] extrinsic to update the value
//! of a parameter. Each parameter can have their own admin origin as given by the
//! [`Config::AdminOrigin`].
//!
//! ### Outbound
//!
//! The outbound side is runtime facing for the most part. More general, it provides a `Get`
//! implementation and can be used in every spot where that is accepted. Two macros are in place:
//! [`pezframe_support::dynamic_params::define_parameters` and
//! [`pezframe_support::dynamic_params:dynamic_pallet_params`] to define and expose parameters in a
//! typed manner.
//!
//! See the [`pallet`] module for more information about the interfaces this pallet exposes,
//! including its configuration trait, dispatchables, storage items, events and errors.
//!
//! ## Overview
//!
//! This pallet is a good fit for updating parameters without a runtime upgrade. It is very handy to
//! not require a runtime upgrade for a simple parameter change since runtime upgrades require a lot
//! of diligence and always bear risks. It seems overkill to update the whole runtime for a simple
//! parameter change. This pallet allows for fine-grained control over who can update what.
//! The only down-side is that it trades off performance with convenience and should therefore only
//! be used in places where that is proven to be uncritical. Values that are rarely accessed but
//! change often would be a perfect fit.
//!
//! ### Example Configuration
//!
//! Here is an example of how to define some parameters, including their default values:
#![doc = docify::embed!("src/tests/mock.rs", dynamic_params)]
//!
//! A permissioned origin can be define on a per-key basis like this:
#![doc = docify::embed!("src/tests/mock.rs", custom_origin)]
//!
//! The pallet will also require a default value for benchmarking. Ideally this is the variant with
//! the longest encoded length. Although in either case the PoV benchmarking will take the worst
//! case over the whole enum.
#![doc = docify::embed!("src/tests/mock.rs", benchmarking_default)]
//!
//! Now the aggregated parameter needs to be injected into the pallet config:
#![doc = docify::embed!("src/tests/mock.rs", impl_config)]
//!
//! As last step, the parameters can now be used in other pallets 🙌
#![doc = docify::embed!("src/tests/mock.rs", usage)]
//!
//! ### Examples Usage
//!
//! Now to demonstrate how the values can be updated:
#![doc = docify::embed!("src/tests/unit.rs", set_parameters_example)]
//!
//! ## Low Level / Implementation Details
//!
//! The pallet stores the parameters in a storage map and implements the matching `Get<Value>` for
//! each `Key` type. The `Get` then accesses the `Parameters` map to retrieve the value. An event is
//! emitted every time that a value was updated. It is even emitted when the value is changed to the
//! same.
//!
//! The key and value types themselves are defined by macros and aggregated into a runtime wide
//! enum. This enum is then injected into the pallet. This allows it to be used without any changes
//! to the pallet that the parameter will be utilized by.
//!
//! ### Design Goals
//!
//! 1. Easy to update without runtime upgrade.
//! 2. Exposes metadata and docs for user convenience.
//! 3. Can be permissioned on a per-key base.
//!
//! ### Design
//!
//! 1. Everything is done at runtime without the need for `const` values. `Get` allows for this -
//! which is coincidentally an upside and a downside. 2. The types are defined through macros, which
//! allows to expose metadata and docs. 3. Access control is done through the `EnsureOriginWithArg`
//! trait, that allows to pass data along to the origin check. It gets passed in the key. The
//! implementor can then match on the key and the origin to decide whether the origin is
//! permissioned to set the value.
use pezframe_support::pezpallet_prelude::*;
use pezframe_system::pezpallet_prelude::*;
use pezframe_support::traits::{
dynamic_params::{AggregatedKeyValue, IntoKey, Key, RuntimeParameterStore, TryIntoKey},
EnsureOriginWithArg,
};
mod benchmarking;
#[cfg(test)]
mod tests;
mod weights;
pub use pallet::*;
pub use weights::WeightInfo;
/// The key type of a parameter.
type KeyOf<T> = <<T as Config>::RuntimeParameters as AggregatedKeyValue>::Key;
/// The value type of a parameter.
type ValueOf<T> = <<T as Config>::RuntimeParameters as AggregatedKeyValue>::Value;
#[pezframe_support::pallet]
pub mod pallet {
use super::*;
#[pallet::config(with_default)]
pub trait Config: pezframe_system::Config {
/// The overarching event type.
#[pallet::no_default_bounds]
#[allow(deprecated)]
type RuntimeEvent: From<Event<Self>> + IsType<<Self as pezframe_system::Config>::RuntimeEvent>;
/// The overarching KV type of the parameters.
///
/// Usually created by [`pezframe_support::dynamic_params`] or equivalent.
#[pallet::no_default_bounds]
type RuntimeParameters: AggregatedKeyValue;
/// The origin which may update a parameter.
///
/// The key of the parameter is passed in as second argument to allow for fine grained
/// control.
#[pallet::no_default_bounds]
type AdminOrigin: EnsureOriginWithArg<Self::RuntimeOrigin, KeyOf<Self>>;
/// Weight information for extrinsics in this module.
type WeightInfo: WeightInfo;
}
#[pallet::event]
#[pallet::generate_deposit(pub(crate) fn deposit_event)]
pub enum Event<T: Config> {
/// A Parameter was set.
///
/// Is also emitted when the value was not changed.
Updated {
/// The key that was updated.
key: <T::RuntimeParameters as AggregatedKeyValue>::Key,
/// The old value before this call.
old_value: Option<<T::RuntimeParameters as AggregatedKeyValue>::Value>,
/// The new value after this call.
new_value: Option<<T::RuntimeParameters as AggregatedKeyValue>::Value>,
},
}
/// Stored parameters.
#[pallet::storage]
pub type Parameters<T: Config> =
StorageMap<_, Blake2_128Concat, KeyOf<T>, ValueOf<T>, OptionQuery>;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Set the value of a parameter.
///
/// The dispatch origin of this call must be `AdminOrigin` for the given `key`. Values be
/// deleted by setting them to `None`.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::set_parameter())]
pub fn set_parameter(
origin: OriginFor<T>,
key_value: T::RuntimeParameters,
) -> DispatchResult {
let (key, new) = key_value.into_parts();
T::AdminOrigin::ensure_origin(origin, &key)?;
let mut old = None;
Parameters::<T>::mutate(&key, |v| {
old = v.clone();
*v = new.clone();
});
Self::deposit_event(Event::Updated { key, old_value: old, new_value: new });
Ok(())
}
}
/// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`].
pub mod config_preludes {
use super::*;
use pezframe_support::derive_impl;
/// A configuration for testing.
pub struct TestDefaultConfig;
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig, no_aggregated_types)]
impl pezframe_system::DefaultConfig for TestDefaultConfig {}
#[pezframe_support::register_default_impl(TestDefaultConfig)]
impl DefaultConfig for TestDefaultConfig {
#[inject_runtime_type]
type RuntimeEvent = ();
#[inject_runtime_type]
type RuntimeParameters = ();
type AdminOrigin = pezframe_support::traits::AsEnsureOriginWithArg<
pezframe_system::EnsureRoot<Self::AccountId>,
>;
type WeightInfo = ();
}
}
}
impl<T: Config> RuntimeParameterStore for Pallet<T> {
type AggregatedKeyValue = T::RuntimeParameters;
fn get<KV, K>(key: K) -> Option<K::Value>
where
KV: AggregatedKeyValue,
K: Key + Into<<KV as AggregatedKeyValue>::Key>,
<KV as AggregatedKeyValue>::Key: IntoKey<
<<Self as RuntimeParameterStore>::AggregatedKeyValue as AggregatedKeyValue>::Key,
>,
<<Self as RuntimeParameterStore>::AggregatedKeyValue as AggregatedKeyValue>::Value:
TryIntoKey<<KV as AggregatedKeyValue>::Value>,
<KV as AggregatedKeyValue>::Value: TryInto<K::WrappedValue>,
{
let key: <KV as AggregatedKeyValue>::Key = key.into();
let val = Parameters::<T>::get(key.into_key());
val.and_then(|v| {
let val: <KV as AggregatedKeyValue>::Value = v.try_into_key().ok()?;
let val: K::WrappedValue = val.try_into().ok()?;
let val = val.into();
Some(val)
})
}
}
@@ -0,0 +1,166 @@
// 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(any(test, feature = "runtime-benchmarks"))]
#![allow(non_snake_case)]
//! Mock runtime that configures the `pezpallet_example_basic` to use dynamic params for testing.
use pezframe_support::{
construct_runtime, derive_impl,
dynamic_params::{dynamic_pallet_params, dynamic_params},
traits::EnsureOriginWithArg,
};
use crate as pezpallet_parameters;
use crate::*;
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
impl pezframe_system::Config for Runtime {
type Block = pezframe_system::mocking::MockBlock<Runtime>;
type AccountData = pezpallet_balances::AccountData<<Self as pezpallet_balances::Config>::Balance>;
}
#[derive_impl(pezpallet_balances::config_preludes::TestDefaultConfig)]
impl pezpallet_balances::Config for Runtime {
type AccountStore = System;
}
#[docify::export]
#[dynamic_params(RuntimeParameters, pezpallet_parameters::Parameters::<Runtime>)]
pub mod dynamic_params {
use super::*;
#[dynamic_pallet_params]
#[codec(index = 3)]
pub mod pallet1 {
#[codec(index = 0)]
pub static Key1: u64 = 0;
#[codec(index = 1)]
pub static Key2: u32 = 1;
#[codec(index = 2)]
pub static Key3: u128 = 2;
}
#[dynamic_pallet_params]
#[codec(index = 1)]
pub mod pallet2 {
#[codec(index = 2)]
pub static Key1: u64 = 0;
#[codec(index = 1)]
pub static Key2: u32 = 2;
#[codec(index = 0)]
pub static Key3: u128 = 4;
}
#[dynamic_pallet_params]
#[codec(index = 2)]
pub mod nis {
#[codec(index = 0)]
pub static Target: u64 = 0;
}
#[dynamic_pallet_params]
#[codec(index = 4)]
pub mod somE_weird_SPElLInG_s {
#[codec(index = 0)]
pub static V: u64 = 0;
}
}
#[docify::export(benchmarking_default)]
#[cfg(feature = "runtime-benchmarks")]
impl Default for RuntimeParameters {
fn default() -> Self {
RuntimeParameters::Pallet1(dynamic_params::pallet1::Parameters::Key1(
dynamic_params::pallet1::Key1,
Some(123),
))
}
}
#[docify::export]
mod custom_origin {
use super::*;
pub struct ParamsManager;
impl EnsureOriginWithArg<RuntimeOrigin, RuntimeParametersKey> for ParamsManager {
type Success = ();
fn try_origin(
origin: RuntimeOrigin,
key: &RuntimeParametersKey,
) -> Result<Self::Success, RuntimeOrigin> {
// Account 123 is allowed to set parameters in benchmarking only:
#[cfg(feature = "runtime-benchmarks")]
if ensure_signed(origin.clone()).is_ok_and(|acc| acc == 123) {
return Ok(());
}
match key {
RuntimeParametersKey::SomEWeirdSPElLInGS(_) |
RuntimeParametersKey::Nis(_) |
RuntimeParametersKey::Pallet1(_) => ensure_root(origin.clone()),
RuntimeParametersKey::Pallet2(_) => ensure_signed(origin.clone()).map(|_| ()),
}
.map_err(|_| origin)
}
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin(_key: &RuntimeParametersKey) -> Result<RuntimeOrigin, ()> {
Ok(RuntimeOrigin::signed(123))
}
}
}
#[docify::export(impl_config)]
#[derive_impl(pezpallet_parameters::config_preludes::TestDefaultConfig)]
impl Config for Runtime {
type AdminOrigin = custom_origin::ParamsManager;
// RuntimeParameters is injected by the `derive_impl` macro.
// RuntimeEvent is injected by the `derive_impl` macro.
// WeightInfo is injected by the `derive_impl` macro.
}
#[docify::export(usage)]
impl pezpallet_example_basic::Config for Runtime {
// Use the dynamic key in the pallet config:
type MagicNumber = dynamic_params::pallet1::Key1;
type WeightInfo = ();
}
construct_runtime!(
pub enum Runtime {
System: pezframe_system,
PalletParameters: crate,
Example: pezpallet_example_basic,
Balances: pezpallet_balances,
}
);
pub fn new_test_ext() -> pezsp_io::TestExternalities {
let mut ext = pezsp_io::TestExternalities::new(Default::default());
ext.execute_with(|| System::set_block_number(1));
ext
}
pub(crate) fn assert_last_event(generic_event: RuntimeEvent) {
let events = pezframe_system::Pallet::<Runtime>::events();
// compare to the last event record
let pezframe_system::EventRecord { event, .. } = &events.last().expect("Event expected");
assert_eq!(event, &generic_event);
}
@@ -0,0 +1,20 @@
// 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.
pub(crate) mod mock;
mod test_renamed;
mod unit;
@@ -0,0 +1,165 @@
// 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(any(test, feature = "runtime-benchmarks"))]
//! Tests that the runtime params can be renamed.
use pezframe_support::{
assert_noop, assert_ok, construct_runtime, derive_impl,
dynamic_params::{dynamic_pallet_params, dynamic_params},
traits::AsEnsureOriginWithArg,
};
use pezframe_system::EnsureRoot;
use crate as pezpallet_parameters;
use crate::*;
use dynamic_params::*;
use RuntimeParametersRenamed::*;
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
impl pezframe_system::Config for Runtime {
type Block = pezframe_system::mocking::MockBlock<Runtime>;
type AccountData = pezpallet_balances::AccountData<<Self as pezpallet_balances::Config>::Balance>;
}
#[derive_impl(pezpallet_balances::config_preludes::TestDefaultConfig)]
impl pezpallet_balances::Config for Runtime {
type AccountStore = System;
}
#[dynamic_params(RuntimeParametersRenamed, pezpallet_parameters::Parameters::<Runtime>)]
pub mod dynamic_params {
use super::*;
#[dynamic_pallet_params]
#[codec(index = 3)]
pub mod pallet1 {
#[codec(index = 0)]
pub static Key1: u64 = 0;
#[codec(index = 1)]
pub static Key2: u32 = 1;
#[codec(index = 2)]
pub static Key3: u128 = 2;
}
#[dynamic_pallet_params]
#[codec(index = 1)]
pub mod pallet2 {
#[codec(index = 2)]
pub static Key1: u64 = 0;
#[codec(index = 1)]
pub static Key2: u32 = 2;
#[codec(index = 0)]
pub static Key3: u128 = 4;
}
}
#[cfg(feature = "runtime-benchmarks")]
impl Default for RuntimeParametersRenamed {
fn default() -> Self {
RuntimeParametersRenamed::Pallet1(dynamic_params::pallet1::Parameters::Key1(
dynamic_params::pallet1::Key1,
Some(123),
))
}
}
#[derive_impl(pezpallet_parameters::config_preludes::TestDefaultConfig)]
impl Config for Runtime {
type AdminOrigin = AsEnsureOriginWithArg<EnsureRoot<Self::AccountId>>;
type RuntimeParameters = RuntimeParametersRenamed;
// RuntimeEvent is injected by the `derive_impl` macro.
// WeightInfo is injected by the `derive_impl` macro.
}
impl pezpallet_example_basic::Config for Runtime {
// Use the dynamic key in the pallet config:
type MagicNumber = dynamic_params::pallet1::Key1;
type WeightInfo = ();
}
construct_runtime!(
pub enum Runtime {
System: pezframe_system,
PalletParameters: crate,
Example: pezpallet_example_basic,
Balances: pezpallet_balances,
}
);
pub fn new_test_ext() -> pezsp_io::TestExternalities {
let mut ext = pezsp_io::TestExternalities::new(Default::default());
ext.execute_with(|| System::set_block_number(1));
ext
}
pub(crate) fn assert_last_event(generic_event: RuntimeEvent) {
let events = pezframe_system::Pallet::<Runtime>::events();
// compare to the last event record
let pezframe_system::EventRecord { event, .. } = &events.last().expect("Event expected");
assert_eq!(event, &generic_event);
}
#[test]
fn set_parameters_example() {
new_test_ext().execute_with(|| {
assert_eq!(pallet1::Key3::get(), 2, "Default works");
// This gets rejected since the origin is not root.
assert_noop!(
PalletParameters::set_parameter(
RuntimeOrigin::signed(1),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
),
DispatchError::BadOrigin
);
assert_ok!(PalletParameters::set_parameter(
RuntimeOrigin::root(),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
));
assert_eq!(pallet1::Key3::get(), 123, "Update works");
assert_last_event(
crate::Event::Updated {
key: RuntimeParametersRenamedKey::Pallet1(pallet1::ParametersKey::Key3(
pallet1::Key3,
)),
old_value: None,
new_value: Some(RuntimeParametersRenamedValue::Pallet1(
pallet1::ParametersValue::Key3(123),
)),
}
.into(),
);
});
}
#[test]
fn get_through_external_pallet_works() {
new_test_ext().execute_with(|| {
assert_eq!(<Runtime as pezpallet_example_basic::Config>::MagicNumber::get(), 0);
assert_ok!(PalletParameters::set_parameter(
RuntimeOrigin::root(),
Pallet1(pallet1::Parameters::Key1(pallet1::Key1, Some(123))),
));
assert_eq!(<Runtime as pezpallet_example_basic::Config>::MagicNumber::get(), 123);
});
}
@@ -0,0 +1,311 @@
// 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.
//! Unit tests for the parameters pallet.
#![cfg(test)]
use crate::tests::mock::{
assert_last_event, dynamic_params::*, new_test_ext, PalletParameters, Runtime,
RuntimeOrigin as Origin, RuntimeParameters, RuntimeParameters::*, RuntimeParametersKey,
RuntimeParametersValue,
};
use codec::Encode;
use pezframe_support::{assert_noop, assert_ok, traits::dynamic_params::AggregatedKeyValue};
use pezsp_core::Get;
use pezsp_runtime::DispatchError;
#[docify::export]
#[test]
fn set_parameters_example() {
new_test_ext().execute_with(|| {
assert_eq!(pallet1::Key3::get(), 2, "Default works");
// This gets rejected since the origin is not root.
assert_noop!(
PalletParameters::set_parameter(
Origin::signed(1),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
),
DispatchError::BadOrigin
);
assert_ok!(PalletParameters::set_parameter(
Origin::root(),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
));
assert_eq!(pallet1::Key3::get(), 123, "Update works");
assert_last_event(
crate::Event::Updated {
key: RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key3(pallet1::Key3)),
old_value: None,
new_value: Some(RuntimeParametersValue::Pallet1(pallet1::ParametersValue::Key3(
123,
))),
}
.into(),
);
});
}
#[test]
fn set_parameters_same_is_noop() {
new_test_ext().execute_with(|| {
assert_ok!(PalletParameters::set_parameter(
Origin::root(),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
));
assert_ok!(PalletParameters::set_parameter(
Origin::root(),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
));
assert_eq!(pallet1::Key3::get(), 123, "Update works");
});
}
#[test]
fn set_parameters_twice_works() {
new_test_ext().execute_with(|| {
assert_ok!(PalletParameters::set_parameter(
Origin::root(),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
));
assert_ok!(PalletParameters::set_parameter(
Origin::root(),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(432))),
));
assert_eq!(pallet1::Key3::get(), 432, "Update works");
});
}
#[test]
fn set_parameters_removing_restores_default_works() {
new_test_ext().execute_with(|| {
assert_ok!(PalletParameters::set_parameter(
Origin::root(),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
));
assert_eq!(pallet1::Key3::get(), 123, "Update works");
assert!(
crate::Parameters::<Runtime>::contains_key(RuntimeParametersKey::Pallet1(
pallet1::ParametersKey::Key3(pallet1::Key3)
)),
"Key inserted"
);
// Removing the value restores the default.
assert_ok!(PalletParameters::set_parameter(
Origin::root(),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, None)),
));
assert_eq!(pallet1::Key3::get(), 2, "Default restored");
assert!(
!crate::Parameters::<Runtime>::contains_key(RuntimeParametersKey::Pallet1(
pallet1::ParametersKey::Key3(pallet1::Key3)
)),
"Key removed"
);
});
}
#[test]
fn set_parameters_to_default_emits_events_works() {
new_test_ext().execute_with(|| {
assert_eq!(pallet1::Key3::get(), 2);
assert_ok!(PalletParameters::set_parameter(
Origin::root(),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(2))),
));
assert_eq!(pallet1::Key3::get(), 2);
assert!(
crate::Parameters::<Runtime>::contains_key(RuntimeParametersKey::Pallet1(
pallet1::ParametersKey::Key3(pallet1::Key3)
)),
"Key inserted"
);
assert_last_event(
crate::Event::Updated {
key: RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key3(pallet1::Key3)),
old_value: None,
new_value: Some(RuntimeParametersValue::Pallet1(pallet1::ParametersValue::Key3(2))),
}
.into(),
);
// It will also emit a second event:
assert_ok!(PalletParameters::set_parameter(
Origin::root(),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(2))),
));
assert_eq!(pezframe_system::Pallet::<Runtime>::events().len(), 2);
});
}
#[test]
fn set_parameters_wrong_origin_errors() {
new_test_ext().execute_with(|| {
// Pallet1 is root origin only:
assert_ok!(PalletParameters::set_parameter(
Origin::root(),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(123))),
));
assert_noop!(
PalletParameters::set_parameter(
Origin::signed(1),
Pallet1(pallet1::Parameters::Key3(pallet1::Key3, Some(432))),
),
DispatchError::BadOrigin
);
// Pallet2 is signed origin only:
assert_ok!(PalletParameters::set_parameter(
Origin::signed(1),
Pallet2(pallet2::Parameters::Key3(pallet2::Key3, Some(123))),
));
assert_noop!(
PalletParameters::set_parameter(
Origin::root(),
Pallet2(pallet2::Parameters::Key3(pallet2::Key3, Some(432))),
),
DispatchError::BadOrigin
);
});
}
#[test]
fn get_through_external_pallet_works() {
new_test_ext().execute_with(|| {
assert_eq!(<Runtime as pezpallet_example_basic::Config>::MagicNumber::get(), 0);
assert_ok!(PalletParameters::set_parameter(
Origin::root(),
Pallet1(pallet1::Parameters::Key1(pallet1::Key1, Some(123))),
));
assert_eq!(<Runtime as pezpallet_example_basic::Config>::MagicNumber::get(), 123);
});
}
#[test]
fn test_define_parameters_key_convert() {
let key1 = pallet1::Key1;
let parameter_key: pallet1::ParametersKey = key1.clone().into();
let key1_2: pallet1::Key1 = parameter_key.clone().try_into().unwrap();
assert_eq!(key1, key1_2);
assert_eq!(parameter_key, pallet1::ParametersKey::Key1(key1));
let key2 = pallet1::Key2;
let parameter_key: pallet1::ParametersKey = key2.clone().into();
let key2_2: pallet1::Key2 = parameter_key.clone().try_into().unwrap();
assert_eq!(key2, key2_2);
assert_eq!(parameter_key, pallet1::ParametersKey::Key2(key2));
}
#[test]
fn test_define_parameters_value_convert() {
let value1 = pallet1::Key1Value(1);
let parameter_value: pallet1::ParametersValue = value1.clone().into();
let value1_2: pallet1::Key1Value = parameter_value.clone().try_into().unwrap();
assert_eq!(value1, value1_2);
assert_eq!(parameter_value, pallet1::ParametersValue::Key1(1));
let value2 = pallet1::Key2Value(2);
let parameter_value: pallet1::ParametersValue = value2.clone().into();
let value2_2: pallet1::Key2Value = parameter_value.clone().try_into().unwrap();
assert_eq!(value2, value2_2);
assert_eq!(parameter_value, pallet1::ParametersValue::Key2(2));
}
#[test]
fn test_define_parameters_aggregrated_key_value() {
let kv1 = pallet1::Parameters::Key1(pallet1::Key1, None);
let (key1, value1) = kv1.clone().into_parts();
assert_eq!(key1, pallet1::ParametersKey::Key1(pallet1::Key1));
assert_eq!(value1, None);
let kv2 = pallet1::Parameters::Key2(pallet1::Key2, Some(2));
let (key2, value2) = kv2.clone().into_parts();
assert_eq!(key2, pallet1::ParametersKey::Key2(pallet1::Key2));
assert_eq!(value2, Some(pallet1::ParametersValue::Key2(2)));
}
#[test]
fn test_define_aggregrated_parameters_key_convert() {
use codec::Encode;
let key1 = pallet1::Key1;
let parameter_key: pallet1::ParametersKey = key1.clone().into();
let runtime_key: RuntimeParametersKey = parameter_key.clone().into();
assert_eq!(runtime_key, RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key1(key1)));
assert_eq!(runtime_key.encode(), vec![3, 0]);
let key2 = pallet2::Key2;
let parameter_key: pallet2::ParametersKey = key2.clone().into();
let runtime_key: RuntimeParametersKey = parameter_key.clone().into();
assert_eq!(runtime_key, RuntimeParametersKey::Pallet2(pallet2::ParametersKey::Key2(key2)));
assert_eq!(runtime_key.encode(), vec![1, 1]);
}
#[test]
fn test_define_aggregrated_parameters_aggregrated_key_value() {
let kv1 = RuntimeParameters::Pallet1(pallet1::Parameters::Key1(pallet1::Key1, None));
let (key1, value1) = kv1.clone().into_parts();
assert_eq!(key1, RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key1(pallet1::Key1)));
assert_eq!(value1, None);
let kv2 = RuntimeParameters::Pallet2(pallet2::Parameters::Key2(pallet2::Key2, Some(2)));
let (key2, value2) = kv2.clone().into_parts();
assert_eq!(key2, RuntimeParametersKey::Pallet2(pallet2::ParametersKey::Key2(pallet2::Key2)));
assert_eq!(value2, Some(RuntimeParametersValue::Pallet2(pallet2::ParametersValue::Key2(2))));
}
#[test]
fn codec_index_works() {
let enc = RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key1(pallet1::Key1)).encode();
assert_eq!(enc, vec![3, 0]);
let enc = RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key2(pallet1::Key2)).encode();
assert_eq!(enc, vec![3, 1]);
let enc = RuntimeParametersKey::Pallet1(pallet1::ParametersKey::Key3(pallet1::Key3)).encode();
assert_eq!(enc, vec![3, 2]);
let enc = RuntimeParametersKey::Pallet2(pallet2::ParametersKey::Key1(pallet2::Key1)).encode();
assert_eq!(enc, vec![1, 2]);
let enc = RuntimeParametersKey::Pallet2(pallet2::ParametersKey::Key2(pallet2::Key2)).encode();
assert_eq!(enc, vec![1, 1]);
let enc = RuntimeParametersKey::Pallet2(pallet2::ParametersKey::Key3(pallet2::Key3)).encode();
assert_eq!(enc, vec![1, 0]);
}
@@ -0,0 +1,107 @@
// 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_parameters`
//!
//! 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_parameters
// --header=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/HEADER-APACHE2
// --output=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/pezframe/parameters/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 pezframe_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use core::marker::PhantomData;
/// Weight functions needed for `pezpallet_parameters`.
pub trait WeightInfo {
fn set_parameter() -> Weight;
}
/// Weights for `pezpallet_parameters` using the Bizinikiwi node and recommended hardware.
pub struct BizinikiwiWeight<T>(PhantomData<T>);
impl<T: pezframe_system::Config> WeightInfo for BizinikiwiWeight<T> {
/// Storage: `Parameters::Parameters` (r:1 w:1)
/// Proof: `Parameters::Parameters` (`max_values`: None, `max_size`: Some(11322), added: 13797, mode: `MaxEncodedLen`)
fn set_parameter() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `14787`
// Minimum execution time: 5_884_000 picoseconds.
Weight::from_parts(6_204_000, 14787)
.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: `Parameters::Parameters` (r:1 w:1)
/// Proof: `Parameters::Parameters` (`max_values`: None, `max_size`: Some(11322), added: 13797, mode: `MaxEncodedLen`)
fn set_parameter() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `14787`
// Minimum execution time: 5_884_000 picoseconds.
Weight::from_parts(6_204_000, 14787)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}