Skip to content
Snippets Groups Projects
Unverified Commit c14015ab authored by bgallois's avatar bgallois
Browse files

fix all pallets benchmarks

parent 39c2c53f
No related branches found
No related tags found
No related merge requests found
Pipeline #35459 failed
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
use super::*; use super::*;
use frame_benchmarking::benchmarks; use frame_benchmarking::benchmarks;
use frame_benchmarking::Zero;
use frame_system::RawOrigin; use frame_system::RawOrigin;
use sp_runtime::traits::Convert; use sp_runtime::traits::Convert;
use sp_runtime::traits::Zero;
#[cfg(test)] #[cfg(test)]
use maplit::btreemap; use maplit::btreemap;
...@@ -80,10 +80,10 @@ benchmarks! { ...@@ -80,10 +80,10 @@ benchmarks! {
assert!(CertsByReceiver::<T>::get(receiver).is_empty() ); assert!(CertsByReceiver::<T>::get(receiver).is_empty() );
} }
on_initialize { on_initialize {
assert!(CertsRemovableOn::<T>::try_get(T::BlockNumber::zero()).is_err()); assert!(CertsRemovableOn::<T>::try_get(BlockNumberFor::<T>::zero()).is_err());
}: {Pallet::<T>::on_initialize(T::BlockNumber::zero());} }: {Pallet::<T>::on_initialize(BlockNumberFor::<T>::zero());}
do_remove_cert_noop { do_remove_cert_noop {
}: {Pallet::<T>::do_remove_cert(100.into(), 101.into(), Some(T::BlockNumber::zero()));} }: {Pallet::<T>::do_remove_cert(100.into(), 101.into(), Some(BlockNumberFor::<T>::zero()));}
do_remove_cert { do_remove_cert {
let issuer: T::IdtyIndex = 1.into(); let issuer: T::IdtyIndex = 1.into();
let receiver: T::IdtyIndex = 0.into(); let receiver: T::IdtyIndex = 0.into();
......
...@@ -19,8 +19,9 @@ ...@@ -19,8 +19,9 @@
use super::*; use super::*;
use codec::Encode; use codec::Encode;
use frame_benchmarking::{benchmarks, vec}; use frame_benchmarking::benchmarks;
use frame_support::traits::{Currency, OnFinalize}; use frame_support::traits::{Currency, OnFinalize};
use frame_system::pallet_prelude::BlockNumberFor;
use frame_system::RawOrigin; use frame_system::RawOrigin;
use pallet_balances::Pallet as Balances; use pallet_balances::Pallet as Balances;
use sp_runtime::traits::{Bounded, One}; use sp_runtime::traits::{Bounded, One};
...@@ -48,7 +49,7 @@ benchmarks! { ...@@ -48,7 +49,7 @@ benchmarks! {
where_clause { where_clause {
where where
T: pallet_balances::Config, T::Balance: From<u64>, T: pallet_balances::Config, T::Balance: From<u64>,
T::BlockNumber: From<u32>, BlockNumberFor<T>: From<u32>,
} }
// request distance evaluation // request distance evaluation
......
...@@ -65,13 +65,13 @@ benchmarks! { ...@@ -65,13 +65,13 @@ benchmarks! {
}: _<T::RuntimeOrigin>(origin.into()) }: _<T::RuntimeOrigin>(origin.into())
on_initialize_sufficient { on_initialize_sufficient {
let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, false, true)?; let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, false, true)?;
}: { Pallet::<T>::on_initialize(T::BlockNumber::one()); } }: { Pallet::<T>::on_initialize(BlockNumberFor::<T>::one()); }
on_initialize_with_balance { on_initialize_with_balance {
let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, true, false)?; let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, true, false)?;
}: { Pallet::<T>::on_initialize(T::BlockNumber::one()); } }: { Pallet::<T>::on_initialize(BlockNumberFor::<T>::one()); }
on_initialize_no_balance { on_initialize_no_balance {
let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, false, false)?; let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, false, false)?;
}: { Pallet::<T>::on_initialize(T::BlockNumber::one()); } }: { Pallet::<T>::on_initialize(BlockNumberFor::<T>::one()); }
on_filled_randomness_pending { on_filled_randomness_pending {
let caller: T::AccountId = whitelisted_caller(); let caller: T::AccountId = whitelisted_caller();
let randomness = H256(T::AccountIdToSalt::convert(caller.clone())); let randomness = H256(T::AccountIdToSalt::convert(caller.clone()));
......
...@@ -69,7 +69,7 @@ fn create_one_identity<T: Config>(owner_key: T::AccountId) -> Result<Account<T>, ...@@ -69,7 +69,7 @@ fn create_one_identity<T: Config>(owner_key: T::AccountId) -> Result<Account<T>,
// Reset next_creatable_identity_on to add more identities with Alice // Reset next_creatable_identity_on to add more identities with Alice
<Identities<T>>::mutate_exists(T::IdtyIndex::from(1u32), |idty_val_opt| { <Identities<T>>::mutate_exists(T::IdtyIndex::from(1u32), |idty_val_opt| {
if let Some(ref mut idty_val) = idty_val_opt { if let Some(ref mut idty_val) = idty_val_opt {
idty_val.next_creatable_identity_on = T::BlockNumber::zero(); idty_val.next_creatable_identity_on = BlockNumberFor::<T>::zero();
} }
}); });
Ok(Account { Ok(Account {
...@@ -84,10 +84,10 @@ fn create_one_identity<T: Config>(owner_key: T::AccountId) -> Result<Account<T>, ...@@ -84,10 +84,10 @@ fn create_one_identity<T: Config>(owner_key: T::AccountId) -> Result<Account<T>,
fn create_dummy_identity<T: Config>(i: u32) -> Result<(), &'static str> { fn create_dummy_identity<T: Config>(i: u32) -> Result<(), &'static str> {
let idty_index: T::IdtyIndex = i.into(); let idty_index: T::IdtyIndex = i.into();
let owner_key: T::AccountId = account("Bob", i, SEED); let owner_key: T::AccountId = account("Bob", i, SEED);
let next_scheduled = T::BlockNumber::zero(); let next_scheduled = BlockNumberFor::<T>::zero();
let value = IdtyValue { let value = IdtyValue {
data: Default::default(), data: Default::default(),
next_creatable_identity_on: T::BlockNumber::zero(), next_creatable_identity_on: BlockNumberFor::<T>::zero(),
old_owner_key: None, old_owner_key: None,
owner_key: owner_key.clone(), owner_key: owner_key.clone(),
next_scheduled, next_scheduled,
...@@ -155,7 +155,7 @@ benchmarks! { ...@@ -155,7 +155,7 @@ benchmarks! {
let account: Account<T> = create_one_identity(old_key.clone())?; let account: Account<T> = create_one_identity(old_key.clone())?;
// Change key a first time to add an old-old key // Change key a first time to add an old-old key
let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero()); let genesis_hash = frame_system::Pallet::<T>::block_hash(BlockNumberFor::<T>::zero());
let new_key_payload = IdtyIndexAccountIdPayload { let new_key_payload = IdtyIndexAccountIdPayload {
genesis_hash: &genesis_hash, genesis_hash: &genesis_hash,
idty_index: account.index, idty_index: account.index,
...@@ -170,7 +170,7 @@ benchmarks! { ...@@ -170,7 +170,7 @@ benchmarks! {
// Change key a second time to benchmark // Change key a second time to benchmark
// The sufficients for the old_old key will drop to 0 during benchmark // The sufficients for the old_old key will drop to 0 during benchmark
let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into();
let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero()); let genesis_hash = frame_system::Pallet::<T>::block_hash(BlockNumberFor::<T>::zero());
let new_key_payload = IdtyIndexAccountIdPayload { let new_key_payload = IdtyIndexAccountIdPayload {
genesis_hash: &genesis_hash, genesis_hash: &genesis_hash,
idty_index: account.index, idty_index: account.index,
...@@ -194,7 +194,7 @@ benchmarks! { ...@@ -194,7 +194,7 @@ benchmarks! {
// Change key // Change key
// The sufficients for the old key will drop to 0 during benchmark (not for revoke, only for remove) // The sufficients for the old key will drop to 0 during benchmark (not for revoke, only for remove)
let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero()); let genesis_hash = frame_system::Pallet::<T>::block_hash(BlockNumberFor::<T>::zero());
let new_key_payload = IdtyIndexAccountIdPayload { let new_key_payload = IdtyIndexAccountIdPayload {
genesis_hash: &genesis_hash, genesis_hash: &genesis_hash,
idty_index: account.index, idty_index: account.index,
...@@ -206,7 +206,7 @@ benchmarks! { ...@@ -206,7 +206,7 @@ benchmarks! {
let signature = sr25519_sign(0.into(), &caller_public, &message).unwrap().into(); let signature = sr25519_sign(0.into(), &caller_public, &message).unwrap().into();
Pallet::<T>::change_owner_key(account.origin.clone(), caller.clone(), signature)?; Pallet::<T>::change_owner_key(account.origin.clone(), caller.clone(), signature)?;
let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero()); let genesis_hash = frame_system::Pallet::<T>::block_hash(BlockNumberFor::<T>::zero());
let revocation_payload = RevocationPayload { let revocation_payload = RevocationPayload {
genesis_hash: &genesis_hash, genesis_hash: &genesis_hash,
idty_index: account.index, idty_index: account.index,
...@@ -255,7 +255,7 @@ benchmarks! { ...@@ -255,7 +255,7 @@ benchmarks! {
let bob_public = sr25519_generate(0.into(), None); let bob_public = sr25519_generate(0.into(), None);
let bob: T::AccountId = MultiSigner::Sr25519(bob_public).into_account().into(); let bob: T::AccountId = MultiSigner::Sr25519(bob_public).into_account().into();
frame_system::Pallet::<T>::inc_providers(&bob); frame_system::Pallet::<T>::inc_providers(&bob);
let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero()); let genesis_hash = frame_system::Pallet::<T>::block_hash(BlockNumberFor::<T>::zero());
let payload = ( let payload = (
LINK_IDTY_PAYLOAD_PREFIX, genesis_hash, T::IdtyIndex::one(), bob.clone(), LINK_IDTY_PAYLOAD_PREFIX, genesis_hash, T::IdtyIndex::one(), bob.clone(),
).encode(); ).encode();
...@@ -308,21 +308,21 @@ benchmarks! { ...@@ -308,21 +308,21 @@ benchmarks! {
// --- prune identities // --- prune identities
prune_identities_noop { prune_identities_noop {
assert!(IdentityChangeSchedule::<T>::try_get(T::BlockNumber::zero()).is_err()); assert!(IdentityChangeSchedule::<T>::try_get(BlockNumberFor::<T>::zero()).is_err());
}: {Pallet::<T>::prune_identities(T::BlockNumber::zero());} }: {Pallet::<T>::prune_identities(BlockNumberFor::<T>::zero());}
prune_identities_none { prune_identities_none {
let idty_index: T::IdtyIndex = 100u32.into(); let idty_index: T::IdtyIndex = 100u32.into();
IdentityChangeSchedule::<T>::append(T::BlockNumber::zero(), idty_index); IdentityChangeSchedule::<T>::append(BlockNumberFor::<T>::zero(), idty_index);
assert!(IdentityChangeSchedule::<T>::try_get(T::BlockNumber::zero()).is_ok()); assert!(IdentityChangeSchedule::<T>::try_get(BlockNumberFor::<T>::zero()).is_ok());
assert!(<Identities<T>>::try_get(idty_index).is_err()); assert!(<Identities<T>>::try_get(idty_index).is_err());
}: {Pallet::<T>::prune_identities(T::BlockNumber::zero());} }: {Pallet::<T>::prune_identities(BlockNumberFor::<T>::zero());}
prune_identities_err { prune_identities_err {
let idty_index: T::IdtyIndex = 100u32.into(); let idty_index: T::IdtyIndex = 100u32.into();
create_dummy_identity::<T>(100u32)?; create_dummy_identity::<T>(100u32)?;
IdentityChangeSchedule::<T>::append(T::BlockNumber::zero(), idty_index); IdentityChangeSchedule::<T>::append(BlockNumberFor::<T>::zero(), idty_index);
}: {Pallet::<T>::prune_identities(T::BlockNumber::zero());} }: {Pallet::<T>::prune_identities(BlockNumberFor::<T>::zero());}
impl_benchmark_test_suite!( impl_benchmark_test_suite!(
Pallet, Pallet,
......
...@@ -34,7 +34,7 @@ benchmarks! { ...@@ -34,7 +34,7 @@ benchmarks! {
where_clause { where_clause {
where where
T::IdtyId: From<u32>, T::IdtyId: From<u32>,
<T as frame_system::Config>::BlockNumber: From<u32>, BlockNumberFor<T>: From<u32>,
} }
// TODO membership add and renewal should be included to distance on_new_session as worst case scenario // TODO membership add and renewal should be included to distance on_new_session as worst case scenario
...@@ -52,7 +52,7 @@ benchmarks! { ...@@ -52,7 +52,7 @@ benchmarks! {
let mut idties: Vec<T::IdtyId> = Vec::new(); let mut idties: Vec<T::IdtyId> = Vec::new();
for j in 1..i+1 { for j in 1..i+1 {
let j: T::IdtyId = j.into(); let j: T::IdtyId = j.into();
Membership::<T>::insert(j, MembershipData::<T::BlockNumber>::default()); Membership::<T>::insert(j, MembershipData::<BlockNumberFor<T>>::default());
idties.push(j); idties.push(j);
} }
MembershipsExpireOn::<T>::insert(block_number, idties); MembershipsExpireOn::<T>::insert(block_number, idties);
......
...@@ -71,7 +71,7 @@ benchmarks! { ...@@ -71,7 +71,7 @@ benchmarks! {
let _ = T::Currency::make_free_balance_be(&recipient, existential_deposit.into()); let _ = T::Currency::make_free_balance_be(&recipient, existential_deposit.into());
}: _( }: _(
RawOrigin::Signed(caller.clone()), RawOrigin::Signed(caller.clone()),
T::BlockNumber::zero(), BlockNumberFor::<T>::zero(),
Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient_lookup) Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient_lookup)
) )
verify { verify {
...@@ -104,7 +104,7 @@ benchmarks! { ...@@ -104,7 +104,7 @@ benchmarks! {
let _ = T::Currency::make_free_balance_be(&recipient2, existential_deposit.into()); let _ = T::Currency::make_free_balance_be(&recipient2, existential_deposit.into());
}: _( }: _(
RawOrigin::Signed(caller.clone()), RawOrigin::Signed(caller.clone()),
T::BlockNumber::zero(), BlockNumberFor::<T>::zero(),
Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient1_lookup), Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient1_lookup),
Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient2_lookup), Account::<<T::Lookup as StaticLookup>::Source>::Normal(recipient2_lookup),
existential_deposit.into() existential_deposit.into()
......
...@@ -23,6 +23,7 @@ use frame_support::ensure; ...@@ -23,6 +23,7 @@ use frame_support::ensure;
use frame_support::pallet_prelude::IsType; use frame_support::pallet_prelude::IsType;
use frame_support::sp_runtime::{traits::One, Saturating}; use frame_support::sp_runtime::{traits::One, Saturating};
use frame_support::traits::{Currency, Get, OnInitialize}; use frame_support::traits::{Currency, Get, OnInitialize};
use frame_system::pallet_prelude::BlockNumberFor;
use frame_system::RawOrigin; use frame_system::RawOrigin;
use sp_core::H256; use sp_core::H256;
...@@ -64,7 +65,7 @@ benchmarks! { ...@@ -64,7 +65,7 @@ benchmarks! {
T: pallet_balances::Config, T: pallet_balances::Config,
T::Balance: From<u64>, T::Balance: From<u64>,
<T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>, <T::Currency as Currency<T::AccountId>>::Balance: IsType<T::Balance>,
T::BlockNumber: From<u32>, BlockNumberFor<T>: From<u32>,
} }
request { request {
// Get account // Get account
...@@ -94,7 +95,7 @@ benchmarks! { ...@@ -94,7 +95,7 @@ benchmarks! {
core::mem::replace(next_in, next_in.saturating_sub(1)) core::mem::replace(next_in, next_in.saturating_sub(1))
}); });
ensure!(next_epoch_hook_in != 1, "Will be next epoch."); ensure!(next_epoch_hook_in != 1, "Will be next epoch.");
}: { Pallet::<T>::on_initialize(T::BlockNumber::one()); } }: { Pallet::<T>::on_initialize(BlockNumberFor::<T>::one()); }
verify { verify {
ensure!(RequestsIds::<T>::count() == 0, "List not processed."); ensure!(RequestsIds::<T>::count() == 0, "List not processed.");
ensure!(RequestsReadyAtNextBlock::<T>::get().is_empty(), "List not processed."); ensure!(RequestsReadyAtNextBlock::<T>::get().is_empty(), "List not processed.");
......
...@@ -59,14 +59,14 @@ benchmarks! { ...@@ -59,14 +59,14 @@ benchmarks! {
IdtyQuota::<T>::insert( IdtyQuota::<T>::insert(
idty_id, idty_id,
Quota { Quota {
last_use: T::BlockNumber::zero(), last_use: BlockNumberFor::<T>::zero(),
amount: quota_amount.into(), amount: quota_amount.into(),
}, },
); );
}: { Pallet::<T>::spend_quota(idty_id, amount.into()) } }: { Pallet::<T>::spend_quota(idty_id, amount.into()) }
verify { verify {
let quota_growth = sp_runtime::Perbill::from_rational( let quota_growth = sp_runtime::Perbill::from_rational(
T::BlockNumber::one(), BlockNumberFor::<T>::one(),
T::ReloadRate::get(), T::ReloadRate::get(),
).mul_floor(T::MaxQuota::get()); ).mul_floor(T::MaxQuota::get());
assert_eq!(IdtyQuota::<T>::get(idty_id).unwrap().amount, quota_growth +quota_amount.into() - amount.into()); assert_eq!(IdtyQuota::<T>::get(idty_id).unwrap().amount, quota_growth +quota_amount.into() - amount.into());
...@@ -77,7 +77,7 @@ benchmarks! { ...@@ -77,7 +77,7 @@ benchmarks! {
IdtyQuota::<T>::insert( IdtyQuota::<T>::insert(
idty_id, idty_id,
Quota { Quota {
last_use: T::BlockNumber::zero(), last_use: BlockNumberFor::<T>::zero(),
amount: 10u64.into(), amount: 10u64.into(),
}, },
); );
...@@ -127,7 +127,7 @@ benchmarks! { ...@@ -127,7 +127,7 @@ benchmarks! {
IdtyQuota::<T>::insert( IdtyQuota::<T>::insert(
idty_id, idty_id,
Quota { Quota {
last_use: T::BlockNumber::zero(), last_use: BlockNumberFor::<T>::zero(),
amount: 10u64.into(), amount: 10u64.into(),
}, },
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment