difftreelog
fix benchmarks
in: master
5 files changed
pallets/common/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -120,7 +120,9 @@
create_collection_raw(
owner,
CollectionMode::NFT,
- |owner: T::CrossAccountId, data| <Pallet<T>>::init_collection(owner.clone(), owner, data),
+ |owner: T::CrossAccountId, data| {
+ <Pallet<T>>::init_collection(owner.clone(), Some(owner), data)
+ },
|h| h,
)
}
pallets/foreign-assets/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/foreign-assets/src/benchmarking.rs
+++ b/pallets/foreign-assets/src/benchmarking.rs
@@ -16,88 +16,29 @@
#![allow(missing_docs)]
-use frame_benchmarking::{account, v2::*};
-use frame_support::traits::Currency;
+use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
-use sp_std::{boxed::Box, vec, vec::Vec};
-use staging_xcm::{opaque::latest::Junction::Parachain, v3::Junctions::X1, VersionedMultiLocation};
+use pallet_common::benchmarking::create_u16_data;
+use sp_std::vec;
+use staging_xcm::prelude::*;
+use up_data_structs::{CollectionMode, MAX_COLLECTION_NAME_LENGTH};
use super::{Call, Config, Pallet};
-use crate::AssetMetadata;
-fn bounded<T: TryFrom<Vec<u8>>>(slice: &[u8]) -> T {
- T::try_from(slice.to_vec())
- .map_err(|_| "slice doesn't fit")
- .unwrap()
-}
-
#[benchmarks]
mod benchmarks {
- use super::*;
-
- #[benchmark]
- fn register_foreign_asset() -> Result<(), BenchmarkError> {
- let owner: T::AccountId = account("user", 0, 1);
- let location: VersionedMultiLocation = VersionedMultiLocation::from(X1(Parachain(1000)));
- let metadata: AssetMetadata<
- <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance,
- > = AssetMetadata {
- name: bounded(b"name"),
- symbol: bounded(b"symbol"),
- decimals: 18,
- minimal_balance: 1u32.into(),
- };
- let mut balance: <<T as Config>::Currency as Currency<
- <T as frame_system::Config>::AccountId,
- >>::Balance = 4_000_000_000u32.into();
- balance = balance * balance;
- <T as Config>::Currency::make_free_balance_be(&owner, balance);
- #[extrinsic_call]
- _(
- RawOrigin::Root,
- owner,
- Box::new(location),
- Box::new(metadata),
- );
-
- Ok(())
- }
+ use super::*;
#[benchmark]
- fn update_foreign_asset() -> Result<(), BenchmarkError> {
- let owner: T::AccountId = account("user", 0, 1);
- let location: VersionedMultiLocation = VersionedMultiLocation::from(X1(Parachain(2000)));
- let metadata: AssetMetadata<
- <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance,
- > = AssetMetadata {
- name: bounded(b"name"),
- symbol: bounded(b"symbol"),
- decimals: 18,
- minimal_balance: 1u32.into(),
- };
- let metadata2: AssetMetadata<
- <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance,
- > = AssetMetadata {
- name: bounded(b"name2"),
- symbol: bounded(b"symbol2"),
- decimals: 18,
- minimal_balance: 1u32.into(),
- };
- let mut balance: <<T as Config>::Currency as Currency<
- <T as frame_system::Config>::AccountId,
- >>::Balance = 4_000_000_000u32.into();
- balance = balance * balance;
- <T as Config>::Currency::make_free_balance_be(&owner, balance);
- Pallet::<T>::register_foreign_asset(
- RawOrigin::Root.into(),
- owner,
- Box::new(location.clone()),
- Box::new(metadata),
- )?;
+ fn force_register_foreign_asset() -> Result<(), BenchmarkError> {
+ let location =
+ MultiLocation::from(X3(Parachain(1000), PalletInstance(42), GeneralIndex(1)));
+ let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
+ let mode = CollectionMode::NFT;
#[extrinsic_call]
- _(RawOrigin::Root, 0, Box::new(location), Box::new(metadata2));
+ _(RawOrigin::Root, location, name, mode);
Ok(())
}
pallets/fungible/src/benchmarking.rsdiffbeforeafterboth1// 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};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| <Pallet<T>>::init_collection(owner.clone(), owner, data),34 FungibleHandle::cast,35 )36}3738#[benchmarks]39mod benchmarks {40 use super::*;4142 #[benchmark]43 fn create_item() -> Result<(), BenchmarkError> {44 bench_init! {45 owner: sub; collection: collection(owner);46 sender: cross_from_sub(owner); to: cross_sub;47 };4849 #[block]50 {51 <Pallet<T>>::create_item(&collection, &sender, (to, 200), &Unlimited)?;52 }5354 Ok(())55 }5657 #[benchmark]58 fn create_multiple_items_ex(b: Linear<0, MAX_ITEMS_PER_BATCH>) -> Result<(), BenchmarkError> {59 bench_init! {60 owner: sub; collection: collection(owner);61 sender: cross_from_sub(owner);62 };63 let data = (0..b)64 .map(|i| {65 bench_init!(to: cross_sub(i););66 (to, 200)67 })68 .collect::<BTreeMap<_, _>>();6970 #[block]71 {72 <Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?;73 }7475 Ok(())76 }7778 #[benchmark]79 fn burn_item() -> Result<(), BenchmarkError> {80 bench_init! {81 owner: sub; collection: collection(owner);82 owner: cross_from_sub; burner: cross_sub;83 };84 <Pallet<T>>::create_item(&collection, &owner, (burner.clone(), 200), &Unlimited)?;8586 #[block]87 {88 <Pallet<T>>::burn(&collection, &burner, 100)?;89 }9091 Ok(())92 }9394 #[benchmark]95 fn transfer_raw() -> Result<(), BenchmarkError> {96 bench_init! {97 owner: sub; collection: collection(owner);98 owner: cross_from_sub; sender: cross_sub; to: cross_sub;99 };100 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;101102 #[block]103 {104 <Pallet<T>>::transfer(&collection, &sender, &to, 200, &Unlimited)?;105 }106107 Ok(())108 }109110 #[benchmark]111 fn approve() -> Result<(), BenchmarkError> {112 bench_init! {113 owner: sub; collection: collection(owner);114 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;115 };116 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;117118 #[block]119 {120 <Pallet<T>>::set_allowance(&collection, &sender, &spender, 100)?;121 }122123 Ok(())124 }125126 #[benchmark]127 fn approve_from() -> Result<(), BenchmarkError> {128 bench_init! {129 owner: sub; collection: collection(owner);130 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;131132 };133 let owner_eth = T::CrossAccountId::from_eth(*sender.as_eth());134 <Pallet<T>>::create_item(&collection, &owner, (owner_eth.clone(), 200), &Unlimited)?;135136 #[block]137 {138 <Pallet<T>>::set_allowance_from(&collection, &sender, &owner_eth, &spender, 100)?;139 }140141 Ok(())142 }143144 #[benchmark]145 fn check_allowed_raw() -> Result<(), BenchmarkError> {146 bench_init! {147 owner: sub; collection: collection(owner);148 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;149 };150 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;151 <Pallet<T>>::set_allowance(&collection, &sender, &spender, 200)?;152153 #[block]154 {155 <Pallet<T>>::check_allowed(&collection, &spender, &sender, 200, &Unlimited)?;156 }157158 Ok(())159 }160161 #[benchmark]162 fn set_allowance_unchecked_raw() -> Result<(), BenchmarkError> {163 bench_init! {164 owner: sub; collection: collection(owner);165 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;166 };167 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;168169 #[block]170 {171 <Pallet<T>>::set_allowance_unchecked(&collection, &sender, &spender, 200);172 }173174 Ok(())175 }176177 #[benchmark]178 fn burn_from() -> Result<(), BenchmarkError> {179 bench_init! {180 owner: sub; collection: collection(owner);181 owner: cross_from_sub; sender: cross_sub; burner: cross_sub;182 };183 <Pallet<T>>::create_item(&collection, &owner, (sender.clone(), 200), &Unlimited)?;184 <Pallet<T>>::set_allowance(&collection, &sender, &burner, 200)?;185186 #[block]187 {188 <Pallet<T>>::burn_from(&collection, &burner, &sender, 100, &Unlimited)?189 }190191 Ok(())192 }193}pallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -18,6 +18,7 @@
use pallet_common::{
bench_init,
benchmarking::{create_collection_raw, property_key, property_value},
+ Pallet as PalletCommon,
};
use sp_std::prelude::*;
use up_data_structs::{
@@ -56,7 +57,9 @@
create_collection_raw(
owner,
CollectionMode::NFT,
- |owner: T::CrossAccountId, data| <Pallet<T>>::init_collection(owner.clone(), owner, data),
+ |owner: T::CrossAccountId, data| {
+ <PalletCommon<T>>::init_collection(owner.clone(), Some(owner), data)
+ },
NonfungibleHandle::cast,
)
}
pallets/structure/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/structure/src/benchmarking.rs
+++ b/pallets/structure/src/benchmarking.rs
@@ -44,7 +44,7 @@
.unwrap();
T::CollectionDispatch::create(
caller_cross.clone(),
- caller_cross.clone(),
+ Some(caller_cross.clone()),
CreateCollectionData {
mode: CollectionMode::NFT,
..Default::default()