difftreelog
feat add weights
in: master
3 files changed
pallets/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()
}
}
runtime/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.tsdiffbeforeafterboth1// Copyright 2019-2023 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';19import {ICollectionCreationOptions} from './util/playgrounds/types';2021describe.only('Native fungible', () => {22 let alice: IKeyringPair;23 let bob: IKeyringPair;2425 before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 const donor = await privateKey({url: import.meta.url});28 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);29 });30 });3132 itSub('destroy_collection()', async ({helper}) => {33 const collection = helper.ft.getCollectionObject(0);34 await expect(collection.burn(alice)).to.be.rejectedWith('common.UnsupportedOperation');35 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.destroyCollection', [0])).to.be.rejectedWith('common.UnsupportedOperation');36 });3738 itSub('add_to_allow_list()', async ({helper}) => {39 const collection = helper.ft.getCollectionObject(0);40 await expect(collection.addToAllowList(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');41 });4243 itSub('remove_from_allow_list()', async ({helper}) => {44 const collection = helper.ft.getCollectionObject(0);45 await expect(collection.removeFromAllowList(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');46 });4748 itSub('change_collection_owner()', async ({helper}) => {49 const collection = helper.ft.getCollectionObject(0);50 await expect(collection.changeOwner(alice, bob.address)).to.be.rejectedWith('common.UnsupportedOperation');51 });5253 itSub('add_collection_admin()', async ({helper}) => {54 const collection = helper.ft.getCollectionObject(0);55 await expect(collection.addAdmin(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');56 });5758 itSub('remove_collection_admin()', async ({helper}) => {59 const collection = helper.ft.getCollectionObject(0);60 await expect(collection.removeAdmin(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');61 });6263 itSub('set_collection_sponsor()', async ({helper}) => {64 const collection = helper.ft.getCollectionObject(0);65 await expect(collection.setSponsor(alice, bob.address)).to.be.rejectedWith('common.UnsupportedOperation');66 });6768 itSub('confirm_sponsorship()', async ({helper}) => {69 const collection = helper.ft.getCollectionObject(0);70 await expect(collection.confirmSponsorship(alice)).to.be.rejectedWith('common.UnsupportedOperation');71 });7273 itSub('remove_collection_sponsor()', async ({helper}) => {74 const collection = helper.ft.getCollectionObject(0);75 await expect(collection.removeSponsor(alice)).to.be.rejectedWith('common.UnsupportedOperation');76 });7778 itSub('create_item()', async ({helper}) => {79 const collection = helper.ft.getCollectionObject(0);80 await expect(collection.mint(alice, 100n, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');81 });8283 itSub('set_collection_properties()', async ({helper}) => {84 const collection = helper.ft.getCollectionObject(0);85 await expect(collection.setProperties(alice, [{key: 'value'}])).to.be.rejectedWith('common.UnsupportedOperation');86 });8788 itSub('delete_collection_properties()', async ({helper}) => {89 const collection = helper.ft.getCollectionObject(0);90 await expect(collection.deleteProperties(alice, ['key'])).to.be.rejectedWith('common.UnsupportedOperation');91 });9293 itSub('set_token_properties()', async ({helper}) => {94 await expect(helper.executeExtrinsic(95 alice,96 'api.tx.unique.setTokenProperties',97 [0, 0, [{key: 'value'}]],98 true,99 )).to.be.rejectedWith('common.UnsupportedOperation');100 });101102 itSub('delete_token_properties()', async ({helper}) => {103 await expect(helper.executeExtrinsic(104 alice,105 'api.tx.unique.deleteTokenProperties',106 [0, 0, ['key']],107 true,108 )).to.be.rejectedWith('common.UnsupportedOperation');109 });110111 itSub('set_transfers_enabled_flag()', async ({helper}) => {112 await expect(helper.executeExtrinsic(113 alice,114 'api.tx.unique.setTransfersEnabledFlag',115 [0, true],116 true,117 )).to.be.rejectedWith('common.UnsupportedOperation');118 });119120 itSub('burn_item()', async ({helper}) => {121 await expect(helper.executeExtrinsic(122 alice,123 'api.tx.unique.burnItem',124 [0, 0, 100n],125 true,126 )).to.be.rejectedWith('common.UnsupportedOperation');127 });128129 itSub('burn_from()', async ({helper}) => {130 const collection = helper.ft.getCollectionObject(0);131 await expect(collection.burnTokens(alice, 100n)).to.be.rejectedWith('common.UnsupportedOperation');132 });133134 itSub('transfer()', async ({helper}) => {135 const collection = helper.ft.getCollectionObject(0);136 const balanceAliceBefore = await helper.balance.getSubstrate(alice.address);137 const balanceBobBefore = await helper.balance.getSubstrate(bob.address);138 await collection.transfer(alice, {Substrate: bob.address}, 100n);139 const balanceAliceAfter = await helper.balance.getSubstrate(alice.address);140 const balanceBobAfter = await helper.balance.getSubstrate(bob.address);141 expect(balanceAliceBefore - balanceAliceAfter > 100n).to.be.true;142 expect(balanceBobAfter - balanceBobBefore === 100n).to.be.true;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 });158159 itSub('transfer_from()', async ({helper}) => {160 const collection = helper.ft.getCollectionObject(0);161 const balanceAliceBefore = await helper.balance.getSubstrate(alice.address);162 const balanceBobBefore = await helper.balance.getSubstrate(bob.address);163164 await collection.transferFrom(alice, {Substrate: alice.address}, {Substrate: bob.address}, 100n);165166 const balanceAliceAfter = await helper.balance.getSubstrate(alice.address);167 const balanceBobAfter = await helper.balance.getSubstrate(bob.address);168 expect(balanceAliceBefore - balanceAliceAfter > 100n).to.be.true;169 expect(balanceBobAfter - balanceBobBefore === 100n).to.be.true;170171 await expect(collection.transferFrom(alice, {Substrate: bob.address}, {Substrate: alice.address}, 100n)).to.be.rejectedWith('common.NoPermission');172 });173174 itSub('set_collection_limits()', async ({helper}) => {175 const collection = helper.ft.getCollectionObject(0);176 await expect(collection.setLimits(alice, {accountTokenOwnershipLimit: 1})).to.be.rejectedWith('common.UnsupportedOperation');177 });178179 itSub('set_collection_permissions()', async ({helper}) => {180 const collection = helper.ft.getCollectionObject(0);181 await expect(collection.setPermissions(alice, {access: 'AllowList'})).to.be.rejectedWith('common.UnsupportedOperation');182 });183184 itSub('repartition()', async ({helper}) => {185 await expect(helper.executeExtrinsic(186 alice,187 'api.tx.unique.repartition',188 [0, 0, 100n],189 true,190 )).to.be.rejectedWith('unique.RepartitionCalledOnNonRefungibleCollection');191 });192193 itSub('force_repair_collection()', async ({helper}) => {194 await expect(helper.executeExtrinsic(195 alice,196 'api.tx.unique.forceRepairCollection',197 [0],198 true,199 )).to.be.rejectedWith('common.UnsupportedOperation');200 });201202 itSub('force_repair_item()', async ({helper}) => {203 await expect(helper.executeExtrinsic(204 alice,205 'api.tx.unique.forceRepairItem',206 [0, 0],207 true,208 )).to.be.rejectedWith('BadOrigin');209 });210});1// Copyright 2019-2023 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from './util';19import {ICollectionCreationOptions} from './util/playgrounds/types';2021describe('Native fungible', () => {22 let alice: IKeyringPair;23 let bob: IKeyringPair;2425 before(async () => {26 await usingPlaygrounds(async (helper, privateKey) => {27 const donor = await privateKey({url: import.meta.url});28 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);29 });30 });3132 itSub('destroy_collection()', async ({helper}) => {33 const collection = helper.ft.getCollectionObject(0);34 await expect(collection.burn(alice)).to.be.rejectedWith('common.UnsupportedOperation');35 await expect(helper.executeExtrinsic(alice, 'api.tx.unique.destroyCollection', [0])).to.be.rejectedWith('common.UnsupportedOperation');36 });3738 itSub('add_to_allow_list()', async ({helper}) => {39 const collection = helper.ft.getCollectionObject(0);40 await expect(collection.addToAllowList(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');41 });4243 itSub('remove_from_allow_list()', async ({helper}) => {44 const collection = helper.ft.getCollectionObject(0);45 await expect(collection.removeFromAllowList(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');46 });4748 itSub('change_collection_owner()', async ({helper}) => {49 const collection = helper.ft.getCollectionObject(0);50 await expect(collection.changeOwner(alice, bob.address)).to.be.rejectedWith('common.UnsupportedOperation');51 });5253 itSub('add_collection_admin()', async ({helper}) => {54 const collection = helper.ft.getCollectionObject(0);55 await expect(collection.addAdmin(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');56 });5758 itSub('remove_collection_admin()', async ({helper}) => {59 const collection = helper.ft.getCollectionObject(0);60 await expect(collection.removeAdmin(alice, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');61 });6263 itSub('set_collection_sponsor()', async ({helper}) => {64 const collection = helper.ft.getCollectionObject(0);65 await expect(collection.setSponsor(alice, bob.address)).to.be.rejectedWith('common.UnsupportedOperation');66 });6768 itSub('confirm_sponsorship()', async ({helper}) => {69 const collection = helper.ft.getCollectionObject(0);70 await expect(collection.confirmSponsorship(alice)).to.be.rejectedWith('common.UnsupportedOperation');71 });7273 itSub('remove_collection_sponsor()', async ({helper}) => {74 const collection = helper.ft.getCollectionObject(0);75 await expect(collection.removeSponsor(alice)).to.be.rejectedWith('common.UnsupportedOperation');76 });7778 itSub('create_item()', async ({helper}) => {79 const collection = helper.ft.getCollectionObject(0);80 await expect(collection.mint(alice, 100n, {Substrate: bob.address})).to.be.rejectedWith('common.UnsupportedOperation');81 });8283 itSub('set_collection_properties()', async ({helper}) => {84 const collection = helper.ft.getCollectionObject(0);85 await expect(collection.setProperties(alice, [{key: 'value'}])).to.be.rejectedWith('common.UnsupportedOperation');86 });8788 itSub('delete_collection_properties()', async ({helper}) => {89 const collection = helper.ft.getCollectionObject(0);90 await expect(collection.deleteProperties(alice, ['key'])).to.be.rejectedWith('common.UnsupportedOperation');91 });9293 itSub('set_token_properties()', async ({helper}) => {94 await expect(helper.executeExtrinsic(95 alice,96 'api.tx.unique.setTokenProperties',97 [0, 0, [{key: 'value'}]],98 true,99 )).to.be.rejectedWith('common.UnsupportedOperation');100 });101102 itSub('delete_token_properties()', async ({helper}) => {103 await expect(helper.executeExtrinsic(104 alice,105 'api.tx.unique.deleteTokenProperties',106 [0, 0, ['key']],107 true,108 )).to.be.rejectedWith('common.UnsupportedOperation');109 });110111 itSub('set_transfers_enabled_flag()', async ({helper}) => {112 await expect(helper.executeExtrinsic(113 alice,114 'api.tx.unique.setTransfersEnabledFlag',115 [0, true],116 true,117 )).to.be.rejectedWith('common.UnsupportedOperation');118 });119120 itSub('burn_item()', async ({helper}) => {121 await expect(helper.executeExtrinsic(122 alice,123 'api.tx.unique.burnItem',124 [0, 0, 100n],125 true,126 )).to.be.rejectedWith('common.UnsupportedOperation');127 });128129 itSub('burn_from()', async ({helper}) => {130 const collection = helper.ft.getCollectionObject(0);131 await expect(collection.burnTokens(alice, 100n)).to.be.rejectedWith('common.UnsupportedOperation');132 });133134 itSub('transfer()', async ({helper}) => {135 const collection = helper.ft.getCollectionObject(0);136 const balanceAliceBefore = await helper.balance.getSubstrate(alice.address);137 const balanceBobBefore = await helper.balance.getSubstrate(bob.address);138 await collection.transfer(alice, {Substrate: bob.address}, 100n);139 const balanceAliceAfter = await helper.balance.getSubstrate(alice.address);140 const balanceBobAfter = await helper.balance.getSubstrate(bob.address);141 expect(balanceAliceBefore - balanceAliceAfter > 100n).to.be.true;142 expect(balanceBobAfter - balanceBobBefore === 100n).to.be.true;143 });144145 itSub('transfer_from()', async ({helper}) => {146 const collection = helper.ft.getCollectionObject(0);147 const balanceAliceBefore = await helper.balance.getSubstrate(alice.address);148 const balanceBobBefore = await helper.balance.getSubstrate(bob.address);149150 await collection.transferFrom(alice, {Substrate: alice.address}, {Substrate: bob.address}, 100n);151152 const balanceAliceAfter = await helper.balance.getSubstrate(alice.address);153 const balanceBobAfter = await helper.balance.getSubstrate(bob.address);154 expect(balanceAliceBefore - balanceAliceAfter > 100n).to.be.true;155 expect(balanceBobAfter - balanceBobBefore === 100n).to.be.true;156157 await expect(collection.transferFrom(alice, {Substrate: bob.address}, {Substrate: alice.address}, 100n)).to.be.rejectedWith('common.NoPermission');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 });173174 itSub('set_collection_limits()', async ({helper}) => {175 const collection = helper.ft.getCollectionObject(0);176 await expect(collection.setLimits(alice, {accountTokenOwnershipLimit: 1})).to.be.rejectedWith('common.UnsupportedOperation');177 });178179 itSub('set_collection_permissions()', async ({helper}) => {180 const collection = helper.ft.getCollectionObject(0);181 await expect(collection.setPermissions(alice, {access: 'AllowList'})).to.be.rejectedWith('common.UnsupportedOperation');182 });183184 itSub('repartition()', async ({helper}) => {185 await expect(helper.executeExtrinsic(186 alice,187 'api.tx.unique.repartition',188 [0, 0, 100n],189 true,190 )).to.be.rejectedWith('unique.RepartitionCalledOnNonRefungibleCollection');191 });192193 itSub('force_repair_collection()', async ({helper}) => {194 await expect(helper.executeExtrinsic(195 alice,196 'api.tx.unique.forceRepairCollection',197 [0],198 true,199 )).to.be.rejectedWith('common.UnsupportedOperation');200 });201202 itSub('force_repair_item()', async ({helper}) => {203 await expect(helper.executeExtrinsic(204 alice,205 'api.tx.unique.forceRepairItem',206 [0, 0],207 true,208 )).to.be.rejectedWith('BadOrigin');209 });210});