1234567891011121314151617#![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); 38 }: { PromototionPallet::<T>::on_initialize(block2); } 3940 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}