git.delta.rocks / unique-network / refs/commits / 14be6d1233ab

difftreelog

fix benchmark compile

Trubnikov Sergey2022-07-20parent: #e2d77d3.patch.diff
in: master

3 files changed

modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -183,7 +183,7 @@
 			value: property_value(),
 		}).collect::<Vec<_>>();
 		let item = create_max_item(&collection, &owner, owner.clone())?;
-	}: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props, false, &Unlimited)?}
+	}: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), false, &Unlimited)?}
 
 	delete_token_properties {
 		let b in 0..MAX_PROPERTIES_PER_ITEM;
@@ -205,7 +205,7 @@
 			value: property_value(),
 		}).collect::<Vec<_>>();
 		let item = create_max_item(&collection, &owner, owner.clone())?;
-		<Pallet<T>>::set_token_properties(&collection, &owner, item, props, false, &Unlimited)?;
+		<Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), false, &Unlimited)?;
 		let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();
-	}: {<Pallet<T>>::delete_token_properties(&collection, &owner, item, to_delete, &Unlimited)?}
+	}: {<Pallet<T>>::delete_token_properties(&collection, &owner, item, to_delete.into_iter(), &Unlimited)?}
 }
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -3,7 +3,7 @@
 //! Autogenerated weights for pallet_nonfungible
 //!
 //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
-//! DATE: 2022-06-15, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`
+//! DATE: 2022-07-20, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`
 //! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024
 
 // Executed Command:
@@ -56,7 +56,7 @@
 	// Storage: Nonfungible TokenData (r:0 w:1)
 	// Storage: Nonfungible Owned (r:0 w:1)
 	fn create_item() -> Weight {
-		(24_135_000 as Weight)
+		(20_328_000 as Weight)
 			.saturating_add(T::DbWeight::get().reads(2 as Weight))
 			.saturating_add(T::DbWeight::get().writes(4 as Weight))
 	}
@@ -65,9 +65,9 @@
 	// Storage: Nonfungible TokenData (r:0 w:4)
 	// Storage: Nonfungible Owned (r:0 w:4)
 	fn create_multiple_items(b: u32, ) -> Weight {
-		(21_952_000 as Weight)
-			// Standard Error: 5_000
-			.saturating_add((4_727_000 as Weight).saturating_mul(b as Weight))
+		(10_134_000 as Weight)
+			// Standard Error: 3_000
+			.saturating_add((4_927_000 as Weight).saturating_mul(b as Weight))
 			.saturating_add(T::DbWeight::get().reads(2 as Weight))
 			.saturating_add(T::DbWeight::get().writes(2 as Weight))
 			.saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))
@@ -77,9 +77,9 @@
 	// Storage: Nonfungible TokenData (r:0 w:4)
 	// Storage: Nonfungible Owned (r:0 w:4)
 	fn create_multiple_items_ex(b: u32, ) -> Weight {
-		(10_432_000 as Weight)
-			// Standard Error: 6_000
-			.saturating_add((7_383_000 as Weight).saturating_mul(b as Weight))
+		(5_710_000 as Weight)
+			// Standard Error: 4_000
+			.saturating_add((7_578_000 as Weight).saturating_mul(b as Weight))
 			.saturating_add(T::DbWeight::get().reads(1 as Weight))
 			.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
 			.saturating_add(T::DbWeight::get().writes(1 as Weight))
@@ -93,7 +93,7 @@
 	// Storage: Nonfungible Owned (r:0 w:1)
 	// Storage: Nonfungible TokenProperties (r:0 w:1)
 	fn burn_item() -> Weight {
-		(29_798_000 as Weight)
+		(28_433_000 as Weight)
 			.saturating_add(T::DbWeight::get().reads(5 as Weight))
 			.saturating_add(T::DbWeight::get().writes(5 as Weight))
 	}
@@ -105,7 +105,7 @@
 	// Storage: Nonfungible Owned (r:0 w:1)
 	// Storage: Nonfungible TokenProperties (r:0 w:1)
 	fn burn_recursively_self_raw() -> Weight {
-		(37_955_000 as Weight)
+		(34_435_000 as Weight)
 			.saturating_add(T::DbWeight::get().reads(5 as Weight))
 			.saturating_add(T::DbWeight::get().writes(5 as Weight))
 	}
@@ -119,8 +119,8 @@
 	// Storage: Common CollectionById (r:1 w:0)
 	fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight {
 		(0 as Weight)
-			// Standard Error: 1_349_000
-			.saturating_add((275_145_000 as Weight).saturating_mul(b as Weight))
+			// Standard Error: 1_539_000
+			.saturating_add((304_456_000 as Weight).saturating_mul(b as Weight))
 			.saturating_add(T::DbWeight::get().reads(7 as Weight))
 			.saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(b as Weight)))
 			.saturating_add(T::DbWeight::get().writes(6 as Weight))
@@ -131,14 +131,14 @@
 	// Storage: Nonfungible Allowance (r:1 w:0)
 	// Storage: Nonfungible Owned (r:0 w:2)
 	fn transfer() -> Weight {
-		(27_867_000 as Weight)
+		(24_376_000 as Weight)
 			.saturating_add(T::DbWeight::get().reads(4 as Weight))
 			.saturating_add(T::DbWeight::get().writes(5 as Weight))
 	}
 	// Storage: Nonfungible TokenData (r:1 w:0)
 	// Storage: Nonfungible Allowance (r:1 w:1)
 	fn approve() -> Weight {
-		(18_824_000 as Weight)
+		(15_890_000 as Weight)
 			.saturating_add(T::DbWeight::get().reads(2 as Weight))
 			.saturating_add(T::DbWeight::get().writes(1 as Weight))
 	}
@@ -147,7 +147,7 @@
 	// Storage: Nonfungible AccountBalance (r:2 w:2)
 	// Storage: Nonfungible Owned (r:0 w:2)
 	fn transfer_from() -> Weight {
-		(32_879_000 as Weight)
+		(28_634_000 as Weight)
 			.saturating_add(T::DbWeight::get().reads(4 as Weight))
 			.saturating_add(T::DbWeight::get().writes(6 as Weight))
 	}
@@ -159,7 +159,7 @@
 	// Storage: Nonfungible Owned (r:0 w:1)
 	// Storage: Nonfungible TokenProperties (r:0 w:1)
 	fn burn_from() -> Weight {
-		(37_061_000 as Weight)
+		(32_201_000 as Weight)
 			.saturating_add(T::DbWeight::get().reads(5 as Weight))
 			.saturating_add(T::DbWeight::get().writes(6 as Weight))
 	}
@@ -167,28 +167,26 @@
 	fn set_token_property_permissions(b: u32, ) -> Weight {
 		(0 as Weight)
 			// Standard Error: 57_000
-			.saturating_add((15_149_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add((15_232_000 as Weight).saturating_mul(b as Weight))
 			.saturating_add(T::DbWeight::get().reads(1 as Weight))
 			.saturating_add(T::DbWeight::get().writes(1 as Weight))
 	}
 	// Storage: Common CollectionPropertyPermissions (r:1 w:0)
-	// Storage: Nonfungible TokenData (r:1 w:0)
 	// Storage: Nonfungible TokenProperties (r:1 w:1)
 	fn set_token_properties(b: u32, ) -> Weight {
 		(0 as Weight)
-			// Standard Error: 2_278_000
-			.saturating_add((409_613_000 as Weight).saturating_mul(b as Weight))
-			.saturating_add(T::DbWeight::get().reads(3 as Weight))
+			// Standard Error: 1_648_000
+			.saturating_add((288_654_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(T::DbWeight::get().reads(2 as Weight))
 			.saturating_add(T::DbWeight::get().writes(1 as Weight))
 	}
 	// Storage: Common CollectionPropertyPermissions (r:1 w:0)
-	// Storage: Nonfungible TokenData (r:1 w:0)
 	// Storage: Nonfungible TokenProperties (r:1 w:1)
 	fn delete_token_properties(b: u32, ) -> Weight {
 		(0 as Weight)
-			// Standard Error: 2_234_000
-			.saturating_add((408_185_000 as Weight).saturating_mul(b as Weight))
-			.saturating_add(T::DbWeight::get().reads(3 as Weight))
+			// Standard Error: 1_632_000
+			.saturating_add((289_190_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(T::DbWeight::get().reads(2 as Weight))
 			.saturating_add(T::DbWeight::get().writes(1 as Weight))
 	}
 }
@@ -200,7 +198,7 @@
 	// Storage: Nonfungible TokenData (r:0 w:1)
 	// Storage: Nonfungible Owned (r:0 w:1)
 	fn create_item() -> Weight {
-		(24_135_000 as Weight)
+		(20_328_000 as Weight)
 			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(4 as Weight))
 	}
@@ -209,9 +207,9 @@
 	// Storage: Nonfungible TokenData (r:0 w:4)
 	// Storage: Nonfungible Owned (r:0 w:4)
 	fn create_multiple_items(b: u32, ) -> Weight {
-		(21_952_000 as Weight)
-			// Standard Error: 5_000
-			.saturating_add((4_727_000 as Weight).saturating_mul(b as Weight))
+		(10_134_000 as Weight)
+			// Standard Error: 3_000
+			.saturating_add((4_927_000 as Weight).saturating_mul(b as Weight))
 			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(2 as Weight))
 			.saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(b as Weight)))
@@ -221,9 +219,9 @@
 	// Storage: Nonfungible TokenData (r:0 w:4)
 	// Storage: Nonfungible Owned (r:0 w:4)
 	fn create_multiple_items_ex(b: u32, ) -> Weight {
-		(10_432_000 as Weight)
-			// Standard Error: 6_000
-			.saturating_add((7_383_000 as Weight).saturating_mul(b as Weight))
+		(5_710_000 as Weight)
+			// Standard Error: 4_000
+			.saturating_add((7_578_000 as Weight).saturating_mul(b as Weight))
 			.saturating_add(RocksDbWeight::get().reads(1 as Weight))
 			.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
 			.saturating_add(RocksDbWeight::get().writes(1 as Weight))
@@ -237,7 +235,7 @@
 	// Storage: Nonfungible Owned (r:0 w:1)
 	// Storage: Nonfungible TokenProperties (r:0 w:1)
 	fn burn_item() -> Weight {
-		(29_798_000 as Weight)
+		(28_433_000 as Weight)
 			.saturating_add(RocksDbWeight::get().reads(5 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(5 as Weight))
 	}
@@ -249,7 +247,7 @@
 	// Storage: Nonfungible Owned (r:0 w:1)
 	// Storage: Nonfungible TokenProperties (r:0 w:1)
 	fn burn_recursively_self_raw() -> Weight {
-		(37_955_000 as Weight)
+		(34_435_000 as Weight)
 			.saturating_add(RocksDbWeight::get().reads(5 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(5 as Weight))
 	}
@@ -263,8 +261,8 @@
 	// Storage: Common CollectionById (r:1 w:0)
 	fn burn_recursively_breadth_plus_self_plus_self_per_each_raw(b: u32, ) -> Weight {
 		(0 as Weight)
-			// Standard Error: 1_349_000
-			.saturating_add((275_145_000 as Weight).saturating_mul(b as Weight))
+			// Standard Error: 1_539_000
+			.saturating_add((304_456_000 as Weight).saturating_mul(b as Weight))
 			.saturating_add(RocksDbWeight::get().reads(7 as Weight))
 			.saturating_add(RocksDbWeight::get().reads((4 as Weight).saturating_mul(b as Weight)))
 			.saturating_add(RocksDbWeight::get().writes(6 as Weight))
@@ -275,14 +273,14 @@
 	// Storage: Nonfungible Allowance (r:1 w:0)
 	// Storage: Nonfungible Owned (r:0 w:2)
 	fn transfer() -> Weight {
-		(27_867_000 as Weight)
+		(24_376_000 as Weight)
 			.saturating_add(RocksDbWeight::get().reads(4 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(5 as Weight))
 	}
 	// Storage: Nonfungible TokenData (r:1 w:0)
 	// Storage: Nonfungible Allowance (r:1 w:1)
 	fn approve() -> Weight {
-		(18_824_000 as Weight)
+		(15_890_000 as Weight)
 			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(1 as Weight))
 	}
@@ -291,7 +289,7 @@
 	// Storage: Nonfungible AccountBalance (r:2 w:2)
 	// Storage: Nonfungible Owned (r:0 w:2)
 	fn transfer_from() -> Weight {
-		(32_879_000 as Weight)
+		(28_634_000 as Weight)
 			.saturating_add(RocksDbWeight::get().reads(4 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(6 as Weight))
 	}
@@ -303,7 +301,7 @@
 	// Storage: Nonfungible Owned (r:0 w:1)
 	// Storage: Nonfungible TokenProperties (r:0 w:1)
 	fn burn_from() -> Weight {
-		(37_061_000 as Weight)
+		(32_201_000 as Weight)
 			.saturating_add(RocksDbWeight::get().reads(5 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(6 as Weight))
 	}
@@ -311,28 +309,26 @@
 	fn set_token_property_permissions(b: u32, ) -> Weight {
 		(0 as Weight)
 			// Standard Error: 57_000
-			.saturating_add((15_149_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add((15_232_000 as Weight).saturating_mul(b as Weight))
 			.saturating_add(RocksDbWeight::get().reads(1 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(1 as Weight))
 	}
 	// Storage: Common CollectionPropertyPermissions (r:1 w:0)
-	// Storage: Nonfungible TokenData (r:1 w:0)
 	// Storage: Nonfungible TokenProperties (r:1 w:1)
 	fn set_token_properties(b: u32, ) -> Weight {
 		(0 as Weight)
-			// Standard Error: 2_278_000
-			.saturating_add((409_613_000 as Weight).saturating_mul(b as Weight))
-			.saturating_add(RocksDbWeight::get().reads(3 as Weight))
+			// Standard Error: 1_648_000
+			.saturating_add((288_654_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(1 as Weight))
 	}
 	// Storage: Common CollectionPropertyPermissions (r:1 w:0)
-	// Storage: Nonfungible TokenData (r:1 w:0)
 	// Storage: Nonfungible TokenProperties (r:1 w:1)
 	fn delete_token_properties(b: u32, ) -> Weight {
 		(0 as Weight)
-			// Standard Error: 2_234_000
-			.saturating_add((408_185_000 as Weight).saturating_mul(b as Weight))
-			.saturating_add(RocksDbWeight::get().reads(3 as Weight))
+			// Standard Error: 1_632_000
+			.saturating_add((289_190_000 as Weight).saturating_mul(b as Weight))
+			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(1 as Weight))
 	}
 }
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
before · pallets/refungible/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 super::*;18use crate::{Pallet, Config, RefungibleHandle};1920use sp_std::prelude::*;21use pallet_common::benchmarking::{create_collection_raw, create_data};22use frame_benchmarking::{benchmarks, account};23use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, CUSTOM_DATA_LIMIT, budget::Unlimited};24use pallet_common::bench_init;25use core::convert::TryInto;26use core::iter::IntoIterator;2728const SEED: u32 = 1;2930fn create_max_item_data<CrossAccountId: Ord>(31	users: impl IntoIterator<Item = (CrossAccountId, u128)>,32) -> CreateRefungibleExData<CrossAccountId> {33	let const_data = create_data::<CUSTOM_DATA_LIMIT>();34	CreateRefungibleExData {35		const_data,36		users: users37			.into_iter()38			.collect::<BTreeMap<_, _>>()39			.try_into()40			.unwrap(),41	}42}43fn create_max_item<T: Config>(44	collection: &RefungibleHandle<T>,45	sender: &T::CrossAccountId,46	users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,47) -> Result<TokenId, DispatchError> {48	let data: CreateRefungibleExData<T::CrossAccountId> = create_max_item_data(users);49	<Pallet<T>>::create_item(&collection, sender, data, &Unlimited)?;50	Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))51}5253fn create_collection<T: Config>(54	owner: T::CrossAccountId,55) -> Result<RefungibleHandle<T>, DispatchError> {56	create_collection_raw(57		owner,58		CollectionMode::NFT,59		<Pallet<T>>::init_collection,60		RefungibleHandle::cast,61	)62}63benchmarks! {64	create_item {65		bench_init!{66			owner: sub; collection: collection(owner);67			sender: cross_from_sub(owner); to: cross_sub;68		};69	}: {create_max_item(&collection, &sender, [(to.clone(), 200)])?}7071	create_multiple_items {72		let b in 0..MAX_ITEMS_PER_BATCH;73		bench_init!{74			owner: sub; collection: collection(owner);75			sender: cross_from_sub(owner); to: cross_sub;76		};77		let data = (0..b).map(|_| create_max_item_data([(to.clone(), 200)])).collect();78	}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}7980	create_multiple_items_ex_multiple_items {81		let b in 0..MAX_ITEMS_PER_BATCH;82		bench_init!{83			owner: sub; collection: collection(owner);84			sender: cross_from_sub(owner);85		};86		let data = (0..b).map(|t| {87			bench_init!(to: cross_sub(t););88			create_max_item_data([(to, 200)])89		}).collect();90	}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}9192	create_multiple_items_ex_multiple_owners {93		let b in 0..MAX_ITEMS_PER_BATCH;94		bench_init!{95			owner: sub; collection: collection(owner);96			sender: cross_from_sub(owner);97		};98		let data = vec![create_max_item_data((0..b).map(|u| {99			bench_init!(to: cross_sub(u););100			(to, 200)101		}))].try_into().unwrap();102	}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}103104	// Other user left, token data is kept105	burn_item_partial {106		bench_init!{107			owner: sub; collection: collection(owner);108			sender: cross_from_sub(owner); burner: cross_sub; another_owner: cross_sub;109		};110		let item = create_max_item(&collection, &sender, [(burner.clone(), 200), (another_owner, 200)])?;111	}: {<Pallet<T>>::burn(&collection, &burner, item, 200)?}112	// No users remaining, token is destroyed113	burn_item_fully {114		bench_init!{115			owner: sub; collection: collection(owner);116			sender: cross_from_sub(owner); burner: cross_sub; another_owner: cross_sub;117		};118		let item = create_max_item(&collection, &sender, [(burner.clone(), 200)])?;119	}: {<Pallet<T>>::burn(&collection, &burner, item, 200)?}120121	transfer_normal {122		bench_init!{123			owner: sub; collection: collection(owner);124			sender: cross_from_sub(owner); receiver: cross_sub;125		};126		let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?;127	}: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?}128	// Target account is created129	transfer_creating {130		bench_init!{131			owner: sub; collection: collection(owner);132			sender: cross_from_sub(owner); receiver: cross_sub;133		};134		let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;135	}: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?}136	// Source account is destroyed137	transfer_removing {138		bench_init!{139			owner: sub; collection: collection(owner);140			sender: cross_from_sub(owner); receiver: cross_sub;141		};142		let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?;143	}: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?}144	// Source account destroyed, target created145	transfer_creating_removing {146		bench_init!{147			owner: sub; collection: collection(owner);148			sender: cross_from_sub(owner); receiver: cross_sub;149		};150		let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;151	}: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?}152153	approve {154		bench_init!{155			owner: sub; collection: collection(owner);156			owner: cross_from_sub; sender: cross_sub; spender: cross_sub;157		};158		let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;159	}: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?}160161	transfer_from_normal {162		bench_init!{163			owner: sub; collection: collection(owner);164			owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;165		};166		let item = create_max_item(&collection, &owner, [(sender.clone(), 200), (receiver.clone(), 200)])?;167		<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?;168	}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 100, &Unlimited)?}169	// Target account is created170	transfer_from_creating {171		bench_init!{172			owner: sub; collection: collection(owner);173			owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;174		};175		let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;176		<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?;177	}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 100, &Unlimited)?}178	// Source account is destroyed179	transfer_from_removing {180		bench_init!{181			owner: sub; collection: collection(owner);182			owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;183		};184		let item = create_max_item(&collection, &owner, [(sender.clone(), 200), (receiver.clone(), 200)])?;185		<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;186	}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 200, &Unlimited)?}187	// Source account destroyed, target created188	transfer_from_creating_removing {189		bench_init!{190			owner: sub; collection: collection(owner);191			owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;192		};193		let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;194		<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;195	}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 200, &Unlimited)?}196197	// Both source account and token is destroyed198	burn_from {199		bench_init!{200			owner: sub; collection: collection(owner);201			owner: cross_from_sub; sender: cross_sub; burner: cross_sub;202		};203		let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;204		<Pallet<T>>::set_allowance(&collection, &sender, &burner, item, 200)?;205	}: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item, 200, &Unlimited)?}206207	repartition_item {208		bench_init!{209			owner: sub; collection: collection(owner);210			sender: cross_from_sub(owner); owner: cross_sub;211		};212		let item = create_max_item(&collection, &sender, [(owner.clone(), 100)])?;213	}: {<Pallet<T>>::repartition(&collection, &owner, item, 200)?}214}
after · pallets/refungible/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 super::*;18use crate::{Pallet, Config, RefungibleHandle};1920use sp_std::prelude::*;21use pallet_common::benchmarking::{create_collection_raw, create_data};22use frame_benchmarking::{benchmarks, account};23use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, CUSTOM_DATA_LIMIT, budget::Unlimited};24use pallet_common::bench_init;25use core::convert::TryInto;26use core::iter::IntoIterator;2728const SEED: u32 = 1;2930fn create_max_item_data<CrossAccountId: Ord>(31	users: impl IntoIterator<Item = (CrossAccountId, u128)>,32) -> CreateRefungibleExData<CrossAccountId> {33	let const_data = create_data::<CUSTOM_DATA_LIMIT>();34	CreateRefungibleExData {35		const_data,36		users: users37			.into_iter()38			.collect::<BTreeMap<_, _>>()39			.try_into()40			.unwrap(),41		properties: Default::default(),42	}43}44fn create_max_item<T: Config>(45	collection: &RefungibleHandle<T>,46	sender: &T::CrossAccountId,47	users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,48) -> Result<TokenId, DispatchError> {49	let data: CreateRefungibleExData<T::CrossAccountId> = create_max_item_data(users);50	<Pallet<T>>::create_item(&collection, sender, data, &Unlimited)?;51	Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))52}5354fn create_collection<T: Config>(55	owner: T::CrossAccountId,56) -> Result<RefungibleHandle<T>, DispatchError> {57	create_collection_raw(58		owner,59		CollectionMode::NFT,60		<Pallet<T>>::init_collection,61		RefungibleHandle::cast,62	)63}64benchmarks! {65	create_item {66		bench_init!{67			owner: sub; collection: collection(owner);68			sender: cross_from_sub(owner); to: cross_sub;69		};70	}: {create_max_item(&collection, &sender, [(to.clone(), 200)])?}7172	create_multiple_items {73		let b in 0..MAX_ITEMS_PER_BATCH;74		bench_init!{75			owner: sub; collection: collection(owner);76			sender: cross_from_sub(owner); to: cross_sub;77		};78		let data = (0..b).map(|_| create_max_item_data([(to.clone(), 200)])).collect();79	}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}8081	create_multiple_items_ex_multiple_items {82		let b in 0..MAX_ITEMS_PER_BATCH;83		bench_init!{84			owner: sub; collection: collection(owner);85			sender: cross_from_sub(owner);86		};87		let data = (0..b).map(|t| {88			bench_init!(to: cross_sub(t););89			create_max_item_data([(to, 200)])90		}).collect();91	}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}9293	create_multiple_items_ex_multiple_owners {94		let b in 0..MAX_ITEMS_PER_BATCH;95		bench_init!{96			owner: sub; collection: collection(owner);97			sender: cross_from_sub(owner);98		};99		let data = vec![create_max_item_data((0..b).map(|u| {100			bench_init!(to: cross_sub(u););101			(to, 200)102		}))].try_into().unwrap();103	}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}104105	// Other user left, token data is kept106	burn_item_partial {107		bench_init!{108			owner: sub; collection: collection(owner);109			sender: cross_from_sub(owner); burner: cross_sub; another_owner: cross_sub;110		};111		let item = create_max_item(&collection, &sender, [(burner.clone(), 200), (another_owner, 200)])?;112	}: {<Pallet<T>>::burn(&collection, &burner, item, 200)?}113	// No users remaining, token is destroyed114	burn_item_fully {115		bench_init!{116			owner: sub; collection: collection(owner);117			sender: cross_from_sub(owner); burner: cross_sub; another_owner: cross_sub;118		};119		let item = create_max_item(&collection, &sender, [(burner.clone(), 200)])?;120	}: {<Pallet<T>>::burn(&collection, &burner, item, 200)?}121122	transfer_normal {123		bench_init!{124			owner: sub; collection: collection(owner);125			sender: cross_from_sub(owner); receiver: cross_sub;126		};127		let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?;128	}: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?}129	// Target account is created130	transfer_creating {131		bench_init!{132			owner: sub; collection: collection(owner);133			sender: cross_from_sub(owner); receiver: cross_sub;134		};135		let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;136	}: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?}137	// Source account is destroyed138	transfer_removing {139		bench_init!{140			owner: sub; collection: collection(owner);141			sender: cross_from_sub(owner); receiver: cross_sub;142		};143		let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?;144	}: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?}145	// Source account destroyed, target created146	transfer_creating_removing {147		bench_init!{148			owner: sub; collection: collection(owner);149			sender: cross_from_sub(owner); receiver: cross_sub;150		};151		let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;152	}: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?}153154	approve {155		bench_init!{156			owner: sub; collection: collection(owner);157			owner: cross_from_sub; sender: cross_sub; spender: cross_sub;158		};159		let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;160	}: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?}161162	transfer_from_normal {163		bench_init!{164			owner: sub; collection: collection(owner);165			owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;166		};167		let item = create_max_item(&collection, &owner, [(sender.clone(), 200), (receiver.clone(), 200)])?;168		<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?;169	}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 100, &Unlimited)?}170	// Target account is created171	transfer_from_creating {172		bench_init!{173			owner: sub; collection: collection(owner);174			owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;175		};176		let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;177		<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?;178	}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 100, &Unlimited)?}179	// Source account is destroyed180	transfer_from_removing {181		bench_init!{182			owner: sub; collection: collection(owner);183			owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;184		};185		let item = create_max_item(&collection, &owner, [(sender.clone(), 200), (receiver.clone(), 200)])?;186		<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;187	}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 200, &Unlimited)?}188	// Source account destroyed, target created189	transfer_from_creating_removing {190		bench_init!{191			owner: sub; collection: collection(owner);192			owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;193		};194		let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;195		<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;196	}: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 200, &Unlimited)?}197198	// Both source account and token is destroyed199	burn_from {200		bench_init!{201			owner: sub; collection: collection(owner);202			owner: cross_from_sub; sender: cross_sub; burner: cross_sub;203		};204		let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;205		<Pallet<T>>::set_allowance(&collection, &sender, &burner, item, 200)?;206	}: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item, 200, &Unlimited)?}207208	repartition_item {209		bench_init!{210			owner: sub; collection: collection(owner);211			sender: cross_from_sub(owner); owner: cross_sub;212		};213		let item = create_max_item(&collection, &sender, [(owner.clone(), 100)])?;214	}: {<Pallet<T>>::repartition(&collection, &owner, item, 200)?}215}