From 9e5de5c02b208d651abb37d81e2dc88518a09400 Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Fri, 28 Apr 2023 11:02:24 +0000 Subject: [PATCH] feat: add weights --- --- 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(PhantomData); impl CommonWeightInfo for CommonWeights { - 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, - ) -> 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 { + 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 { + 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() } } --- 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 = >::$method($($args)*) + .max(>::$method($($args)*)) .max(>::$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 CommonWeightConfigs for T {} +impl CommonWeightConfigs for T {} #[cfg(feature = "refungible")] -pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {} +pub trait CommonWeightConfigs: + FungibleConfig + NativeFungibleConfig + NonfungibleConfig + RefungibleConfig +{ +} #[cfg(feature = "refungible")] -impl CommonWeightConfigs for T {} +impl + CommonWeightConfigs for T +{ +} pub struct CommonWeights(PhantomData); --- 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'); -- gitstuff