difftreelog
fieat: add repair_item extrinsic + test
in: master
15 files changed
pallets/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.
pallets/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)
+ }
}
pallets/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]
pallets/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)?}
}
pallets/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(),
+ )
+ }
}
pallets/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(())
+ }
}
pallets/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))
+ }
}
pallets/refungible/src/benchmarking.rsdiffbeforeafterboth1// 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 super::*;18use crate::{Pallet, Config, RefungibleHandle};1920use core::convert::TryInto;21use core::iter::IntoIterator;22use frame_benchmarking::{benchmarks, account};23use pallet_common::{24 bench_init,25 benchmarking::{create_collection_raw, property_key, property_value, create_data},26};27use sp_core::H160;28use sp_std::prelude::*;29use up_data_structs::{30 CollectionMode, MAX_ITEMS_PER_BATCH, MAX_PROPERTIES_PER_ITEM, CUSTOM_DATA_LIMIT,31 budget::Unlimited,32};3334const SEED: u32 = 1;3536fn create_max_item_data<CrossAccountId: Ord>(37 users: impl IntoIterator<Item = (CrossAccountId, u128)>,38) -> CreateItemData<CrossAccountId> {39 CreateItemData {40 users: users41 .into_iter()42 .collect::<BTreeMap<_, _>>()43 .try_into()44 .unwrap(),45 properties: Default::default(),46 }47}4849fn create_max_item<T: Config>(50 collection: &RefungibleHandle<T>,51 sender: &T::CrossAccountId,52 users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,53) -> Result<TokenId, DispatchError> {54 let data: CreateItemData<T::CrossAccountId> = create_max_item_data(users);55 <Pallet<T>>::create_item(&collection, sender, data, &Unlimited)?;56 Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))57}5859fn create_collection<T: Config>(60 owner: T::CrossAccountId,61) -> Result<RefungibleHandle<T>, DispatchError> {62 create_collection_raw(63 owner,64 CollectionMode::ReFungible,65 |owner: T::CrossAccountId, data| {66 <Pallet<T>>::init_collection(owner.clone(), owner, data, Default::default())67 },68 RefungibleHandle::cast,69 )70}7172benchmarks! {73 create_item {74 bench_init!{75 owner: sub; collection: collection(owner);76 sender: cross_from_sub(owner); to: cross_sub;77 };78 }: {create_max_item(&collection, &sender, [(to.clone(), 200)])?}7980 create_multiple_items {81 let b in 0..MAX_ITEMS_PER_BATCH;82 bench_init!{83 owner: sub; collection: collection(owner);84 sender: cross_from_sub(owner); to: cross_sub;85 };86 let data = (0..b).map(|_| create_max_item_data([(to.clone(), 200)])).collect();87 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}8889 create_multiple_items_ex_multiple_items {90 let b in 0..MAX_ITEMS_PER_BATCH;91 bench_init!{92 owner: sub; collection: collection(owner);93 sender: cross_from_sub(owner);94 };95 let data = (0..b).map(|t| {96 bench_init!(to: cross_sub(t););97 create_max_item_data([(to, 200)])98 }).collect();99 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}100101 create_multiple_items_ex_multiple_owners {102 let b in 0..MAX_ITEMS_PER_BATCH;103 bench_init!{104 owner: sub; collection: collection(owner);105 sender: cross_from_sub(owner);106 };107 let data = vec![create_max_item_data((0..b).map(|u| {108 bench_init!(to: cross_sub(u););109 (to, 200)110 }))].try_into().unwrap();111 }: {<Pallet<T>>::create_multiple_items(&collection, &sender, data, &Unlimited)?}112113 // Other user left, token data is kept114 burn_item_partial {115 bench_init!{116 owner: sub; collection: collection(owner);117 sender: cross_from_sub(owner); burner: cross_sub; another_owner: cross_sub;118 };119 let item = create_max_item(&collection, &sender, [(burner.clone(), 200), (another_owner, 200)])?;120 }: {<Pallet<T>>::burn(&collection, &burner, item, 200)?}121 // No users remaining, token is destroyed122 burn_item_fully {123 bench_init!{124 owner: sub; collection: collection(owner);125 sender: cross_from_sub(owner); burner: cross_sub; another_owner: cross_sub;126 };127 let item = create_max_item(&collection, &sender, [(burner.clone(), 200)])?;128 }: {<Pallet<T>>::burn(&collection, &burner, item, 200)?}129130 transfer_normal {131 bench_init!{132 owner: sub; collection: collection(owner);133 sender: cross_from_sub(owner); receiver: cross_sub;134 };135 let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?;136 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?}137 // Target account is created138 transfer_creating {139 bench_init!{140 owner: sub; collection: collection(owner);141 sender: cross_from_sub(owner); receiver: cross_sub;142 };143 let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;144 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 100, &Unlimited)?}145 // Source account is destroyed146 transfer_removing {147 bench_init!{148 owner: sub; collection: collection(owner);149 sender: cross_from_sub(owner); receiver: cross_sub;150 };151 let item = create_max_item(&collection, &sender, [(sender.clone(), 200), (receiver.clone(), 200)])?;152 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?}153 // Source account destroyed, target created154 transfer_creating_removing {155 bench_init!{156 owner: sub; collection: collection(owner);157 sender: cross_from_sub(owner); receiver: cross_sub;158 };159 let item = create_max_item(&collection, &sender, [(sender.clone(), 200)])?;160 }: {<Pallet<T>>::transfer(&collection, &sender, &receiver, item, 200, &Unlimited)?}161162 approve {163 bench_init!{164 owner: sub; collection: collection(owner);165 owner: cross_from_sub; sender: cross_sub; spender: cross_sub;166 };167 let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;168 }: {<Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?}169170 transfer_from_normal {171 bench_init!{172 owner: sub; collection: collection(owner);173 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;174 };175 let item = create_max_item(&collection, &owner, [(sender.clone(), 200), (receiver.clone(), 200)])?;176 <Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?;177 }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 100, &Unlimited)?}178 // Target account is created179 transfer_from_creating {180 bench_init!{181 owner: sub; collection: collection(owner);182 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;183 };184 let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;185 <Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 100)?;186 }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 100, &Unlimited)?}187 // Source account is destroyed188 transfer_from_removing {189 bench_init!{190 owner: sub; collection: collection(owner);191 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;192 };193 let item = create_max_item(&collection, &owner, [(sender.clone(), 200), (receiver.clone(), 200)])?;194 <Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;195 }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 200, &Unlimited)?}196 // Source account destroyed, target created197 transfer_from_creating_removing {198 bench_init!{199 owner: sub; collection: collection(owner);200 owner: cross_from_sub; sender: cross_sub; spender: cross_sub; receiver: cross_sub;201 };202 let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;203 <Pallet<T>>::set_allowance(&collection, &sender, &spender, item, 200)?;204 }: {<Pallet<T>>::transfer_from(&collection, &spender, &sender, &receiver, item, 200, &Unlimited)?}205206 // Both source account and token is destroyed207 burn_from {208 bench_init!{209 owner: sub; collection: collection(owner);210 owner: cross_from_sub; sender: cross_sub; burner: cross_sub;211 };212 let item = create_max_item(&collection, &owner, [(sender.clone(), 200)])?;213 <Pallet<T>>::set_allowance(&collection, &sender, &burner, item, 200)?;214 }: {<Pallet<T>>::burn_from(&collection, &burner, &sender, item, 200, &Unlimited)?}215216 set_token_property_permissions {217 let b in 0..MAX_PROPERTIES_PER_ITEM;218 bench_init!{219 owner: sub; collection: collection(owner);220 owner: cross_from_sub;221 };222 let perms = (0..b).map(|k| PropertyKeyPermission {223 key: property_key(k as usize),224 permission: PropertyPermission {225 mutable: false,226 collection_admin: false,227 token_owner: false,228 },229 }).collect::<Vec<_>>();230 }: {<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?}231232 set_token_properties {233 let b in 0..MAX_PROPERTIES_PER_ITEM;234 bench_init!{235 owner: sub; collection: collection(owner);236 owner: cross_from_sub;237 };238 let perms = (0..b).map(|k| PropertyKeyPermission {239 key: property_key(k as usize),240 permission: PropertyPermission {241 mutable: false,242 collection_admin: true,243 token_owner: true,244 },245 }).collect::<Vec<_>>();246 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;247 let props = (0..b).map(|k| Property {248 key: property_key(k as usize),249 value: property_value(),250 }).collect::<Vec<_>>();251 let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;252 }: {<Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), false, &Unlimited)?}253254 delete_token_properties {255 let b in 0..MAX_PROPERTIES_PER_ITEM;256 bench_init!{257 owner: sub; collection: collection(owner);258 owner: cross_from_sub;259 };260 let perms = (0..b).map(|k| PropertyKeyPermission {261 key: property_key(k as usize),262 permission: PropertyPermission {263 mutable: true,264 collection_admin: true,265 token_owner: true,266 },267 }).collect::<Vec<_>>();268 <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;269 let props = (0..b).map(|k| Property {270 key: property_key(k as usize),271 value: property_value(),272 }).collect::<Vec<_>>();273 let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;274 <Pallet<T>>::set_token_properties(&collection, &owner, item, props.into_iter(), false, &Unlimited)?;275 let to_delete = (0..b).map(|k| property_key(k as usize)).collect::<Vec<_>>();276 }: {<Pallet<T>>::delete_token_properties(&collection, &owner, item, to_delete.into_iter(), &Unlimited)?}277278 repartition_item {279 bench_init!{280 owner: sub; collection: collection(owner);281 sender: cross_from_sub(owner); owner: cross_sub;282 };283 let item = create_max_item(&collection, &sender, [(owner.clone(), 100)])?;284 }: {<Pallet<T>>::repartition(&collection, &owner, item, 200)?}285286 token_owner {287 bench_init!{288 owner: sub; collection: collection(owner);289 sender: cross_from_sub(owner); owner: cross_sub;290 };291 let item = create_max_item(&collection, &sender, [(owner.clone(), 100)])?;292 }: {<Pallet<T>>::token_owner(collection.id, item)}293294 set_allowance_for_all {295 bench_init!{296 owner: sub; collection: collection(owner); owner: cross_from_sub;297 operator: cross_sub;298 };299 }: {<Pallet<T>>::set_allowance_for_all(&collection, &owner, &operator, true)}300301 allowance_for_all {302 bench_init!{303 owner: sub; collection: collection(owner); owner: cross_from_sub;304 operator: cross_sub;305 };306 }: {<Pallet<T>>::allowance_for_all(&collection, &owner, &operator)}307}pallets/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> {
pallets/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(())
+ }
}
pallets/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))
+ }
}
pallets/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)
+ })
+ }
}
}
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -1218,6 +1218,10 @@
Ok(())
}
+
+ pub fn values(&self) -> impl Iterator<Item = &Value> {
+ self.0.values()
+ }
}
impl<Value> IntoIterator for PropertiesMap<Value> {
@@ -1290,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 {
runtime/common/weights.rsdiffbeforeafterboth--- a/runtime/common/weights.rs
+++ b/runtime/common/weights.rs
@@ -124,6 +124,10 @@
fn set_allowance_for_all() -> Weight {
max_weight_of!(set_allowance_for_all())
}
+
+ fn repair_item() -> Weight {
+ max_weight_of!(repair_item())
+ }
}
#[cfg(feature = "refungible")]
tests/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 = [
@@ -401,6 +401,39 @@
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', () => {