git.delta.rocks / unique-network / refs/commits / c12162af7885

difftreelog

Merge pull request #785 from UniqueNetwork/feature/force-repair-things

ut-akuznetsov2022-12-16parents: #d8b03ef #196e170.patch.diff
in: master

12 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1223,7 +1223,7 @@
 	}
 
 	/// Set a scoped collection property, where the scope is a special prefix
-	/// prohibiting a user to change the property.
+	/// prohibiting a user access to change the property directly.
 	///
 	/// * `collection_id` - ID of the collection for which the property is being set.
 	/// * `scope` - Property scope.
@@ -1242,7 +1242,7 @@
 	}
 
 	/// Set scoped collection properties, where the scope is a special prefix
-	/// prohibiting a user to change the properties.
+	/// prohibiting a user access to change the properties directly.
 	///
 	/// * `collection_id` - ID of the collection for which the properties is being set.
 	/// * `scope` - Property scope.
@@ -1730,6 +1730,15 @@
 		);
 		Ok(new_permission)
 	}
+
+	/// Repair possibly broken properties of a collection.
+	pub fn repair_collection(collection_id: CollectionId) -> DispatchResult {
+		CollectionProperties::<T>::mutate(collection_id, |properties| {
+			properties.recompute_consumed_space();
+		});
+
+		Ok(())
+	}
 }
 
 /// Indicates unsupported methods by returning [Error::UnsupportedOperation].
@@ -1819,7 +1828,7 @@
 	fn set_allowance_for_all() -> Weight;
 
 	/// The price of repairing an item.
-	fn repair_item() -> Weight;
+	fn force_repair_item() -> Weight;
 }
 
 /// Weight info extension trait for refungible pallet.
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -113,7 +113,7 @@
 		Weight::zero()
 	}
 
-	fn repair_item() -> Weight {
+	fn force_repair_item() -> Weight {
 		Weight::zero()
 	}
 }
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -127,7 +127,7 @@
 		<SelfWeightOf<T>>::set_allowance_for_all()
 	}
 
-	fn repair_item() -> Weight {
+	fn force_repair_item() -> Weight {
 		<SelfWeightOf<T>>::repair_item()
 	}
 }
@@ -540,7 +540,7 @@
 	fn repair_item(&self, token: TokenId) -> DispatchResultWithPostInfo {
 		with_weight(
 			<Pallet<T>>::repair_item(self, token),
-			<CommonWeights<T>>::repair_item(),
+			<CommonWeights<T>>::force_repair_item(),
 		)
 	}
 }
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -157,7 +157,7 @@
 		<SelfWeightOf<T>>::set_allowance_for_all()
 	}
 
-	fn repair_item() -> Weight {
+	fn force_repair_item() -> Weight {
 		<SelfWeightOf<T>>::repair_item()
 	}
 }
@@ -544,7 +544,7 @@
 	fn repair_item(&self, token: TokenId) -> DispatchResultWithPostInfo {
 		with_weight(
 			<Pallet<T>>::repair_item(self, token),
-			<CommonWeights<T>>::repair_item(),
+			<CommonWeights<T>>::force_repair_item(),
 		)
 	}
 }
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -82,7 +82,7 @@
 	BoundedVec,
 };
 use scale_info::TypeInfo;
-use frame_system::{self as system, ensure_signed};
+use frame_system::{self as system, ensure_signed, ensure_root};
 use sp_std::{vec, vec::Vec};
 use up_data_structs::{
 	MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
@@ -983,18 +983,33 @@
 			})
 		}
 
-		/// Repairs a broken item
+		/// Repairs a collection if the data was somehow corrupted.
 		///
 		/// # Arguments
 		///
+		/// * `collection_id`: ID of the collection to repair.
+		#[weight = <SelfWeightOf<T>>::force_repair_collection()]
+		pub fn force_repair_collection(
+			origin,
+			collection_id: CollectionId,
+		) -> DispatchResult {
+			ensure_root(origin)?;
+			<PalletCommon<T>>::repair_collection(collection_id)
+		}
+
+		/// Repairs a token if the data was somehow corrupted.
+		///
+		/// # 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,
+		#[weight = T::CommonWeightInfo::force_repair_item()]
+		pub fn force_repair_item(
+			origin,
 			collection_id: CollectionId,
 			item_id: TokenId,
 		) -> DispatchResultWithPostInfo {
+			ensure_root(origin)?;
 			dispatch_tx::<T, _>(collection_id, |d| {
 				d.repair_item(item_id)
 			})
modifiedpallets/unique/src/weights.rsdiffbeforeafterboth
--- a/pallets/unique/src/weights.rs
+++ b/pallets/unique/src/weights.rs
@@ -45,6 +45,7 @@
 	fn remove_collection_sponsor() -> Weight;
 	fn set_transfers_enabled_flag() -> Weight;
 	fn set_collection_limits() -> Weight;
+	fn force_repair_collection() -> Weight;
 }
 
 /// Weights for pallet_unique using the Substrate node and recommended hardware.
@@ -139,6 +140,12 @@
 			.saturating_add(T::DbWeight::get().reads(1 as u64))
 			.saturating_add(T::DbWeight::get().writes(1 as u64))
 	}
+	// Storage: Common CollectionProperties (r:1 w:1)
+	fn force_repair_collection() -> 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
@@ -232,4 +239,10 @@
 			.saturating_add(RocksDbWeight::get().reads(1 as u64))
 			.saturating_add(RocksDbWeight::get().writes(1 as u64))
 	}
+	// Storage: Common CollectionProperties (r:1 w:1)
+	fn force_repair_collection() -> 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))
+	}
 }
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	}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}
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 force_repair_item() -> Weight {129		max_weight_of!(force_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
@@ -44,8 +44,9 @@
     "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 ./**/collectionProperties.test.ts ./**/tokenProperties.test.ts ./**/getPropertiesRpc.test.ts",
-    "testCollectionProperties": "mocha --timeout 9999999 -r ts-node/register ./**/collectionProperties.test.ts",
+    "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/collectionProperties.*test.ts ./**/tokenProperties.*test.ts ./**/getPropertiesRpc.test.ts",
+    "testCollectionProperties": "mocha --timeout 9999999 -r ts-node/register ./**/collectionProperties.*test.ts",
+    "testTokenProperties": "mocha --timeout 9999999 -r ts-node/register ./**/tokenProperties.*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",
addedtests/src/nesting/collectionProperties.seqtest.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/nesting/collectionProperties.seqtest.ts
@@ -0,0 +1,61 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, usingPlaygrounds, expect, requirePalletsOrSkip} from '../util';
+
+describe('Integration Test: Collection Properties with sudo', () => {
+  let superuser: IKeyringPair;
+  let alice: IKeyringPair;
+  
+  before(async () => {
+    await usingPlaygrounds(async (helper, privateKey) => {
+      superuser = await privateKey('//Alice');
+      const donor = await privateKey({filename: __filename});
+      [alice] = await helper.arrange.createAccounts([100n], donor);
+    });
+  });
+
+  [
+    {mode: 'nft' as const, requiredPallets: []},
+    {mode: 'ft' as const, requiredPallets: []},
+    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]}, 
+  ].map(testSuite => describe(`${testSuite.mode.toUpperCase()}`, () => {
+    before(async function() {
+      // eslint-disable-next-line require-await
+      await usingPlaygrounds(async helper => {
+        requirePalletsOrSkip(this, helper, testSuite.requiredPallets);
+      });
+    });
+
+    itSub('Repairing an unbroken collection\'s properties preserves the consumed space', async({helper}) => {
+      const properties = [
+        {key: 'sea-creatures', value: 'mermaids'},
+        {key: 'goldenratio', value: '1.6180339887498948482045868343656381177203091798057628621354486227052604628189'},
+      ];
+      const collection = await helper[testSuite.mode].mintCollection(alice, {properties});
+
+      const newProperty = ' '.repeat(4096);
+      await collection.setProperties(alice, [{key: 'space', value: newProperty}]);
+      const originalSpace = await collection.getPropertiesConsumedSpace();
+      expect(originalSpace).to.be.equal(properties[0].value.length + properties[1].value.length + newProperty.length);
+
+      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.unique.forceRepairCollection', [collection.collectionId], true);
+      const recomputedSpace = await collection.getPropertiesConsumedSpace();
+      expect(recomputedSpace).to.be.equal(originalSpace);
+    });
+  }));
+});
\ No newline at end of file
modifiedtests/src/nesting/collectionProperties.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/collectionProperties.test.ts
+++ b/tests/src/nesting/collectionProperties.test.ts
@@ -314,6 +314,16 @@
         ).to.be.rejectedWith(/common\.InvalidCharacterInPropertyKey/);
       }
     });
+
+    itSub('Forbids to repair a collection if called with non-sudo', async({helper}) => {
+      const collection = await helper[testSuite.mode].mintCollection(alice, {properties: [
+        {key: 'sea-creatures', value: 'mermaids'},
+        {key: 'goldenratio', value: '1.6180339887498948482045868343656381177203091798057628621354486227052604628189'},
+      ]});
+
+      await expect(helper.executeExtrinsic(alice, 'api.tx.unique.forceRepairCollection', [collection.collectionId], true))
+        .to.be.rejectedWith(/BadOrigin/);
+    });
   }));
 });
   
\ No newline at end of file
addedtests/src/nesting/tokenProperties.seqtest.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/nesting/tokenProperties.seqtest.ts
@@ -0,0 +1,72 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, usingPlaygrounds, expect, requirePalletsOrSkip} from '../util';
+
+describe('Integration Test: Token Properties with sudo', () => {
+  let superuser: IKeyringPair;
+  let alice: IKeyringPair; // collection owner
+
+  before(async () => {
+    await usingPlaygrounds(async (helper, privateKey) => {
+      superuser = await privateKey('//Alice');
+      const donor = await privateKey({filename: __filename});
+      [alice] = await helper.arrange.createAccounts([100n], donor);
+    });
+  });
+
+  [
+    {mode: 'nft' as const, pieces: undefined, requiredPallets: []},
+    {mode: 'rft' as const, pieces: 100n, requiredPallets: [Pallets.ReFungible]}, 
+  ].map(testSuite => describe(`${testSuite.mode.toUpperCase()}`, () => {
+    before(async function() {
+      // eslint-disable-next-line require-await
+      await usingPlaygrounds(async helper => {
+        requirePalletsOrSkip(this, helper, testSuite.requiredPallets);
+      });
+    });
+    
+    itSub('force_repair_item preserves valid consumed space', async({helper}) => {
+      const propKey = 'tok-prop';
+
+      const collection = await helper[testSuite.mode].mintCollection(alice, {
+        tokenPropertyPermissions: [
+          {
+            key: propKey,
+            permission: {mutable: true, tokenOwner: true},
+          },
+        ],
+      });
+      const token = await (
+        testSuite.pieces
+          ? collection.mintToken(alice, testSuite.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.getSudo().executeExtrinsic(superuser, 'api.tx.unique.forceRepairItem', [token.collectionId, token.tokenId], true);
+      const recomputedSpace = await token.getTokenPropertiesConsumedSpace();
+      expect(recomputedSpace).to.be.equal(originalSpace);
+    });
+  }));
+});
\ No newline at end of file
modifiedtests/src/nesting/tokenProperties.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/tokenProperties.test.ts
+++ b/tests/src/nesting/tokenProperties.test.ts
@@ -406,39 +406,6 @@
     {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);
-    }));
-
-  [
-    {mode: 'nft' as const, pieces: undefined, requiredPallets: []},
-    {mode: 'rft' as const, pieces: 100n, requiredPallets: [Pallets.ReFungible]}, 
-  ].map(testCase =>
     itSub.ifWithPallets(`Modifying a token property with different sizes correctly changes the consumed space (${testCase.mode})`, testCase.requiredPallets, async({helper}) => {
       const propKey = 'tok-prop';
 
@@ -697,6 +664,35 @@
         permission: {mutable: true, tokenOwner: true, collectionAdmin: true},
       }])).to.be.rejectedWith(/common\.PropertyLimitReached/);
     }));
+
+  [
+    {mode: 'nft' as const, pieces: undefined, requiredPallets: []},
+    {mode: 'rft' as const, pieces: 100n, requiredPallets: [Pallets.ReFungible]}, 
+  ].map(testCase =>
+    itSub.ifWithPallets(`Forbids force_repair_item from non-sudo (${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}]);
+
+      await expect(helper.executeExtrinsic(alice, 'api.tx.unique.forceRepairItem', [token.collectionId, token.tokenId], true))
+        .to.be.rejectedWith(/BadOrigin/);
+    }));
 });
 
 describe('ReFungible token properties permissions tests', () => {