mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Refactor Identity to benchmark v2 (#1838)
This PR refactors `identity/benchmarkings.rs` to use benchmarking v2. These changes are needed to improve the readability and maintainability of the benchmarking code. Changes were implemented using [this](https://github.com/paritytech/polkadot-sdk/commit/9ec80090f5065ce0e3234886c43bc623e8e60d77) commit as a guide. The logic of the benchmarks remains the same. No known issue to backlink. ## Local Testing To test the new benchmarks: 1. `cargo build --features runtime-benchmarks` 2. `./target/debug/polkadot benchmark pallet --steps=5 --repeat=2 --pallet=pallet_identity --extrinsic='*'` --------- Co-authored-by: Richard Melkonian <movses@richards-mbp.home> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com> Co-authored-by: command-bot <> Co-authored-by: Francisco Aguirre <franciscoaguirreperez@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -22,7 +22,9 @@
|
||||
use super::*;
|
||||
|
||||
use crate::Pallet as Identity;
|
||||
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller, BenchmarkError};
|
||||
use frame_benchmarking::{
|
||||
account, impl_benchmark_test_suite, v2::*, whitelisted_caller, BenchmarkError,
|
||||
};
|
||||
use frame_support::{
|
||||
ensure,
|
||||
traits::{EnsureOrigin, Get},
|
||||
@@ -118,110 +120,128 @@ fn create_identity_info<T: Config>(num_fields: u32) -> IdentityInfo<T::MaxAdditi
|
||||
}
|
||||
}
|
||||
|
||||
benchmarks! {
|
||||
add_registrar {
|
||||
let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
|
||||
#[benchmarks]
|
||||
mod benchmarks {
|
||||
use super::*;
|
||||
|
||||
#[benchmark]
|
||||
fn add_registrar(r: Linear<1, { T::MaxRegistrars::get() - 1 }>) -> Result<(), BenchmarkError> {
|
||||
add_registrars::<T>(r)?;
|
||||
ensure!(Registrars::<T>::get().len() as u32 == r, "Registrars not set up correctly.");
|
||||
let origin =
|
||||
T::RegistrarOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
let account = T::Lookup::unlookup(account("registrar", r + 1, SEED));
|
||||
}: _<T::RuntimeOrigin>(origin, account)
|
||||
verify {
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, account);
|
||||
|
||||
ensure!(Registrars::<T>::get().len() as u32 == r + 1, "Registrars not added.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
set_identity {
|
||||
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
|
||||
let x in 0 .. T::MaxAdditionalFields::get();
|
||||
let caller = {
|
||||
// The target user
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
#[benchmark]
|
||||
fn set_identity(
|
||||
r: Linear<1, { T::MaxRegistrars::get() }>,
|
||||
x: Linear<0, { T::MaxAdditionalFields::get() }>,
|
||||
) -> Result<(), BenchmarkError> {
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// Add an initial identity
|
||||
let initial_info = create_identity_info::<T>(1);
|
||||
Identity::<T>::set_identity(caller_origin.clone(), Box::new(initial_info.clone()))?;
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
let caller_origin: <T as frame_system::Config>::RuntimeOrigin =
|
||||
RawOrigin::Signed(caller.clone()).into();
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
// User requests judgement from all the registrars, and they approve
|
||||
for i in 0..r {
|
||||
let registrar: T::AccountId = account("registrar", i, SEED);
|
||||
let registrar_lookup = T::Lookup::unlookup(registrar.clone());
|
||||
let balance_to_use = T::Currency::minimum_balance() * 10u32.into();
|
||||
let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);
|
||||
// Add an initial identity
|
||||
let initial_info = create_identity_info::<T>(1);
|
||||
Identity::<T>::set_identity(caller_origin.clone(), Box::new(initial_info.clone()))?;
|
||||
|
||||
// User requests judgement from all the registrars, and they approve
|
||||
for i in 0..r {
|
||||
let registrar: T::AccountId = account("registrar", i, SEED);
|
||||
let _ = T::Lookup::unlookup(registrar.clone());
|
||||
let balance_to_use = T::Currency::minimum_balance() * 10u32.into();
|
||||
let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);
|
||||
|
||||
Identity::<T>::request_judgement(caller_origin.clone(), i, 10u32.into())?;
|
||||
Identity::<T>::provide_judgement(
|
||||
RawOrigin::Signed(registrar).into(),
|
||||
i,
|
||||
caller_lookup.clone(),
|
||||
Judgement::Reasonable,
|
||||
T::Hashing::hash_of(&initial_info),
|
||||
)?;
|
||||
}
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller.clone()), Box::new(create_identity_info::<T>(x)));
|
||||
|
||||
Identity::<T>::request_judgement(caller_origin.clone(), i, 10u32.into())?;
|
||||
Identity::<T>::provide_judgement(
|
||||
RawOrigin::Signed(registrar).into(),
|
||||
i,
|
||||
caller_lookup.clone(),
|
||||
Judgement::Reasonable,
|
||||
T::Hashing::hash_of(&initial_info),
|
||||
)?;
|
||||
}
|
||||
caller
|
||||
};
|
||||
}: _(RawOrigin::Signed(caller.clone()), Box::new(create_identity_info::<T>(x)))
|
||||
verify {
|
||||
assert_last_event::<T>(Event::<T>::IdentitySet { who: caller }.into());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// We need to split `set_subs` into two benchmarks to accurately isolate the potential
|
||||
// writes caused by new or old sub accounts. The actual weight should simply be
|
||||
// the sum of these two weights.
|
||||
set_subs_new {
|
||||
#[benchmark]
|
||||
fn set_subs_new(s: Linear<0, { T::MaxSubAccounts::get() }>) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
// Create a new subs vec with s sub accounts
|
||||
let s in 0 .. T::MaxSubAccounts::get() => ();
|
||||
|
||||
// Create a new subs vec with sub accounts
|
||||
let subs = create_sub_accounts::<T>(&caller, s)?;
|
||||
ensure!(SubsOf::<T>::get(&caller).1.len() == 0, "Caller already has subs");
|
||||
}: set_subs(RawOrigin::Signed(caller.clone()), subs)
|
||||
verify {
|
||||
|
||||
#[extrinsic_call]
|
||||
set_subs(RawOrigin::Signed(caller.clone()), subs);
|
||||
|
||||
ensure!(SubsOf::<T>::get(&caller).1.len() as u32 == s, "Subs not added");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
set_subs_old {
|
||||
#[benchmark]
|
||||
fn set_subs_old(p: Linear<0, { T::MaxSubAccounts::get() }>) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
|
||||
// Give them p many previous sub accounts.
|
||||
let p in 0 .. T::MaxSubAccounts::get() => {
|
||||
let _ = add_sub_accounts::<T>(&caller, p)?;
|
||||
};
|
||||
let _ = add_sub_accounts::<T>(&caller, p)?;
|
||||
|
||||
// Remove all subs.
|
||||
let subs = create_sub_accounts::<T>(&caller, 0)?;
|
||||
ensure!(
|
||||
SubsOf::<T>::get(&caller).1.len() as u32 == p,
|
||||
"Caller does have subs",
|
||||
);
|
||||
}: set_subs(RawOrigin::Signed(caller.clone()), subs)
|
||||
verify {
|
||||
ensure!(SubsOf::<T>::get(&caller).1.len() as u32 == p, "Caller does have subs",);
|
||||
|
||||
#[extrinsic_call]
|
||||
set_subs(RawOrigin::Signed(caller.clone()), subs);
|
||||
|
||||
ensure!(SubsOf::<T>::get(&caller).1.len() == 0, "Subs not removed");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
clear_identity {
|
||||
#[benchmark]
|
||||
fn clear_identity(
|
||||
r: Linear<1, { T::MaxRegistrars::get() }>,
|
||||
s: Linear<0, { T::MaxSubAccounts::get() }>,
|
||||
x: Linear<0, { T::MaxAdditionalFields::get() }>,
|
||||
) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
|
||||
let caller_origin =
|
||||
<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
|
||||
let caller_lookup = <T::Lookup as StaticLookup>::unlookup(caller.clone());
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
|
||||
let s in 0 .. T::MaxSubAccounts::get() => {
|
||||
// Give them s many sub accounts
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let _ = add_sub_accounts::<T>(&caller, s)?;
|
||||
};
|
||||
let x in 0 .. T::MaxAdditionalFields::get();
|
||||
// Register the registrars
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// Add sub accounts
|
||||
let _ = add_sub_accounts::<T>(&caller, s)?;
|
||||
|
||||
// Create their main identity with x additional fields
|
||||
let info = create_identity_info::<T>(x);
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
|
||||
Identity::<T>::set_identity(caller_origin.clone(), Box::new(info.clone()))?;
|
||||
|
||||
// User requests judgement from all the registrars, and they approve
|
||||
for i in 0..r {
|
||||
let registrar: T::AccountId = account("registrar", i, SEED);
|
||||
let balance_to_use = T::Currency::minimum_balance() * 10u32.into();
|
||||
let balance_to_use = T::Currency::minimum_balance() * 10u32.into();
|
||||
let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);
|
||||
|
||||
Identity::<T>::request_judgement(caller_origin.clone(), i, 10u32.into())?;
|
||||
@@ -233,111 +253,175 @@ benchmarks! {
|
||||
T::Hashing::hash_of(&info),
|
||||
)?;
|
||||
}
|
||||
|
||||
ensure!(IdentityOf::<T>::contains_key(&caller), "Identity does not exist.");
|
||||
}: _(RawOrigin::Signed(caller.clone()))
|
||||
verify {
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller.clone()));
|
||||
|
||||
ensure!(!IdentityOf::<T>::contains_key(&caller), "Identity not cleared.");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
request_judgement {
|
||||
#[benchmark]
|
||||
fn request_judgement(
|
||||
r: Linear<1, { T::MaxRegistrars::get() }>,
|
||||
x: Linear<0, { T::MaxAdditionalFields::get() }>,
|
||||
) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
|
||||
let x in 0 .. T::MaxAdditionalFields::get() => {
|
||||
// Create their main identity with x additional fields
|
||||
let info = create_identity_info::<T>(x);
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));
|
||||
Identity::<T>::set_identity(caller_origin, Box::new(info))?;
|
||||
};
|
||||
}: _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into())
|
||||
verify {
|
||||
assert_last_event::<T>(Event::<T>::JudgementRequested { who: caller, registrar_index: r-1 }.into());
|
||||
// Register the registrars
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
// Create their main identity with x additional fields
|
||||
let info = create_identity_info::<T>(x);
|
||||
let caller_origin =
|
||||
<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
|
||||
Identity::<T>::set_identity(caller_origin.clone(), Box::new(info))?;
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into());
|
||||
|
||||
assert_last_event::<T>(
|
||||
Event::<T>::JudgementRequested { who: caller, registrar_index: r - 1 }.into(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
cancel_request {
|
||||
#[benchmark]
|
||||
fn cancel_request(
|
||||
r: Linear<1, { T::MaxRegistrars::get() }>,
|
||||
x: Linear<0, { T::MaxAdditionalFields::get() }>,
|
||||
) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
|
||||
let x in 0 .. T::MaxAdditionalFields::get() => {
|
||||
// Create their main identity with x additional fields
|
||||
let info = create_identity_info::<T>(x);
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller));
|
||||
Identity::<T>::set_identity(caller_origin, Box::new(info))?;
|
||||
};
|
||||
// Register the registrars
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
Identity::<T>::request_judgement(caller_origin, r - 1, 10u32.into())?;
|
||||
}: _(RawOrigin::Signed(caller.clone()), r - 1)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::<T>::JudgementUnrequested { who: caller, registrar_index: r-1 }.into());
|
||||
// Create their main identity with x additional fields
|
||||
let info = create_identity_info::<T>(x);
|
||||
let caller_origin =
|
||||
<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone()));
|
||||
Identity::<T>::set_identity(caller_origin.clone(), Box::new(info))?;
|
||||
|
||||
Identity::<T>::request_judgement(caller_origin.clone(), r - 1, 10u32.into())?;
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller.clone()), r - 1);
|
||||
|
||||
assert_last_event::<T>(
|
||||
Event::<T>::JudgementUnrequested { who: caller, registrar_index: r - 1 }.into(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
set_fee {
|
||||
#[benchmark]
|
||||
fn set_fee(r: Linear<1, { T::MaxRegistrars::get() - 1 }>) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
|
||||
let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
let registrar_origin = T::RegistrarOrigin::try_successful_origin()
|
||||
.expect("RegistrarOrigin has no successful origin required for the benchmark");
|
||||
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
|
||||
|
||||
let registrars = Registrars::<T>::get();
|
||||
ensure!(registrars[r as usize].as_ref().unwrap().fee == 0u32.into(), "Fee already set.");
|
||||
}: _(RawOrigin::Signed(caller), r, 100u32.into())
|
||||
verify {
|
||||
let registrars = Registrars::<T>::get();
|
||||
ensure!(registrars[r as usize].as_ref().unwrap().fee == 100u32.into(), "Fee not changed.");
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller), r, 100u32.into());
|
||||
|
||||
let updated_registrars = Registrars::<T>::get();
|
||||
ensure!(
|
||||
updated_registrars[r as usize].as_ref().unwrap().fee == 100u32.into(),
|
||||
"Fee not changed."
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
set_account_id {
|
||||
#[benchmark]
|
||||
fn set_account_id(r: Linear<1, { T::MaxRegistrars::get() - 1 }>) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
let registrar_origin = T::RegistrarOrigin::try_successful_origin()
|
||||
.expect("RegistrarOrigin has no successful origin required for the benchmark");
|
||||
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
|
||||
|
||||
let registrars = Registrars::<T>::get();
|
||||
ensure!(registrars[r as usize].as_ref().unwrap().account == caller, "id not set.");
|
||||
|
||||
let new_account = T::Lookup::unlookup(account("new", 0, SEED));
|
||||
}: _(RawOrigin::Signed(caller), r, new_account)
|
||||
verify {
|
||||
let registrars = Registrars::<T>::get();
|
||||
ensure!(registrars[r as usize].as_ref().unwrap().account == account("new", 0, SEED), "id not changed.");
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller), r, new_account);
|
||||
|
||||
let updated_registrars = Registrars::<T>::get();
|
||||
ensure!(
|
||||
updated_registrars[r as usize].as_ref().unwrap().account == account("new", 0, SEED),
|
||||
"id not changed."
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
set_fields {
|
||||
#[benchmark]
|
||||
fn set_fields(r: Linear<1, { T::MaxRegistrars::get() - 1 }>) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
let registrar_origin = T::RegistrarOrigin::try_successful_origin()
|
||||
.expect("RegistrarOrigin has no successful origin required for the benchmark");
|
||||
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
|
||||
let fields = IdentityFields(
|
||||
IdentityField::Display | IdentityField::Legal | IdentityField::Web | IdentityField::Riot
|
||||
| IdentityField::Email | IdentityField::PgpFingerprint | IdentityField::Image | IdentityField::Twitter
|
||||
|
||||
let fields =
|
||||
IdentityFields(
|
||||
IdentityField::Display |
|
||||
IdentityField::Legal | IdentityField::Web |
|
||||
IdentityField::Riot | IdentityField::Email |
|
||||
IdentityField::PgpFingerprint |
|
||||
IdentityField::Image | IdentityField::Twitter,
|
||||
);
|
||||
|
||||
let registrars = Registrars::<T>::get();
|
||||
ensure!(
|
||||
registrars[r as usize].as_ref().unwrap().fields == Default::default(),
|
||||
"fields already set."
|
||||
);
|
||||
let registrars = Registrars::<T>::get();
|
||||
ensure!(registrars[r as usize].as_ref().unwrap().fields == Default::default(), "fields already set.");
|
||||
}: _(RawOrigin::Signed(caller), r, fields)
|
||||
verify {
|
||||
let registrars = Registrars::<T>::get();
|
||||
ensure!(registrars[r as usize].as_ref().unwrap().fields != Default::default(), "fields not set.");
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller), r, fields);
|
||||
|
||||
let updated_registrars = Registrars::<T>::get();
|
||||
ensure!(
|
||||
updated_registrars[r as usize].as_ref().unwrap().fields != Default::default(),
|
||||
"fields not set."
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
provide_judgement {
|
||||
#[benchmark]
|
||||
fn provide_judgement(
|
||||
r: Linear<1, { T::MaxRegistrars::get() - 1 }>,
|
||||
x: Linear<0, { T::MaxAdditionalFields::get() }>,
|
||||
) -> Result<(), BenchmarkError> {
|
||||
// The user
|
||||
let user: T::AccountId = account("user", r, SEED);
|
||||
let user_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(user.clone()));
|
||||
let user_origin =
|
||||
<T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(user.clone()));
|
||||
let user_lookup = <T::Lookup as StaticLookup>::unlookup(user.clone());
|
||||
let _ = T::Currency::make_free_balance_be(&user, BalanceOf::<T>::max_value());
|
||||
|
||||
@@ -345,8 +429,7 @@ benchmarks! {
|
||||
let caller_lookup = T::Lookup::unlookup(caller.clone());
|
||||
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
|
||||
|
||||
let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
|
||||
let x in 0 .. T::MaxAdditionalFields::get();
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
let info = create_identity_info::<T>(x);
|
||||
let info_hash = T::Hashing::hash_of(&info);
|
||||
@@ -356,18 +439,28 @@ benchmarks! {
|
||||
.expect("RegistrarOrigin has no successful origin required for the benchmark");
|
||||
Identity::<T>::add_registrar(registrar_origin, caller_lookup)?;
|
||||
Identity::<T>::request_judgement(user_origin, r, 10u32.into())?;
|
||||
}: _(RawOrigin::Signed(caller), r, user_lookup, Judgement::Reasonable, info_hash)
|
||||
verify {
|
||||
assert_last_event::<T>(Event::<T>::JudgementGiven { target: user, registrar_index: r }.into())
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller), r, user_lookup, Judgement::Reasonable, info_hash);
|
||||
|
||||
assert_last_event::<T>(
|
||||
Event::<T>::JudgementGiven { target: user, registrar_index: r }.into(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
kill_identity {
|
||||
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
|
||||
let s in 0 .. T::MaxSubAccounts::get();
|
||||
let x in 0 .. T::MaxAdditionalFields::get();
|
||||
#[benchmark]
|
||||
fn kill_identity(
|
||||
r: Linear<1, { T::MaxRegistrars::get() }>,
|
||||
s: Linear<0, { T::MaxSubAccounts::get() }>,
|
||||
x: Linear<0, { T::MaxAdditionalFields::get() }>,
|
||||
) -> Result<(), BenchmarkError> {
|
||||
add_registrars::<T>(r)?;
|
||||
|
||||
let target: T::AccountId = account("target", 0, SEED);
|
||||
let target_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(target.clone()).into();
|
||||
let target_origin: <T as frame_system::Config>::RuntimeOrigin =
|
||||
RawOrigin::Signed(target.clone()).into();
|
||||
let target_lookup = T::Lookup::unlookup(target.clone());
|
||||
let _ = T::Currency::make_free_balance_be(&target, BalanceOf::<T>::max_value());
|
||||
|
||||
@@ -378,7 +471,7 @@ benchmarks! {
|
||||
// User requests judgement from all the registrars, and they approve
|
||||
for i in 0..r {
|
||||
let registrar: T::AccountId = account("registrar", i, SEED);
|
||||
let balance_to_use = T::Currency::minimum_balance() * 10u32.into();
|
||||
let balance_to_use = T::Currency::minimum_balance() * 10u32.into();
|
||||
let _ = T::Currency::make_free_balance_be(®istrar, balance_to_use);
|
||||
|
||||
Identity::<T>::request_judgement(target_origin.clone(), i, 10u32.into())?;
|
||||
@@ -390,62 +483,86 @@ benchmarks! {
|
||||
T::Hashing::hash_of(&info),
|
||||
)?;
|
||||
}
|
||||
|
||||
ensure!(IdentityOf::<T>::contains_key(&target), "Identity not set");
|
||||
|
||||
let origin =
|
||||
T::ForceOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
|
||||
}: _<T::RuntimeOrigin>(origin, target_lookup)
|
||||
verify {
|
||||
|
||||
#[extrinsic_call]
|
||||
_(origin as T::RuntimeOrigin, target_lookup);
|
||||
|
||||
ensure!(!IdentityOf::<T>::contains_key(&target), "Identity not removed");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
add_sub {
|
||||
let s in 0 .. T::MaxSubAccounts::get() - 1;
|
||||
|
||||
#[benchmark]
|
||||
fn add_sub(s: Linear<0, { T::MaxSubAccounts::get() - 1 }>) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let _ = add_sub_accounts::<T>(&caller, s)?;
|
||||
let sub = account("new_sub", 0, SEED);
|
||||
let data = Data::Raw(vec![0; 32].try_into().unwrap());
|
||||
|
||||
ensure!(SubsOf::<T>::get(&caller).1.len() as u32 == s, "Subs not set.");
|
||||
}: _(RawOrigin::Signed(caller.clone()), T::Lookup::unlookup(sub), data)
|
||||
verify {
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller.clone()), T::Lookup::unlookup(sub), data);
|
||||
|
||||
ensure!(SubsOf::<T>::get(&caller).1.len() as u32 == s + 1, "Subs not added.");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
rename_sub {
|
||||
let s in 1 .. T::MaxSubAccounts::get();
|
||||
|
||||
#[benchmark]
|
||||
fn rename_sub(s: Linear<1, { T::MaxSubAccounts::get() }>) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let (sub, _) = add_sub_accounts::<T>(&caller, s)?.remove(0);
|
||||
let data = Data::Raw(vec![1; 32].try_into().unwrap());
|
||||
|
||||
ensure!(SuperOf::<T>::get(&sub).unwrap().1 != data, "data already set");
|
||||
}: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()), data.clone())
|
||||
verify {
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()), data.clone());
|
||||
|
||||
ensure!(SuperOf::<T>::get(&sub).unwrap().1 == data, "data not set");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
remove_sub {
|
||||
let s in 1 .. T::MaxSubAccounts::get();
|
||||
|
||||
#[benchmark]
|
||||
fn remove_sub(s: Linear<1, { T::MaxSubAccounts::get() }>) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let (sub, _) = add_sub_accounts::<T>(&caller, s)?.remove(0);
|
||||
ensure!(SuperOf::<T>::contains_key(&sub), "Sub doesn't exists");
|
||||
}: _(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()))
|
||||
verify {
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller), T::Lookup::unlookup(sub.clone()));
|
||||
|
||||
ensure!(!SuperOf::<T>::contains_key(&sub), "Sub not removed");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
quit_sub {
|
||||
let s in 0 .. T::MaxSubAccounts::get() - 1;
|
||||
|
||||
#[benchmark]
|
||||
fn quit_sub(s: Linear<0, { T::MaxSubAccounts::get() - 1 }>) -> Result<(), BenchmarkError> {
|
||||
let caller: T::AccountId = whitelisted_caller();
|
||||
let sup = account("super", 0, SEED);
|
||||
let _ = add_sub_accounts::<T>(&sup, s)?;
|
||||
let sup_origin = RawOrigin::Signed(sup).into();
|
||||
Identity::<T>::add_sub(sup_origin, T::Lookup::unlookup(caller.clone()), Data::Raw(vec![0; 32].try_into().unwrap()))?;
|
||||
Identity::<T>::add_sub(
|
||||
sup_origin,
|
||||
T::Lookup::unlookup(caller.clone()),
|
||||
Data::Raw(vec![0; 32].try_into().unwrap()),
|
||||
)?;
|
||||
ensure!(SuperOf::<T>::contains_key(&caller), "Sub doesn't exists");
|
||||
}: _(RawOrigin::Signed(caller.clone()))
|
||||
verify {
|
||||
|
||||
#[extrinsic_call]
|
||||
_(RawOrigin::Signed(caller.clone()));
|
||||
|
||||
ensure!(!SuperOf::<T>::contains_key(&caller), "Sub not removed");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl_benchmark_test_suite!(Identity, crate::tests::new_test_ext(), crate::tests::Test);
|
||||
|
||||
Reference in New Issue
Block a user