git.delta.rocks / unique-network / refs/commits / ddfc60f7e94f

difftreelog

source

pallets/app-promotion/src/benchmarking.rs3.3 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg(feature = "runtime-benchmarks")]1819use super::*;20use crate::Pallet as PromototionPallet;2122use sp_runtime::traits::Bounded;2324use frame_benchmarking::{benchmarks, account};25use frame_support::traits::OnInitialize;26use frame_system::{Origin, RawOrigin};2728const SEED: u32 = 0;29benchmarks! {30	where_clause{31		where T: Config3233	}34	on_initialize {35		let block1: T::BlockNumber = T::BlockNumber::from(1u32);36		let block2: T::BlockNumber = T::BlockNumber::from(2u32);37		PromototionPallet::<T>::on_initialize(block1); // Create Treasury account38	}: { PromototionPallet::<T>::on_initialize(block2); } // Benchmark deposit_into_existing path3940	start_app_promotion {41		let caller = account::<T::AccountId>("caller", 0, SEED);4243	} : {PromototionPallet::<T>::start_app_promotion(RawOrigin::Root.into(), T::BlockNumber::from(2u32))?}4445	set_admin_address {46		let caller = account::<T::AccountId>("caller", 0, SEED);47		let _ = T::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());48	} : {PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), caller)?}4950	stake {51		let caller = account::<T::AccountId>("caller", 0, SEED);52		let share = Perbill::from_rational(1u32, 10);53		let _ = T::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());54	} : {PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * T::Currency::total_balance(&caller))?}5556	unstake {57		let caller = account::<T::AccountId>("caller", 0, SEED);58		let share = Perbill::from_rational(1u32, 10);59		let _ = T::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());60		let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * T::Currency::total_balance(&caller))?;6162	} : {PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * T::Currency::total_balance(&caller))?}6364	recalculate_stake {65		let caller = account::<T::AccountId>("caller", 0, SEED);66		let share = Perbill::from_rational(1u32, 10);67		let _ = T::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());68		let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * T::Currency::total_balance(&caller))?;69		let block = <T::BlockNumberProvider as BlockNumberProvider>::current_block_number();70		let mut acc = <BalanceOf<T>>::default();71	} : {PromototionPallet::<T>::recalculate_stake(&caller, block, share * T::Currency::total_balance(&caller), &mut acc)}72}