git.delta.rocks / unique-network / refs/commits / 42f53fc98c25

difftreelog

Merge pull request #773 from UniqueNetwork/fix/properties-size-overflow

ut-akuznetsov2022-12-14parents: #6e587d7 #4a0df43.patch.diff
in: master
Fix/properties size overflow

18 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1815,6 +1815,9 @@
 
 	/// The price of setting approval for all
 	fn set_allowance_for_all() -> Weight;
+
+	/// The price of repairing an item.
+	fn repair_item() -> Weight;
 }
 
 /// Weight info extension trait for refungible pallet.
@@ -2136,6 +2139,9 @@
 
 	/// Tells whether the given `owner` approves the `operator`.
 	fn allowance_for_all(&self, owner: T::CrossAccountId, operator: T::CrossAccountId) -> bool;
+
+	/// Repairs a possibly broken item.
+	fn repair_item(&self, token: TokenId) -> DispatchResultWithPostInfo;
 }
 
 /// Extension for RFT collection.
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -111,6 +111,10 @@
 	fn set_allowance_for_all() -> Weight {
 		Weight::zero()
 	}
+
+	fn repair_item() -> Weight {
+		Weight::zero()
+	}
 }
 
 /// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete
@@ -441,4 +445,9 @@
 	fn allowance_for_all(&self, _owner: T::CrossAccountId, _operator: T::CrossAccountId) -> bool {
 		false
 	}
+
+	/// Repairs a possibly broken item.
+	fn repair_item(&self, _token: TokenId) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::FungibleTokensAreAlwaysValid)
+	}
 }
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -129,6 +129,8 @@
 		SettingPropertiesNotAllowed,
 		/// Setting allowance for all is not allowed.
 		SettingAllowanceForAllNotAllowed,
+		/// Only a fungible collection could be possibly broken; any fungible token is valid.
+		FungibleTokensAreAlwaysValid,
 	}
 
 	#[pallet::config]
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -236,4 +236,12 @@
 			operator: cross_sub;
 		};
 	}: {<Pallet<T>>::allowance_for_all(&collection, &owner, &operator)}
+
+	repair_item {
+		bench_init!{
+			owner: sub; collection: collection(owner);
+			owner: cross_from_sub;
+		};
+		let item = create_max_item(&collection, &owner, owner.clone())?;
+	}: {<Pallet<T>>::repair_item(&collection, item)?}
 }
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -126,6 +126,10 @@
 	fn set_allowance_for_all() -> Weight {
 		<SelfWeightOf<T>>::set_allowance_for_all()
 	}
+
+	fn repair_item() -> Weight {
+		<SelfWeightOf<T>>::repair_item()
+	}
 }
 
 fn map_create_data<T: Config>(
@@ -532,4 +536,11 @@
 	fn allowance_for_all(&self, owner: T::CrossAccountId, operator: T::CrossAccountId) -> bool {
 		<Pallet<T>>::allowance_for_all(self, &owner, &operator)
 	}
+
+	fn repair_item(&self, token: TokenId) -> DispatchResultWithPostInfo {
+		with_weight(
+			<Pallet<T>>::repair_item(self, token),
+			<CommonWeights<T>>::repair_item(),
+		)
+	}
 }
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -1398,4 +1398,12 @@
 	) -> bool {
 		<CollectionAllowance<T>>::get((collection.id, owner, operator))
 	}
+
+	pub fn repair_item(collection: &NonfungibleHandle<T>, token: TokenId) -> DispatchResult {
+		<TokenProperties<T>>::mutate((collection.id, token), |properties| {
+			properties.recompute_consumed_space();
+		});
+
+		Ok(())
+	}
 }
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -50,6 +50,7 @@
 	fn token_owner() -> Weight;
 	fn set_allowance_for_all() -> Weight;
 	fn allowance_for_all() -> Weight;
+	fn repair_item() -> Weight;
 }
 
 /// Weights for pallet_nonfungible using the Substrate node and recommended hardware.
@@ -208,6 +209,12 @@
 		Weight::from_ref_time(6_161_000 as u64)
 			.saturating_add(T::DbWeight::get().reads(1 as u64))
 	}
+	// Storage: Nonfungible TokenProperties (r:1 w:1)
+	fn repair_item() -> Weight {
+		Weight::from_ref_time(5_701_000 as u64)
+			.saturating_add(T::DbWeight::get().reads(1 as u64))
+			.saturating_add(T::DbWeight::get().writes(1 as u64))
+	}
 }
 
 // For backwards compatibility and tests
@@ -365,4 +372,10 @@
 		Weight::from_ref_time(6_161_000 as u64)
 			.saturating_add(RocksDbWeight::get().reads(1 as u64))
 	}
+	// Storage: Nonfungible TokenProperties (r:1 w:1)
+	fn repair_item() -> Weight {
+		Weight::from_ref_time(5_701_000 as u64)
+			.saturating_add(RocksDbWeight::get().reads(1 as u64))
+			.saturating_add(RocksDbWeight::get().writes(1 as u64))
+	}
 }
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -304,4 +304,12 @@
 			operator: cross_sub;
 		};
 	}: {<Pallet<T>>::allowance_for_all(&collection, &owner, &operator)}
+
+	repair_item {
+		bench_init!{
+			owner: sub; collection: collection(owner);
+			owner: cross_from_sub;
+		};
+		let item = create_max_item(&collection, &owner, [(owner.clone(), 100)])?;
+	}: {<Pallet<T>>::repair_item(&collection, item)?}
 }
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -156,6 +156,10 @@
 	fn set_allowance_for_all() -> Weight {
 		<SelfWeightOf<T>>::set_allowance_for_all()
 	}
+
+	fn repair_item() -> Weight {
+		<SelfWeightOf<T>>::repair_item()
+	}
 }
 
 fn map_create_data<T: Config>(
@@ -536,6 +540,13 @@
 	fn allowance_for_all(&self, owner: T::CrossAccountId, operator: T::CrossAccountId) -> bool {
 		<Pallet<T>>::allowance_for_all(self, &owner, &operator)
 	}
+
+	fn repair_item(&self, token: TokenId) -> DispatchResultWithPostInfo {
+		with_weight(
+			<Pallet<T>>::repair_item(self, token),
+			<CommonWeights<T>>::repair_item(),
+		)
+	}
 }
 
 impl<T: Config> RefungibleExtensions<T> for RefungibleHandle<T> {
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -1461,4 +1461,12 @@
 	) -> bool {
 		<CollectionAllowance<T>>::get((collection.id, owner, operator))
 	}
+
+	pub fn repair_item(collection: &RefungibleHandle<T>, token: TokenId) -> DispatchResult {
+		<TokenProperties<T>>::mutate((collection.id, token), |properties| {
+			properties.recompute_consumed_space();
+		});
+
+		Ok(())
+	}
 }
modifiedpallets/refungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -57,6 +57,7 @@
 	fn token_owner() -> Weight;
 	fn set_allowance_for_all() -> Weight;
 	fn allowance_for_all() -> Weight;
+	fn repair_item() -> Weight;
 }
 
 /// Weights for pallet_refungible using the Substrate node and recommended hardware.
@@ -272,6 +273,12 @@
 		Weight::from_ref_time(5_901_000 as u64)
 			.saturating_add(T::DbWeight::get().reads(1 as u64))
 	}
+	// Storage: Refungible TokenProperties (r:1 w:1)
+	fn repair_item() -> Weight {
+		Weight::from_ref_time(5_489_000 as u64)
+			.saturating_add(T::DbWeight::get().reads(1 as u64))
+			.saturating_add(T::DbWeight::get().writes(1 as u64))
+	}
 }
 
 // For backwards compatibility and tests
@@ -486,4 +493,10 @@
 		Weight::from_ref_time(5_901_000 as u64)
 			.saturating_add(RocksDbWeight::get().reads(1 as u64))
 	}
+	// Storage: Refungible TokenProperties (r:1 w:1)
+	fn repair_item() -> Weight {
+		Weight::from_ref_time(5_489_000 as u64)
+			.saturating_add(RocksDbWeight::get().reads(1 as u64))
+			.saturating_add(RocksDbWeight::get().writes(1 as u64))
+	}
 }
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -982,6 +982,23 @@
 				d.set_allowance_for_all(sender, operator, approve)
 			})
 		}
+
+		/// Repairs a broken item
+		///
+		/// # Arguments
+		///
+		/// * `collection_id`: ID of the collection the item belongs to.
+		/// * `item_id`: ID of the item.
+		#[weight = T::CommonWeightInfo::repair_item()]
+		pub fn repair_item(
+			_origin,
+			collection_id: CollectionId,
+			item_id: TokenId,
+		) -> DispatchResultWithPostInfo {
+			dispatch_tx::<T, _>(collection_id, |d| {
+				d.repair_item(item_id)
+			})
+		}
 	}
 }
 
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -1133,7 +1133,7 @@
 		scope: PropertyScope,
 		key: PropertyKey,
 		value: Self::Value,
-	) -> Result<(), PropertiesError>;
+	) -> Result<Option<Self::Value>, PropertiesError>;
 
 	/// Try to set property with scope from iterator.
 	fn try_scoped_set_from_iter<I, KV>(
@@ -1154,7 +1154,11 @@
 	}
 
 	/// Try to set property.
-	fn try_set(&mut self, key: PropertyKey, value: Self::Value) -> Result<(), PropertiesError> {
+	fn try_set(
+		&mut self,
+		key: PropertyKey,
+		value: Self::Value,
+	) -> Result<Option<Self::Value>, PropertiesError> {
 		self.try_scoped_set(PropertyScope::None, key, value)
 	}
 
@@ -1214,6 +1218,10 @@
 
 		Ok(())
 	}
+
+	pub fn values(&self) -> impl Iterator<Item = &Value> {
+		self.0.values()
+	}
 }
 
 impl<Value> IntoIterator for PropertiesMap<Value> {
@@ -1239,15 +1247,13 @@
 		scope: PropertyScope,
 		key: PropertyKey,
 		value: Self::Value,
-	) -> Result<(), PropertiesError> {
+	) -> Result<Option<Self::Value>, PropertiesError> {
 		Self::check_property_key(&key)?;
 
 		let key = scope.apply(key)?;
 		self.0
 			.try_insert(key, value)
-			.map_err(|_| PropertiesError::PropertyLimitReached)?;
-
-		Ok(())
+			.map_err(|_| PropertiesError::PropertyLimitReached)
 	}
 }
 
@@ -1288,6 +1294,12 @@
 	pub fn get(&self, key: &PropertyKey) -> Option<&PropertyValue> {
 		self.map.get(key)
 	}
+
+	/// Recomputes the consumed space for the current properties state.
+	/// Needed to repair a token due to a bug fixed in the [PR #733](https://github.com/UniqueNetwork/unique-chain/pull/773).
+	pub fn recompute_consumed_space(&mut self) {
+		self.consumed_space = self.map.values().map(|value| value.len() as u32).sum();
+	}
 }
 
 impl IntoIterator for Properties {
@@ -1307,7 +1319,7 @@
 		scope: PropertyScope,
 		key: PropertyKey,
 		value: Self::Value,
-	) -> Result<(), PropertiesError> {
+	) -> Result<Option<Self::Value>, PropertiesError> {
 		let value_len = value.len();
 
 		if self.consumed_space as usize + value_len > self.space_limit as usize
@@ -1316,11 +1328,13 @@
 			return Err(PropertiesError::NoSpaceForProperty);
 		}
 
-		self.map.try_scoped_set(scope, key, value)?;
+		let old_value = self.map.try_scoped_set(scope, key, value)?;
 
-		self.consumed_space += value_len as u32;
+		if old_value.is_none() {
+			self.consumed_space += value_len as u32;
+		}
 
-		Ok(())
+		Ok(old_value)
 	}
 }
 
modifiedruntime/common/weights.rsdiffbeforeafterboth
before · runtime/common/weights.rs
1// Copyright 2019-2022 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/>.1617use core::marker::PhantomData;18use frame_support::{weights::Weight};19use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};2021use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};22use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};2324#[cfg(feature = "refungible")]25use pallet_refungible::{26	Config as RefungibleConfig, weights::WeightInfo, common::CommonWeights as RefungibleWeights,27};28use up_data_structs::{CreateItemExData, CreateItemData};2930macro_rules! max_weight_of {31	($method:ident ( $($args:tt)* )) => {{32		let max_weight = <FungibleWeights<T>>::$method($($args)*)33			.max(<NonfungibleWeights<T>>::$method($($args)*));3435		#[cfg(feature = "refungible")]36		let max_weight = max_weight.max(<RefungibleWeights<T>>::$method($($args)*));3738		max_weight39	}};40}4142#[cfg(not(feature = "refungible"))]43pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}4445#[cfg(not(feature = "refungible"))]46impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}4748#[cfg(feature = "refungible")]49pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}5051#[cfg(feature = "refungible")]52impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}5354pub struct CommonWeights<T>(PhantomData<T>);5556impl<T> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T>57where58	T: CommonWeightConfigs,59{60	fn create_item() -> Weight {61		dispatch_weight::<T>() + max_weight_of!(create_item())62	}6364	fn create_multiple_items(data: &[CreateItemData]) -> Weight {65		dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))66	}6768	fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {69		dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))70	}7172	fn burn_item() -> Weight {73		dispatch_weight::<T>() + max_weight_of!(burn_item())74	}7576	fn set_collection_properties(amount: u32) -> Weight {77		dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))78	}7980	fn delete_collection_properties(amount: u32) -> Weight {81		dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))82	}8384	fn set_token_properties(amount: u32) -> Weight {85		dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))86	}8788	fn delete_token_properties(amount: u32) -> Weight {89		dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))90	}9192	fn set_token_property_permissions(amount: u32) -> Weight {93		dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))94	}9596	fn transfer() -> Weight {97		dispatch_weight::<T>() + max_weight_of!(transfer())98	}99100	fn approve() -> Weight {101		dispatch_weight::<T>() + max_weight_of!(approve())102	}103104	fn transfer_from() -> Weight {105		dispatch_weight::<T>() + max_weight_of!(transfer_from())106	}107108	fn burn_from() -> Weight {109		dispatch_weight::<T>() + max_weight_of!(burn_from())110	}111112	fn burn_recursively_self_raw() -> Weight {113		max_weight_of!(burn_recursively_self_raw())114	}115116	fn burn_recursively_breadth_raw(amount: u32) -> Weight {117		max_weight_of!(burn_recursively_breadth_raw(amount))118	}119120	fn token_owner() -> Weight {121		max_weight_of!(token_owner())122	}123124	fn set_allowance_for_all() -> Weight {125		max_weight_of!(set_allowance_for_all())126	}127}128129#[cfg(feature = "refungible")]130impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>131where132	T: FungibleConfig + NonfungibleConfig + RefungibleConfig,133{134	fn repartition() -> Weight {135		dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()136	}137}138139#[cfg(not(feature = "refungible"))]140impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>141where142	T: FungibleConfig + NonfungibleConfig,143{144	fn repartition() -> Weight {145		dispatch_weight::<T>()146	}147}
after · runtime/common/weights.rs
1// Copyright 2019-2022 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/>.1617use core::marker::PhantomData;18use frame_support::{weights::Weight};19use pallet_common::{CommonWeightInfo, dispatch::dispatch_weight, RefungibleExtensionsWeightInfo};2021use pallet_fungible::{Config as FungibleConfig, common::CommonWeights as FungibleWeights};22use pallet_nonfungible::{Config as NonfungibleConfig, common::CommonWeights as NonfungibleWeights};2324#[cfg(feature = "refungible")]25use pallet_refungible::{26	Config as RefungibleConfig, weights::WeightInfo, common::CommonWeights as RefungibleWeights,27};28use up_data_structs::{CreateItemExData, CreateItemData};2930macro_rules! max_weight_of {31	($method:ident ( $($args:tt)* )) => {{32		let max_weight = <FungibleWeights<T>>::$method($($args)*)33			.max(<NonfungibleWeights<T>>::$method($($args)*));3435		#[cfg(feature = "refungible")]36		let max_weight = max_weight.max(<RefungibleWeights<T>>::$method($($args)*));3738		max_weight39	}};40}4142#[cfg(not(feature = "refungible"))]43pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig {}4445#[cfg(not(feature = "refungible"))]46impl<T: FungibleConfig + NonfungibleConfig> CommonWeightConfigs for T {}4748#[cfg(feature = "refungible")]49pub trait CommonWeightConfigs: FungibleConfig + NonfungibleConfig + RefungibleConfig {}5051#[cfg(feature = "refungible")]52impl<T: FungibleConfig + NonfungibleConfig + RefungibleConfig> CommonWeightConfigs for T {}5354pub struct CommonWeights<T>(PhantomData<T>);5556impl<T> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T>57where58	T: CommonWeightConfigs,59{60	fn create_item() -> Weight {61		dispatch_weight::<T>() + max_weight_of!(create_item())62	}6364	fn create_multiple_items(data: &[CreateItemData]) -> Weight {65		dispatch_weight::<T>() + max_weight_of!(create_multiple_items(data))66	}6768	fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {69		dispatch_weight::<T>() + max_weight_of!(create_multiple_items_ex(data))70	}7172	fn burn_item() -> Weight {73		dispatch_weight::<T>() + max_weight_of!(burn_item())74	}7576	fn set_collection_properties(amount: u32) -> Weight {77		dispatch_weight::<T>() + max_weight_of!(set_collection_properties(amount))78	}7980	fn delete_collection_properties(amount: u32) -> Weight {81		dispatch_weight::<T>() + max_weight_of!(delete_collection_properties(amount))82	}8384	fn set_token_properties(amount: u32) -> Weight {85		dispatch_weight::<T>() + max_weight_of!(set_token_properties(amount))86	}8788	fn delete_token_properties(amount: u32) -> Weight {89		dispatch_weight::<T>() + max_weight_of!(delete_token_properties(amount))90	}9192	fn set_token_property_permissions(amount: u32) -> Weight {93		dispatch_weight::<T>() + max_weight_of!(set_token_property_permissions(amount))94	}9596	fn transfer() -> Weight {97		dispatch_weight::<T>() + max_weight_of!(transfer())98	}99100	fn approve() -> Weight {101		dispatch_weight::<T>() + max_weight_of!(approve())102	}103104	fn transfer_from() -> Weight {105		dispatch_weight::<T>() + max_weight_of!(transfer_from())106	}107108	fn burn_from() -> Weight {109		dispatch_weight::<T>() + max_weight_of!(burn_from())110	}111112	fn burn_recursively_self_raw() -> Weight {113		max_weight_of!(burn_recursively_self_raw())114	}115116	fn burn_recursively_breadth_raw(amount: u32) -> Weight {117		max_weight_of!(burn_recursively_breadth_raw(amount))118	}119120	fn token_owner() -> Weight {121		max_weight_of!(token_owner())122	}123124	fn set_allowance_for_all() -> Weight {125		max_weight_of!(set_allowance_for_all())126	}127128	fn repair_item() -> Weight {129		max_weight_of!(repair_item())130	}131}132133#[cfg(feature = "refungible")]134impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>135where136	T: FungibleConfig + NonfungibleConfig + RefungibleConfig,137{138	fn repartition() -> Weight {139		dispatch_weight::<T>() + <<T as RefungibleConfig>::WeightInfo>::repartition_item()140	}141}142143#[cfg(not(feature = "refungible"))]144impl<T> RefungibleExtensionsWeightInfo for CommonWeights<T>145where146	T: FungibleConfig + NonfungibleConfig,147{148	fn repartition() -> Weight {149		dispatch_weight::<T>()150	}151}
modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -41,11 +41,10 @@
     "testEvent": "yarn setup && mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.*test.ts",
     "testRmrk": "yarn setup && mocha --timeout 9999999 -r ts-node/register ./**/rmrk/*.*test.ts",
     "testEthPayable": "mocha --timeout 9999999 -r ts-node/register './**/eth/payable.test.ts'",
-    "testEthTokenProperties": "mocha --timeout 9999999 -r ts-node/register ./**/eth/tokenProperties.test.ts",
     "testEvmCoder": "mocha --timeout 9999999 -r ts-node/register './**/eth/evmCoder.test.ts'",
     "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",
     "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",
-    "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts ./**/getPropertiesRpc.test.ts",
+    "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/collectionProperties.test.ts ./**/tokenProperties.test.ts ./**/getPropertiesRpc.test.ts",
     "testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",
     "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",
     "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
modifiedtests/src/nesting/collectionProperties.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/collectionProperties.test.ts
+++ b/tests/src/nesting/collectionProperties.test.ts
@@ -25,7 +25,7 @@
   before(async () => {
     await usingPlaygrounds(async (helper, privateKey) => {
       const donor = await privateKey({filename: __filename});
-      [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);
+      [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
     });
   });
   
@@ -131,6 +131,66 @@
   itSub.ifWithPallets('Deletes properties of a ReFungible collection', [Pallets.ReFungible], async ({helper}) => {
     await testDeleteProperties(await helper.rft.mintCollection(alice));
   });
+
+  [
+    // TODO enable properties for FT collection in Substrate (release 040)
+    // {mode: 'ft' as const, requiredPallets: []},
+    {mode: 'nft' as const, requiredPallets: []},
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]}, 
+  ].map(testCase =>
+    itSub.ifWithPallets(`Allows modifying a collection property multiple times (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {
+      const propKey = 'tok-prop';
+
+      const collection = await helper[testCase.mode].mintCollection(alice);
+
+      const maxCollectionPropertiesSize = 40960;
+
+      const propDataSize = 4096;
+
+      let propDataChar = 'a';
+      const makeNewPropData = () => {
+        propDataChar = String.fromCharCode(propDataChar.charCodeAt(0) + 1);
+        return `${propDataChar}`.repeat(propDataSize);
+      };
+
+      await collection.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
+      const originalSpace = await collection.getPropertiesConsumedSpace();
+      expect(originalSpace).to.be.equal(propDataSize);
+
+      const sameSizePropertiesPossibleNum = maxCollectionPropertiesSize / propDataSize;
+
+      // It is possible to modify a property as many times as needed.
+      // It will not consume any additional space.
+      for (let i = 0; i < sameSizePropertiesPossibleNum + 1; i++) {
+        await collection.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
+        const consumedSpace = await collection.getPropertiesConsumedSpace();
+        expect(consumedSpace).to.be.equal(originalSpace);
+      }
+    }));
+
+  [
+    // TODO enable properties for FT collection in Substrate (release 040)
+    // {mode: 'ft' as const, requiredPallets: []},
+    {mode: 'nft' as const, requiredPallets: []},
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]}, 
+  ].map(testCase =>
+    itSub.ifWithPallets(`Adding then removing a collection property doesn't change the consumed space (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {
+      const propKey = 'tok-prop';
+
+      const collection = await helper[testCase.mode].mintCollection(alice);
+      const originalSpace = await collection.getPropertiesConsumedSpace();
+
+      const propDataSize = 4096;
+      const propData = 'a'.repeat(propDataSize);
+
+      await collection.setProperties(alice, [{key: propKey, value: propData}]);
+      let consumedSpace = await collection.getPropertiesConsumedSpace();
+      expect(consumedSpace).to.be.equal(propDataSize);
+
+      await collection.deleteProperties(alice, [propKey]);
+      consumedSpace = await collection.getPropertiesConsumedSpace();
+      expect(consumedSpace).to.be.equal(originalSpace);
+    }));
 });
   
 describe('Negative Integration Test: Collection Properties', () => {
modifiedtests/src/nesting/tokenProperties.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/tokenProperties.test.ts
+++ b/tests/src/nesting/tokenProperties.test.ts
@@ -28,7 +28,7 @@
   before(async () => {
     await usingPlaygrounds(async (helper, privateKey) => {
       const donor = await privateKey({filename: __filename});
-      [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+      [alice, bob, charlie] = await helper.arrange.createAccounts([200n, 100n, 100n], donor);
     });
 
     permissions = [
@@ -320,6 +320,120 @@
     expect((await nestedToken.getData())!.properties).to.be.empty;
     expect(await targetToken.getProperties()).to.be.empty;
   });
+
+  [
+    {mode: 'nft' as const, storage: 'nonfungible' as const, pieces: undefined, requiredPallets: []},
+    {mode: 'rft' as const, storage: 'refungible' as const, pieces: 100n, requiredPallets: [Pallets.ReFungible]}, 
+  ].map(testCase =>
+    itSub.ifWithPallets(`Allows modifying a token property multiple times (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {
+      const propKey = 'tok-prop';
+
+      const collection = await helper[testCase.mode].mintCollection(alice, {
+        tokenPropertyPermissions: [
+          {
+            key: propKey,
+            permission: {mutable: true, tokenOwner: true},
+          },
+        ],
+      });
+
+      const maxTokenPropertiesSize = 32768;
+
+      const propDataSize = 4096;
+
+      let propDataChar = 'a';
+      const makeNewPropData = () => {
+        propDataChar = String.fromCharCode(propDataChar.charCodeAt(0) + 1);
+        return `${propDataChar}`.repeat(propDataSize);
+      };
+
+      const token = await (
+        testCase.pieces
+          ? collection.mintToken(alice, testCase.pieces)
+          : collection.mintToken(alice)
+      );
+
+      await token.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
+      const originalSpace = await token.getTokenPropertiesConsumedSpace();
+      expect(originalSpace).to.be.equal(propDataSize);
+
+      const sameSizePropertiesPossibleNum = maxTokenPropertiesSize / propDataSize;
+
+      // It is possible to modify a property as many times as needed.
+      // It will not consume any additional space.
+      for (let i = 0; i < sameSizePropertiesPossibleNum + 1; i++) {
+        await token.setProperties(alice, [{key: propKey, value: makeNewPropData()}]);
+        const consumedSpace = await token.getTokenPropertiesConsumedSpace();
+        expect(consumedSpace).to.be.equal(originalSpace);
+      }
+    }));
+
+  [
+    {mode: 'nft' as const, pieces: undefined, requiredPallets: []},
+    {mode: 'rft' as const, pieces: 100n, requiredPallets: [Pallets.ReFungible]}, 
+  ].map(testCase =>
+    itSub.ifWithPallets(`Adding then removing a token property doesn't change the consumed space (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {
+      const propKey = 'tok-prop';
+
+      const collection = await helper[testCase.mode].mintCollection(alice, {
+        tokenPropertyPermissions: [
+          {
+            key: propKey,
+            permission: {mutable: true, tokenOwner: true},
+          },
+        ],
+      });
+      const token = await (
+        testCase.pieces
+          ? collection.mintToken(alice, testCase.pieces)
+          : collection.mintToken(alice)
+      );
+      const originalSpace = await token.getTokenPropertiesConsumedSpace();
+
+      const propDataSize = 4096;
+      const propData = 'a'.repeat(propDataSize);
+
+      await token.setProperties(alice, [{key: propKey, value: propData}]);
+      let consumedSpace = await token.getTokenPropertiesConsumedSpace();
+      expect(consumedSpace).to.be.equal(propDataSize);
+
+      await token.deleteProperties(alice, [propKey]);
+      consumedSpace = await token.getTokenPropertiesConsumedSpace();
+      expect(consumedSpace).to.be.equal(originalSpace);
+    }));
+
+  [
+    {mode: 'nft' as const, pieces: undefined, requiredPallets: []},
+    {mode: 'rft' as const, pieces: 100n, requiredPallets: [Pallets.ReFungible]}, 
+  ].map(testCase =>
+    itSub.ifWithPallets(`repair_item preserves valid consumed space (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {
+      const propKey = 'tok-prop';
+
+      const collection = await helper[testCase.mode].mintCollection(alice, {
+        tokenPropertyPermissions: [
+          {
+            key: propKey,
+            permission: {mutable: true, tokenOwner: true},
+          },
+        ],
+      });
+      const token = await (
+        testCase.pieces
+          ? collection.mintToken(alice, testCase.pieces)
+          : collection.mintToken(alice)
+      );
+
+      const propDataSize = 4096;
+      const propData = 'a'.repeat(propDataSize);
+
+      await token.setProperties(alice, [{key: propKey, value: propData}]);
+      const originalSpace = await token.getTokenPropertiesConsumedSpace();
+      expect(originalSpace).to.be.equal(propDataSize);
+
+      await helper.executeExtrinsic(alice, 'api.tx.unique.repairItem', [token.collectionId, token.tokenId], true);
+      const recomputedSpace = await token.getTokenPropertiesConsumedSpace();
+      expect(recomputedSpace).to.be.equal(originalSpace);
+    }));
 });
 
 describe('Negative Integration Test: Token Properties', () => {
@@ -476,7 +590,7 @@
     await testForbidsAddingPropertiesIfPropertyNotDeclared(token, amount);
   });
 
-  async function testForbidsAddingTooManyProperties(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {
+  async function testForbidsAddingTooLargeProperties(token: UniqueNFToken | UniqueRFToken, pieces: bigint) {
     const originalSpace = await prepare(token, pieces);
 
     await expect(
@@ -504,15 +618,36 @@
     expect(consumedSpace).to.be.equal(originalSpace);
   }
 
-  itSub('Forbids adding too many properties to a token (NFT)', async ({helper}) =>  {
+  itSub('Forbids adding too large properties to a token (NFT)', async ({helper}) =>  {
     const [token, amount] = await mintCollectionWithAllPermissionsAndToken(helper, 'NFT');
-    await testForbidsAddingTooManyProperties(token, amount);
+    await testForbidsAddingTooLargeProperties(token, amount);
   });
 
-  itSub.ifWithPallets('Forbids adding too many properties to a token (ReFungible)', [Pallets.ReFungible], async ({helper}) => {
+  itSub.ifWithPallets('Forbids adding too large properties to a token (ReFungible)', [Pallets.ReFungible], async ({helper}) => {
     const [token, amount] = await mintCollectionWithAllPermissionsAndToken(helper, 'RFT');
-    await testForbidsAddingTooManyProperties(token, amount);
+    await testForbidsAddingTooLargeProperties(token, amount);
   });
+
+  [
+    {mode: 'nft' as const, requiredPallets: []},
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]}, 
+  ].map(testCase =>
+    itSub.ifWithPallets(`Forbids adding too many propeties to a token (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {
+      const collection = await helper[testCase.mode].mintCollection(alice);
+      const maxPropertiesPerItem = 64;
+
+      for (let i = 0; i < maxPropertiesPerItem; i++) {
+        await collection.setTokenPropertyPermissions(alice, [{
+          key: `${i+1}`,
+          permission: {mutable: true, tokenOwner: true, collectionAdmin: true},
+        }]);
+      }
+
+      await expect(collection.setTokenPropertyPermissions(alice, [{
+        key: `${maxPropertiesPerItem}-th`,
+        permission: {mutable: true, tokenOwner: true, collectionAdmin: true},
+      }])).to.be.rejectedWith(/common\.PropertyLimitReached/);
+    }));
 });
 
 describe('ReFungible token properties permissions tests', () => {
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -1100,6 +1100,13 @@
     return (await this.helper.callRpc('api.rpc.unique.collectionProperties', [collectionId, propertyKeys])).toHuman();
   }
 
+  async getPropertiesConsumedSpace(collectionId: number): Promise<number> {
+    const api = this.helper.getApi();
+    const props = (await api.query.common.collectionProperties(collectionId)).toJSON();
+        
+    return (props! as any).consumedSpace;
+  }
+
   async getCollectionOptions(collectionId: number) {
     return (await this.helper.callRpc('api.rpc.unique.collectionById', [collectionId])).toHuman();
   }
@@ -3035,6 +3042,10 @@
     return await this.helper.collection.getProperties(this.collectionId, propertyKeys);
   }
 
+  async getPropertiesConsumedSpace() {
+    return await this.helper.collection.getPropertiesConsumedSpace(this.collectionId);
+  }
+
   async getTokenNextSponsored(tokenId: number, addressObj: ICrossAccountId) {
     return await this.helper.collection.getTokenNextSponsored(this.collectionId, tokenId, addressObj);
   }
@@ -3158,6 +3169,13 @@
     return await this.helper.nft.getTokenProperties(this.collectionId, tokenId, propertyKeys);
   }
 
+  async getTokenPropertiesConsumedSpace(tokenId: number): Promise<number> {
+    const api = this.helper.getApi();
+    const props = (await api.query.nonfungible.tokenProperties(this.collectionId, tokenId)).toJSON();
+        
+    return (props! as any).consumedSpace;
+  }
+
   async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId) {
     return await this.helper.nft.transferToken(signer, this.collectionId, tokenId, addressObj);
   }
@@ -3269,6 +3287,13 @@
     return await this.helper.rft.getTokenProperties(this.collectionId, tokenId, propertyKeys);
   }
 
+  async getTokenPropertiesConsumedSpace(tokenId: number): Promise<number> {
+    const api = this.helper.getApi();
+    const props = (await api.query.refungible.tokenProperties(this.collectionId, tokenId)).toJSON();
+        
+    return (props! as any).consumedSpace;
+  }
+
   async transferToken(signer: TSigner, tokenId: number, addressObj: ICrossAccountId, amount=1n) {
     return await this.helper.rft.transferToken(signer, this.collectionId, tokenId, addressObj, amount);
   }
@@ -3421,6 +3446,10 @@
     return await this.collection.getTokenProperties(this.tokenId, propertyKeys);
   }
 
+  async getTokenPropertiesConsumedSpace() {
+    return await this.collection.getTokenPropertiesConsumedSpace(this.tokenId);
+  }
+
   async setProperties(signer: TSigner, properties: IProperty[]) {
     return await this.collection.setTokenProperties(signer, this.tokenId, properties);
   }