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 setCollectionLimitsExpectSuccess,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 (api, privateKeyWrapper) => {28 alice = privateKeyWrapper('//Alice');29 bob = privateKeyWrapper('//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: {tokenOwner: true}});37 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');3839 40 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 45 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');4647 48 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 53 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 58 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: {tokenOwner: true}});6768 const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');69 const tokenB = await createItemExpectSuccess(alice, collection, 'NFT');7071 72 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 77 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 setCollectionLimitsExpectSuccess(alice, collectionA, {ownerCanTransfer: true});97 await setCollectionPermissionsExpectSuccess(alice, collectionA, {nesting: {tokenOwner: true}});98 const collectionB = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});99100 const targetToken = await createItemExpectSuccess(alice, collectionA, 'NFT');101 const targetAddress = {Ethereum: tokenIdToAddress(collectionA, targetToken)};102 let children = await getTokenChildren(api, collectionA, targetToken);103 expect(children.length).to.be.equal(0, 'Children length check at creation');104105 106 const tokenA = await createItemExpectSuccess(alice, collectionA, 'NFT', targetAddress);107 children = await getTokenChildren(api, collectionA, targetToken);108 expect(children.length).to.be.equal(1, 'Children length check at nesting #1');109 expect(children).to.have.deep.members([110 {token: tokenA, collection: collectionA},111 ], 'Children contents check at nesting #1');112113 114 const tokenB = await createItemExpectSuccess(alice, collectionA, 'NFT');115 await transferExpectSuccess(collectionA, tokenB, alice, targetAddress);116 children = await getTokenChildren(api, collectionA, targetToken);117 expect(children.length).to.be.equal(2, 'Children length check at nesting #2');118 expect(children).to.have.deep.members([119 {token: tokenA, collection: collectionA},120 {token: tokenB, collection: collectionA},121 ], 'Children contents check at nesting #2');122123 124 await transferExpectSuccess(collectionA, tokenB, alice, bob);125 children = await getTokenChildren(api, collectionA, targetToken);126 expect(children.length).to.be.equal(1, 'Children length check at unnesting');127 expect(children).to.be.have.deep.members([128 {token: tokenA, collection: collectionA},129 ], 'Children contents check at unnesting');130131 132 const tokenC = await createItemExpectSuccess(alice, collectionB, 'Fungible');133 await transferExpectSuccess(collectionB, tokenC, alice, targetAddress, 1, 'Fungible');134 children = await getTokenChildren(api, collectionA, targetToken);135 expect(children.length).to.be.equal(2, 'Children length check at nesting #3 (from another collection)');136 expect(children).to.be.have.deep.members([137 {token: tokenA, collection: collectionA},138 {token: tokenC, collection: collectionB},139 ], 'Children contents check at nesting #3 (from another collection)');140141 142 await transferFromExpectSuccess(collectionB, tokenC, alice, targetAddress, {Ethereum: tokenIdToAddress(collectionA, tokenA)}, 1, 'Fungible');143 children = await getTokenChildren(api, collectionA, targetToken);144 expect(children.length).to.be.equal(1, 'Children length check at deeper nesting');145 expect(children).to.be.have.deep.members([146 {token: tokenA, collection: collectionA},147 ], 'Children contents check at deeper nesting');148 });149 });150151 152153 it('NFT: allows an Owner to nest/unnest their token', async () => {154 await usingApi(async api => {155 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});156 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});157 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');158159 160 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});161 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});162 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});163164 165 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');166 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});167 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});168 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});169 });170 });171172 it('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {173 await usingApi(async api => {174 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});175 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[collection]}});176 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');177178 179 const nestedToken = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, targetToken)});180 expect(await getTopmostTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Substrate: alice.address});181 expect(await getTokenOwner(api, collection, nestedToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});182183 184 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');185 await transferExpectSuccess(collection, newToken, alice, {Ethereum: tokenIdToAddress(collection, targetToken)});186 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});187 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, targetToken).toLowerCase()});188 });189 });190191 192193 it('Fungible: allows an Owner to nest/unnest their token', async () => {194 await usingApi(async api => {195 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});196 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});197 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});198 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};199200 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});201202 203 await expect(executeTransaction(api, alice, api.tx.unique.createItem(204 collectionFT,205 targetAddress,206 {Fungible: {Value: 10}},207 ))).to.not.be.rejected;208209 210 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');211 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');212 });213 });214215 it('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {216 await usingApi(async api => {217 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});218 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});219 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};220221 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});222223 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted: [collectionFT]}});224225 226 await expect(executeTransaction(api, alice, api.tx.unique.createItem(227 collectionFT,228 targetAddress,229 {Fungible: {Value: 10}},230 ))).to.not.be.rejected;231232 233 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');234 await transferExpectSuccess(collectionFT, newToken, alice, targetAddress, 1, 'Fungible');235 });236 });237238 239240 it('ReFungible: allows an Owner to nest/unnest their token', async () => {241 await usingApi(async api => {242 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});243 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});244 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});245 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};246247 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});248249 250 await expect(executeTransaction(api, alice, api.tx.unique.createItem(251 collectionRFT,252 targetAddress,253 {ReFungible: {const_data: [], pieces: 100}},254 ))).to.not.be.rejected;255256 257 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');258 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');259 });260 });261262 it('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', async () => {263 await usingApi(async api => {264 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});265 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT', {Substrate: alice.address});266 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};267268 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});269270 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionRFT]}});271272 273 await expect(executeTransaction(api, alice, api.tx.unique.createItem(274 collectionRFT,275 targetAddress,276 {ReFungible: {const_data: [], pieces: 100}},277 ))).to.not.be.rejected;278279 280 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');281 await transferExpectSuccess(collectionRFT, newToken, alice, targetAddress, 100, 'ReFungible');282 });283 });284});285286describe('Negative Test: Nesting', async() => {287 before(async () => {288 await usingApi(async (api, privateKeyWrapper) => {289 alice = privateKeyWrapper('//Alice');290 bob = privateKeyWrapper('//Bob');291 });292 });293294 it('Disallows excessive token nesting', async () => {295 await usingApi(async api => {296 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});297 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});298 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');299300 const maxNestingLevel = 5;301 let prevToken = targetToken;302303 304 for (let i = 0; i < maxNestingLevel; i++) {305 const nestedToken = await createItemExpectSuccess(306 alice,307 collection,308 'NFT',309 {Ethereum: tokenIdToAddress(collection, prevToken)},310 );311312 prevToken = nestedToken;313 }314315 316 await expect(executeTransaction(api, alice, api.tx.unique.createItem(317 collection,318 {Ethereum: tokenIdToAddress(collection, prevToken)},319 {nft: {const_data: [], variable_data: []}} as any,320 )), 'while creating nested token').to.be.rejectedWith(/^structure\.DepthLimit$/);321322 expect(await getTopmostTokenOwner(api, collection, prevToken)).to.be.deep.equal({Substrate: alice.address});323 });324 });325326 327328 it('NFT: disallows to nest token if nesting is disabled', async () => {329 await usingApi(async api => {330 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});331 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {}});332 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');333334 335 await expect(executeTransaction(api, alice, api.tx.unique.createItem(336 collection,337 {Ethereum: tokenIdToAddress(collection, targetToken)},338 {nft: {const_data: [], variable_data: []}} as any,339 )), 'while creating nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);340341 342 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');343 344 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/);345 expect(await getTopmostTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});346 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});347 });348 });349350 it('NFT: disallows a non-Owner to nest someone else\'s token', async () => {351 await usingApi(async api => {352 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});353 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true}});354355 await addToAllowListExpectSuccess(alice, collection, bob.address);356 await enableAllowListExpectSuccess(alice, collection);357 await enablePublicMintingExpectSuccess(alice, collection);358359 360 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');361362 363 await expect(executeTransaction(api, alice, api.tx.unique.createItem(364 collection,365 {Ethereum: tokenIdToAddress(collection, targetToken)},366 {nft: {const_data: [], variable_data: []}} as any,367 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);368369 370 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');371 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/);372 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});373 });374 });375376 it('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {377 await usingApi(async api => {378 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});379 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[collection]}});380381 await addToAllowListExpectSuccess(alice, collection, bob.address);382 await enableAllowListExpectSuccess(alice, collection);383 await enablePublicMintingExpectSuccess(alice, collection);384385 386 const targetToken = await createItemExpectSuccess(bob, collection, 'NFT');387388 389 await expect(executeTransaction(api, alice, api.tx.unique.createItem(390 collection,391 {Ethereum: tokenIdToAddress(collection, targetToken)},392 {nft: {const_data: [], variable_data: []}} as any,393 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);394395 396 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');397 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/);398 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});399 });400 });401402 it('NFT: disallows to nest token in an unlisted collection', async () => {403 await usingApi(async api => {404 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});405 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: {tokenOwner: true, restricted:[]}});406407 408 const targetToken = await createItemExpectSuccess(alice, collection, 'NFT');409410 411 await expect(executeTransaction(api, alice, api.tx.unique.createItem(412 collection,413 {Ethereum: tokenIdToAddress(collection, targetToken)},414 {nft: {const_data: [], variable_data: []}} as any,415 )), 'while creating nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);416417 418 const newToken = await createItemExpectSuccess(alice, collection, 'NFT');419 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/);420 expect(await getTokenOwner(api, collection, newToken)).to.be.deep.equal({Substrate: alice.address});421 });422 });423424 425426 it('Fungible: disallows to nest token if nesting is disabled', async () => {427 await usingApi(async api => {428 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});429 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {}});430 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');431 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};432433 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});434435 436 await expect(executeTransaction(api, alice, api.tx.unique.createItem(437 collectionFT,438 targetAddress,439 {Fungible: {Value: 10}},440 )), 'while creating nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);441442 443 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');444 445 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);446447 448 const newToken2 = await createItemExpectSuccess(alice, collectionFT, 'Fungible');449 450 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/);451 });452 });453454 it('Fungible: disallows a non-Owner to nest someone else\'s token', async () => {455 await usingApi(async api => {456 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});457 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});458459 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);460 await enableAllowListExpectSuccess(alice, collectionNFT);461 await enablePublicMintingExpectSuccess(alice, collectionNFT);462463 464 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');465 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};466467 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});468469 470 await expect(executeTransaction(api, alice, api.tx.unique.createItem(471 collectionFT,472 targetAddress,473 {Fungible: {Value: 10}},474 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);475476 477 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');478 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);479 });480 });481482 it('Fungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {483 await usingApi(async api => {484 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});485 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);486 await enableAllowListExpectSuccess(alice, collectionNFT);487 await enablePublicMintingExpectSuccess(alice, collectionNFT);488489 490 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');491 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};492493 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});494 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionFT]}});495496 497 await expect(executeTransaction(api, alice, api.tx.unique.createItem(498 collectionFT,499 targetAddress,500 {Fungible: {Value: 10}},501 )), 'while creating nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);502503 504 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');505 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);506 });507 });508509 it('Fungible: disallows to nest token in an unlisted collection', async () => {510 await usingApi(async api => {511 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});512 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[]}});513514 515 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');516 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};517518 const collectionFT = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});519520 521 await expect(executeTransaction(api, alice, api.tx.unique.createItem(522 collectionFT,523 targetAddress,524 {Fungible: {Value: 10}},525 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);526527 528 const newToken = await createItemExpectSuccess(alice, collectionFT, 'Fungible');529 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);530 });531 });532533 534535 it('ReFungible: disallows to nest token if nesting is disabled', async () => {536 await usingApi(async api => {537 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});538 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {}});539 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');540 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};541542 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});543544 545 await expect(executeTransaction(api, alice, api.tx.unique.createItem(546 collectionRFT,547 targetAddress,548 {ReFungible: {const_data: [], pieces: 100}},549 )), 'while creating a nested token').to.be.rejectedWith(/^common\.UserIsNotAllowedToNest$/);550551 552 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');553 554 await transferExpectFailure(collectionRFT, newToken, alice, targetAddress, 100);555 556 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);557558 559 const newToken2 = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');560 561 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/);562 });563 });564565 it('ReFungible: disallows a non-Owner to nest someone else\'s token', async () => {566 await usingApi(async api => {567 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});568 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true}});569570 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);571 await enableAllowListExpectSuccess(alice, collectionNFT);572 await enablePublicMintingExpectSuccess(alice, collectionNFT);573574 575 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');576 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};577578 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});579580 581 await expect(executeTransaction(api, alice, api.tx.unique.createItem(582 collectionRFT,583 targetAddress,584 {ReFungible: {const_data: [], pieces: 100}},585 )), 'while creating a nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);586587 588 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');589 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);590 });591 });592593 it('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async () => {594 await usingApi(async api => {595 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});596 await addToAllowListExpectSuccess(alice, collectionNFT, bob.address);597 await enableAllowListExpectSuccess(alice, collectionNFT);598 await enablePublicMintingExpectSuccess(alice, collectionNFT);599600 601 const targetToken = await createItemExpectSuccess(bob, collectionNFT, 'NFT');602 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};603604 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});605 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[collectionRFT]}});606607 608 await expect(executeTransaction(api, alice, api.tx.unique.createItem(609 collectionRFT,610 targetAddress,611 {ReFungible: {const_data: [], pieces: 100}},612 )), 'while creating a nested token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);613614 615 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');616 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);617 });618 });619620 it('ReFungible: disallows to nest token to an unlisted collection', async () => {621 await usingApi(async api => {622 const collectionNFT = await createCollectionExpectSuccess({mode: {type: 'NFT'}});623 await setCollectionPermissionsExpectSuccess(alice, collectionNFT, {nesting: {tokenOwner: true, restricted:[]}});624625 626 const targetToken = await createItemExpectSuccess(alice, collectionNFT, 'NFT');627 const targetAddress = {Ethereum: tokenIdToAddress(collectionNFT, targetToken)};628629 const collectionRFT = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});630631 632 await expect(executeTransaction(api, alice, api.tx.unique.createItem(633 collectionRFT,634 targetAddress,635 {ReFungible: {const_data: [], pieces: 100}},636 )), 'while creating a nested token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);637638 639 const newToken = await createItemExpectSuccess(alice, collectionRFT, 'ReFungible');640 await expect(executeTransaction(api, alice, api.tx.unique.transfer(targetAddress, collectionRFT, newToken, 1)), 'while nesting new token').to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);641 });642 });643});