Skip to content

Commit

Permalink
fix : remove _{ } syntax from benchmark macro (#7822)
Browse files Browse the repository at this point in the history
* commented use of common

* hack to pass tests

* another hack

* remove all commented code

* fix the easy tests

* temp hack

* follow through comma hack until better solution

* patch macro

* missed one

* update benchmarks

* update docs

* fix docs

* removed too much

* fix changes

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
  • Loading branch information
stanly-johnson and shawntabrizi committed Jan 6, 2021
1 parent d986887 commit 30c1361
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,6 @@ fn create_identity_info<T: Config>(num_fields: u32) -> IdentityInfo {
}

benchmarks! {
// These are the common parameters along with their instancing.
_ {
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
// extra parameter for the set_subs bench for previous sub accounts
let p in 1 .. T::MaxSubAccounts::get() => ();
let s in 1 .. 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 1 .. 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>::Origin::from(RawOrigin::Signed(caller));
Identity::<T>::set_identity(caller_origin, info)?;
};
}

add_registrar {
let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
ensure!(Registrars::<T>::get().len() as u32 == r, "Registrars not set up correctly.");
Expand All @@ -135,10 +116,8 @@ benchmarks! {
}

set_identity {
let r in ...;
// This X doesn't affect the caller ID up front like with the others, so we don't use the
// standard preparation.
let x in _ .. _ => ();
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
let x in 1 .. T::MaxAdditionalFields::get();
let caller = {
// The target user
let caller: T::AccountId = whitelisted_caller();
Expand Down Expand Up @@ -204,9 +183,19 @@ benchmarks! {
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 ...;
let s in ...;
let x in ...;
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
let s in 1 .. 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 1 .. 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>::Origin::from(RawOrigin::Signed(caller));
Identity::<T>::set_identity(caller_origin, info)?;
};

// User requests judgement from all the registrars, and they approve
for i in 0..r {
Expand All @@ -228,8 +217,14 @@ benchmarks! {
let caller: T::AccountId = whitelisted_caller();
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());

let r in ...;
let x in ...;
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
let x in 1 .. 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>::Origin::from(RawOrigin::Signed(caller));
Identity::<T>::set_identity(caller_origin, info)?;
};
}: _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into())
verify {
assert_last_event::<T>(Event::<T>::JudgementRequested(caller, r-1).into());
Expand All @@ -240,8 +235,14 @@ benchmarks! {
let caller_origin = <T as frame_system::Config>::Origin::from(RawOrigin::Signed(caller.clone()));
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());

let r in ...;
let x in ...;
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
let x in 1 .. 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>::Origin::from(RawOrigin::Signed(caller));
Identity::<T>::set_identity(caller_origin, info)?;
};

Identity::<T>::request_judgement(caller_origin, r - 1, 10u32.into())?;
}: _(RawOrigin::Signed(caller.clone()), r - 1)
Expand Down Expand Up @@ -308,8 +309,7 @@ benchmarks! {
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());

let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
// For this x, it's the user identity that gts the fields, not the caller.
let x in _ .. _ => {
let x in 1 .. T::MaxAdditionalFields::get() => {
let info = create_identity_info::<T>(x);
Identity::<T>::set_identity(user_origin.clone(), info)?;
};
Expand All @@ -322,10 +322,9 @@ benchmarks! {
}

kill_identity {
let r in ...;
// Setting up our own account below.
let s in _ .. _ => {};
let x in _ .. _ => {};
let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?;
let s in 1 .. T::MaxSubAccounts::get();
let x in 1 .. T::MaxAdditionalFields::get();

let target: T::AccountId = account("target", 0, SEED);
let target_origin: <T as frame_system::Config>::Origin = RawOrigin::Signed(target.clone()).into();
Expand Down

0 comments on commit 30c1361

Please sign in to comment.