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.rsdiffbeforeafterboth18use 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};202021use 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};232632macro_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)*));364037 #[cfg(feature = "refungible")]41 #[cfg(feature = "refungible")]42}46}434744#[cfg(not(feature = "refungible"))]48#[cfg(not(feature = "refungible"))]45pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}49pub trait CommonWeightConfigs: FungibleConfig + NativeFungibleConfig + NonfungibleConfig {}465047#[cfg(not(feature = "refungible"))]51#[cfg(not(feature = "refungible"))]48impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}52impl<T: FungibleConfig + NativeFungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}495350#[cfg(feature = "refungible")]54#[cfg(feature = "refungible")]51pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}55pub trait CommonWeightConfigs:56 FungibleConfig + NativeFungibleConfig + NonfungibleConfig + RefungibleConfig57{58}525953#[cfg(feature = "refungible")]60#[cfg(feature = "refungible")]54impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}61impl<T: FungibleConfig + NativeFungibleConfig + NonfungibleConfig + RefungibleConfig>62 CommonWeightConfigs for T63{64}tests/src/NativeFungible.test.tsdiffbeforeafterboth18import {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';202021describe.only('Native fungible', () => {21describe('Native fungible', () => {22 let alice: IKeyringPair;22 let alice: IKeyringPair;23 let bob: IKeyringPair;23 let bob: IKeyringPair;2424142 expect(balanceBobAfter - balanceBobBefore === 100n).to.be.true;142 expect(balanceBobAfter - balanceBobBefore === 100n).to.be.true;143 });143 });144145 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 });149150 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 });158144159 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 });159160 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 });164165 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 });173173174 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);