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

difftreelog

source

pallets/app-promotion/src/benchmarking.rs7.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;23use sp_std::vec;2425use frame_benchmarking::{benchmarks, account};2627use frame_system::{Origin, RawOrigin};28use pallet_unique::benchmarking::create_nft_collection;29use pallet_evm_migration::Pallet as EvmMigrationPallet;3031// trait BenchmarkingConfig: Config + pallet_unique::Config { }3233// impl<T: Config + pallet_unique::Config> BenchmarkingConfig for T { }3435const SEED: u32 = 0;36benchmarks! {37	where_clause{38		where T:  Config + pallet_unique::Config + pallet_evm_migration::Config ,39		T::BlockNumber: From<u32>40	}41	start_app_promotion {4243	} : {PromototionPallet::<T>::start_app_promotion(RawOrigin::Root.into(), None)?}4445	stop_app_promotion{46		PromototionPallet::<T>::start_app_promotion(RawOrigin::Root.into(), Some(25.into()))?;47	} : {PromototionPallet::<T>::stop_app_promotion(RawOrigin::Root.into())?}4849	set_admin_address {50		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);51		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());52	} : {PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin))?}5354	payout_stakers{55		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);56		let share = Perbill::from_rational(1u32, 10);57		PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;58		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());59		let staker: T::AccountId = account("caller", 0, SEED);60		let _ = <T as Config>::Currency::make_free_balance_be(&staker,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());61		let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), share * <T as Config>::Currency::total_balance(&staker))?;62	} : {PromototionPallet::<T>::payout_stakers(RawOrigin::Signed(pallet_admin.clone()).into(), Some(1))?}6364	stake {65		let caller = account::<T::AccountId>("caller", 0, SEED);66		let share = Perbill::from_rational(1u32, 10);67		let _ = <T as Config>::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());68	} : {PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))?}6970	unstake {71		let caller = account::<T::AccountId>("caller", 0, SEED);72		let share = Perbill::from_rational(1u32, 10);73		let _ = <T as Config>::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());74		let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))?;7576	} : {PromototionPallet::<T>::unstake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))?}7778	recalculate_stake {79		let caller = account::<T::AccountId>("caller", 0, SEED);80		let share = Perbill::from_rational(1u32, 10);81		let _ = <T as Config>::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());82		let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))?;83		let block = <T::RelayBlockNumberProvider as BlockNumberProvider>::current_block_number();84		let mut acc = <BalanceOf<T>>::default();85	} : {PromototionPallet::<T>::recalculate_stake(&caller, block, share * <T as Config>::Currency::total_balance(&caller), &mut acc)}8687	sponsor_collection {88		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);89		PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;90		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());91		let caller: T::AccountId = account("caller", 0, SEED);92		let _ = <T as Config>::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());93		let collection = create_nft_collection::<T>(caller.clone())?;94	} : {PromototionPallet::<T>::sponsor_collection(RawOrigin::Signed(pallet_admin.clone()).into(), collection)?}9596	stop_sponsoring_collection {97		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);98		PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;99		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());100		let caller: T::AccountId = account("caller", 0, SEED);101		let _ = <T as Config>::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());102		let collection = create_nft_collection::<T>(caller.clone())?;103		PromototionPallet::<T>::sponsor_collection(RawOrigin::Signed(pallet_admin.clone()).into(), collection)?;104	} : {PromototionPallet::<T>::stop_sponsoring_collection(RawOrigin::Signed(pallet_admin.clone()).into(), collection)?}105106	sponsor_contract {107		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);108		PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;109110		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());111		let address = H160::from_low_u64_be(SEED as u64);112		let data: Vec<u8> = (0..20 as u8).collect();113		<EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;114		<EvmMigrationPallet<T>>::finish(RawOrigin::Root.into(), address, data)?;115	} : {PromototionPallet::<T>::sponsor_conract(RawOrigin::Signed(pallet_admin.clone()).into(), address)?}116117	stop_sponsoring_contract {118		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);119		PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;120121		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());122		let address = H160::from_low_u64_be(SEED as u64);123		let data: Vec<u8> = (0..20 as u8).collect();124		<EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;125		<EvmMigrationPallet<T>>::finish(RawOrigin::Root.into(), address, data)?;126		PromototionPallet::<T>::sponsor_conract(RawOrigin::Signed(pallet_admin.clone()).into(), address)?;127	} : {PromototionPallet::<T>::stop_sponsoring_contract(RawOrigin::Signed(pallet_admin.clone()).into(), address)?}128}