Skip to content
Snippets Groups Projects
Commit 7b2a06f8 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

add benchmark

parent f1f91e4a
No related branches found
No related tags found
1 merge request!215refac membership
......@@ -123,6 +123,8 @@ benchmarks! {
T::AccountId: From<AccountId32>,
T::IdtyIndex: From<u32>,
}
// create identity
create_identity {
let caller: T::AccountId = Identities::<T>::get(T::IdtyIndex::one()).unwrap().owner_key; // Alice
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
......@@ -134,6 +136,7 @@ benchmarks! {
assert_has_event::<T>(Event::<T>::IdtyCreated { idty_index: idty_index.unwrap(), owner_key: owner_key }.into());
}
// confirm identity
confirm_identity {
let caller: T::AccountId = Identities::<T>::get(T::IdtyIndex::one()).unwrap().owner_key;
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
......@@ -146,6 +149,7 @@ benchmarks! {
assert_has_event::<T>(Event::<T>::IdtyConfirmed { idty_index: idty_index.unwrap(), owner_key: owner_key, name: IdtyName("new_identity".into()) }.into());
}
// change owner key
change_owner_key {
let old_key: T::AccountId = account("new_identity", 2, SEED);
let account: Account<T> = create_one_identity(old_key.clone())?;
......@@ -183,6 +187,7 @@ benchmarks! {
assert!(IdentityIndexOf::<T>::get(&caller).unwrap() == account.index, "Owner key not changed");
}
// revoke identity
revoke_identity {
let old_key: T::AccountId = account("new_identity", 2, SEED);
let account: Account<T> = create_one_identity(old_key.clone())?;
......@@ -234,6 +239,7 @@ benchmarks! {
}
}
// fix sufficients identity
fix_sufficients {
let new_identity: T::AccountId = account("Bob", 2, SEED);
let account: Account<T> = create_one_identity(new_identity)?;
......@@ -243,6 +249,7 @@ benchmarks! {
assert!(sufficient < frame_system::Pallet::<T>::sufficients(&account.key), "Sufficient not incremented");
}
// link account
link_account {
let alice_origin = RawOrigin::Signed(Identities::<T>::get(T::IdtyIndex::one()).unwrap().owner_key);
let bob_public = sr25519_generate(0.into(), None);
......@@ -253,9 +260,32 @@ benchmarks! {
).encode();
let signature = sr25519_sign(0.into(), &bob_public, &payload).unwrap().into();
}: _<T::RuntimeOrigin>(alice_origin.into(), bob, signature)
// Base weight of an empty initialize
on_initialize {
}: {Pallet::<T>::on_initialize(BlockNumberFor::<T>::zero());}
// --- do revoke identity
do_revoke_identity_noop {
let idty_index: T::IdtyIndex = 0u32.into();
assert!(Identities::<T>::get(idty_index).is_none());
}: {Pallet::<T>::do_revoke_identity(idty_index, RevocationReason::Root);}
do_revoke_identity {
let idty_index: T::IdtyIndex = 1u32.into();
let new_identity: T::AccountId = account("Bob", 2, SEED);
assert!(Identities::<T>::get(idty_index).is_some());
Identities::<T>::mutate( idty_index, |id| {
if let Some(id) = id {
id.old_owner_key = Some((new_identity, BlockNumberFor::<T>::zero()));
}
});
assert!(Identities::<T>::get(idty_index).unwrap().old_owner_key.is_some());
}: {Pallet::<T>::do_revoke_identity(idty_index, RevocationReason::Root);}
verify {
assert_has_event::<T>(Event::<T>::IdtyRevoked { idty_index, reason: RevocationReason::Root }.into());
}
// --- do remove identity
do_remove_identity_noop {
let idty_index: T::IdtyIndex = 0u32.into();
assert!(Identities::<T>::get(idty_index).is_none());
......@@ -274,15 +304,19 @@ benchmarks! {
verify {
assert_has_event::<T>(Event::<T>::IdtyRemoved { idty_index, reason: RemovalReason::Revoked }.into());
}
// --- prune identities
prune_identities_noop {
assert!(IdentityChangeSchedule::<T>::try_get(T::BlockNumber::zero()).is_err());
}: {Pallet::<T>::prune_identities(T::BlockNumber::zero());}
prune_identities_none {
let idty_index: T::IdtyIndex = 100u32.into();
IdentityChangeSchedule::<T>::append(T::BlockNumber::zero(), idty_index);
assert!(IdentityChangeSchedule::<T>::try_get(T::BlockNumber::zero()).is_ok());
assert!(<Identities<T>>::try_get(idty_index).is_err());
}: {Pallet::<T>::prune_identities(T::BlockNumber::zero());}
prune_identities_err {
let idty_index: T::IdtyIndex = 100u32.into();
create_dummy_identity::<T>(100u32)?;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment