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

difftreelog

source

pallets/proxy-rmrk-equip/src/benchmarking.rs3.9 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/>.1617use sp_std::vec;1819use frame_benchmarking::{benchmarks, account};20use frame_system::RawOrigin;21use frame_support::{22	traits::{Currency, Get},23	BoundedVec,24};2526use up_data_structs::*;2728use super::*;2930const SEED: u32 = 1;3132fn create_data<S: Get<u32>>() -> BoundedVec<u8, S> {33	vec![b'A'; S::get() as usize].try_into().expect("size == S")34}3536fn create_u32_array<S: Get<u32>>() -> BoundedVec<u32, S> {37	vec![0; S::get() as usize].try_into().expect("size == S")38}3940fn create_max_part(id: RmrkSlotId) -> RmrkPartType {41	RmrkPartType::SlotPart(RmrkSlotPart {42		id,43		equippable: RmrkEquippableList::Custom(create_u32_array()),44		src: create_data(),45		z: 1,46	})47}4849fn create_parts_array<S: Get<u32>>(num: u32) -> BoundedVec<RmrkPartType, S> {50	let mut parts: BoundedVec<RmrkPartType, S> = vec![].try_into().expect("0 <= S");5152	for i in 0..num {53		parts.try_push(create_max_part(i)).expect("num <= S");54	}5556	parts57}5859fn create_max_theme_property() -> RmrkThemeProperty {60	RmrkThemeProperty {61		key: create_data(),62		value: create_data(),63	}64}6566fn create_theme_properties_array<S: Get<u32>>(num: u32) -> BoundedVec<RmrkThemeProperty, S> {67	vec![create_max_theme_property(); num as usize]68		.try_into()69		.expect("num <= S")70}7172fn create_max_theme(name: RmrkString, props_num: u32) -> RmrkBoundedTheme {73	RmrkBoundedTheme {74		name,75		properties: create_theme_properties_array(props_num),76		inherit: false,77	}78}7980benchmarks! {81	create_base {82		let b in 0..RmrkPartsLimit::get();8384		let caller = account("caller", 0, SEED);85		<T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());8687		let base_type = create_data();88		let symbol = create_data();89		let parts = create_parts_array(b);90	}: _(RawOrigin::Signed(caller), base_type, symbol, parts)9192	theme_add {93		let b in 0..MaxPropertiesPerTheme::get();9495		let caller = account("caller", 0, SEED);96		<T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());9798		let base_type = create_data();99		let symbol = create_data();100		let parts = create_parts_array(0);101102		<Pallet<T>>::create_base(RawOrigin::Signed(caller.clone()).into(), base_type, symbol, parts)?;103		let base_id = 1;104105106		let default_theme_name = b"default".to_vec().try_into().expect("default is a valid name; qed");107		let default_theme = create_max_theme(default_theme_name, 0);108109		<Pallet<T>>::theme_add(RawOrigin::Signed(caller.clone()).into(), base_id, default_theme)?;110111		let theme = create_max_theme(create_data(), b);112	}: _(RawOrigin::Signed(caller), base_id, theme)113114	equippable {115		let caller = account("caller", 0, SEED);116		<T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());117118		let base_id = 1;119		let slot_id = 42;120121		let base_type = create_data();122		let symbol = create_data();123		let parts = vec! {124			RmrkPartType::SlotPart(RmrkSlotPart {125				id: slot_id,126				equippable: RmrkEquippableList::All,127				src: create_data(),128				z: 1,129			})130		}.try_into().expect("1 <= RmrkPartsLimit");131132		<Pallet<T>>::create_base(RawOrigin::Signed(caller.clone()).into(), base_type, symbol, parts)?;133134		let equippables = RmrkEquippableList::Custom(create_u32_array());135	}: _(RawOrigin::Signed(caller), base_id, slot_id, equippables)136}