Skip to content
Snippets Groups Projects

Duniter-account pallet benchmark

Merged Benjamin Gallois requested to merge bgallois/duniter-v2s:duniter-account-benchmark into master
All threads resolved!
Files
4
+ 52
0
// Copyright 2021-2023 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![cfg(feature = "runtime-benchmarks")]
use super::*;
use frame_benchmarking::{benchmarks, whitelisted_caller};
use frame_support::sp_runtime::{traits::One, Saturating};
use frame_support::traits::Get;
use frame_support::traits::Currency;
use crate::Pallet;
fn create_pending_accounts<T: Config>(i: u32, is_balance: bool) -> Result<(), &'static str> {
for _ in 0..i {
let caller: T::AccountId = whitelisted_caller();
if is_balance {
let existential_deposit = T::ExistentialDeposit::get();
let balance = existential_deposit.saturating_mul((200u32).into());
let _ = <pallet_balances::Pallet<T> as Currency<T::AccountId>>::make_free_balance_be(
&caller,
balance.into(),
);
}
PendingNewAccounts::<T>::insert(caller, ());
}
Ok(())
}
benchmarks! {
on_initialize_with_balance {
let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, true)?;
}: { Pallet::<T>::on_initialize(T::BlockNumber::one()); }
on_initialize_no_balance {
let i in 0 .. T::MaxNewAccountsPerBlock::get() => create_pending_accounts::<T>(i, false)?;
}: { Pallet::<T>::on_initialize(T::BlockNumber::one()); }
}
Loading