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
18use frame_support::{weights::Weight};18use frame_support::{weights::Weight};
19use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};19use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};
2020
21use pallet_balances_adapter::{
22 Config as NativeFungibleConfig, common::CommonWeights as NativeFungibleWeights,
23};
21use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};24use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};
22use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};25use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};
2326
32macro_rules! max_weight_of {35macro_rules! max_weight_of {
33 ($method:ident ( $($args:tt)* )) => {{36 ($method:ident ( $($args:tt)* )) => {{
34 let max_weight = <FungibleWeights<T>>::$method($($args)*)37 let max_weight = <FungibleWeights<T>>::$method($($args)*)
38 .max(<NativeFungibleWeights<T>>::$method($($args)*))
35 .max(<NonfungibleWeights<T>>::$method($($args)*));39 .max(<NonfungibleWeights<T>>::$method($($args)*));
3640
37 #[cfg(feature = "refungible")]41 #[cfg(feature = "refungible")]
42}46}
4347
44#[cfg(not(feature = "refungible"))]48#[cfg(not(feature = "refungible"))]
45pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}49pub trait CommonWeightConfigs: FungibleConfig + NativeFungibleConfig + NonfungibleConfig {}
4650
47#[cfg(not(feature = "refungible"))]51#[cfg(not(feature = "refungible"))]
48impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}52impl<T: FungibleConfig + NativeFungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}
4953
50#[cfg(feature = "refungible")]54#[cfg(feature = "refungible")]
51pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}55pub trait CommonWeightConfigs:
56 FungibleConfig + NativeFungibleConfig + NonfungibleConfig + RefungibleConfig
57{
58}
5259
53#[cfg(feature = "refungible")]60#[cfg(feature = "refungible")]
54impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}61impl<T: FungibleConfig + NativeFungibleConfig + NonfungibleConfig + RefungibleConfig>
62 CommonWeightConfigs for T
63{
64}
modifiedtests/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');