git.delta.rocks / unique-network / refs/commits / 081dbb6ae4fb

difftreelog

source

pallets/app-promotion/src/benchmarking.rs7.4 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> + Into<u32>,40		<<T as Config>::Currency as Currency<T::AccountId>>::Balance: Sum + From<u128>41	}42	start_app_promotion {4344	} : {PromototionPallet::<T>::start_app_promotion(RawOrigin::Root.into(), None)?}4546	stop_app_promotion{47		PromototionPallet::<T>::start_app_promotion(RawOrigin::Root.into(), Some(25.into()))?;48	} : {PromototionPallet::<T>::stop_app_promotion(RawOrigin::Root.into())?}4950	set_admin_address {51		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);52		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());53	} : {PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin))?}5455	payout_stakers{56		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);57		let share = Perbill::from_rational(1u32, 10);58		PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;59		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());60		let staker: T::AccountId = account("caller", 0, SEED);61		let _ = <T as Config>::Currency::make_free_balance_be(&staker,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());62		let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(staker.clone()).into(), share * <T as Config>::Currency::total_balance(&staker))?;63	} : {PromototionPallet::<T>::payout_stakers(RawOrigin::Signed(pallet_admin.clone()).into(), Some(1))?}6465	stake {66		let caller = account::<T::AccountId>("caller", 0, SEED);67		let share = Perbill::from_rational(1u32, 10);68		let _ = <T as Config>::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());69	} : {PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))?}7071	unstake {72		let caller = account::<T::AccountId>("caller", 0, SEED);73		let share = Perbill::from_rational(1u32, 10);74		let _ = <T as Config>::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());75		let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))?;7677	} : {PromototionPallet::<T>::unstake(RawOrigin::Signed(caller.clone()).into())?}7879	// recalculate_and_insert_stake{80	// 	let caller = account::<T::AccountId>("caller", 0, SEED);81	// 	let share = Perbill::from_rational(1u32, 10);82	// 	let _ = <T as Config>::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());83	// 	let _ = PromototionPallet::<T>::stake(RawOrigin::Signed(caller.clone()).into(), share * <T as Config>::Currency::total_balance(&caller))?;84	// 	let block = <T::RelayBlockNumberProvider as BlockNumberProvider>::current_block_number();85	// 	let mut acc = <BalanceOf<T>>::default();86	// } : {PromototionPallet::<T>::recalculate_and_insert_stake(&caller, block, share * <T as Config>::Currency::total_balance(&caller), &mut acc)}8788	sponsor_collection {89		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);90		PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;91		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());92		let caller: T::AccountId = account("caller", 0, SEED);93		let _ = <T as Config>::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());94		let collection = create_nft_collection::<T>(caller.clone())?;95	} : {PromototionPallet::<T>::sponsor_collection(RawOrigin::Signed(pallet_admin.clone()).into(), collection)?}9697	stop_sponsoring_collection {98		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);99		PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;100		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());101		let caller: T::AccountId = account("caller", 0, SEED);102		let _ = <T as Config>::Currency::make_free_balance_be(&caller,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());103		let collection = create_nft_collection::<T>(caller.clone())?;104		PromototionPallet::<T>::sponsor_collection(RawOrigin::Signed(pallet_admin.clone()).into(), collection)?;105	} : {PromototionPallet::<T>::stop_sponsoring_collection(RawOrigin::Signed(pallet_admin.clone()).into(), collection)?}106107	sponsor_contract {108		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);109		PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;110111		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());112		let address = H160::from_low_u64_be(SEED as u64);113		let data: Vec<u8> = (0..20 as u8).collect();114		<EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;115		<EvmMigrationPallet<T>>::finish(RawOrigin::Root.into(), address, data)?;116	} : {PromototionPallet::<T>::sponsor_conract(RawOrigin::Signed(pallet_admin.clone()).into(), address)?}117118	stop_sponsoring_contract {119		let pallet_admin = account::<T::AccountId>("admin", 0, SEED);120		PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;121122		let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin,  Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());123		let address = H160::from_low_u64_be(SEED as u64);124		let data: Vec<u8> = (0..20 as u8).collect();125		<EvmMigrationPallet<T>>::begin(RawOrigin::Root.into(), address)?;126		<EvmMigrationPallet<T>>::finish(RawOrigin::Root.into(), address, data)?;127		PromototionPallet::<T>::sponsor_conract(RawOrigin::Signed(pallet_admin.clone()).into(), address)?;128	} : {PromototionPallet::<T>::stop_sponsoring_contract(RawOrigin::Signed(pallet_admin.clone()).into(), address)?}129}