difftreelog
feat add weights
in: master
3 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth2use core::marker::PhantomData;2use core::marker::PhantomData;3use crate::{Config, NativeFungibleHandle};3use crate::{Config, NativeFungibleHandle};4use frame_support::{4use frame_support::{5 fail,5 traits::{Currency, ExistenceRequirement},6 traits::{Currency, ExistenceRequirement},6 fail,7 weights::Weight,7};8};9use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};8use pallet_common::{erc::CrossAccountId, CommonCollectionOperations, CommonWeightInfo, with_weight};10use pallet_common::{erc::CrossAccountId, CommonCollectionOperations, CommonWeightInfo, with_weight};9use up_data_structs::TokenId;11use up_data_structs::TokenId;101211pub struct CommonWeights<T: Config>(PhantomData<T>);13pub struct CommonWeights<T: Config>(PhantomData<T>);12impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {14impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {13 fn create_multiple_items(15 fn create_multiple_items(amount: &[up_data_structs::CreateItemData]) -> Weight {14 amount: &[up_data_structs::CreateItemData],15 ) -> frame_support::weights::Weight {16 todo!()16 Weight::default()17 }17 }181819 fn create_multiple_items_ex(19 fn create_multiple_items_ex(20 cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,20 cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,21 ) -> frame_support::weights::Weight {21 ) -> Weight {22 todo!()22 Weight::default()23 }23 }242425 fn burn_item() -> frame_support::weights::Weight {25 fn burn_item() -> Weight {26 todo!()26 Weight::default()27 }27 }282829 fn set_collection_properties(amount: u32) -> frame_support::weights::Weight {29 fn set_collection_properties(amount: u32) -> Weight {30 todo!()30 Weight::default()31 }31 }323233 fn delete_collection_properties(amount: u32) -> frame_support::weights::Weight {33 fn delete_collection_properties(amount: u32) -> Weight {34 todo!()34 Weight::default()35 }35 }363637 fn set_token_properties(amount: u32) -> frame_support::weights::Weight {37 fn set_token_properties(amount: u32) -> Weight {38 todo!()38 Weight::default()39 }39 }404041 fn delete_token_properties(amount: u32) -> frame_support::weights::Weight {41 fn delete_token_properties(amount: u32) -> Weight {42 todo!()42 Weight::default()43 }43 }444445 fn set_token_property_permissions(amount: u32) -> frame_support::weights::Weight {45 fn set_token_property_permissions(amount: u32) -> Weight {46 todo!()46 Weight::default()47 }47 }484849 fn transfer() -> frame_support::weights::Weight {49 fn transfer() -> Weight {50 todo!()50 <BalancesWeight<T> as WeightInfo>::transfer()51 }51 }525253 fn approve() -> frame_support::weights::Weight {53 fn approve() -> Weight {54 todo!()54 Weight::default()55 }55 }565657 fn approve_from() -> frame_support::weights::Weight {57 fn approve_from() -> Weight {58 todo!()58 Weight::default()59 }59 }606061 fn transfer_from() -> frame_support::weights::Weight {61 fn transfer_from() -> Weight {62 todo!()62 <BalancesWeight<T> as WeightInfo>::transfer()63 }63 }646465 fn burn_from() -> frame_support::weights::Weight {65 fn burn_from() -> Weight {66 todo!()66 Weight::default()67 }67 }686869 fn burn_recursively_self_raw() -> frame_support::weights::Weight {69 fn burn_recursively_self_raw() -> Weight {70 todo!()70 Weight::default()71 }71 }727273 fn burn_recursively_breadth_raw(amount: u32) -> frame_support::weights::Weight {73 fn burn_recursively_breadth_raw(amount: u32) -> Weight {74 todo!()74 Weight::default()75 }75 }767677 fn token_owner() -> frame_support::weights::Weight {77 fn token_owner() -> Weight {78 todo!()78 Weight::default()79 }79 }808081 fn set_allowance_for_all() -> frame_support::weights::Weight {81 fn set_allowance_for_all() -> Weight {82 todo!()82 Weight::default()83 }83 }848485 fn force_repair_item() -> frame_support::weights::Weight {85 fn force_repair_item() -> Weight {86 todo!()86 Weight::default()87 }87 }88}88}8989runtime/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>);
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');