git.delta.rocks / unique-network / refs/commits / 0f77c1087f67

difftreelog

fix benchmarks

Daniel Shiposha2023-11-27parent: #c01d30b.patch.diff
in: master

5 files changed

modifiedpallets/common/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -33,7 +33,7 @@
 	MAX_COLLECTION_NAME_LENGTH, MAX_PROPERTIES_PER_ITEM, MAX_TOKEN_PREFIX_LENGTH,
 };
 
-use crate::{BenchmarkPropertyWriter, CollectionHandle, Config, Pallet};
+use crate::{BenchmarkPropertyWriter, CollectionHandle, CollectionIssuer, Config, Pallet};
 
 const SEED: u32 = 1;
 
@@ -121,7 +121,7 @@
 		owner,
 		CollectionMode::NFT,
 		|owner: T::CrossAccountId, data| {
-			<Pallet<T>>::init_collection(owner.clone(), Some(owner), false, data)
+			<Pallet<T>>::init_collection(owner.clone(), CollectionIssuer::User(owner), data)
 		},
 		|h| h,
 	)
modifiedpallets/fungible/src/benchmarking.rsdiffbeforeafterboth
before · pallets/fungible/src/benchmarking.rs
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 frame_benchmarking::{account, v2::*};18use pallet_common::{bench_init, benchmarking::create_collection_raw, Pallet as PalletCommon};19use sp_std::prelude::*;20use up_data_structs::{budget::Unlimited, CollectionMode, MAX_ITEMS_PER_BATCH};2122use super::*;23use crate::{Config, FungibleHandle, Pallet};2425const SEED: u32 = 1;2627fn create_collection<T: Config>(28	owner: T::CrossAccountId,29) -> Result<FungibleHandle<T>, DispatchError> {30	create_collection_raw(31		owner,32		CollectionMode::Fungible(0),33		|owner: T::CrossAccountId, data| {34			<PalletCommon<T>>::init_collection(owner.clone(), Some(owner), false, data)35		},36		FungibleHandle::cast,37	)38}3940#[benchmarks]41mod benchmarks {42	use super::*;4344	#[benchmark]45	fn create_item() -> Result<(), BenchmarkError> {46		bench_init! {47			owner: sub; collection: collection(owner);48			sender: cross_from_sub(owner); to: cross_sub;49		};5051		#[block]52		{53			<Pallet<T>>::create_item(&collection, &sender, (to, 200), &Unlimited)?;54		}5556		Ok(())57	}5859	#[benchmark]60	fn create_multiple_items_ex(b: Linear<0, MAX_ITEMS_PER_BATCH>) -> Result<(), BenchmarkError> {61		bench_init! {62			owner: sub; collection: collection(owner);63			sender: cross_from_sub(owner);64		};65		let data = (0..b)66			.map(|i| {67				bench_init!(to: cross_sub(i););68				(to, 200)69			})70			.collect::<BTreeMap<_, _>>();7172		#[block]73		{74			<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?;75		}7677		Ok(())78	}7980	#[benchmark]81	fn burn_item() -> Result<(), BenchmarkError> {82		bench_init! {83			owner: sub; collection: collection(owner);84			owner: cross_from_sub; burner: cross_sub;85		};86		<Pallet<T>>::create_item(&collection, &owner, (burner.clone(), 200), &Unlimited)?;8788		#[block]89		{90			<Pallet<T>>::burn(&collection, &burner, 100)?;91		}9293		Ok(())94	}9596	#[benchmark]97	fn transfer_raw() -> Result<(), BenchmarkError> {98		bench_init! {99			owner: sub; collection: collection(owner);100			owner: cross_from_sub; sender: cross_sub; to: cross_sub;101		};102		<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;103104		#[block]105		{106			<Pallet<T>>::transfer(&collection, &sender, &to, 200, &Unlimited)?;107		}108109		Ok(())110	}111112	#[benchmark]113	fn approve() -> Result<(), BenchmarkError> {114		bench_init! {115			owner: sub; collection: collection(owner);116			owner: cross_from_sub; sender: cross_sub; spender: cross_sub;117		};118		<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;119120		#[block]121		{122			<Pallet<T>>::set_allowance(&collection, &sender, &spender, 100)?;123		}124125		Ok(())126	}127128	#[benchmark]129	fn approve_from() -> Result<(), BenchmarkError> {130		bench_init! {131			owner: sub; collection: collection(owner);132			owner: cross_from_sub; sender: cross_sub; spender: cross_sub;133134		};135		let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth());136		<Pallet<T>>::create_item(&collection, &owner, (owner_eth.clone(), 200), &Unlimited)?;137138		#[block]139		{140			<Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, &spender, 100)?;141		}142143		Ok(())144	}145146	#[benchmark]147	fn check_allowed_raw() -> Result<(), BenchmarkError> {148		bench_init! {149			owner: sub; collection: collection(owner);150			owner: cross_from_sub; sender: cross_sub; spender: cross_sub;151		};152		<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;153		<Pallet<T>>::set_allowance(&collection, &sender, &spender, 200)?;154155		#[block]156		{157			<Pallet<T>>::check_allowed(&collection, &spender, &sender, 200, &Unlimited)?;158		}159160		Ok(())161	}162163	#[benchmark]164	fn set_allowance_unchecked_raw() -> Result<(), BenchmarkError> {165		bench_init! {166			owner: sub; collection: collection(owner);167			owner: cross_from_sub; sender: cross_sub; spender: cross_sub;168		};169		<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;170171		#[block]172		{173			<Pallet<T>>::set_allowance_unchecked(&collection, &sender, &spender, 200);174		}175176		Ok(())177	}178179	#[benchmark]180	fn burn_from() -> Result<(), BenchmarkError> {181		bench_init! {182			owner: sub; collection: collection(owner);183			owner: cross_from_sub; sender: cross_sub; burner: cross_sub;184		};185		<Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;186		<Pallet<T>>::set_allowance(&collection, &sender, &burner, 200)?;187188		#[block]189		{190			<Pallet<T>>::burn_from(&collection, &burner, &sender, 100, &Unlimited)?191		}192193		Ok(())194	}195}
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -18,7 +18,7 @@
 use pallet_common::{
 	bench_init,
 	benchmarking::{create_collection_raw, property_key, property_value},
-	Pallet as PalletCommon,
+	CollectionIssuer, Pallet as PalletCommon,
 };
 use sp_std::prelude::*;
 use up_data_structs::{
@@ -58,7 +58,7 @@
 		owner,
 		CollectionMode::NFT,
 		|owner: T::CrossAccountId, data| {
-			<PalletCommon<T>>::init_collection(owner.clone(), Some(owner), false, data)
+			<PalletCommon<T>>::init_collection(owner.clone(), CollectionIssuer::User(owner), data)
 		},
 		NonfungibleHandle::cast,
 	)
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -20,7 +20,7 @@
 use pallet_common::{
 	bench_init,
 	benchmarking::{create_collection_raw, property_key, property_value},
-	Pallet as PalletCommon,
+	CollectionIssuer, Pallet as PalletCommon,
 };
 use sp_std::prelude::*;
 use up_data_structs::{
@@ -63,7 +63,7 @@
 		owner,
 		CollectionMode::ReFungible,
 		|owner: T::CrossAccountId, data| {
-			<PalletCommon<T>>::init_collection(owner.clone(), Some(owner), false, data)
+			<PalletCommon<T>>::init_collection(owner.clone(), CollectionIssuer::User(owner), data)
 		},
 		RefungibleHandle::cast,
 	)
modifiedpallets/structure/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/structure/src/benchmarking.rs
+++ b/pallets/structure/src/benchmarking.rs
@@ -16,7 +16,7 @@
 
 use frame_benchmarking::v2::{account, benchmarks, BenchmarkError};
 use frame_support::traits::{fungible::Balanced, tokens::Precision, Get};
-use pallet_common::Config as CommonConfig;
+use pallet_common::{CollectionIssuer, Config as CommonConfig};
 use pallet_evm::account::CrossAccountId;
 use sp_std::vec;
 use up_data_structs::{
@@ -44,7 +44,7 @@
 		.unwrap();
 		T::CollectionDispatch::create(
 			caller_cross.clone(),
-			Some(caller_cross.clone()),
+			CollectionIssuer::User(caller_cross.clone()),
 			CreateCollectionData {
 				mode: CollectionMode::NFT,
 				..Default::default()