difftreelog
feat(rpc) token children
in: master
9 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -21,7 +21,7 @@
use jsonrpc_derive::rpc;
use up_data_structs::{
RpcCollection, CollectionId, CollectionStats, CollectionLimits, TokenId, Property,
- PropertyKeyPermission, TokenData,
+ PropertyKeyPermission, TokenData, TokenChild,
};
use sp_api::{BlockId, BlockT, ProvideRuntimeApi, ApiExt};
use sp_blockchain::HeaderBackend;
@@ -72,6 +72,13 @@
token: TokenId,
at: Option<BlockHash>,
) -> Result<Option<CrossAccountId>>;
+ #[rpc(name = "unique_tokenChildren")]
+ fn token_children(
+ &self,
+ collection: CollectionId,
+ token: TokenId,
+ at: Option<BlockHash>,
+ ) -> Result<Vec<TokenChild>>;
#[rpc(name = "unique_collectionProperties")]
fn collection_properties(
@@ -411,6 +418,7 @@
pass_method!(
topmost_token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>, unique_api
);
+ pass_method!(token_children(collection: CollectionId, token: TokenId) -> Vec<TokenChild>, unique_api);
pass_method!(total_supply(collection: CollectionId) -> u32, unique_api);
pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32, unique_api);
pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string(), unique_api);
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -40,6 +40,7 @@
MAX_TOKEN_PREFIX_LENGTH,
COLLECTION_ADMINS_LIMIT,
TokenId,
+ TokenChild,
CollectionStats,
MAX_TOKEN_OWNERSHIP,
CollectionMode,
@@ -502,6 +503,7 @@
CollectionStats,
CollectionId,
TokenId,
+ TokenChild,
PhantomType<(
TokenData<T::CrossAccountId>,
RpcCollection<T::AccountId>,
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -22,7 +22,7 @@
use up_data_structs::{
AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,
- PropertyKey, PropertyKeyPermission, Properties, PropertyScope, TrySetProperty,
+ PropertyKey, PropertyKeyPermission, Properties, PropertyScope, TrySetProperty, TokenChild,
};
use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
use pallet_common::{
@@ -988,6 +988,15 @@
.is_some()
}
+ pub fn token_children_ids(collection_id: CollectionId, token_id: TokenId) -> Vec<TokenChild> {
+ <TokenChildren<T>>::iter_prefix((collection_id, token_id))
+ .map(|((child_collection_id, child_id), _)| TokenChild {
+ collection: child_collection_id,
+ token: child_id,
+ })
+ .collect()
+ }
+
/// Delegated to `create_multiple_items`
pub fn create_item(
collection: &NonfungibleHandle<T>,
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -585,6 +585,14 @@
#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
+// todo possibly rename to be used generally as an address pair
+pub struct TokenChild {
+ pub token: TokenId,
+ pub collection: CollectionId,
+}
+
+#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]
+#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct CollectionStats {
pub created: u32,
pub destroyed: u32,
primitives/rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -18,7 +18,7 @@
use up_data_structs::{
CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits, Property,
- PropertyKeyPermission, TokenData,
+ PropertyKeyPermission, TokenData, TokenChild,
};
use sp_std::vec::Vec;
use codec::Decode;
@@ -41,6 +41,7 @@
fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;
fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;
+ fn token_children(collection: CollectionId, token: TokenId) -> Result<Vec<TokenChild>>;
fn collection_properties(collection: CollectionId, properties: Option<Vec<Vec<u8>>>) -> Result<Vec<Property>>;
runtime/common/src/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -29,7 +29,9 @@
Ok(Some(<pallet_structure::Pallet<Runtime>>::find_topmost_owner(collection, token, &budget)?))
}
-
+ fn token_children(collection: CollectionId, token: TokenId) -> Result<Vec<TokenChild>, DispatchError> {
+ Ok(<pallet_nonfungible::Pallet<Runtime>>::token_children_ids(collection, token))
+ }
fn collection_properties(
collection: CollectionId,
keys: Option<Vec<Vec<u8>>>
tests/src/interfaces/unique/definitions.tsdiffbeforeafterboth--- a/tests/src/interfaces/unique/definitions.ts
+++ b/tests/src/interfaces/unique/definitions.ts
@@ -50,6 +50,7 @@
allowance: fun('Get allowed amount', [collectionParam, crossAccountParam('sender'), crossAccountParam('spender'), tokenParam], 'u128'),
tokenOwner: fun('Get token owner', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),
topmostTokenOwner: fun('Get token owner, in case of nested token - find parent recursive', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),
+ tokenChildren: fun('Get tokens nested directly into the token', [collectionParam, tokenParam], 'Vec<UpDataStructsTokenChild>'),
constMetadata: fun('Get token constant metadata', [collectionParam, tokenParam], 'Vec<u8>'),
variableMetadata: fun('Get token variable metadata', [collectionParam, tokenParam], 'Vec<u8>'),
collectionProperties: fun(
tests/src/nesting/nest.test.tsdiffbeforeafterboth1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import privateKey from '../substrate/privateKey';4import usingApi, {executeTransaction} from '../substrate/substrate-api';5import {6 addToAllowListExpectSuccess,7 createCollectionExpectSuccess,8 createItemExpectSuccess,9 enableAllowListExpectSuccess,10 enablePublicMintingExpectSuccess,11 getTokenOwner,12 getTopmostTokenOwner,13 normalizeAccountId,14 setCollectionPermissionsExpectSuccess,15 transferExpectFailure,16 transferExpectSuccess,17 transferFromExpectSuccess,18} from '../util/helpers';19import {IKeyringPair} from '@polkadot/types/types';2021let alice: IKeyringPair;22let bob: IKeyringPair;2324describe('Integration Test: Nesting', () => {25 before(async () => {26 await usingApi(async () => {27 alice = privateKey('//Alice');28 bob = privateKey('//Bob');29 });30 });3132 it('Performs the full suite: bundles a token, transfers, and unnests', async () => {33 await usingApi(async api => {34 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});35 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});36 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');3738 // Create a nested token39 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});40 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});41 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});4243 // Create a token to be nested44 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');4546 // Nest47 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});48 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});49 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});5051 // Move bundle to different user52 await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});53 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});54 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});5556 // Unnest57 await transferFromExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});58 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});59 });60 });6162 it('Transfers an already bundled token', async () => {63 await usingApi(async api => {64 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});65 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});6667 const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');68 const tokenB = await createItemExpectSuccess(alice, collection, 'NFT');6970 // Create a nested token71 const tokenC = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)});72 expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});73 expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenA).toLowerCase()});7475 // Transfer the nested token to another token76 await expect(executeTransaction(77 api,78 alice,79 api.tx.unique.transferFrom(80 normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenA)}), 81 normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenB)}), 82 collection,83 tokenC,84 1,85 ),86 )).to.not.be.rejected;87 expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});88 expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenB).toLowerCase()});89 });90 });9192 // ---------- Non-Fungible ----------9394 it('NFT: allows an Owner to nest/unnest their token', async () => {95 await usingApi(async api => {96 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});97 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});98 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');99100 // Create a nested token101 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});102 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});103 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});104105 // Create a token to be nested and nest106 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');107 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});108 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});109 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});110 });111 });112113 it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {114 await usingApi(async api => {115 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});116 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});117 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');118119 // Create a nested token120 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});121 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});122 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});123124 // Create a token to be nested and nest125 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');126 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});127 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});128 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});129 });130 });131132 // ---------- Fungible ----------133134 it('Fungible: allows an Owner to nest/unnest their token', async () => {135 await usingApi(async api => {136 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});137 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});138 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});139 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};140141 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});142143 // Create a nested token144 await expect(executeTransaction(api, alice, api.tx.unique.createItem(145 collectionFT,146 targetAddress,147 {Fungible: {Value: 10}},148 ))).to.not.be.rejected;149150 // Nest a new token151 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');152 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');153 });154 });155156 it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {157 await usingApi(async api => {158 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});159 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});160 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};161162 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});163164 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}});165166 // Create a nested token167 await expect(executeTransaction(api, alice, api.tx.unique.createItem(168 collectionFT,169 targetAddress,170 {Fungible: {Value: 10}},171 ))).to.not.be.rejected;172173 // Nest a new token174 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');175 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');176 });177 });178179 // ---------- Re-Fungible ----------180181 it('ReFungible: allows an Owner to nest/unnest their token', async () => {182 await usingApi(async api => {183 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});184 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});185 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});186 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};187188 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});189190 // Create a nested token191 await expect(executeTransaction(api, alice, api.tx.unique.createItem(192 collectionRFT,193 targetAddress,194 {ReFungible: {const_data: [], pieces: 100}},195 ))).to.not.be.rejected;196197 // Nest a new token198 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');199 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');200 });201 });202203 it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {204 await usingApi(async api => {205 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});206 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});207 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};208209 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});210211 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});212213 // Create a nested token214 await expect(executeTransaction(api, alice, api.tx.unique.createItem(215 collectionRFT,216 targetAddress,217 {ReFungible: {const_data: [], pieces: 100}},218 ))).to.not.be.rejected;219220 // Nest a new token221 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');222 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');223 });224 });225});226227describe('Negative Test: Nesting', async() => {228 before(async () => {229 await usingApi(async () => {230 alice = privateKey('//Alice');231 bob = privateKey('//Bob');232 });233 });234235 it('Disallows excessive token nesting', async () => {236 await usingApi(async api => {237 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});238 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});239 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');240241 const maxNestingLevel = 5;242 let prevToken = targetToken;243244 // Create a nested-token matryoshka245 for (let i = 0; i < maxNestingLevel; i++) {246 const nestedToken = await createItemExpectSuccess(247 alice,248 collection,249 'NFT',250 {Ethereum: tokenIdToAddress(collection, prevToken)},251 );252253 prevToken = nestedToken;254 }255256 // The nesting depth is limited by `maxNestingLevel`257 await expect(executeTransaction(api, alice, api.tx.unique.createItem(258 collection,259 {Ethereum: tokenIdToAddress(collection, prevToken)},260 {nft: {const_data: [], variable_data: []}} as any,261 )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);262263 expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});264 });265 });266267 // ---------- Non-Fungible ----------268269 it('NFT: disallows to nest token if nesting is disabled', async () => {270 await usingApi(async api => {271 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});272 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Disabled'});273 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');274275 // Try to create a nested token276 await expect(executeTransaction(api, alice, api.tx.unique.createItem(277 collection,278 {Ethereum: tokenIdToAddress(collection, targetToken)},279 {nft: {const_data: [], variable_data: []}} as any,280 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);281282 // Create a token to be nested283 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');284 // Try to nest285 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);286 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});287 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});288 });289 });290291 it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {292 await usingApi(async api => {293 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});294 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});295296 await addToAllowListExpectSuccess(alice, collection, bob.address);297 await enableAllowListExpectSuccess(alice, collection);298 await enablePublicMintingExpectSuccess(alice, collection);299300 // Create a token to attempt to be nested into301 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');302303 // Try to create a nested token in the wrong collection304 await expect(executeTransaction(api, alice, api.tx.unique.createItem(305 collection,306 {Ethereum: tokenIdToAddress(collection, targetToken)},307 {nft: {const_data: [], variable_data: []}} as any,308 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);309310 // Try to create and nest a token in the wrong collection311 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');312 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);313 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});314 });315 });316317 it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {318 await usingApi(async api => {319 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});320 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});321322 await addToAllowListExpectSuccess(alice, collection, bob.address);323 await enableAllowListExpectSuccess(alice, collection);324 await enablePublicMintingExpectSuccess(alice, collection);325326 // Create a token to attempt to be nested into327 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');328329 // Try to create a nested token in the wrong collection330 await expect(executeTransaction(api, alice, api.tx.unique.createItem(331 collection,332 {Ethereum: tokenIdToAddress(collection, targetToken)},333 {nft: {const_data: [], variable_data: []}} as any,334 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);335336 // Try to create and nest a token in the wrong collection337 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');338 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);339 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});340 });341 });342343 it('NFT: disallows to nest token in an unlisted collection', async () => {344 await usingApi(async api => {345 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});346 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});347348 // Create a token to attempt to be nested into349 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');350351 // Try to create a nested token in the wrong collection352 await expect(executeTransaction(api, alice, api.tx.unique.createItem(353 collection,354 {Ethereum: tokenIdToAddress(collection, targetToken)},355 {nft: {const_data: [], variable_data: []}} as any,356 )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);357358 // Try to create and nest a token in the wrong collection359 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');360 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);361 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});362 });363 });364365 // ---------- Fungible ----------366367 it('Fungible: disallows to nest token if nesting is disabled', async () => {368 await usingApi(async api => {369 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});370 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});371 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');372 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};373374 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});375376 // Try to create a nested token377 await expect(executeTransaction(api, alice, api.tx.unique.createItem(378 collectionFT,379 targetAddress,380 {Fungible: {Value: 10}},381 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);382383 // Create a token to be nested384 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');385 // Try to nest386 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);387388 // Create another token to be nested389 const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');390 // Try to nest inside a fungible token391 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionFT, newToken)}, collectionFT, newToken2, 1)), 'while nesting new token inside fungible').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);392 });393 });394395 it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {396 await usingApi(async api => {397 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});398 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});399400 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);401 await enableAllowListExpectSuccess(alice, collectionNFT);402 await enablePublicMintingExpectSuccess(alice, collectionNFT);403404 // Create a token to attempt to be nested into405 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');406 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};407408 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});409410 // Try to create a nested token in the wrong collection411 await expect(executeTransaction(api, alice, api.tx.unique.createItem(412 collectionFT,413 targetAddress,414 {Fungible: {Value: 10}},415 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);416417 // Try to create and nest a token in the wrong collection418 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');419 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);420 });421 });422423 it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {424 await usingApi(async api => {425 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});426 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);427 await enableAllowListExpectSuccess(alice, collectionNFT);428 await enablePublicMintingExpectSuccess(alice, collectionNFT);429430 // Create a token to attempt to be nested into431 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');432 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};433434 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});435 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});436437 // Try to create a nested token in the wrong collection438 await expect(executeTransaction(api, alice, api.tx.unique.createItem(439 collectionFT,440 targetAddress,441 {Fungible: {Value: 10}},442 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);443444 // Try to create and nest a token in the wrong collection445 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');446 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);447 });448 });449450 it('Fungible: disallows to nest token in an unlisted collection', async () => {451 await usingApi(async api => {452 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});453 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});454455 // Create a token to attempt to be nested into456 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');457 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};458459 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});460461 // Try to create a nested token in the wrong collection462 await expect(executeTransaction(api, alice, api.tx.unique.createItem(463 collectionFT,464 targetAddress,465 {Fungible: {Value: 10}},466 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);467468 // Try to create and nest a token in the wrong collection469 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');470 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);471 });472 });473474 // ---------- Re-Fungible ----------475476 it('ReFungible: disallows to nest token if nesting is disabled', async () => {477 await usingApi(async api => {478 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});479 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});480 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');481 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};482483 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});484485 // Create a nested token486 await expect(executeTransaction(api, alice, api.tx.unique.createItem(487 collectionRFT,488 targetAddress,489 {ReFungible: {const_data: [], pieces: 100}},490 )), 'while creating a nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);491492 // Create a token to be nested493 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');494 // Try to nest495 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);496 // Try to nest497 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);498499 // Create another token to be nested500 const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');501 // Try to nest inside a fungible token502 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionRFT, newToken)}, collectionRFT, newToken2, 1)), 'while nesting new token inside refungible').to.be.rejectedWith(/refungible\.RefungibleDisallowsNesting/);503 });504 });505506 it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {507 await usingApi(async api => {508 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});509 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});510511 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);512 await enableAllowListExpectSuccess(alice, collectionNFT);513 await enablePublicMintingExpectSuccess(alice, collectionNFT);514515 // Create a token to attempt to be nested into516 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');517 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};518519 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});520521 // Try to create a nested token in the wrong collection522 await expect(executeTransaction(api, alice, api.tx.unique.createItem(523 collectionRFT,524 targetAddress,525 {ReFungible: {const_data: [], pieces: 100}},526 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);527528 // Try to create and nest a token in the wrong collection529 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');530 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);531 });532 });533534 it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {535 await usingApi(async api => {536 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});537 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);538 await enableAllowListExpectSuccess(alice, collectionNFT);539 await enablePublicMintingExpectSuccess(alice, collectionNFT);540541 // Create a token to attempt to be nested into542 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');543 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};544545 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});546 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});547548 // Try to create a nested token in the wrong collection549 await expect(executeTransaction(api, alice, api.tx.unique.createItem(550 collectionRFT,551 targetAddress,552 {ReFungible: {const_data: [], pieces: 100}},553 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);554555 // Try to create and nest a token in the wrong collection556 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');557 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);558 });559 });560561 it('ReFungible: disallows to nest token to an unlisted collection', async () => {562 await usingApi(async api => {563 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});564 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});565566 // Create a token to attempt to be nested into567 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');568 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};569570 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});571572 // Try to create a nested token in the wrong collection573 await expect(executeTransaction(api, alice, api.tx.unique.createItem(574 collectionRFT,575 targetAddress,576 {ReFungible: {const_data: [], pieces: 100}},577 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);578579 // Try to create and nest a token in the wrong collection580 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');581 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);582 });583 });584});1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import privateKey from '../substrate/privateKey';4import usingApi, {executeTransaction} from '../substrate/substrate-api';5import {6 addToAllowListExpectSuccess,7 createCollectionExpectSuccess,8 createItemExpectSuccess,9 enableAllowListExpectSuccess,10 enablePublicMintingExpectSuccess,11 getTokenChildren,12 getTokenOwner,13 getTopmostTokenOwner,14 normalizeAccountId,15 setCollectionPermissionsExpectSuccess,16 transferExpectFailure,17 transferExpectSuccess,18 transferFromExpectSuccess,19} from '../util/helpers';20import {IKeyringPair} from '@polkadot/types/types';2122let alice: IKeyringPair;23let bob: IKeyringPair;2425describe('Integration Test: Nesting', () => {26 before(async () => {27 await usingApi(async () => {28 alice = privateKey('//Alice');29 bob = privateKey('//Bob');30 });31 });3233 it('Performs the full suite: bundles a token, transfers, and unnests', async () => {34 await usingApi(async api => {35 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});36 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});37 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');3839 // Create a nested token40 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});41 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});42 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});4344 // Create a token to be nested45 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');4647 // Nest48 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});49 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});50 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});5152 // Move bundle to different user53 await transferExpectSuccess(collection, targetToken, alice, {Substrate: bob.address});54 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: bob.address});55 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});5657 // Unnest58 await transferFromExpectSuccess(collection, newToken, bob, {Ethereum: tokenIdToAddress(collection, targetToken)}, {Substrate: bob.address});59 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: bob.address});60 });61 });6263 it('Transfers an already bundled token', async () => {64 await usingApi(async api => {65 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});66 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});6768 const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');69 const tokenB = await createItemExpectSuccess(alice, collection, 'NFT');7071 // Create a nested token72 const tokenC = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)});73 expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});74 expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenA).toLowerCase()});7576 // Transfer the nested token to another token77 await expect(executeTransaction(78 api,79 alice,80 api.tx.unique.transferFrom(81 normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenA)}), 82 normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenB)}), 83 collection,84 tokenC,85 1,86 ),87 )).to.not.be.rejected;88 expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});89 expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenB).toLowerCase()});90 });91 });9293 it('Checks token children', async () => {94 await usingApi(async api => {95 const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});96 await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: 'Owner'});97 const collectionB = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});9899 const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');100 const targetAddress = {Ethereum: tokenIdToAddress(collectionA, targetToken)};101 let children = await getTokenChildren(api, collectionA, targetToken);102 expect(children.length).to.be.equal(0, 'Children length check at creation');103104 // Create a nested NFT token105 const tokenA = await createItemExpectSuccess(alice, collectionA, 'NFT', targetAddress);106 children = await getTokenChildren(api, collectionA, targetToken);107 expect(children.length).to.be.equal(1, 'Children length check at nesting #1');108 expect(children).to.have.deep.members([109 {token: tokenA, collection: collectionA},110 ], 'Children contents check at nesting #1');111112 // Create then nest113 const tokenB = await createItemExpectSuccess(alice, collectionA, 'NFT');114 await transferExpectSuccess(collectionA, tokenB, alice, targetAddress);115 children = await getTokenChildren(api, collectionA, targetToken);116 expect(children.length).to.be.equal(2, 'Children length check at nesting #2');117 expect(children).to.have.deep.members([118 {token: tokenA, collection: collectionA},119 {token: tokenB, collection: collectionA},120 ], 'Children contents check at nesting #2');121122 // Move token B to a different user outside the nesting tree123 await transferFromExpectSuccess(collectionA, tokenB, alice, targetAddress, bob);124 children = await getTokenChildren(api, collectionA, targetToken);125 expect(children.length).to.be.equal(1, 'Children length check at unnesting');126 expect(children).to.be.have.deep.members([127 {token: tokenA, collection: collectionA},128 ], 'Children contents check at unnesting');129 130 // Create a fungible token in another collection and then nest131 const tokenC = await createItemExpectSuccess(alice, collectionB, 'Fungible');132 await transferExpectSuccess(collectionB, tokenC, alice, targetAddress, 1, 'Fungible');133 children = await getTokenChildren(api, collectionA, targetToken);134 expect(children.length).to.be.equal(2, 'Children length check at nesting #3 (from another collection)');135 expect(children).to.be.have.deep.members([136 {token: tokenA, collection: collectionA},137 {token: tokenC, collection: collectionB},138 ], 'Children contents check at nesting #3 (from another collection)');139140 // Move the fungible token inside token A deeper in the nesting tree141 await transferFromExpectSuccess(collectionB, tokenC, alice, targetAddress, {Ethereum: tokenIdToAddress(collectionA, tokenA)}, 1, 'Fungible');142 children = await getTokenChildren(api, collectionA, targetToken);143 expect(children.length).to.be.equal(1, 'Children length check at deeper nesting');144 expect(children).to.be.have.deep.members([145 {token: tokenA, collection: collectionA},146 ], 'Children contents check at deeper nesting');147 });148 });149150 // ---------- Non-Fungible ----------151152 it('NFT: allows an Owner to nest/unnest their token', async () => {153 await usingApi(async api => {154 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});155 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});156 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');157158 // Create a nested token159 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});160 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});161 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});162163 // Create a token to be nested and nest164 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');165 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});166 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});167 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});168 });169 });170171 it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {172 await usingApi(async api => {173 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});174 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});175 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');176177 // Create a nested token178 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});179 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});180 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});181182 // Create a token to be nested and nest183 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');184 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});185 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});186 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});187 });188 });189190 // ---------- Fungible ----------191192 it('Fungible: allows an Owner to nest/unnest their token', async () => {193 await usingApi(async api => {194 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});195 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});196 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});197 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};198199 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});200201 // Create a nested token202 await expect(executeTransaction(api, alice, api.tx.unique.createItem(203 collectionFT,204 targetAddress,205 {Fungible: {Value: 10}},206 ))).to.not.be.rejected;207208 // Nest a new token209 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');210 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');211 });212 });213214 it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {215 await usingApi(async api => {216 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});217 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});218 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};219220 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});221222 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}});223224 // Create a nested token225 await expect(executeTransaction(api, alice, api.tx.unique.createItem(226 collectionFT,227 targetAddress,228 {Fungible: {Value: 10}},229 ))).to.not.be.rejected;230231 // Nest a new token232 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');233 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');234 });235 });236237 // ---------- Re-Fungible ----------238239 it('ReFungible: allows an Owner to nest/unnest their token', async () => {240 await usingApi(async api => {241 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});242 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});243 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});244 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};245246 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});247248 // Create a nested token249 await expect(executeTransaction(api, alice, api.tx.unique.createItem(250 collectionRFT,251 targetAddress,252 {ReFungible: {const_data: [], pieces: 100}},253 ))).to.not.be.rejected;254255 // Nest a new token256 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');257 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');258 });259 });260261 it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {262 await usingApi(async api => {263 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});264 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});265 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};266267 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});268269 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});270271 // Create a nested token272 await expect(executeTransaction(api, alice, api.tx.unique.createItem(273 collectionRFT,274 targetAddress,275 {ReFungible: {const_data: [], pieces: 100}},276 ))).to.not.be.rejected;277278 // Nest a new token279 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');280 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');281 });282 });283});284285describe('Negative Test: Nesting', async() => {286 before(async () => {287 await usingApi(async () => {288 alice = privateKey('//Alice');289 bob = privateKey('//Bob');290 });291 });292293 // TODO delete if this is actually wrong294 // TODO remake all other nesting tests if this is right295 it('Affirms that transfer is disallowed to transfer nested tokens', async () => {296 await usingApi(async () => {297 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});298 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});299300 const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');301 const tokenB = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)});302 303 await transferExpectFailure(collection, tokenB, alice, bob);304 });305 });306307 it('Disallows excessive token nesting', async () => {308 await usingApi(async api => {309 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});310 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});311 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');312313 const maxNestingLevel = 5;314 let prevToken = targetToken;315316 // Create a nested-token matryoshka317 for (let i = 0; i < maxNestingLevel; i++) {318 const nestedToken = await createItemExpectSuccess(319 alice,320 collection,321 'NFT',322 {Ethereum: tokenIdToAddress(collection, prevToken)},323 );324325 prevToken = nestedToken;326 }327328 // The nesting depth is limited by `maxNestingLevel`329 await expect(executeTransaction(api, alice, api.tx.unique.createItem(330 collection,331 {Ethereum: tokenIdToAddress(collection, prevToken)},332 {nft: {const_data: [], variable_data: []}} as any,333 )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);334335 expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});336 });337 });338339 // ---------- Non-Fungible ----------340341 it('NFT: disallows to nest token if nesting is disabled', async () => {342 await usingApi(async api => {343 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});344 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Disabled'});345 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');346347 // Try to create a nested token348 await expect(executeTransaction(api, alice, api.tx.unique.createItem(349 collection,350 {Ethereum: tokenIdToAddress(collection, targetToken)},351 {nft: {const_data: [], variable_data: []}} as any,352 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);353354 // Create a token to be nested355 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');356 // Try to nest357 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);358 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});359 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});360 });361 });362363 it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {364 await usingApi(async api => {365 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});366 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});367368 await addToAllowListExpectSuccess(alice, collection, bob.address);369 await enableAllowListExpectSuccess(alice, collection);370 await enablePublicMintingExpectSuccess(alice, collection);371372 // Create a token to attempt to be nested into373 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');374375 // Try to create a nested token in the wrong collection376 await expect(executeTransaction(api, alice, api.tx.unique.createItem(377 collection,378 {Ethereum: tokenIdToAddress(collection, targetToken)},379 {nft: {const_data: [], variable_data: []}} as any,380 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);381382 // Try to create and nest a token in the wrong collection383 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');384 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);385 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});386 });387 });388389 it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {390 await usingApi(async api => {391 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});392 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});393394 await addToAllowListExpectSuccess(alice, collection, bob.address);395 await enableAllowListExpectSuccess(alice, collection);396 await enablePublicMintingExpectSuccess(alice, collection);397398 // Create a token to attempt to be nested into399 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');400401 // Try to create a nested token in the wrong collection402 await expect(executeTransaction(api, alice, api.tx.unique.createItem(403 collection,404 {Ethereum: tokenIdToAddress(collection, targetToken)},405 {nft: {const_data: [], variable_data: []}} as any,406 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);407408 // Try to create and nest a token in the wrong collection409 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');410 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.AddressNotInAllowlist/);411 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});412 });413 });414415 it('NFT: disallows to nest token in an unlisted collection', async () => {416 await usingApi(async api => {417 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});418 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});419420 // Create a token to attempt to be nested into421 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');422423 // Try to create a nested token in the wrong collection424 await expect(executeTransaction(api, alice, api.tx.unique.createItem(425 collection,426 {Ethereum: tokenIdToAddress(collection, targetToken)},427 {nft: {const_data: [], variable_data: []}} as any,428 )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);429430 // Try to create and nest a token in the wrong collection431 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');432 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);433 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});434 });435 });436437 // ---------- Fungible ----------438439 it('Fungible: disallows to nest token if nesting is disabled', async () => {440 await usingApi(async api => {441 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});442 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});443 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');444 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};445446 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});447448 // Try to create a nested token449 await expect(executeTransaction(api, alice, api.tx.unique.createItem(450 collectionFT,451 targetAddress,452 {Fungible: {Value: 10}},453 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);454455 // Create a token to be nested456 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');457 // Try to nest458 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);459460 // Create another token to be nested461 const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');462 // Try to nest inside a fungible token463 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionFT, newToken)}, collectionFT, newToken2, 1)), 'while nesting new token inside fungible').to.be.rejectedWith(/fungible\.FungibleDisallowsNesting/);464 });465 });466467 it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {468 await usingApi(async api => {469 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});470 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});471472 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);473 await enableAllowListExpectSuccess(alice, collectionNFT);474 await enablePublicMintingExpectSuccess(alice, collectionNFT);475476 // Create a token to attempt to be nested into477 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');478 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};479480 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});481482 // Try to create a nested token in the wrong collection483 await expect(executeTransaction(api, alice, api.tx.unique.createItem(484 collectionFT,485 targetAddress,486 {Fungible: {Value: 10}},487 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);488489 // Try to create and nest a token in the wrong collection490 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');491 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);492 });493 });494495 it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {496 await usingApi(async api => {497 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});498 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);499 await enableAllowListExpectSuccess(alice, collectionNFT);500 await enablePublicMintingExpectSuccess(alice, collectionNFT);501502 // Create a token to attempt to be nested into503 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');504 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};505506 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});507 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});508509 // Try to create a nested token in the wrong collection510 await expect(executeTransaction(api, alice, api.tx.unique.createItem(511 collectionFT,512 targetAddress,513 {Fungible: {Value: 10}},514 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);515516 // Try to create and nest a token in the wrong collection517 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');518 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);519 });520 });521522 it('Fungible: disallows to nest token in an unlisted collection', async () => {523 await usingApi(async api => {524 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});525 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});526527 // Create a token to attempt to be nested into528 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');529 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};530531 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});532533 // Try to create a nested token in the wrong collection534 await expect(executeTransaction(api, alice, api.tx.unique.createItem(535 collectionFT,536 targetAddress,537 {Fungible: {Value: 10}},538 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);539540 // Try to create and nest a token in the wrong collection541 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');542 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);543 });544 });545546 // ---------- Re-Fungible ----------547548 it('ReFungible: disallows to nest token if nesting is disabled', async () => {549 await usingApi(async api => {550 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});551 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});552 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');553 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};554555 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});556557 // Create a nested token558 await expect(executeTransaction(api, alice, api.tx.unique.createItem(559 collectionRFT,560 targetAddress,561 {ReFungible: {const_data: [], pieces: 100}},562 )), 'while creating a nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);563564 // Create a token to be nested565 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');566 // Try to nest567 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);568 // Try to nest569 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);570571 // Create another token to be nested572 const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');573 // Try to nest inside a fungible token574 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collectionRFT, newToken)}, collectionRFT, newToken2, 1)), 'while nesting new token inside refungible').to.be.rejectedWith(/refungible\.RefungibleDisallowsNesting/);575 });576 });577578 it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {579 await usingApi(async api => {580 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});581 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});582583 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);584 await enableAllowListExpectSuccess(alice, collectionNFT);585 await enablePublicMintingExpectSuccess(alice, collectionNFT);586587 // Create a token to attempt to be nested into588 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');589 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};590591 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});592593 // Try to create a nested token in the wrong collection594 await expect(executeTransaction(api, alice, api.tx.unique.createItem(595 collectionRFT,596 targetAddress,597 {ReFungible: {const_data: [], pieces: 100}},598 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);599600 // Try to create and nest a token in the wrong collection601 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');602 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);603 });604 });605606 it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {607 await usingApi(async api => {608 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});609 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);610 await enableAllowListExpectSuccess(alice, collectionNFT);611 await enablePublicMintingExpectSuccess(alice, collectionNFT);612613 // Create a token to attempt to be nested into614 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');615 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};616617 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});618 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});619620 // Try to create a nested token in the wrong collection621 await expect(executeTransaction(api, alice, api.tx.unique.createItem(622 collectionRFT,623 targetAddress,624 {ReFungible: {const_data: [], pieces: 100}},625 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);626627 // Try to create and nest a token in the wrong collection628 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');629 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);630 });631 });632633 it('ReFungible: disallows to nest token to an unlisted collection', async () => {634 await usingApi(async api => {635 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});636 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});637638 // Create a token to attempt to be nested into639 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');640 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};641642 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});643644 // Try to create a nested token in the wrong collection645 await expect(executeTransaction(api, alice, api.tx.unique.createItem(646 collectionRFT,647 targetAddress,648 {ReFungible: {const_data: [], pieces: 100}},649 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);650651 // Try to create and nest a token in the wrong collection652 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');653 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);654 });655 });656});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -28,6 +28,7 @@
import {default as usingApi, executeTransaction, submitTransactionAsync, submitTransactionExpectFailAsync} from '../substrate/substrate-api';
import {hexToStr, strToUTF16, utf16ToStr} from './util';
import {UpDataStructsRpcCollection, UpDataStructsCreateItemData, UpDataStructsProperty} from '@polkadot/types/lookup';
+import {UpDataStructsTokenChild} from '../interfaces';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -1072,6 +1073,13 @@
if (owner == null) throw new Error('owner == null');
return normalizeAccountId(owner);
}
+export async function getTokenChildren(
+ api: ApiPromise,
+ collectionId: number,
+ tokenId: number,
+): Promise<UpDataStructsTokenChild[]> {
+ return (await api.rpc.unique.tokenChildren(collectionId, tokenId)).toJSON() as any;
+}
export async function isTokenExists(
api: ApiPromise,
collectionId: number,