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
2use 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;
1012
11pub 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 }
1818
19 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 }
2424
25 fn burn_item() -> frame_support::weights::Weight {25 fn burn_item() -> Weight {
26 todo!()26 Weight::default()
27 }27 }
2828
29 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 }
3232
33 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 }
3636
37 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 }
4040
41 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 }
4444
45 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 }
4848
49 fn transfer() -> frame_support::weights::Weight {49 fn transfer() -> Weight {
50 todo!()50 <BalancesWeight<T> as WeightInfo>::transfer()
51 }51 }
5252
53 fn approve() -> frame_support::weights::Weight {53 fn approve() -> Weight {
54 todo!()54 Weight::default()
55 }55 }
5656
57 fn approve_from() -> frame_support::weights::Weight {57 fn approve_from() -> Weight {
58 todo!()58 Weight::default()
59 }59 }
6060
61 fn transfer_from() -> frame_support::weights::Weight {61 fn transfer_from() -> Weight {
62 todo!()62 <BalancesWeight<T> as WeightInfo>::transfer()
63 }63 }
6464
65 fn burn_from() -> frame_support::weights::Weight {65 fn burn_from() -> Weight {
66 todo!()66 Weight::default()
67 }67 }
6868
69 fn burn_recursively_self_raw() -> frame_support::weights::Weight {69 fn burn_recursively_self_raw() -> Weight {
70 todo!()70 Weight::default()
71 }71 }
7272
73 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 }
7676
77 fn token_owner() -> frame_support::weights::Weight {77 fn token_owner() -> Weight {
78 todo!()78 Weight::default()
79 }79 }
8080
81 fn set_allowance_for_all() -> frame_support::weights::Weight {81 fn set_allowance_for_all() -> Weight {
82 todo!()82 Weight::default()
83 }83 }
8484
85 fn force_repair_item() -> frame_support::weights::Weight {85 fn force_repair_item() -> Weight {
86 todo!()86 Weight::default()
87 }87 }
88}88}
8989
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
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);