git.delta.rocks / unique-network / refs/commits / 1ac708f72a4b

difftreelog

Merge pull request #411 from UniqueNetwork/feature/total_pieces

bugrazoid2022-07-06parents: #e82bbde #a5763d4.patch.diff
in: master
Add rpc method for total_pieces

11 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -184,12 +184,21 @@
 		token: TokenId,
 		at: Option<BlockHash>,
 	) -> Result<Option<u64>>;
+
 	#[method(name = "unique_effectiveCollectionLimits")]
 	fn effective_collection_limits(
 		&self,
 		collection_id: CollectionId,
 		at: Option<BlockHash>,
 	) -> Result<Option<CollectionLimits>>;
+
+	#[method(name = "unique_totalPieces")]
+	fn total_pieces(
+		&self,
+		collection_id: CollectionId,
+		token_id: TokenId,
+		at: Option<BlockHash>,
+	) -> Result<Option<u128>>;
 }
 
 mod rmrk_unique_rpc {
@@ -463,6 +472,7 @@
 	pass_method!(collection_stats() -> CollectionStats, unique_api);
 	pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);
 	pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);
+	pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128>, unique_api);
 }
 
 #[allow(deprecated)]
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1384,6 +1384,8 @@
 	fn account_balance(&self, account: T::CrossAccountId) -> u32;
 	/// Amount of specific token account have (Applicable to fungible/refungible)
 	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128;
+	/// Amount of token pieces
+	fn total_pieces(&self, token: TokenId) -> Option<u128>;
 	fn allowance(
 		&self,
 		sender: T::CrossAccountId,
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -25,7 +25,8 @@
 use up_data_structs::{Property, PropertyKey, PropertyValue, PropertyKeyPermission};
 
 use crate::{
-	Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,
+	Allowance, TotalSupply, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf,
+	weights::WeightInfo,
 };
 
 pub struct CommonWeights<T: Config>(PhantomData<T>);
@@ -405,4 +406,11 @@
 	fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {
 		None
 	}
+
+	fn total_pieces(&self, token: TokenId) -> Option<u128> {
+		if token != TokenId::default() {
+			return None;
+		}
+		<TotalSupply<T>>::try_get(self.id).ok()
+	}
 }
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -487,4 +487,12 @@
 	fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {
 		None
 	}
+
+	fn total_pieces(&self, token: TokenId) -> Option<u128> {
+		if <TokenData<T>>::contains_key((self.id, token)) {
+			Some(1)
+		} else {
+			None
+		}
+	}
 }
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -411,6 +411,10 @@
 	fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {
 		Some(self)
 	}
+
+	fn total_pieces(&self, token: TokenId) -> Option<u128> {
+		<Pallet<T>>::total_pieces(self.id, token)
+	}
 }
 
 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
@@ -710,4 +710,8 @@
 		<TotalSupply<T>>::insert((collection.id, token), amount);
 		Ok(())
 	}
+
+	fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128> {
+		<TotalSupply<T>>::try_get((collection_id, token_id)).ok()
+	}
 }
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -181,6 +181,7 @@
 pub struct TokenData<CrossAccountId> {
 	pub properties: Vec<Property>,
 	pub owner: Option<CrossAccountId>,
+	pub pieces: u128,
 }
 
 pub struct OverflowError;
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -80,5 +80,6 @@
 		fn collection_stats() -> Result<CollectionStats>;
 		fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;
 		fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;
+		fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Result<Option<u128>>;
 	}
 }
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -89,7 +89,8 @@
                 ) -> Result<TokenData<CrossAccountId>, DispatchError> {
                     let token_data = TokenData {
                         properties: Self::token_properties(collection, token_id, keys)?,
-                        owner: Self::token_owner(collection, token_id)?
+                        owner: Self::token_owner(collection, token_id)?,
+                        pieces: Self::total_pieces(collection, token_id)?.unwrap_or(0),
                     };
 
                     Ok(token_data)
@@ -142,6 +143,10 @@
                 fn effective_collection_limits(collection: CollectionId) -> Result<Option<CollectionLimits>, DispatchError> {
                     Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))
                 }
+
+                fn total_pieces(collection: CollectionId, token_id: TokenId) -> Result<Option<u128>, DispatchError> {
+                    dispatch_unique_runtime!(collection.total_pieces(token_id))
+                }
             }
 
             impl sp_api::Core<Block> for Runtime {
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
before · tests/src/createItem.test.ts
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/>.1617import {default as usingApi} from './substrate/substrate-api';18import chai from 'chai';19import {IKeyringPair} from '@polkadot/types/types';20import {21  createCollectionExpectSuccess,22  createItemExpectSuccess,23  addCollectionAdminExpectSuccess,24  createCollectionWithPropsExpectSuccess,25  createItemWithPropsExpectSuccess,26  createItemWithPropsExpectFailure,27} from './util/helpers';2829const expect = chai.expect;30let alice: IKeyringPair;31let bob: IKeyringPair;3233describe('integration test: ext. ():', () => {34  before(async () => {35    await usingApi(async (api, privateKeyWrapper) => {36      alice = privateKeyWrapper('//Alice');37      bob = privateKeyWrapper('//Bob');38    });39  });4041  it('Create new item in NFT collection', async () => {42    const createMode = 'NFT';43    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});44    await createItemExpectSuccess(alice, newCollectionID, createMode);45  });46  it('Create new item in Fungible collection', async () => {47    const createMode = 'Fungible';48    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});49    await createItemExpectSuccess(alice, newCollectionID, createMode);50  });51  it('Create new item in ReFungible collection', async () => {52    const createMode = 'ReFungible';53    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});54    await createItemExpectSuccess(alice, newCollectionID, createMode);55  });56  it('Create new item in NFT collection with collection admin permissions', async () => {57    const createMode = 'NFT';58    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});59    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);60    await createItemExpectSuccess(bob, newCollectionID, createMode);61  });62  it('Create new item in Fungible collection with collection admin permissions', async () => {63    const createMode = 'Fungible';64    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});65    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);66    await createItemExpectSuccess(bob, newCollectionID, createMode);67  });68  it('Create new item in ReFungible collection with collection admin permissions', async () => {69    const createMode = 'ReFungible';70    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});71    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);72    await createItemExpectSuccess(bob, newCollectionID, createMode);73  });7475  it('Set property Admin', async () => {76    const createMode = 'NFT';77    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 78      propPerm:   [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});79    80    await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);81  });8283  it('Set property AdminConst', async () => {84    const createMode = 'NFT';85    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 86      propPerm:   [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});87    88    await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);89  });9091  it('Set property itemOwnerOrAdmin', async () => {92    const createMode = 'NFT';93    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},94      propPerm:   [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});95    96    await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);97  });98});99100describe('Negative integration test: ext. createItem():', () => {101  before(async () => {102    await usingApi(async (api, privateKeyWrapper) => {103      alice = privateKeyWrapper('//Alice');104      bob = privateKeyWrapper('//Bob');105    });106  });107108  it('Regular user cannot create new item in NFT collection', async () => {109    const createMode = 'NFT';110    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});111    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;112  });113  it('Regular user cannot create new item in Fungible collection', async () => {114    const createMode = 'Fungible';115    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});116    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;117  });118  it('Regular user cannot create new item in ReFungible collection', async () => {119    const createMode = 'ReFungible';120    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});121    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;122  });123124  it('No editing rights', async () => {125    await usingApi(async () => {126      const createMode = 'NFT';127      const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 128        propPerm:   [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});129      await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);130131      await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);132    });133  });134135  it('User doesnt have editing rights', async () => {136    await usingApi(async () => {137      const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});138      await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);139    });140  });141142  it('Adding property without access rights', async () => {143    await usingApi(async () => {144      const newCollectionID = await createCollectionWithPropsExpectSuccess();145      await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);146147      await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'k', value: 'v'}]);148    });149  });150151  it('Adding more than 64 prps', async () => {152    await usingApi(async () => {153      const prps = [];154155      for (let i = 0; i < 65; i++) {156        prps.push({key: `key${i}`, value: `value${i}`});157      }158159      const newCollectionID = await createCollectionWithPropsExpectSuccess();160      161      await createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', prps);162    });163  });164165  it('Trying to add bigger property than allowed', async () => {166    await usingApi(async () => {167      const newCollectionID = await createCollectionWithPropsExpectSuccess();168      169      await createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]);170    });171  });172});
after · tests/src/createItem.test.ts
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/>.1617import {default as usingApi} from './substrate/substrate-api';18import chai from 'chai';19import {IKeyringPair} from '@polkadot/types/types';20import {21  createCollectionExpectSuccess,22  createItemExpectSuccess,23  addCollectionAdminExpectSuccess,24  createCollectionWithPropsExpectSuccess,25  createItemWithPropsExpectSuccess,26  createItemWithPropsExpectFailure,27  createCollection,28  transferExpectSuccess,29} from './util/helpers';3031const expect = chai.expect;32let alice: IKeyringPair;33let bob: IKeyringPair;3435describe('integration test: ext. ():', () => {36  before(async () => {37    await usingApi(async (api, privateKeyWrapper) => {38      alice = privateKeyWrapper('//Alice');39      bob = privateKeyWrapper('//Bob');40    });41  });4243  it('Create new item in NFT collection', async () => {44    const createMode = 'NFT';45    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});46    await createItemExpectSuccess(alice, newCollectionID, createMode);47  });48  it('Create new item in Fungible collection', async () => {49    const createMode = 'Fungible';50    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});51    await createItemExpectSuccess(alice, newCollectionID, createMode);52  });53  it('Create new item in ReFungible collection', async () => {54    const createMode = 'ReFungible';55    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});56    await createItemExpectSuccess(alice, newCollectionID, createMode);57  });58  it('Create new item in NFT collection with collection admin permissions', async () => {59    const createMode = 'NFT';60    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});61    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);62    await createItemExpectSuccess(bob, newCollectionID, createMode);63  });64  it('Create new item in Fungible collection with collection admin permissions', async () => {65    const createMode = 'Fungible';66    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});67    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);68    await createItemExpectSuccess(bob, newCollectionID, createMode);69  });70  it('Create new item in ReFungible collection with collection admin permissions', async () => {71    const createMode = 'ReFungible';72    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});73    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);74    await createItemExpectSuccess(bob, newCollectionID, createMode);75  });7677  it('Set property Admin', async () => {78    const createMode = 'NFT';79    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 80      propPerm:   [{key: 'k', permission: {mutable: true, collectionAdmin: true, tokenOwner: false}}]});81    82    await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'k', value: 't2'}]);83  });8485  it('Set property AdminConst', async () => {86    const createMode = 'NFT';87    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 88      propPerm:   [{key: 'key1', permission: {mutable: false, collectionAdmin: true, tokenOwner: false}}]});89    90    await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);91  });9293  it('Set property itemOwnerOrAdmin', async () => {94    const createMode = 'NFT';95    const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode},96      propPerm:   [{key: 'key1', permission: {mutable: true, collectionAdmin: true, tokenOwner: true}}]});97    98    await createItemWithPropsExpectSuccess(alice, newCollectionID, createMode, [{key: 'key1', value: 'val1'}]);99  });100101  it('Check total pieces of Fungible token', async () => {102    await usingApi(async api => {103      const createMode = 'Fungible';104      const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});105      const amountPieces = 10n;106      const tokenId = await createItemExpectSuccess(alice, collectionId, createMode, bob.address);107      {108        const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);109        expect(totalPieces.isSome).to.be.true;110        expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);111      }112113      await transferExpectSuccess(collectionId, tokenId, bob, alice, 1, createMode);114      {115        const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);116        expect(totalPieces.isSome).to.be.true;117        expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);118      }119120      const totalPieces = (await api.rpc.unique.tokenData(collectionId, tokenId, [])).pieces;121      expect(totalPieces.isSome).to.be.true;122      expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);123    });124  });125126  it('Check total pieces of NFT token', async () => {127    await usingApi(async api => {128      const createMode = 'NFT';129      const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});130      const amountPieces = 1n;131      const tokenId = await createItemExpectSuccess(alice, collectionId, createMode, bob.address);132      {133        const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);134        expect(totalPieces.isSome).to.be.true;135        expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);136      }137138      await transferExpectSuccess(collectionId, tokenId, bob, alice, 1, createMode);139      {140        const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);141        expect(totalPieces.isSome).to.be.true;142        expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);143      }144145      const totalPieces = (await api.rpc.unique.tokenData(collectionId, tokenId, [])).pieces;146      expect(totalPieces.isSome).to.be.true;147      expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);148    });149  });150151  it('Check total pieces of ReFungible token', async () => {152    await usingApi(async api => {153      const createMode = 'ReFungible';154      const createCollectionResult = await createCollection(api, alice, {mode: {type: createMode}});155      const collectionId  = createCollectionResult.collectionId;156      const amountPieces = 100n;157      const tokenId = await createItemExpectSuccess(alice, collectionId, createMode, bob.address);158      {159        const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);160        expect(totalPieces.isSome).to.be.true;161        expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);162      }163164      await transferExpectSuccess(collectionId, tokenId, bob, alice, 60n, createMode);165      {166        const totalPieces = await api.rpc.unique.totalPieces(collectionId, tokenId);167        expect(totalPieces.isSome).to.be.true;168        expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);169      }170171      const totalPieces = (await api.rpc.unique.tokenData(collectionId, tokenId, [])).pieces;172      expect(totalPieces.isSome).to.be.true;173      expect(totalPieces.unwrap().toBigInt()).to.be.eq(amountPieces);174    });175  });176});177178describe('Negative integration test: ext. createItem():', () => {179  before(async () => {180    await usingApi(async (api, privateKeyWrapper) => {181      alice = privateKeyWrapper('//Alice');182      bob = privateKeyWrapper('//Bob');183    });184  });185186  it('Regular user cannot create new item in NFT collection', async () => {187    const createMode = 'NFT';188    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});189    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;190  });191  it('Regular user cannot create new item in Fungible collection', async () => {192    const createMode = 'Fungible';193    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});194    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;195  });196  it('Regular user cannot create new item in ReFungible collection', async () => {197    const createMode = 'ReFungible';198    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});199    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;200  });201202  it('No editing rights', async () => {203    await usingApi(async () => {204      const createMode = 'NFT';205      const newCollectionID = await createCollectionWithPropsExpectSuccess({mode: {type: createMode}, 206        propPerm:   [{key: 'key1', permission: {mutable: false, collectionAdmin: false, tokenOwner: false}}]});207      await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);208209      await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);210    });211  });212213  it('User doesnt have editing rights', async () => {214    await usingApi(async () => {215      const newCollectionID = await createCollectionWithPropsExpectSuccess({propPerm: [{key: 'key1', permission: {mutable: true, collectionAdmin: false, tokenOwner: false}}]});216      await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'key1', value: 'v'}]);217    });218  });219220  it('Adding property without access rights', async () => {221    await usingApi(async () => {222      const newCollectionID = await createCollectionWithPropsExpectSuccess();223      await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);224225      await createItemWithPropsExpectFailure(bob, newCollectionID, 'NFT', [{key: 'k', value: 'v'}]);226    });227  });228229  it('Adding more than 64 prps', async () => {230    await usingApi(async () => {231      const prps = [];232233      for (let i = 0; i < 65; i++) {234        prps.push({key: `key${i}`, value: `value${i}`});235      }236237      const newCollectionID = await createCollectionWithPropsExpectSuccess();238      239      await createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', prps);240    });241  });242243  it('Trying to add bigger property than allowed', async () => {244    await usingApi(async () => {245      const newCollectionID = await createCollectionWithPropsExpectSuccess();246      247      await createItemWithPropsExpectFailure(alice, newCollectionID, 'NFT', [{key: 'k', value: 'vvvvvv'.repeat(5000)}, {key: 'k2', value: 'vvv'.repeat(5000)}]);248    });249  });250251  it('Check total pieces for invalid Fungible token', async () => {252    await usingApi(async api => {253      const createCollectionResult = await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}});254      const collectionId  = createCollectionResult.collectionId;255      const invalidTokenId = 1000_000;256      257      expect((await api.rpc.unique.totalPieces(collectionId, invalidTokenId)).isNone).to.be.true;258      expect((await api.rpc.unique.tokenData(collectionId, invalidTokenId, [])).pieces.isNone).to.be.true;259    });260  });261262  it('Check total pieces for invalid NFT token', async () => {263    await usingApi(async api => {264      const createCollectionResult = await createCollection(api, alice, {mode: {type: 'NFT'}});265      const collectionId  = createCollectionResult.collectionId;266      const invalidTokenId = 1000_000;267      268      expect((await api.rpc.unique.totalPieces(collectionId, invalidTokenId)).isNone).to.be.true;269      expect((await api.rpc.unique.tokenData(collectionId, invalidTokenId, [])).pieces.isNone).to.be.true;270    });271  });272273  it('Check total pieces for invalid Refungible token', async () => {274    await usingApi(async api => {275      const createCollectionResult = await createCollection(api, alice, {mode: {type: 'ReFungible'}});276      const collectionId  = createCollectionResult.collectionId;277      const invalidTokenId = 1000_000;278      279      expect((await api.rpc.unique.totalPieces(collectionId, invalidTokenId)).isNone).to.be.true;280      expect((await api.rpc.unique.tokenData(collectionId, invalidTokenId, [])).pieces.isNone).to.be.true;281    });282  });283});
modifiedtests/src/interfaces/unique/definitions.tsdiffbeforeafterboth
--- a/tests/src/interfaces/unique/definitions.ts
+++ b/tests/src/interfaces/unique/definitions.ts
@@ -79,5 +79,6 @@
     allowed: fun('Check if user is allowed to use collection', [collectionParam, crossAccountParam()], 'bool'),
     nextSponsored: fun('Get number of blocks when sponsored transaction is available', [collectionParam, crossAccountParam(), tokenParam], 'Option<u64>'),
     effectiveCollectionLimits: fun('Get effective collection limits', [collectionParam], 'Option<UpDataStructsCollectionLimits>'),
+    totalPieces: fun('Get total pieces of token', [collectionParam, tokenParam], 'Option<u128>'),
   },
 };