1import {expect} from 'chai';2import {tokenIdToAddress} from '../eth/util/helpers';3import usingApi, {executeTransaction} from '../substrate/substrate-api';4import {5 addToAllowListExpectSuccess,6 createCollectionExpectSuccess,7 createItemExpectSuccess,8 enableAllowListExpectSuccess,9 enablePublicMintingExpectSuccess,10 getTokenChildren,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 (api, privateKeyWrapper) => {27 alice = privateKeyWrapper('//Alice');28 bob = privateKeyWrapper('//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: {tokenOwner: true}});36 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');3738 39 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 44 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');4546 47 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 52 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 57 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: {tokenOwner: true}});6667 const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');68 const tokenB = await createItemExpectSuccess(alice, collection, 'NFT');6970 71 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 76 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 it('Checks token children', async () => {93 await usingApi(async api => {94 const collectionA = await createCollectionExpectSuccess({mode: {type: 'NFT'}});95 await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {tokenOwner: true}});96 const collectionB = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});9798 const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');99 const targetAddress = {Ethereum: tokenIdToAddress(collectionA, targetToken)};100 let children = await getTokenChildren(api, collectionA, targetToken);101 expect(children.length).to.be.equal(0, 'Children length check at creation');102103 104 const tokenA = await createItemExpectSuccess(alice, collectionA, 'NFT', targetAddress);105 children = await getTokenChildren(api, collectionA, targetToken);106 expect(children.length).to.be.equal(1, 'Children length check at nesting #1');107 expect(children).to.have.deep.members([108 {token: tokenA, collection: collectionA},109 ], 'Children contents check at nesting #1');110111 112 const tokenB = await createItemExpectSuccess(alice, collectionA, 'NFT');113 await transferExpectSuccess(collectionA, tokenB, alice, targetAddress);114 children = await getTokenChildren(api, collectionA, targetToken);115 expect(children.length).to.be.equal(2, 'Children length check at nesting #2');116 expect(children).to.have.deep.members([117 {token: tokenA, collection: collectionA},118 {token: tokenB, collection: collectionA},119 ], 'Children contents check at nesting #2');120121 122 await transferExpectSuccess(collectionA, tokenB, alice, bob);123 children = await getTokenChildren(api, collectionA, targetToken);124 expect(children.length).to.be.equal(1, 'Children length check at unnesting');125 expect(children).to.be.have.deep.members([126 {token: tokenA, collection: collectionA},127 ], 'Children contents check at unnesting');128129 130 const tokenC = await createItemExpectSuccess(alice, collectionB, 'Fungible');131 await transferExpectSuccess(collectionB, tokenC, alice, targetAddress, 1, 'Fungible');132 children = await getTokenChildren(api, collectionA, targetToken);133 expect(children.length).to.be.equal(2, 'Children length check at nesting #3 (from another collection)');134 expect(children).to.be.have.deep.members([135 {token: tokenA, collection: collectionA},136 {token: tokenC, collection: collectionB},137 ], 'Children contents check at nesting #3 (from another collection)');138139 140 await transferFromExpectSuccess(collectionB, tokenC, alice, targetAddress, {Ethereum: tokenIdToAddress(collectionA, tokenA)}, 1, 'Fungible');141 children = await getTokenChildren(api, collectionA, targetToken);142 expect(children.length).to.be.equal(1, 'Children length check at deeper nesting');143 expect(children).to.be.have.deep.members([144 {token: tokenA, collection: collectionA},145 ], 'Children contents check at deeper nesting');146 });147 });148149 150151 it('NFT: allows an Owner to nest/unnest their token', async () => {152 await usingApi(async api => {153 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});154 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});155 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');156157 158 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});159 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});160 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});161162 163 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');164 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});165 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});166 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});167 });168 });169170 it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {171 await usingApi(async api => {172 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});173 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[collection]}});174 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');175176 177 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});178 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});179 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});180181 182 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');183 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});184 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});185 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});186 });187 });188189 190191 it('Fungible: allows an Owner to nest/unnest their token', async () => {192 await usingApi(async api => {193 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});194 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});195 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});196 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};197198 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});199200 201 await expect(executeTransaction(api, alice, api.tx.unique.createItem(202 collectionFT,203 targetAddress,204 {Fungible: {Value: 10}},205 ))).to.not.be.rejected;206207 208 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');209 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');210 });211 });212213 it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {214 await usingApi(async api => {215 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});216 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});217 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};218219 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});220221 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted: [collectionFT]}});222223 224 await expect(executeTransaction(api, alice, api.tx.unique.createItem(225 collectionFT,226 targetAddress,227 {Fungible: {Value: 10}},228 ))).to.not.be.rejected;229230 231 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');232 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');233 });234 });235236 237238 it('ReFungible: allows an Owner to nest/unnest their token', async () => {239 await usingApi(async api => {240 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});241 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});242 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});243 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};244245 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});246247 248 await expect(executeTransaction(api, alice, api.tx.unique.createItem(249 collectionRFT,250 targetAddress,251 {ReFungible: {const_data: [], pieces: 100}},252 ))).to.not.be.rejected;253254 255 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');256 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');257 });258 });259260 it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {261 await usingApi(async api => {262 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});263 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});264 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};265266 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});267268 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionRFT]}});269270 271 await expect(executeTransaction(api, alice, api.tx.unique.createItem(272 collectionRFT,273 targetAddress,274 {ReFungible: {const_data: [], pieces: 100}},275 ))).to.not.be.rejected;276277 278 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');279 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');280 });281 });282});283284describe('Negative Test: Nesting', async() => {285 before(async () => {286 await usingApi(async (api, privateKeyWrapper) => {287 alice = privateKeyWrapper('//Alice');288 bob = privateKeyWrapper('//Bob');289 });290 });291292 it('Disallows excessive token nesting', async () => {293 await usingApi(async api => {294 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});295 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});296 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');297298 const maxNestingLevel = 5;299 let prevToken = targetToken;300301 302 for (let i = 0; i < maxNestingLevel; i++) {303 const nestedToken = await createItemExpectSuccess(304 alice,305 collection,306 'NFT',307 {Ethereum: tokenIdToAddress(collection, prevToken)},308 );309310 prevToken = nestedToken;311 }312313 314 await expect(executeTransaction(api, alice, api.tx.unique.createItem(315 collection,316 {Ethereum: tokenIdToAddress(collection, prevToken)},317 {nft: {const_data: [], variable_data: []}} as any,318 )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);319320 expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});321 });322 });323324 325326 it('NFT: disallows to nest token if nesting is disabled', async () => {327 await usingApi(async api => {328 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});329 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {}});330 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');331332 333 await expect(executeTransaction(api, alice, api.tx.unique.createItem(334 collection,335 {Ethereum: tokenIdToAddress(collection, targetToken)},336 {nft: {const_data: [], variable_data: []}} as any,337 )), 'while creating nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);338339 340 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');341 342 await expect(executeTransaction(api, alice, api.tx.unique.transfer({Ethereum: tokenIdToAddress(collection, targetToken)}, collection, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);343 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});344 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});345 });346 });347348 it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {349 await usingApi(async api => {350 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});351 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});352353 await addToAllowListExpectSuccess(alice, collection, bob.address);354 await enableAllowListExpectSuccess(alice, collection);355 await enablePublicMintingExpectSuccess(alice, collection);356357 358 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');359360 361 await expect(executeTransaction(api, alice, api.tx.unique.createItem(362 collection,363 {Ethereum: tokenIdToAddress(collection, targetToken)},364 {nft: {const_data: [], variable_data: []}} as any,365 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);366367 368 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');369 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/);370 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});371 });372 });373374 it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {375 await usingApi(async api => {376 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});377 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[collection]}});378379 await addToAllowListExpectSuccess(alice, collection, bob.address);380 await enableAllowListExpectSuccess(alice, collection);381 await enablePublicMintingExpectSuccess(alice, collection);382383 384 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');385386 387 await expect(executeTransaction(api, alice, api.tx.unique.createItem(388 collection,389 {Ethereum: tokenIdToAddress(collection, targetToken)},390 {nft: {const_data: [], variable_data: []}} as any,391 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);392393 394 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');395 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/);396 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});397 });398 });399400 it('NFT: disallows to nest token in an unlisted collection', async () => {401 await usingApi(async api => {402 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});403 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[]}});404405 406 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');407408 409 await expect(executeTransaction(api, alice, api.tx.unique.createItem(410 collection,411 {Ethereum: tokenIdToAddress(collection, targetToken)},412 {nft: {const_data: [], variable_data: []}} as any,413 )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);414415 416 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');417 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/);418 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});419 });420 });421422 423424 it('Fungible: disallows to nest token if nesting is disabled', async () => {425 await usingApi(async api => {426 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});427 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {}});428 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');429 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};430431 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});432433 434 await expect(executeTransaction(api, alice, api.tx.unique.createItem(435 collectionFT,436 targetAddress,437 {Fungible: {Value: 10}},438 )), 'while creating nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);439440 441 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');442 443 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);444445 446 const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');447 448 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/);449 });450 });451452 it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {453 await usingApi(async api => {454 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});455 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});456457 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);458 await enableAllowListExpectSuccess(alice, collectionNFT);459 await enablePublicMintingExpectSuccess(alice, collectionNFT);460461 462 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');463 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};464465 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});466467 468 await expect(executeTransaction(api, alice, api.tx.unique.createItem(469 collectionFT,470 targetAddress,471 {Fungible: {Value: 10}},472 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);473474 475 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');476 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);477 });478 });479480 it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {481 await usingApi(async api => {482 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});483 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);484 await enableAllowListExpectSuccess(alice, collectionNFT);485 await enablePublicMintingExpectSuccess(alice, collectionNFT);486487 488 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');489 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};490491 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});492 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionFT]}});493494 495 await expect(executeTransaction(api, alice, api.tx.unique.createItem(496 collectionFT,497 targetAddress,498 {Fungible: {Value: 10}},499 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);500501 502 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');503 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);504 });505 });506507 it('Fungible: disallows to nest token in an unlisted collection', async () => {508 await usingApi(async api => {509 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});510 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[]}});511512 513 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');514 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};515516 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});517518 519 await expect(executeTransaction(api, alice, api.tx.unique.createItem(520 collectionFT,521 targetAddress,522 {Fungible: {Value: 10}},523 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);524525 526 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');527 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);528 });529 });530531 532533 it('ReFungible: disallows to nest token if nesting is disabled', async () => {534 await usingApi(async api => {535 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});536 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {}});537 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');538 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};539540 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});541542 543 await expect(executeTransaction(api, alice, api.tx.unique.createItem(544 collectionRFT,545 targetAddress,546 {ReFungible: {const_data: [], pieces: 100}},547 )), 'while creating a nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);548549 550 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');551 552 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);553 554 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);555556 557 const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');558 559 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/);560 });561 });562563 it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {564 await usingApi(async api => {565 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});566 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});567568 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);569 await enableAllowListExpectSuccess(alice, collectionNFT);570 await enablePublicMintingExpectSuccess(alice, collectionNFT);571572 573 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');574 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};575576 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});577578 579 await expect(executeTransaction(api, alice, api.tx.unique.createItem(580 collectionRFT,581 targetAddress,582 {ReFungible: {const_data: [], pieces: 100}},583 )), 'while creating a nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);584585 586 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');587 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);588 });589 });590591 it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {592 await usingApi(async api => {593 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});594 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);595 await enableAllowListExpectSuccess(alice, collectionNFT);596 await enablePublicMintingExpectSuccess(alice, collectionNFT);597598 599 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');600 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};601602 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});603 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionRFT]}});604605 606 await expect(executeTransaction(api, alice, api.tx.unique.createItem(607 collectionRFT,608 targetAddress,609 {ReFungible: {const_data: [], pieces: 100}},610 )), 'while creating a nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);611612 613 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');614 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);615 });616 });617618 it('ReFungible: disallows to nest token to an unlisted collection', async () => {619 await usingApi(async api => {620 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});621 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[]}});622623 624 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');625 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};626627 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});628629 630 await expect(executeTransaction(api, alice, api.tx.unique.createItem(631 collectionRFT,632 targetAddress,633 {ReFungible: {const_data: [], pieces: 100}},634 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);635636 637 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');638 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);639 });640 });641});