git.delta.rocks / unique-network / refs/commits / 30ec3c77e171

difftreelog

source

pallets/configuration/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//! Benchmarking setup for pallet-configuration1819use frame_benchmarking::v2::*;20use frame_support::assert_ok;21use frame_system::{pallet_prelude::*, EventRecord, RawOrigin};22use sp_std::vec;2324use super::*;2526fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {27	let events = frame_system::Pallet::<T>::events();28	let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();29	// compare to the last event record30	let EventRecord { event, .. } = &events[events.len() - 1];31	assert_eq!(event, &system_event);32}3334#[benchmarks(35	where36		T: Config,37		T::Balance: From<u32>38)]39mod benchmarks {40	use super::*;4142	#[benchmark]43	fn set_weight_to_fee_coefficient_override() -> Result<(), BenchmarkError> {44		let coeff: u64 = 999;4546		#[block]47		{48			assert_ok!(<Pallet<T>>::set_weight_to_fee_coefficient_override(49				RawOrigin::Root.into(),50				Some(coeff)51			));52		}5354		Ok(())55	}5657	#[benchmark]58	fn set_min_gas_price_override() -> Result<(), BenchmarkError> {59		let coeff: u64 = 999;6061		#[block]62		{63			assert_ok!(<Pallet<T>>::set_min_gas_price_override(64				RawOrigin::Root.into(),65				Some(coeff)66			));67		}6869		Ok(())70	}7172	#[benchmark]73	fn set_app_promotion_configuration_override() -> Result<(), BenchmarkError> {74		let configuration: AppPromotionConfiguration<BlockNumberFor<T>> = Default::default();7576		#[block]77		{78			assert_ok!(<Pallet<T>>::set_app_promotion_configuration_override(79				RawOrigin::Root.into(),80				configuration81			));82		}8384		Ok(())85	}8687	#[benchmark]88	fn set_collator_selection_desired_collators() -> Result<(), BenchmarkError> {89		let max: u32 = 999;9091		#[block]92		{93			assert_ok!(<Pallet<T>>::set_collator_selection_desired_collators(94				RawOrigin::Root.into(),95				Some(max)96			));97		}9899		assert_last_event::<T>(100			Event::NewDesiredCollators {101				desired_collators: Some(max),102			}103			.into(),104		);105106		Ok(())107	}108109	#[benchmark]110	fn set_collator_selection_license_bond() -> Result<(), BenchmarkError> {111		let bond_cost: Option<T::Balance> = Some(1000u32.into());112113		#[block]114		{115			assert_ok!(<Pallet<T>>::set_collator_selection_license_bond(116				RawOrigin::Root.into(),117				bond_cost118			));119		}120121		assert_last_event::<T>(Event::NewCollatorLicenseBond { bond_cost }.into());122123		Ok(())124	}125126	#[benchmark]127	fn set_collator_selection_kick_threshold() -> Result<(), BenchmarkError> {128		let threshold: Option<BlockNumberFor<T>> = Some(900u32.into());129130		#[block]131		{132			assert_ok!(<Pallet<T>>::set_collator_selection_kick_threshold(133				RawOrigin::Root.into(),134				threshold135			));136		}137138		assert_last_event::<T>(139			Event::NewCollatorKickThreshold {140				length_in_blocks: threshold,141			}142			.into(),143		);144145		Ok(())146	}147}