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 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 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: 'Owner'});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, tokenC, 1),83 )).to.not.be.rejected;84 expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});85 expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenB).toLowerCase()});86 });87 });8889 9091 it('NFT: allows an Owner to nest/unnest their token', async () => {92 await usingApi(async api => {93 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});94 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});95 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');9697 98 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});99 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});100 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});101102 103 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');104 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});105 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});106 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});107 });108 });109110 it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {111 await usingApi(async api => {112 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});113 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});114 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');115116 117 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});118 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});119 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});120121 122 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');123 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});124 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});125 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});126 });127 });128129 130131 it('Fungible: allows an Owner to nest/unnest their token', async () => {132 await usingApi(async api => {133 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});134 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});135 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});136 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};137138 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});139140 141 await expect(executeTransaction(api, alice, api.tx.unique.createItem(142 collectionFT,143 targetAddress,144 {Fungible: {Value: 10}},145 ))).to.not.be.rejected;146147 148 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');149 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');150 });151 });152153 it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {154 await usingApi(async api => {155 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});156 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});157 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};158159 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});160161 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted: [collectionFT]}});162163 164 await expect(executeTransaction(api, alice, api.tx.unique.createItem(165 collectionFT,166 targetAddress,167 {Fungible: {Value: 10}},168 ))).to.not.be.rejected;169170 171 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');172 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');173 });174 });175176 177178 it('ReFungible: allows an Owner to nest/unnest their token', async () => {179 await usingApi(async api => {180 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});181 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});182 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});183 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};184185 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});186187 188 await expect(executeTransaction(api, alice, api.tx.unique.createItem(189 collectionRFT,190 targetAddress,191 {ReFungible: {const_data: [], pieces: 100}},192 ))).to.not.be.rejected;193194 195 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');196 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');197 });198 });199200 it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {201 await usingApi(async api => {202 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});203 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});204 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};205206 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});207208 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});209210 211 await expect(executeTransaction(api, alice, api.tx.unique.createItem(212 collectionRFT,213 targetAddress,214 {ReFungible: {const_data: [], pieces: 100}},215 ))).to.not.be.rejected;216217 218 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');219 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');220 });221 });222});223224describe('Negative Test: Nesting', async() => {225 before(async () => {226 await usingApi(async () => {227 alice = privateKey('//Alice');228 bob = privateKey('//Bob');229 });230 });231232 it('Disallows excessive token nesting', async () => {233 await usingApi(async api => {234 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});235 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});236 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');237238 const maxNestingLevel = 5;239 let prevToken = targetToken;240241 242 for (let i = 0; i < maxNestingLevel; i++) {243 const nestedToken = await createItemExpectSuccess(244 alice,245 collection,246 'NFT',247 {Ethereum: tokenIdToAddress(collection, prevToken)},248 );249250 prevToken = nestedToken;251 }252253 254 await expect(executeTransaction(api, alice, api.tx.unique.createItem(255 collection,256 {Ethereum: tokenIdToAddress(collection, prevToken)},257 {nft: {const_data: [], variable_data: []}} as any,258 )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);259260 expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});261 });262 });263264 265266 it('NFT: disallows to nest token if nesting is disabled', async () => {267 await usingApi(async api => {268 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});269 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Disabled'});270 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');271272 273 await expect(executeTransaction(api, alice, api.tx.unique.createItem(274 collection,275 {Ethereum: tokenIdToAddress(collection, targetToken)},276 {nft: {const_data: [], variable_data: []}} as any,277 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);278279 280 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');281 282 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/);283 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});284 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});285 });286 });287288 it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {289 await usingApi(async api => {290 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});291 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});292293 await addToAllowListExpectSuccess(alice, collection, bob.address);294 await enableAllowListExpectSuccess(alice, collection);295 await enablePublicMintingExpectSuccess(alice, collection);296297 298 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');299300 301 await expect(executeTransaction(api, alice, api.tx.unique.createItem(302 collection,303 {Ethereum: tokenIdToAddress(collection, targetToken)},304 {nft: {const_data: [], variable_data: []}} as any,305 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);306307 308 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');309 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/);310 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});311 });312 });313314 it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {315 await usingApi(async api => {316 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});317 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[collection]}});318319 await addToAllowListExpectSuccess(alice, collection, bob.address);320 await enableAllowListExpectSuccess(alice, collection);321 await enablePublicMintingExpectSuccess(alice, collection);322323 324 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');325326 327 await expect(executeTransaction(api, alice, api.tx.unique.createItem(328 collection,329 {Ethereum: tokenIdToAddress(collection, targetToken)},330 {nft: {const_data: [], variable_data: []}} as any,331 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);332333 334 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');335 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/);336 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});337 });338 });339340 it('NFT: disallows to nest token in an unlisted collection', async () => {341 await usingApi(async api => {342 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});343 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {OwnerRestricted:[]}});344345 346 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');347348 349 await expect(executeTransaction(api, alice, api.tx.unique.createItem(350 collection,351 {Ethereum: tokenIdToAddress(collection, targetToken)},352 {nft: {const_data: [], variable_data: []}} as any,353 )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);354355 356 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');357 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/);358 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});359 });360 });361362 363364 it('Fungible: disallows to nest token if nesting is disabled', async () => {365 await usingApi(async api => {366 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});367 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});368 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');369 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};370371 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});372373 374 await expect(executeTransaction(api, alice, api.tx.unique.createItem(375 collectionFT,376 targetAddress,377 {Fungible: {Value: 10}},378 )), 'while creating nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);379380 381 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');382 383 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);384385 386 const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');387 388 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/);389 });390 });391392 it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {393 await usingApi(async api => {394 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});395 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});396397 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);398 await enableAllowListExpectSuccess(alice, collectionNFT);399 await enablePublicMintingExpectSuccess(alice, collectionNFT);400401 402 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');403 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};404405 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});406407 408 await expect(executeTransaction(api, alice, api.tx.unique.createItem(409 collectionFT,410 targetAddress,411 {Fungible: {Value: 10}},412 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);413414 415 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');416 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);417 });418 });419420 it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {421 await usingApi(async api => {422 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});423 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);424 await enableAllowListExpectSuccess(alice, collectionNFT);425 await enablePublicMintingExpectSuccess(alice, collectionNFT);426427 428 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');429 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};430431 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});432 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionFT]}});433434 435 await expect(executeTransaction(api, alice, api.tx.unique.createItem(436 collectionFT,437 targetAddress,438 {Fungible: {Value: 10}},439 )), 'while creating nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);440441 442 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');443 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);444 });445 });446447 it('Fungible: disallows to nest token in an unlisted collection', async () => {448 await usingApi(async api => {449 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});450 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});451452 453 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');454 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};455456 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});457458 459 await expect(executeTransaction(api, alice, api.tx.unique.createItem(460 collectionFT,461 targetAddress,462 {Fungible: {Value: 10}},463 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);464465 466 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');467 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);468 });469 });470471 472473 it('ReFungible: disallows to nest token if nesting is disabled', async () => {474 await usingApi(async api => {475 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});476 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Disabled'});477 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');478 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};479480 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});481482 483 await expect(executeTransaction(api, alice, api.tx.unique.createItem(484 collectionRFT,485 targetAddress,486 {ReFungible: {const_data: [], pieces: 100}},487 )), 'while creating a nested token').to.be.rejectedWith(/^common\.NestingIsDisabled$/);488489 490 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');491 492 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);493 494 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.NestingIsDisabled/);495496 497 const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');498 499 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/);500 });501 });502503 it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {504 await usingApi(async api => {505 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});506 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: 'Owner'});507508 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);509 await enableAllowListExpectSuccess(alice, collectionNFT);510 await enablePublicMintingExpectSuccess(alice, collectionNFT);511512 513 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');514 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};515516 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});517518 519 await expect(executeTransaction(api, alice, api.tx.unique.createItem(520 collectionRFT,521 targetAddress,522 {ReFungible: {const_data: [], pieces: 100}},523 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);524525 526 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');527 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);528 });529 });530531 it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {532 await usingApi(async api => {533 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});534 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);535 await enableAllowListExpectSuccess(alice, collectionNFT);536 await enablePublicMintingExpectSuccess(alice, collectionNFT);537538 539 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');540 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};541542 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});543 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[collectionRFT]}});544545 546 await expect(executeTransaction(api, alice, api.tx.unique.createItem(547 collectionRFT,548 targetAddress,549 {ReFungible: {const_data: [], pieces: 100}},550 )), 'while creating a nested token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);551552 553 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');554 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.OnlyOwnerAllowedToNest/);555 });556 });557558 it('ReFungible: disallows to nest token to an unlisted collection', async () => {559 await usingApi(async api => {560 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});561 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {OwnerRestricted:[]}});562563 564 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');565 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};566567 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});568569 570 await expect(executeTransaction(api, alice, api.tx.unique.createItem(571 collectionRFT,572 targetAddress,573 {ReFungible: {const_data: [], pieces: 100}},574 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);575576 577 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');578 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);579 });580 });581});