Files
pezkuwi-sdk/pezcumulus/teyrchains/pezpallets/trust/src/benchmarking.rs
T
pezkuwichain 3139ffa25e fix: Complete snowbridge pezpallet rebrand and critical bug fixes
- snowbridge-pezpallet-* → pezsnowbridge-pezpallet-* (201 refs)
- pallet/ directories → pezpallet/ (4 locations)
- Fixed pezpallet.rs self-include recursion bug
- Fixed sc-chain-spec hardcoded crate name in derive macro
- Reverted .pezpallet_by_name() to .pallet_by_name() (subxt API)
- Added BizinikiwiConfig type alias for zombienet tests
- Deleted obsolete session state files

Verified: pezsnowbridge-pezpallet-*, pezpallet-staking,
pezpallet-staking-async, pezframe-benchmarking-cli all pass cargo check
2025-12-16 09:57:23 +03:00

73 lines
2.3 KiB
Rust

//! Benchmarking setup for pezpallet-trust
//!
//! These benchmarks measure the performance of trust score operations.
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use crate::Pezpallet as TrustPallet;
use pezframe_benchmarking::{v2::*, whitelisted_caller};
use pezframe_support::pezpallet_prelude::*;
use pezframe_system::RawOrigin;
use pezsp_runtime::traits::Zero;
// We don't use IdentityKycPallet directly - just mock the citizenship status
// This simplifies benchmarks and avoids coupling with identity-kyc internals
#[benchmarks]
mod benchmarks {
use super::*;
/// Helper to setup a citizen for benchmarking
/// Instead of calling identity-kyc extrinsics, we mock the citizenship source
fn setup_citizen<T: Config>(account: &T::AccountId) {
// For benchmarks, we rely on the runtime's CitizenshipSource implementation
// The benchmark mock should configure CitizenshipSource to return true for whitelisted
// accounts This is typically done via TestCitizenshipProvider in mock.rs
// Initialize trust score storage for the account so update operations work
TrustScores::<T>::insert(account, T::Score::zero());
}
#[benchmark]
fn force_recalculate_trust_score() -> Result<(), BenchmarkError> {
// Setup
let account: T::AccountId = whitelisted_caller();
setup_citizen::<T>(&account);
#[extrinsic_call]
force_recalculate_trust_score(RawOrigin::Root, account.clone());
// Verify - trust score should be calculated (may be zero if no component scores)
assert!(TrustScores::<T>::contains_key(&account));
Ok(())
}
#[benchmark]
fn update_all_trust_scores() {
// Setup - Ensure no batch update is in progress
crate::BatchUpdateInProgress::<T>::put(false);
#[extrinsic_call]
update_all_trust_scores(RawOrigin::Root);
// Verify - The function completed (may or may not have set BatchUpdateInProgress
// depending on whether there are citizens to process)
// We just verify it doesn't panic
}
#[benchmark]
fn periodic_trust_score_update() {
// Setup - Ensure no batch update is in progress
crate::BatchUpdateInProgress::<T>::put(false);
#[extrinsic_call]
periodic_trust_score_update(RawOrigin::Root);
// Verify - The function completed successfully
}
impl_benchmark_test_suite!(TrustPallet, crate::mock::new_test_ext(), crate::mock::Test);
}