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
@@ -0,0 +1,172 @@
// 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.
// Benchmarks for Indices Pallet
#![cfg(feature = "runtime-benchmarks")]
use crate::*;
use pezframe_benchmarking::v2::*;
use pezframe_support::traits::Get;
use pezframe_system::RawOrigin;
use pezsp_runtime::traits::Bounded;
const SEED: u32 = 0;
#[benchmarks]
mod benchmarks {
use super::*;
#[benchmark]
fn claim() {
let account_index = T::AccountIndex::from(SEED);
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), account_index);
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, caller);
}
#[benchmark]
fn transfer() -> Result<(), BenchmarkError> {
let account_index = T::AccountIndex::from(SEED);
// Setup accounts
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup = T::Lookup::unlookup(recipient.clone());
T::Currency::make_free_balance_be(&recipient, BalanceOf::<T>::max_value());
// Claim the index
Pallet::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), recipient_lookup, account_index);
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, recipient);
Ok(())
}
#[benchmark]
fn free() -> Result<(), BenchmarkError> {
let account_index = T::AccountIndex::from(SEED);
// Setup accounts
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// Claim the index
Pallet::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), account_index);
assert_eq!(Accounts::<T>::get(account_index), None);
Ok(())
}
#[benchmark]
fn force_transfer() -> Result<(), BenchmarkError> {
let account_index = T::AccountIndex::from(SEED);
// Setup accounts
let original: T::AccountId = account("original", 0, SEED);
T::Currency::make_free_balance_be(&original, BalanceOf::<T>::max_value());
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup = T::Lookup::unlookup(recipient.clone());
T::Currency::make_free_balance_be(&recipient, BalanceOf::<T>::max_value());
// Claim the index
Pallet::<T>::claim(RawOrigin::Signed(original).into(), account_index)?;
#[extrinsic_call]
_(RawOrigin::Root, recipient_lookup, account_index, false);
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, recipient);
Ok(())
}
#[benchmark]
fn freeze() -> Result<(), BenchmarkError> {
let account_index = T::AccountIndex::from(SEED);
// Setup accounts
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// Claim the index
Pallet::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), account_index);
assert_eq!(Accounts::<T>::get(account_index).unwrap().2, true);
Ok(())
}
#[benchmark]
fn poke_deposit() -> Result<(), BenchmarkError> {
let account_index = T::AccountIndex::from(SEED);
// Setup accounts
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
let original_deposit = T::Deposit::get();
// Claim the index
Pallet::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;
// Verify the initial deposit amount in storage and reserved balance
assert_eq!(Accounts::<T>::get(account_index).unwrap().1, original_deposit);
assert_eq!(T::Currency::reserved_balance(&caller), original_deposit);
// The additional amount we'll add to the deposit for the index
let additional_amount = 2u32.into();
// Reserve the additional amount from the caller's balance
T::Currency::reserve(&caller, additional_amount)?;
// Verify the additional amount was reserved
assert_eq!(
T::Currency::reserved_balance(&caller),
original_deposit.saturating_add(additional_amount)
);
// Increase the deposited amount in storage by additional_amount
Accounts::<T>::try_mutate(account_index, |maybe_value| -> Result<(), BenchmarkError> {
let (account, amount, perm) = maybe_value
.take()
.ok_or(BenchmarkError::Stop("Mutating storage to change deposits failed"))?;
*maybe_value = Some((account, amount.saturating_add(additional_amount), perm));
Ok(())
})?;
// Verify the deposit was increased by additional_amount
assert_eq!(
Accounts::<T>::get(account_index).unwrap().1,
original_deposit.saturating_add(additional_amount)
);
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), account_index);
assert!(Accounts::<T>::contains_key(account_index));
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, caller);
assert_eq!(Accounts::<T>::get(account_index).unwrap().1, original_deposit);
assert_eq!(T::Currency::reserved_balance(&caller), original_deposit);
Ok(())
}
// TODO in another PR: lookup and unlookup trait weights (not critical)
impl_benchmark_test_suite!(Pallet, mock::new_test_ext(), mock::Test);
}
+378
View File
@@ -0,0 +1,378 @@
// 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.
//! An index is a short form of an address. This module handles allocation
//! of indices for a newly created accounts.
#![cfg_attr(not(feature = "std"), no_std)]
mod benchmarking;
mod mock;
mod tests;
pub mod weights;
extern crate alloc;
use alloc::vec::Vec;
use codec::Codec;
use pezframe_support::traits::{BalanceStatus::Reserved, Currency, ReservableCurrency};
use pezsp_runtime::{
traits::{AtLeast32Bit, LookupError, Saturating, StaticLookup, Zero},
MultiAddress,
};
pub use weights::WeightInfo;
type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as pezframe_system::Config>::AccountId>>::Balance;
type AccountIdLookupOf<T> = <<T as pezframe_system::Config>::Lookup as StaticLookup>::Source;
pub use pallet::*;
#[pezframe_support::pallet]
pub mod pallet {
use super::*;
use pezframe_support::pezpallet_prelude::*;
use pezframe_system::pezpallet_prelude::*;
/// The module's config trait.
#[pallet::config]
pub trait Config: pezframe_system::Config {
/// Type used for storing an account's index; implies the maximum number of accounts the
/// system can hold.
type AccountIndex: Parameter
+ Member
+ MaybeSerializeDeserialize
+ Codec
+ Default
+ AtLeast32Bit
+ Copy
+ MaxEncodedLen;
/// The currency trait.
type Currency: ReservableCurrency<Self::AccountId>;
/// The deposit needed for reserving an index.
#[pallet::constant]
type Deposit: Get<BalanceOf<Self>>;
/// The overarching event type.
#[allow(deprecated)]
type RuntimeEvent: From<Event<Self>> + IsType<<Self as pezframe_system::Config>::RuntimeEvent>;
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Assign an previously unassigned index.
///
/// Payment: `Deposit` is reserved from the sender account.
///
/// The dispatch origin for this call must be _Signed_.
///
/// - `index`: the index to be claimed. This must not be in use.
///
/// Emits `IndexAssigned` if successful.
///
/// ## Complexity
/// - `O(1)`.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::claim())]
pub fn claim(origin: OriginFor<T>, index: T::AccountIndex) -> DispatchResult {
let who = ensure_signed(origin)?;
Accounts::<T>::try_mutate(index, |maybe_value| {
ensure!(maybe_value.is_none(), Error::<T>::InUse);
*maybe_value = Some((who.clone(), T::Deposit::get(), false));
T::Currency::reserve(&who, T::Deposit::get())
})?;
Self::deposit_event(Event::IndexAssigned { who, index });
Ok(())
}
/// Assign an index already owned by the sender to another account. The balance reservation
/// is effectively transferred to the new account.
///
/// The dispatch origin for this call must be _Signed_.
///
/// - `index`: the index to be re-assigned. This must be owned by the sender.
/// - `new`: the new owner of the index. This function is a no-op if it is equal to sender.
///
/// Emits `IndexAssigned` if successful.
///
/// ## Complexity
/// - `O(1)`.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::transfer())]
pub fn transfer(
origin: OriginFor<T>,
new: AccountIdLookupOf<T>,
index: T::AccountIndex,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let new = T::Lookup::lookup(new)?;
ensure!(who != new, Error::<T>::NotTransfer);
Accounts::<T>::try_mutate(index, |maybe_value| -> DispatchResult {
let (account, amount, perm) = maybe_value.take().ok_or(Error::<T>::NotAssigned)?;
ensure!(!perm, Error::<T>::Permanent);
ensure!(account == who, Error::<T>::NotOwner);
let lost = T::Currency::repatriate_reserved(&who, &new, amount, Reserved)?;
*maybe_value = Some((new.clone(), amount.saturating_sub(lost), false));
Ok(())
})?;
Self::deposit_event(Event::IndexAssigned { who: new, index });
Ok(())
}
/// Free up an index owned by the sender.
///
/// Payment: Any previous deposit placed for the index is unreserved in the sender account.
///
/// The dispatch origin for this call must be _Signed_ and the sender must own the index.
///
/// - `index`: the index to be freed. This must be owned by the sender.
///
/// Emits `IndexFreed` if successful.
///
/// ## Complexity
/// - `O(1)`.
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::free())]
pub fn free(origin: OriginFor<T>, index: T::AccountIndex) -> DispatchResult {
let who = ensure_signed(origin)?;
Accounts::<T>::try_mutate(index, |maybe_value| -> DispatchResult {
let (account, amount, perm) = maybe_value.take().ok_or(Error::<T>::NotAssigned)?;
ensure!(!perm, Error::<T>::Permanent);
ensure!(account == who, Error::<T>::NotOwner);
T::Currency::unreserve(&who, amount);
Ok(())
})?;
Self::deposit_event(Event::IndexFreed { index });
Ok(())
}
/// Force an index to an account. This doesn't require a deposit. If the index is already
/// held, then any deposit is reimbursed to its current owner.
///
/// The dispatch origin for this call must be _Root_.
///
/// - `index`: the index to be (re-)assigned.
/// - `new`: the new owner of the index. This function is a no-op if it is equal to sender.
/// - `freeze`: if set to `true`, will freeze the index so it cannot be transferred.
///
/// Emits `IndexAssigned` if successful.
///
/// ## Complexity
/// - `O(1)`.
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::force_transfer())]
pub fn force_transfer(
origin: OriginFor<T>,
new: AccountIdLookupOf<T>,
index: T::AccountIndex,
freeze: bool,
) -> DispatchResult {
ensure_root(origin)?;
let new = T::Lookup::lookup(new)?;
Accounts::<T>::mutate(index, |maybe_value| {
if let Some((account, amount, _)) = maybe_value.take() {
T::Currency::unreserve(&account, amount);
}
*maybe_value = Some((new.clone(), Zero::zero(), freeze));
});
Self::deposit_event(Event::IndexAssigned { who: new, index });
Ok(())
}
/// Freeze an index so it will always point to the sender account. This consumes the
/// deposit.
///
/// The dispatch origin for this call must be _Signed_ and the signing account must have a
/// non-frozen account `index`.
///
/// - `index`: the index to be frozen in place.
///
/// Emits `IndexFrozen` if successful.
///
/// ## Complexity
/// - `O(1)`.
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::freeze())]
pub fn freeze(origin: OriginFor<T>, index: T::AccountIndex) -> DispatchResult {
let who = ensure_signed(origin)?;
Accounts::<T>::try_mutate(index, |maybe_value| -> DispatchResult {
let (account, amount, perm) = maybe_value.take().ok_or(Error::<T>::NotAssigned)?;
ensure!(!perm, Error::<T>::Permanent);
ensure!(account == who, Error::<T>::NotOwner);
let _ = T::Currency::slash_reserved(&who, amount);
*maybe_value = Some((account, Zero::zero(), true));
Ok(())
})?;
Self::deposit_event(Event::IndexFrozen { index, who });
Ok(())
}
/// Poke the deposit reserved for an index.
///
/// The dispatch origin for this call must be _Signed_ and the signing account must have a
/// non-frozen account `index`.
///
/// The transaction fees is waived if the deposit is changed after poking/reconsideration.
///
/// - `index`: the index whose deposit is to be poked/reconsidered.
///
/// Emits `DepositPoked` if successful.
#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::poke_deposit())]
pub fn poke_deposit(
origin: OriginFor<T>,
index: T::AccountIndex,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Accounts::<T>::try_mutate(index, |maybe_value| -> DispatchResultWithPostInfo {
let (account, old_amount, perm) =
maybe_value.take().ok_or(Error::<T>::NotAssigned)?;
ensure!(!perm, Error::<T>::Permanent);
ensure!(account == who, Error::<T>::NotOwner);
let new_amount = T::Deposit::get();
if old_amount == new_amount {
*maybe_value = Some((account, old_amount, perm));
return Ok(Pays::Yes.into());
} else if new_amount > old_amount {
// Need to reserve more
let extra = new_amount.saturating_sub(old_amount);
T::Currency::reserve(&who, extra)?;
} else if new_amount < old_amount {
// Need to unreserve some
let excess = old_amount.saturating_sub(new_amount);
let remaining_unreserved = T::Currency::unreserve(&who, excess);
// Defensive logging if we can't unreserve the full amount.
if !remaining_unreserved.is_zero() {
defensive!(
"Failed to unreserve full amount. (Index, Requested, Actual): ",
(index, excess, excess - remaining_unreserved)
);
}
}
*maybe_value = Some((account, new_amount, perm));
Self::deposit_event(Event::DepositPoked {
who,
index,
old_deposit: old_amount,
new_deposit: new_amount,
});
Ok(Pays::No.into())
})
}
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// A account index was assigned.
IndexAssigned { who: T::AccountId, index: T::AccountIndex },
/// A account index has been freed up (unassigned).
IndexFreed { index: T::AccountIndex },
/// A account index has been frozen to its current account ID.
IndexFrozen { index: T::AccountIndex, who: T::AccountId },
/// A deposit to reserve an index has been poked/reconsidered.
DepositPoked {
who: T::AccountId,
index: T::AccountIndex,
old_deposit: BalanceOf<T>,
new_deposit: BalanceOf<T>,
},
}
#[pallet::error]
pub enum Error<T> {
/// The index was not already assigned.
NotAssigned,
/// The index is assigned to another account.
NotOwner,
/// The index was not available.
InUse,
/// The source and destination accounts are identical.
NotTransfer,
/// The index is permanent and may not be freed/changed.
Permanent,
}
/// The lookup from index to account.
#[pallet::storage]
pub type Accounts<T: Config> =
StorageMap<_, Blake2_128Concat, T::AccountIndex, (T::AccountId, BalanceOf<T>, bool)>;
#[pallet::genesis_config]
#[derive(pezframe_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
pub indices: Vec<(T::AccountIndex, T::AccountId)>,
}
#[pallet::genesis_build]
impl<T: Config> BuildGenesisConfig for GenesisConfig<T> {
fn build(&self) {
for (a, b) in &self.indices {
<Accounts<T>>::insert(a, (b, <BalanceOf<T>>::zero(), false))
}
}
}
}
impl<T: Config> Pallet<T> {
// PUBLIC IMMUTABLES
/// Lookup an T::AccountIndex to get an Id, if there's one there.
pub fn lookup_index(index: T::AccountIndex) -> Option<T::AccountId> {
Accounts::<T>::get(index).map(|x| x.0)
}
/// Lookup an address to get an Id, if there's one there.
pub fn lookup_address(a: MultiAddress<T::AccountId, T::AccountIndex>) -> Option<T::AccountId> {
match a {
MultiAddress::Id(i) => Some(i),
MultiAddress::Index(i) => Self::lookup_index(i),
_ => None,
}
}
}
impl<T: Config> StaticLookup for Pallet<T> {
type Source = MultiAddress<T::AccountId, T::AccountIndex>;
type Target = T::AccountId;
fn lookup(a: Self::Source) -> Result<Self::Target, LookupError> {
Self::lookup_address(a).ok_or(LookupError)
}
fn unlookup(a: Self::Target) -> Self::Source {
MultiAddress::Id(a)
}
}
+74
View File
@@ -0,0 +1,74 @@
// 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.
//! Test utilities
#![cfg(test)]
use crate::{self as pezpallet_indices, Config};
use pezframe_support::{derive_impl, parameter_types};
use pezsp_runtime::BuildStorage;
type Block = pezframe_system::mocking::MockBlock<Test>;
parameter_types! {
pub static IndexDeposit: u64 = 1;
}
pezframe_support::construct_runtime!(
pub enum Test
{
System: pezframe_system,
Balances: pezpallet_balances,
Indices: pezpallet_indices,
}
);
#[derive_impl(pezframe_system::config_preludes::TestDefaultConfig)]
impl pezframe_system::Config for Test {
type Nonce = u64;
type Lookup = Indices;
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 Config for Test {
type AccountIndex = u64;
type Currency = Balances;
type Deposit = IndexDeposit;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
pub fn new_test_ext() -> pezsp_io::TestExternalities {
let mut t = pezframe_system::GenesisConfig::<Test>::default().build_storage().unwrap();
pezpallet_balances::GenesisConfig::<Test> {
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
..Default::default()
}
.assimilate_storage(&mut t)
.unwrap();
let mut ext: pezsp_io::TestExternalities = t.into();
// Initialize the block number to 1 for event registration
ext.execute_with(|| System::set_block_number(1));
ext
}
+237
View File
@@ -0,0 +1,237 @@
// 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 for the module.
#![cfg(test)]
use super::{mock::*, *};
use pezframe_support::{assert_noop, assert_ok, pezpallet_prelude::Pays};
use pezpallet_balances::Error as BalancesError;
use pezsp_runtime::MultiAddress::Id;
#[test]
fn claiming_should_work() {
new_test_ext().execute_with(|| {
assert_noop!(
Indices::claim(Some(0).into(), 0),
BalancesError::<Test, _>::InsufficientBalance
);
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_noop!(Indices::claim(Some(2).into(), 0), Error::<Test>::InUse);
assert_eq!(Balances::reserved_balance(1), 1);
});
}
#[test]
fn freeing_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_ok!(Indices::claim(Some(2).into(), 1));
assert_noop!(Indices::free(Some(0).into(), 0), Error::<Test>::NotOwner);
assert_noop!(Indices::free(Some(1).into(), 1), Error::<Test>::NotOwner);
assert_noop!(Indices::free(Some(1).into(), 2), Error::<Test>::NotAssigned);
assert_ok!(Indices::free(Some(1).into(), 0));
assert_eq!(Balances::reserved_balance(1), 0);
assert_noop!(Indices::free(Some(1).into(), 0), Error::<Test>::NotAssigned);
});
}
#[test]
fn freezing_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_noop!(Indices::freeze(Some(1).into(), 1), Error::<Test>::NotAssigned);
assert_noop!(Indices::freeze(Some(2).into(), 0), Error::<Test>::NotOwner);
assert_ok!(Indices::freeze(Some(1).into(), 0));
assert_noop!(Indices::freeze(Some(1).into(), 0), Error::<Test>::Permanent);
assert_noop!(Indices::free(Some(1).into(), 0), Error::<Test>::Permanent);
assert_noop!(Indices::transfer(Some(1).into(), Id(2), 0), Error::<Test>::Permanent);
});
}
#[test]
fn indexing_lookup_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_ok!(Indices::claim(Some(2).into(), 1));
assert_eq!(Indices::lookup_index(0), Some(1));
assert_eq!(Indices::lookup_index(1), Some(2));
assert_eq!(Indices::lookup_index(2), None);
});
}
#[test]
fn reclaim_index_on_accounts_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_ok!(Indices::free(Some(1).into(), 0));
assert_ok!(Indices::claim(Some(2).into(), 0));
assert_eq!(Indices::lookup_index(0), Some(2));
assert_eq!(Balances::reserved_balance(2), 1);
});
}
#[test]
fn transfer_index_on_accounts_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_noop!(Indices::transfer(Some(1).into(), Id(2), 1), Error::<Test>::NotAssigned);
assert_noop!(Indices::transfer(Some(2).into(), Id(3), 0), Error::<Test>::NotOwner);
assert_ok!(Indices::transfer(Some(1).into(), Id(3), 0));
assert_eq!(Balances::reserved_balance(1), 0);
assert_eq!(Balances::reserved_balance(3), 1);
assert_eq!(Indices::lookup_index(0), Some(3));
});
}
#[test]
fn force_transfer_index_on_preowned_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_ok!(Indices::force_transfer(RuntimeOrigin::root(), Id(3), 0, false));
assert_eq!(Balances::reserved_balance(1), 0);
assert_eq!(Balances::reserved_balance(3), 0);
assert_eq!(Indices::lookup_index(0), Some(3));
});
}
#[test]
fn force_transfer_index_on_free_should_work() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::force_transfer(RuntimeOrigin::root(), Id(3), 0, false));
assert_eq!(Balances::reserved_balance(3), 0);
assert_eq!(Indices::lookup_index(0), Some(3));
});
}
#[test]
fn poke_deposit_should_fail_for_unassigned_index() {
new_test_ext().execute_with(|| {
assert_noop!(Indices::poke_deposit(Some(1).into(), 0), Error::<Test>::NotAssigned);
});
}
#[test]
fn poke_deposit_should_fail_for_wrong_owner() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_noop!(Indices::poke_deposit(Some(2).into(), 0), Error::<Test>::NotOwner);
});
}
#[test]
fn poke_deposit_should_fail_for_permanent_index() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_ok!(Indices::freeze(Some(1).into(), 0));
assert_noop!(Indices::poke_deposit(Some(1).into(), 0), Error::<Test>::Permanent);
});
}
#[test]
fn poke_deposit_should_fail_for_insufficient_balance() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
// Set deposit higher than available balance
IndexDeposit::set(1000);
assert_noop!(
Indices::poke_deposit(Some(1).into(), 0),
BalancesError::<Test, _>::InsufficientBalance
);
});
}
#[test]
fn poke_deposit_should_work_when_deposit_increases() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_eq!(Balances::reserved_balance(1), 1);
// Change deposit to 3
IndexDeposit::set(3);
// poke_deposit should work and be free
let initial_balance = Balances::free_balance(1);
let result = Indices::poke_deposit(Some(1).into(), 0);
assert_ok!(result.as_ref());
let post_info = result.unwrap();
assert_eq!(post_info.pays_fee, Pays::No);
assert_eq!(Balances::reserved_balance(1), 3);
// Balance should only reduce by the deposit difference
assert_eq!(Balances::free_balance(1), initial_balance - 2);
System::assert_has_event(
Event::DepositPoked { who: 1, index: 0, old_deposit: 1, new_deposit: 3 }.into(),
);
});
}
#[test]
fn poke_deposit_should_work_when_deposit_decreases() {
new_test_ext().execute_with(|| {
// Set initial deposit to 3
IndexDeposit::set(3);
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_eq!(Balances::reserved_balance(1), 3);
// Change deposit to 1
IndexDeposit::set(1);
let initial_balance = Balances::free_balance(1);
let result = Indices::poke_deposit(Some(1).into(), 0);
assert_ok!(result.as_ref());
let post_info = result.unwrap();
assert_eq!(post_info.pays_fee, Pays::No);
assert_eq!(Balances::reserved_balance(1), 1);
// Balance should increase by the unreserved amount
assert_eq!(Balances::free_balance(1), initial_balance + 2);
System::assert_has_event(
Event::DepositPoked { who: 1, index: 0, old_deposit: 3, new_deposit: 1 }.into(),
);
});
}
#[test]
fn poke_deposit_should_charge_fee_when_deposit_unchanged() {
new_test_ext().execute_with(|| {
assert_ok!(Indices::claim(Some(1).into(), 0));
assert_eq!(Balances::reserved_balance(1), 1);
// poke_deposit with same deposit amount
let result = Indices::poke_deposit(Some(1).into(), 0);
assert_ok!(result.as_ref());
// Verify fee payment
let post_info = result.unwrap();
assert_eq!(post_info.pays_fee, Pays::Yes);
// Reserved balance should remain the same
assert_eq!(Balances::reserved_balance(1), 1);
// Verify no DepositPoked event was emitted
assert!(!System::events().iter().any(|record| matches!(
record.event,
RuntimeEvent::Indices(Event::DepositPoked { .. })
)));
});
}
+230
View File
@@ -0,0 +1,230 @@
// 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_indices`
//!
//! 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_indices
// --header=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/HEADER-APACHE2
// --output=/__w/pezkuwi-sdk/pezkuwi-sdk/bizinikiwi/pezframe/indices/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_indices`.
pub trait WeightInfo {
fn claim() -> Weight;
fn transfer() -> Weight;
fn free() -> Weight;
fn force_transfer() -> Weight;
fn freeze() -> Weight;
fn poke_deposit() -> Weight;
}
/// Weights for `pezpallet_indices` using the Bizinikiwi node and recommended hardware.
pub struct BizinikiwiWeight<T>(PhantomData<T>);
impl<T: pezframe_system::Config> WeightInfo for BizinikiwiWeight<T> {
/// Storage: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn claim() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `3534`
// Minimum execution time: 19_563_000 picoseconds.
Weight::from_parts(19_884_000, 3534)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn transfer() -> Weight {
// Proof Size summary in bytes:
// Measured: `178`
// Estimated: `3593`
// Minimum execution time: 32_346_000 picoseconds.
Weight::from_parts(33_179_000, 3593)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
/// Storage: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn free() -> Weight {
// Proof Size summary in bytes:
// Measured: `75`
// Estimated: `3534`
// Minimum execution time: 19_788_000 picoseconds.
Weight::from_parts(20_434_000, 3534)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn force_transfer() -> Weight {
// Proof Size summary in bytes:
// Measured: `177`
// Estimated: `3593`
// Minimum execution time: 23_211_000 picoseconds.
Weight::from_parts(23_690_000, 3593)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
/// Storage: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn freeze() -> Weight {
// Proof Size summary in bytes:
// Measured: `75`
// Estimated: `3534`
// Minimum execution time: 22_510_000 picoseconds.
Weight::from_parts(23_224_000, 3534)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn poke_deposit() -> Weight {
// Proof Size summary in bytes:
// Measured: `75`
// Estimated: `3534`
// Minimum execution time: 20_268_000 picoseconds.
Weight::from_parts(20_592_000, 3534)
.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: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn claim() -> Weight {
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `3534`
// Minimum execution time: 19_563_000 picoseconds.
Weight::from_parts(19_884_000, 3534)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn transfer() -> Weight {
// Proof Size summary in bytes:
// Measured: `178`
// Estimated: `3593`
// Minimum execution time: 32_346_000 picoseconds.
Weight::from_parts(33_179_000, 3593)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
/// Storage: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn free() -> Weight {
// Proof Size summary in bytes:
// Measured: `75`
// Estimated: `3534`
// Minimum execution time: 19_788_000 picoseconds.
Weight::from_parts(20_434_000, 3534)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
fn force_transfer() -> Weight {
// Proof Size summary in bytes:
// Measured: `177`
// Estimated: `3593`
// Minimum execution time: 23_211_000 picoseconds.
Weight::from_parts(23_690_000, 3593)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(2_u64))
}
/// Storage: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn freeze() -> Weight {
// Proof Size summary in bytes:
// Measured: `75`
// Estimated: `3534`
// Minimum execution time: 22_510_000 picoseconds.
Weight::from_parts(23_224_000, 3534)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
/// Storage: `Indices::Accounts` (r:1 w:1)
/// Proof: `Indices::Accounts` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`)
fn poke_deposit() -> Weight {
// Proof Size summary in bytes:
// Measured: `75`
// Estimated: `3534`
// Minimum execution time: 20_268_000 picoseconds.
Weight::from_parts(20_592_000, 3534)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}