git.delta.rocks / unique-network / refs/commits / 9e5de5c02b20

difftreelog

feat add weights

Trubnikov Sergey2023-04-28parent: #7b90ee4.patch.diff
in: master

3 files changed

modifiedpallets/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()
 	}
 }
 
modifiedruntime/common/weights/mod.rsdiffbeforeafterboth
--- a/runtime/common/weights/mod.rs
+++ b/runtime/common/weights/mod.rs
@@ -18,6 +18,9 @@
 use frame_support::{weights::Weight};
 use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};
 
+use pallet_balances_adapter::{
+	Config as NativeFungibleConfig, common::CommonWeights as NativeFungibleWeights,
+};
 use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};
 use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};
 
@@ -32,6 +35,7 @@
 macro_rules! max_weight_of {
 	($method:ident ( $($args:tt)* )) => {{
 		let max_weight = <FungibleWeights<T>>::$method($($args)*)
+			.max(<NativeFungibleWeights<T>>::$method($($args)*))
 			.max(<NonfungibleWeights<T>>::$method($($args)*));
 
 		#[cfg(feature = "refungible")]
@@ -42,16 +46,22 @@
 }
 
 #[cfg(not(feature = "refungible"))]
-pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}
+pub trait CommonWeightConfigs: FungibleConfig + NativeFungibleConfig + NonfungibleConfig {}
 
 #[cfg(not(feature = "refungible"))]
-impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}
+impl<T: FungibleConfig + NativeFungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}
 
 #[cfg(feature = "refungible")]
-pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}
+pub trait CommonWeightConfigs:
+	FungibleConfig + NativeFungibleConfig + NonfungibleConfig + RefungibleConfig
+{
+}
 
 #[cfg(feature = "refungible")]
-impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}
+impl<T: FungibleConfig + NativeFungibleConfig + NonfungibleConfig + RefungibleConfig>
+	CommonWeightConfigs for T
+{
+}
 
 pub struct CommonWeights<T>(PhantomData<T>);
 
modifiedtests/src/NativeFungible.test.tsdiffbeforeafterboth
18import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';18import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';
19import {ICollectionCreationOptions} from './util/playgrounds/types';19import {ICollectionCreationOptions} from './util/playgrounds/types';
2020
21describe.only('Native fungible', () => {21describe('Native fungible', () => {
22 let alice: IKeyringPair;22 let alice: IKeyringPair;
23 let bob: IKeyringPair;23 let bob: IKeyringPair;
2424
142 expect(balanceBobAfter - balanceBobBefore === 100n).to.be.true;142 expect(balanceBobAfter - balanceBobBefore === 100n).to.be.true;
143 });143 });
144
145 itSub('approve()', async ({helper}) => {
146 const collection = helper.ft.getCollectionObject(0);
147 await expect(collection.approveTokens(alice, {Substrate: bob.address}, 100n)).to.be.rejectedWith('common.UnsupportedOperation');
148 });
149
150 itSub('approve_from()', async ({helper}) => {
151 await expect(helper.executeExtrinsic(
152 alice,
153 'api.tx.unique.approveFrom',
154 [{Substrate: alice.address}, {Substrate: bob.address}, 0, 0, 100n],
155 true,
156 )).to.be.rejectedWith('common.UnsupportedOperation');
157 });
158144
159 itSub('transfer_from()', async ({helper}) => {145 itSub('transfer_from()', async ({helper}) => {
160 const collection = helper.ft.getCollectionObject(0);146 const collection = helper.ft.getCollectionObject(0);
171 await expect(collection.transferFrom(alice, {Substrate: bob.address}, {Substrate: alice.address}, 100n)).to.be.rejectedWith('common.NoPermission');157 await expect(collection.transferFrom(alice, {Substrate: bob.address}, {Substrate: alice.address}, 100n)).to.be.rejectedWith('common.NoPermission');
172 });158 });
159
160 itSub('approve()', async ({helper}) => {
161 const collection = helper.ft.getCollectionObject(0);
162 await expect(collection.approveTokens(alice, {Substrate: bob.address}, 100n)).to.be.rejectedWith('common.UnsupportedOperation');
163 });
164
165 itSub('approve_from()', async ({helper}) => {
166 await expect(helper.executeExtrinsic(
167 alice,
168 'api.tx.unique.approveFrom',
169 [{Substrate: alice.address}, {Substrate: bob.address}, 0, 0, 100n],
170 true,
171 )).to.be.rejectedWith('common.UnsupportedOperation');
172 });
173173
174 itSub('set_collection_limits()', async ({helper}) => {174 itSub('set_collection_limits()', async ({helper}) => {
175 const collection = helper.ft.getCollectionObject(0);175 const collection = helper.ft.getCollectionObject(0);