Files
pezkuwi-sdk/pezcumulus/teyrchains/pezpallets/tiki/src/benchmarking.rs
T
Kurdistan Tech Ministry 99be20ba05 fix(ci): fix check-toml-format, check-licenses-headers, check-zepter
- taplo.toml: add .cargo/** to exclude list (prevents scanning cached registry files)
- deny.toml: reformat with taplo (tab indentation, proper spacing)
- pezpallets: add Apache-2.0 SPDX license header to 51 files missing headers
  (referral, trust, perwerde, pez-treasury, pez-rewards, welati, token-wrapper,
   messaging, staking-score, presale, identity-kyc)
- ci: check-zepter: prepend $HOME/.cargo/bin to PATH after cargo install
  so newly installed 1.82.1 takes precedence over system 1.78.2
- identity-kyc: fix clippy::needless_borrows_for_generic_args at lib.rs:326
2026-04-22 04:52:25 +03:00

213 lines
6.4 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// This file is part of PezkuwiChain.
// Copyright (C) Dijital Kurdistan Tech Institute
// SPDX-License-Identifier: Apache-2.0
//! Benchmarking setup for pezpallet-tiki
use super::*;
#[allow(unused)]
use crate::Pezpallet as Tiki;
use pezframe_benchmarking::v2::*;
use pezframe_system::RawOrigin;
// Gerekli trait'leri import ediyoruz
use pezframe_support::traits::{Currency, Get};
use pezpallet_balances::Pezpallet as Balances;
use pezsp_runtime::traits::StaticLookup;
extern crate alloc;
// Gerekli trait kısıtlamalarını ana benchmarks bloğuna ekliyoruz.
#[benchmarks(
where
T::CollectionId: Copy + Default + PartialOrd,
T: pezpallet_balances::Config,
)]
mod benchmarks {
use super::*;
// Bu yardımcı fonksiyon, runtime'da tanımlanan Tiki koleksiyonunu oluşturur.
fn ensure_collection_exists<T: Config + pezpallet_balances::Config>()
where
T::CollectionId: Default + PartialOrd,
{
let collection_id = T::TikiCollectionId::get();
// Koleksiyon sahibi olarak fonlanmış `whitelisted_caller`'ı kullanıyoruz.
let caller: T::AccountId = whitelisted_caller();
// Fund the caller account with sufficient balance for NFT deposits
// Use a very large balance to ensure all deposit requirements can be met
let funding = Balances::<T>::minimum_balance() * 1_000_000_000u32.into();
Balances::<T>::make_free_balance_be(&caller, funding);
// `while` döngüsü, 'Step' trait'ine olan ihtiyacı ortadan kaldırır.
while pezpallet_nfts::NextCollectionId::<T>::get().unwrap_or_default() <= collection_id {
let _ = pezpallet_nfts::Pezpallet::<T>::force_create(
RawOrigin::Root.into(),
T::Lookup::unlookup(caller.clone()),
pezpallet_nfts::CollectionConfig {
settings: Default::default(),
max_supply: None,
mint_settings: Default::default(),
},
);
}
}
// Helper to ensure user has a citizen NFT
fn ensure_citizen_nft<T: Config + pezpallet_balances::Config>(
who: T::AccountId,
) -> Result<(), DispatchError>
where
T::CollectionId: Default + PartialOrd,
{
ensure_collection_exists::<T>();
// Fund the user account with sufficient balance for NFT deposits
// Use a very large balance to ensure all deposit requirements can be met
let funding = Balances::<T>::minimum_balance() * 1_000_000_000u32.into();
Balances::<T>::make_free_balance_be(&who, funding);
if Tiki::<T>::citizen_nft(&who).is_none() {
Tiki::<T>::mint_citizen_nft_for_user(&who)?;
}
Ok(())
}
#[benchmark]
fn grant_tiki() -> Result<(), BenchmarkError> {
// NFT'yi alacak 'dest' hesabı olarak fonlanmış `whitelisted_caller`'ı kullanıyoruz.
let dest: T::AccountId = whitelisted_caller();
// Appointed role kullan (Serok yerine Wezir)
let tiki = crate::Tiki::Wezir;
// Ensure the dest account has a citizen NFT before granting a tiki
ensure_citizen_nft::<T>(dest.clone())?;
#[extrinsic_call]
_(RawOrigin::Root, T::Lookup::unlookup(dest.clone()), tiki);
// For non-unique roles, check user has the role
assert!(Tiki::<T>::user_tikis(&dest).contains(&tiki));
Ok(())
}
#[benchmark]
fn revoke_tiki() -> Result<(), BenchmarkError> {
// NFT'yi alacak 'dest' hesabı olarak fonlanmış `whitelisted_caller`'ı kullanıyoruz.
let dest: T::AccountId = whitelisted_caller();
let tiki = crate::Tiki::Wezir; // Use appointed role
// Ensure the dest account has a citizen NFT and the tiki before revoking
ensure_citizen_nft::<T>(dest.clone())?;
Tiki::<T>::internal_grant_role(&dest, tiki)?; // Use internal function to grant without origin check
// Verify the role was granted
assert!(Tiki::<T>::user_tikis(&dest).contains(&tiki));
#[extrinsic_call]
_(RawOrigin::Root, T::Lookup::unlookup(dest.clone()), tiki);
// User should no longer have this role
assert!(!Tiki::<T>::user_tikis(&dest).contains(&tiki));
Ok(())
}
#[benchmark]
fn force_mint_citizen_nft() -> Result<(), BenchmarkError> {
let dest: T::AccountId = whitelisted_caller();
// Ensure collection exists first
ensure_collection_exists::<T>();
// Henüz vatandaş olmamalı
assert!(Tiki::<T>::citizen_nft(&dest).is_none());
#[extrinsic_call]
_(RawOrigin::Root, T::Lookup::unlookup(dest.clone()));
// Vatandaş olduğundan emin ol
assert!(Tiki::<T>::citizen_nft(&dest).is_some());
assert!(Tiki::<T>::is_citizen(&dest));
Ok(())
}
#[benchmark]
fn grant_earned_role() -> Result<(), BenchmarkError> {
let dest: T::AccountId = whitelisted_caller();
let tiki = crate::Tiki::Axa; // Earned bir rol
// Ön koşul: Vatandaş olmalı
ensure_citizen_nft::<T>(dest.clone())?;
#[extrinsic_call]
_(RawOrigin::Root, T::Lookup::unlookup(dest.clone()), tiki);
// Rolün verildiğini doğrula
assert!(Tiki::<T>::has_tiki(&dest, &tiki));
Ok(())
}
#[benchmark]
fn grant_elected_role() -> Result<(), BenchmarkError> {
let dest: T::AccountId = whitelisted_caller();
let tiki = crate::Tiki::Parlementer; // Elected bir rol
// Ön koşul: Vatandaş olmalı
ensure_citizen_nft::<T>(dest.clone())?;
#[extrinsic_call]
_(RawOrigin::Root, T::Lookup::unlookup(dest.clone()), tiki);
// Rolün verildiğini doğrula
assert!(Tiki::<T>::has_tiki(&dest, &tiki));
Ok(())
}
#[benchmark]
fn apply_for_citizenship() -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
// Fund the caller
let funding = Balances::<T>::minimum_balance() * 1_000_000_000u32.into();
Balances::<T>::make_free_balance_be(&caller, funding);
// Ensure collection exists
ensure_collection_exists::<T>();
// Set KYC status to Approved directly in storage
pezpallet_identity_kyc::KycStatuses::<T>::insert(
&caller,
pezpallet_identity_kyc::types::KycLevel::Approved,
);
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()));
// Verify citizenship was granted
assert!(Tiki::<T>::is_citizen(&caller));
Ok(())
}
#[benchmark]
fn check_transfer_permission() -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
let dest: T::AccountId = account("dest", 0, 0);
// Ensure collections exist past tiki collection so we have a valid non-tiki ID
ensure_collection_exists::<T>();
// NextCollectionId is past tiki, so it's a non-tiki collection (call succeeds)
let non_tiki_id = pezpallet_nfts::NextCollectionId::<T>::get().unwrap_or_default();
#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()), non_tiki_id, 0u32, caller.clone(), dest);
Ok(())
}
impl_benchmark_test_suite!(Tiki, crate::mock::new_test_ext(), crate::mock::Test);
}