difftreelog
feat add weights
in: master
3 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/common.rs
+++ b/pallets/balances-adapter/src/common.rs
@@ -2,88 +2,88 @@
use core::marker::PhantomData;
use crate::{Config, NativeFungibleHandle};
use frame_support::{
+ fail,
traits::{Currency, ExistenceRequirement},
- fail,
+ weights::Weight,
};
+use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};
use pallet_common::{erc::CrossAccountId, CommonCollectionOperations, CommonWeightInfo, with_weight};
use up_data_structs::TokenId;
pub struct CommonWeights<T: Config>(PhantomData<T>);
impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
- fn create_multiple_items(
- amount: &[up_data_structs::CreateItemData],
- ) -> frame_support::weights::Weight {
- todo!()
+ fn create_multiple_items(amount: &[up_data_structs::CreateItemData]) -> Weight {
+ Weight::default()
}
fn create_multiple_items_ex(
cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,
- ) -> frame_support::weights::Weight {
- todo!()
+ ) -> Weight {
+ Weight::default()
}
- fn burn_item() -> frame_support::weights::Weight {
- todo!()
+ fn burn_item() -> Weight {
+ Weight::default()
}
- fn set_collection_properties(amount: u32) -> frame_support::weights::Weight {
- todo!()
+ fn set_collection_properties(amount: u32) -> Weight {
+ Weight::default()
}
- fn delete_collection_properties(amount: u32) -> frame_support::weights::Weight {
- todo!()
+ fn delete_collection_properties(amount: u32) -> Weight {
+ Weight::default()
}
- fn set_token_properties(amount: u32) -> frame_support::weights::Weight {
- todo!()
+ fn set_token_properties(amount: u32) -> Weight {
+ Weight::default()
}
- fn delete_token_properties(amount: u32) -> frame_support::weights::Weight {
- todo!()
+ fn delete_token_properties(amount: u32) -> Weight {
+ Weight::default()
}
- fn set_token_property_permissions(amount: u32) -> frame_support::weights::Weight {
- todo!()
+ fn set_token_property_permissions(amount: u32) -> Weight {
+ Weight::default()
}
- fn transfer() -> frame_support::weights::Weight {
- todo!()
+ fn transfer() -> Weight {
+ <BalancesWeight<T> as WeightInfo>::transfer()
}
- fn approve() -> frame_support::weights::Weight {
- todo!()
+ fn approve() -> Weight {
+ Weight::default()
}
- fn approve_from() -> frame_support::weights::Weight {
- todo!()
+ fn approve_from() -> Weight {
+ Weight::default()
}
- fn transfer_from() -> frame_support::weights::Weight {
- todo!()
+ fn transfer_from() -> Weight {
+ <BalancesWeight<T> as WeightInfo>::transfer()
}
- fn burn_from() -> frame_support::weights::Weight {
- todo!()
+ fn burn_from() -> Weight {
+ Weight::default()
}
- fn burn_recursively_self_raw() -> frame_support::weights::Weight {
- todo!()
+ fn burn_recursively_self_raw() -> Weight {
+ Weight::default()
}
- fn burn_recursively_breadth_raw(amount: u32) -> frame_support::weights::Weight {
- todo!()
+ fn burn_recursively_breadth_raw(amount: u32) -> Weight {
+ Weight::default()
}
- fn token_owner() -> frame_support::weights::Weight {
- todo!()
+ fn token_owner() -> Weight {
+ Weight::default()
}
- fn set_allowance_for_all() -> frame_support::weights::Weight {
- todo!()
+ fn set_allowance_for_all() -> Weight {
+ Weight::default()
}
- fn force_repair_item() -> frame_support::weights::Weight {
- todo!()
+ fn force_repair_item() -> Weight {
+ Weight::default()
}
}
runtime/common/weights/mod.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}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 core::marker::PhantomData;18use frame_support::{weights::Weight};19use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};2021use pallet_balances_adapter::{22 Config as NativeFungibleConfig, common::CommonWeights as NativeFungibleWeights,23};24use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};25use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};2627#[cfg(feature = "refungible")]28use pallet_refungible::{29 Config as RefungibleConfig, weights::WeightInfo, common::CommonWeights as RefungibleWeights,30};31use up_data_structs::{CreateItemExData, CreateItemData};3233pub mod xcm;3435macro_rules! max_weight_of {36 ($method:ident ( $($args:tt)* )) => {{37 let max_weight = <FungibleWeights<T>>::$method($($args)*)38 .max(<NativeFungibleWeights<T>>::$method($($args)*))39 .max(<NonfungibleWeights<T>>::$method($($args)*));4041 #[cfg(feature = "refungible")]42 let max_weight = max_weight.max(<RefungibleWeights<T>>::$method($($args)*));4344 max_weight45 }};46}4748#[cfg(not(feature = "refungible"))]49pub trait CommonWeightConfigs: FungibleConfig + NativeFungibleConfig + NonfungibleConfig {}5051#[cfg(not(feature = "refungible"))]52impl<T: FungibleConfig + NativeFungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}5354#[cfg(feature = "refungible")]55pub trait CommonWeightConfigs:56 FungibleConfig + NativeFungibleConfig + NonfungibleConfig + RefungibleConfig57{58}5960#[cfg(feature = "refungible")]61impl<T: FungibleConfig + NativeFungibleConfig + NonfungibleConfig + RefungibleConfig>62 CommonWeightConfigs for T63{64}6566pub struct CommonWeights<T>(PhantomData<T>);6768impl<T> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T>69where70 T: CommonWeightConfigs,71{72 fn create_item(data: &CreateItemData) -> Weight {73 dispatch_weight::<T>() + max_weight_of!(create_item(data))74 }7576 fn create_multiple_items(data: &[CreateItemData]) -> Weight {77 dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))78 }7980 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {81 dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))82 }8384 fn burn_item() -> Weight {85 dispatch_weight::<T>() + max_weight_of!(burn_item())86 }8788 fn set_collection_properties(amount: u32) -> Weight {89 dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))90 }9192 fn delete_collection_properties(amount: u32) -> Weight {93 dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))94 }9596 fn set_token_properties(amount: u32) -> Weight {97 dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))98 }99100 fn delete_token_properties(amount: u32) -> Weight {101 dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))102 }103104 fn set_token_property_permissions(amount: u32) -> Weight {105 dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))106 }107108 fn transfer() -> Weight {109 dispatch_weight::<T>() + max_weight_of!(transfer())110 }111112 fn approve() -> Weight {113 dispatch_weight::<T>() + max_weight_of!(approve())114 }115116 fn approve_from() -> Weight {117 dispatch_weight::<T>() + max_weight_of!(approve_from())118 }119120 fn transfer_from() -> Weight {121 dispatch_weight::<T>() + max_weight_of!(transfer_from())122 }123124 fn burn_from() -> Weight {125 dispatch_weight::<T>() + max_weight_of!(burn_from())126 }127128 fn burn_recursively_self_raw() -> Weight {129 max_weight_of!(burn_recursively_self_raw())130 }131132 fn burn_recursively_breadth_raw(amount: u32) -> Weight {133 max_weight_of!(burn_recursively_breadth_raw(amount))134 }135136 fn token_owner() -> Weight {137 max_weight_of!(token_owner())138 }139140 fn set_allowance_for_all() -> Weight {141 max_weight_of!(set_allowance_for_all())142 }143144 fn force_repair_item() -> Weight {145 max_weight_of!(force_repair_item())146 }147}148149#[cfg(feature = "refungible")]150impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>151where152 T: FungibleConfig + NonfungibleConfig + RefungibleConfig,153{154 fn repartition() -> Weight {155 dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()156 }157}158159#[cfg(not(feature = "refungible"))]160impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>161where162 T: FungibleConfig + NonfungibleConfig,163{164 fn repartition() -> Weight {165 dispatch_weight::<T>()166 }167}tests/src/NativeFungible.test.tsdiffbeforeafterboth--- a/tests/src/NativeFungible.test.ts
+++ b/tests/src/NativeFungible.test.ts
@@ -18,7 +18,7 @@
import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';
import {ICollectionCreationOptions} from './util/playgrounds/types';
-describe.only('Native fungible', () => {
+describe('Native fungible', () => {
let alice: IKeyringPair;
let bob: IKeyringPair;
@@ -140,20 +140,6 @@
const balanceBobAfter = await helper.balance.getSubstrate(bob.address);
expect(balanceAliceBefore - balanceAliceAfter > 100n).to.be.true;
expect(balanceBobAfter - balanceBobBefore === 100n).to.be.true;
- });
-
- itSub('approve()', async ({helper}) => {
- const collection = helper.ft.getCollectionObject(0);
- await expect(collection.approveTokens(alice, {Substrate: bob.address}, 100n)).to.be.rejectedWith('common.UnsupportedOperation');
- });
-
- itSub('approve_from()', async ({helper}) => {
- await expect(helper.executeExtrinsic(
- alice,
- 'api.tx.unique.approveFrom',
- [{Substrate: alice.address}, {Substrate: bob.address}, 0, 0, 100n],
- true,
- )).to.be.rejectedWith('common.UnsupportedOperation');
});
itSub('transfer_from()', async ({helper}) => {
@@ -171,6 +157,20 @@
await expect(collection.transferFrom(alice, {Substrate: bob.address}, {Substrate: alice.address}, 100n)).to.be.rejectedWith('common.NoPermission');
});
+ itSub('approve()', async ({helper}) => {
+ const collection = helper.ft.getCollectionObject(0);
+ await expect(collection.approveTokens(alice, {Substrate: bob.address}, 100n)).to.be.rejectedWith('common.UnsupportedOperation');
+ });
+
+ itSub('approve_from()', async ({helper}) => {
+ await expect(helper.executeExtrinsic(
+ alice,
+ 'api.tx.unique.approveFrom',
+ [{Substrate: alice.address}, {Substrate: bob.address}, 0, 0, 100n],
+ true,
+ )).to.be.rejectedWith('common.UnsupportedOperation');
+ });
+
itSub('set_collection_limits()', async ({helper}) => {
const collection = helper.ft.getCollectionObject(0);
await expect(collection.setLimits(alice, {accountTokenOwnershipLimit: 1})).to.be.rejectedWith('common.UnsupportedOperation');