1c0e57d984
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.
137 lines
4.2 KiB
Rust
137 lines
4.2 KiB
Rust
//! Benchmarking setup for pezpallet-identity-kyc
|
|
|
|
#![cfg(feature = "runtime-benchmarks")]
|
|
|
|
use super::*;
|
|
use crate::Pallet as IdentityKyc;
|
|
use pezframe_benchmarking::v2::*;
|
|
use pezframe_support::traits::Currency;
|
|
use pezframe_system::RawOrigin;
|
|
use pezsp_core::H256;
|
|
|
|
/// Helper function to create a funded account
|
|
fn funded_account<T: Config>(name: &'static str, index: u32) -> T::AccountId {
|
|
let caller: T::AccountId = account(name, index, 0);
|
|
let amount = T::KycApplicationDeposit::get() * 10u32.into();
|
|
T::Currency::make_free_balance_be(&caller, amount);
|
|
caller
|
|
}
|
|
|
|
/// Helper function to setup a citizen (for referrer)
|
|
fn setup_citizen<T: Config>(who: &T::AccountId) {
|
|
KycStatuses::<T>::insert(who, KycLevel::Approved);
|
|
}
|
|
|
|
/// Helper function to setup an applicant in PendingReferral state
|
|
fn setup_pending_referral<T: Config>(applicant: &T::AccountId, referrer: &T::AccountId) {
|
|
let identity_hash = H256::repeat_byte(0x01);
|
|
let application = CitizenshipApplication { identity_hash, referrer: referrer.clone() };
|
|
Applications::<T>::insert(applicant, application);
|
|
KycStatuses::<T>::insert(applicant, KycLevel::PendingReferral);
|
|
|
|
// Reserve deposit
|
|
let deposit = T::KycApplicationDeposit::get();
|
|
let _ = T::Currency::reserve(applicant, deposit);
|
|
}
|
|
|
|
/// Helper function to setup an applicant in ReferrerApproved state
|
|
fn setup_referrer_approved<T: Config>(applicant: &T::AccountId, referrer: &T::AccountId) {
|
|
let identity_hash = H256::repeat_byte(0x01);
|
|
let application = CitizenshipApplication { identity_hash, referrer: referrer.clone() };
|
|
Applications::<T>::insert(applicant, application);
|
|
KycStatuses::<T>::insert(applicant, KycLevel::ReferrerApproved);
|
|
|
|
// Reserve deposit
|
|
let deposit = T::KycApplicationDeposit::get();
|
|
let _ = T::Currency::reserve(applicant, deposit);
|
|
}
|
|
|
|
#[benchmarks]
|
|
mod benchmarks {
|
|
use super::*;
|
|
|
|
#[benchmark]
|
|
fn apply_for_citizenship() {
|
|
let referrer: T::AccountId = funded_account::<T>("referrer", 0);
|
|
setup_citizen::<T>(&referrer);
|
|
|
|
let applicant: T::AccountId = funded_account::<T>("applicant", 1);
|
|
let identity_hash = H256::repeat_byte(0x42);
|
|
|
|
#[extrinsic_call]
|
|
apply_for_citizenship(
|
|
RawOrigin::Signed(applicant.clone()),
|
|
identity_hash,
|
|
referrer.clone(),
|
|
);
|
|
|
|
assert_eq!(KycStatuses::<T>::get(&applicant), KycLevel::PendingReferral);
|
|
}
|
|
|
|
#[benchmark]
|
|
fn approve_referral() {
|
|
let referrer: T::AccountId = funded_account::<T>("referrer", 0);
|
|
setup_citizen::<T>(&referrer);
|
|
|
|
let applicant: T::AccountId = funded_account::<T>("applicant", 1);
|
|
setup_pending_referral::<T>(&applicant, &referrer);
|
|
|
|
#[extrinsic_call]
|
|
approve_referral(RawOrigin::Signed(referrer.clone()), applicant.clone());
|
|
|
|
assert_eq!(KycStatuses::<T>::get(&applicant), KycLevel::ReferrerApproved);
|
|
}
|
|
|
|
#[benchmark]
|
|
fn confirm_citizenship() {
|
|
let referrer: T::AccountId = funded_account::<T>("referrer", 0);
|
|
setup_citizen::<T>(&referrer);
|
|
|
|
let applicant: T::AccountId = funded_account::<T>("applicant", 1);
|
|
setup_referrer_approved::<T>(&applicant, &referrer);
|
|
|
|
#[extrinsic_call]
|
|
confirm_citizenship(RawOrigin::Signed(applicant.clone()));
|
|
|
|
assert_eq!(KycStatuses::<T>::get(&applicant), KycLevel::Approved);
|
|
}
|
|
|
|
#[benchmark]
|
|
fn revoke_citizenship() {
|
|
let citizen: T::AccountId = funded_account::<T>("citizen", 0);
|
|
setup_citizen::<T>(&citizen);
|
|
|
|
#[extrinsic_call]
|
|
revoke_citizenship(RawOrigin::Root, citizen.clone());
|
|
|
|
assert_eq!(KycStatuses::<T>::get(&citizen), KycLevel::Revoked);
|
|
}
|
|
|
|
#[benchmark]
|
|
fn renounce_citizenship() {
|
|
let citizen: T::AccountId = funded_account::<T>("citizen", 0);
|
|
setup_citizen::<T>(&citizen);
|
|
|
|
#[extrinsic_call]
|
|
renounce_citizenship(RawOrigin::Signed(citizen.clone()));
|
|
|
|
assert_eq!(KycStatuses::<T>::get(&citizen), KycLevel::NotStarted);
|
|
}
|
|
|
|
#[benchmark]
|
|
fn cancel_application() {
|
|
let referrer: T::AccountId = funded_account::<T>("referrer", 0);
|
|
setup_citizen::<T>(&referrer);
|
|
|
|
let applicant: T::AccountId = funded_account::<T>("applicant", 1);
|
|
setup_pending_referral::<T>(&applicant, &referrer);
|
|
|
|
#[extrinsic_call]
|
|
cancel_application(RawOrigin::Signed(applicant.clone()));
|
|
|
|
assert_eq!(KycStatuses::<T>::get(&applicant), KycLevel::NotStarted);
|
|
}
|
|
|
|
impl_benchmark_test_suite!(IdentityKyc, crate::mock::new_test_ext(), crate::mock::Test);
|
|
}
|