difftreelog
fix weights in tests
in: master
4 files changed
runtime/common/weights.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 core::marker::PhantomData;18use frame_support::{weights::Weight};19use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};2021use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};22use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};2324#[cfg(feature = "refungible")]25use pallet_refungible::{26 Config as RefungibleConfig, weights::WeightInfo, common::CommonWeights as RefungibleWeights,27};28use up_data_structs::{CreateItemExData, CreateItemData};2930pub mod xcm;3132macro_rules! max_weight_of {33 ($method:ident ( $($args:tt)* )) => {{34 let max_weight = <FungibleWeights<T>>::$method($($args)*)35 .max(<NonfungibleWeights<T>>::$method($($args)*));3637 #[cfg(feature = "refungible")]38 let max_weight = max_weight.max(<RefungibleWeights<T>>::$method($($args)*));3940 max_weight41 }};42}4344#[cfg(not(feature = "refungible"))]45pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}4647#[cfg(not(feature = "refungible"))]48impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}4950#[cfg(feature = "refungible")]51pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}5253#[cfg(feature = "refungible")]54impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}5556pub struct CommonWeights<T>(PhantomData<T>);5758impl<T> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T>59where60 T: CommonWeightConfigs,61{62 fn create_item(data: &CreateItemData) -> Weight {63 dispatch_weight::<T>() + max_weight_of!(create_item(data))64 }6566 fn create_multiple_items(data: &[CreateItemData]) -> Weight {67 dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))68 }6970 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {71 dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))72 }7374 fn burn_item() -> Weight {75 dispatch_weight::<T>() + max_weight_of!(burn_item())76 }7778 fn set_collection_properties(amount: u32) -> Weight {79 dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))80 }8182 fn delete_collection_properties(amount: u32) -> Weight {83 dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))84 }8586 fn set_token_properties(amount: u32) -> Weight {87 dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))88 }8990 fn delete_token_properties(amount: u32) -> Weight {91 dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))92 }9394 fn set_token_property_permissions(amount: u32) -> Weight {95 dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))96 }9798 fn transfer() -> Weight {99 dispatch_weight::<T>() + max_weight_of!(transfer())100 }101102 fn approve() -> Weight {103 dispatch_weight::<T>() + max_weight_of!(approve())104 }105106 fn approve_from() -> Weight {107 dispatch_weight::<T>() + max_weight_of!(approve_from())108 }109110 fn transfer_from() -> Weight {111 dispatch_weight::<T>() + max_weight_of!(transfer_from())112 }113114 fn burn_from() -> Weight {115 dispatch_weight::<T>() + max_weight_of!(burn_from())116 }117118 fn burn_recursively_self_raw() -> Weight {119 max_weight_of!(burn_recursively_self_raw())120 }121122 fn burn_recursively_breadth_raw(amount: u32) -> Weight {123 max_weight_of!(burn_recursively_breadth_raw(amount))124 }125126 fn token_owner() -> Weight {127 max_weight_of!(token_owner())128 }129130 fn set_allowance_for_all() -> Weight {131 max_weight_of!(set_allowance_for_all())132 }133134 fn force_repair_item() -> Weight {135 max_weight_of!(force_repair_item())136 }137}138139#[cfg(feature = "refungible")]140impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>141where142 T: FungibleConfig + NonfungibleConfig + RefungibleConfig,143{144 fn repartition() -> Weight {145 dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()146 }147}148149#[cfg(not(feature = "refungible"))]150impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>151where152 T: FungibleConfig + NonfungibleConfig,153{154 fn repartition() -> Weight {155 dispatch_weight::<T>()156 }157}runtime/common/weights/mod.rsdiffbeforeafterboth--- /dev/null
+++ b/runtime/common/weights/mod.rs
@@ -0,0 +1,157 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+use core::marker::PhantomData;
+use frame_support::{weights::Weight};
+use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};
+
+use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};
+use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};
+
+#[cfg(feature = "refungible")]
+use pallet_refungible::{
+ Config as RefungibleConfig, weights::WeightInfo, common::CommonWeights as RefungibleWeights,
+};
+use up_data_structs::{CreateItemExData, CreateItemData};
+
+pub mod xcm;
+
+macro_rules! max_weight_of {
+ ($method:ident ( $($args:tt)* )) => {{
+ let max_weight = <FungibleWeights<T>>::$method($($args)*)
+ .max(<NonfungibleWeights<T>>::$method($($args)*));
+
+ #[cfg(feature = "refungible")]
+ let max_weight = max_weight.max(<RefungibleWeights<T>>::$method($($args)*));
+
+ max_weight
+ }};
+}
+
+#[cfg(not(feature = "refungible"))]
+pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}
+
+#[cfg(not(feature = "refungible"))]
+impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}
+
+#[cfg(feature = "refungible")]
+pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}
+
+#[cfg(feature = "refungible")]
+impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}
+
+pub struct CommonWeights<T>(PhantomData<T>);
+
+impl<T> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T>
+where
+ T: CommonWeightConfigs,
+{
+ fn create_item(data: &CreateItemData) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(create_item(data))
+ }
+
+ fn create_multiple_items(data: &[CreateItemData]) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))
+ }
+
+ fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))
+ }
+
+ fn burn_item() -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(burn_item())
+ }
+
+ fn set_collection_properties(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))
+ }
+
+ fn delete_collection_properties(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))
+ }
+
+ fn set_token_properties(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))
+ }
+
+ fn delete_token_properties(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))
+ }
+
+ fn set_token_property_permissions(amount: u32) -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))
+ }
+
+ fn transfer() -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(transfer())
+ }
+
+ fn approve() -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(approve())
+ }
+
+ fn approve_from() -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(approve_from())
+ }
+
+ fn transfer_from() -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(transfer_from())
+ }
+
+ fn burn_from() -> Weight {
+ dispatch_weight::<T>() + max_weight_of!(burn_from())
+ }
+
+ fn burn_recursively_self_raw() -> Weight {
+ max_weight_of!(burn_recursively_self_raw())
+ }
+
+ fn burn_recursively_breadth_raw(amount: u32) -> Weight {
+ max_weight_of!(burn_recursively_breadth_raw(amount))
+ }
+
+ fn token_owner() -> Weight {
+ max_weight_of!(token_owner())
+ }
+
+ fn set_allowance_for_all() -> Weight {
+ max_weight_of!(set_allowance_for_all())
+ }
+
+ fn force_repair_item() -> Weight {
+ max_weight_of!(force_repair_item())
+ }
+}
+
+#[cfg(feature = "refungible")]
+impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>
+where
+ T: FungibleConfig + NonfungibleConfig + RefungibleConfig,
+{
+ fn repartition() -> Weight {
+ dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()
+ }
+}
+
+#[cfg(not(feature = "refungible"))]
+impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>
+where
+ T: FungibleConfig + NonfungibleConfig,
+{
+ fn repartition() -> Weight {
+ dispatch_weight::<T>()
+ }
+}
runtime/tests/Cargo.tomldiffbeforeafterboth--- a/runtime/tests/Cargo.toml
+++ b/runtime/tests/Cargo.toml
@@ -43,4 +43,5 @@
evm-coder = { workspace = true }
up-sponsorship = { default-features = false, git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.39" }
xcm = { workspace = true }
+pallet-xcm = { workspace = true }
pallet-configuration = { workspace = true }
runtime/tests/src/lib.rsdiffbeforeafterboth--- a/runtime/tests/src/lib.rs
+++ b/runtime/tests/src/lib.rs
@@ -44,7 +44,7 @@
use dispatch::CollectionDispatchT;
-#[path = "../../common/weights.rs"]
+#[path = "../../common/weights/mod.rs"]
mod weights;
use weights::CommonWeights;