1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, Pallets, usingPlaygrounds} from '../util/playgrounds';1920describe('Integration Test: Composite nesting tests', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;2324 before(async () => {25 await usingPlaygrounds(async (helper, privateKey) => {26 const donor = await privateKey({filename: __filename});27 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);28 });29 });3031 itSub('Performs the full suite: bundles a token, transfers, and unnests', async ({helper}) => {32 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});33 const targetToken = await collection.mintToken(alice);3435 36 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());37 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});38 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());39 40 41 const newToken = await collection.mintToken(alice);4243 44 await newToken.nest(alice, targetToken);45 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});46 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());4748 49 await targetToken.transfer(alice, {Substrate: bob.address});50 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});51 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());52 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});53 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());5455 56 await newToken.unnest(bob, targetToken, {Substrate: bob.address});57 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});58 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});59 });6061 itSub('Transfers an already bundled token', async ({helper}) => {62 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});63 const tokenA = await collection.mintToken(alice);64 const tokenB = await collection.mintToken(alice);6566 67 const tokenC = await collection.mintToken(alice, tokenA.nestingAccount());68 expect(await tokenC.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());69 70 71 await expect(tokenC.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount())).to.be.fulfilled;72 expect(await tokenC.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});73 expect(await tokenC.getOwner()).to.be.deep.equal(tokenB.nestingAccount().toLowerCase());74 });7576 itSub('Checks token children', async ({helper}) => {77 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});78 const collectionB = await helper.ft.mintCollection(alice);79 80 const targetToken = await collectionA.mintToken(alice);81 expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');8283 84 const tokenA = await collectionA.mintToken(alice, targetToken.nestingAccount());85 expect(await targetToken.getChildren()).to.have.deep.members([86 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},87 ], 'Children contents check at nesting #1').and.be.length(1, 'Children length check at nesting #1');8889 90 const tokenB = await collectionA.mintToken(alice);91 await tokenB.nest(alice, targetToken);92 expect(await targetToken.getChildren()).to.have.deep.members([93 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},94 {tokenId: tokenB.tokenId, collectionId: collectionA.collectionId},95 ], 'Children contents check at nesting #2').and.be.length(2, 'Children length check at nesting #2');9697 98 await tokenB.unnest(alice, targetToken, {Substrate: bob.address});99 expect(await targetToken.getChildren()).to.be.have.deep.members([100 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},101 ], 'Children contents check at nesting #3 (unnesting)').and.be.length(1, 'Children length check at nesting #3 (unnesting)');102103 104 await collectionB.mint(alice, 10n);105 await collectionB.transfer(alice, targetToken.nestingAccount(), 2n);106 expect(await targetToken.getChildren()).to.be.have.deep.members([107 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},108 {tokenId: 0, collectionId: collectionB.collectionId},109 ], 'Children contents check at nesting #4 (from another collection)')110 .and.be.length(2, 'Children length check at nesting #4 (from another collection)');111 112 113 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);114 expect(await targetToken.getChildren()).to.be.have.deep.members([115 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},116 {tokenId: 0, collectionId: collectionB.collectionId},117 ], 'Children contents check at nesting #5 (deeper)').and.be.length(2, 'Children length check at nesting #5 (deeper)');118 expect(await tokenA.getChildren()).to.be.have.deep.members([119 {tokenId: 0, collectionId: collectionB.collectionId},120 ], 'Children contents check at nesting #5.5 (deeper)').and.be.length(1, 'Children length check at nesting #5.5 (deeper)');121122 123 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);124 expect(await targetToken.getChildren()).to.be.have.deep.members([125 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},126 ], 'Children contents check at nesting #6 (deeper)').and.be.length(1, 'Children length check at nesting #6 (deeper)');127 expect(await tokenA.getChildren()).to.be.have.deep.members([128 {tokenId: 0, collectionId: collectionB.collectionId},129 ], 'Children contents check at nesting #6.5 (deeper)').and.be.length(1, 'Children length check at nesting #6.5 (deeper)');130 });131});132133describe('Integration Test: Various token type nesting', () => {134 let alice: IKeyringPair;135 let bob: IKeyringPair;136 let charlie: IKeyringPair;137138 before(async () => {139 await usingPlaygrounds(async (helper, privateKey) => {140 const donor = await privateKey({filename: __filename});141 [alice, bob, charlie] = await helper.arrange.createAccounts([50n, 10n, 10n], donor);142 });143 });144145 itSub('Admin (NFT): allows an Admin to nest a token', async ({helper}) => {146 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true}}});147 await collection.addAdmin(alice, {Substrate: bob.address});148 const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});149150 151 const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());152 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});153 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());154155 156 const newToken = await collection.mintToken(bob);157 await newToken.nest(bob, targetToken);158 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});159 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());160 });161162 itSub('Admin (NFT): Admin and Token Owner can operate together', async ({helper}) => {163 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true, tokenOwner: true}}});164 await collection.addAdmin(alice, {Substrate: bob.address});165 const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});166167 168 const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());169 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});170 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());171172 173 const newToken = await collection.mintToken(alice, {Substrate: charlie.address});174 await newToken.nest(charlie, targetToken);175 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});176 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());177 });178179 itSub('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async ({helper}) => {180 const collectionA = await helper.nft.mintCollection(alice);181 await collectionA.addAdmin(alice, {Substrate: bob.address});182 const collectionB = await helper.nft.mintCollection(alice);183 await collectionB.addAdmin(alice, {Substrate: bob.address});184 await collectionA.setPermissions(alice, {nesting: {collectionAdmin: true, restricted:[collectionB.collectionId]}});185 const targetToken = await collectionA.mintToken(alice, {Substrate: charlie.address});186187 188 const nestedToken = await collectionB.mintToken(bob, targetToken.nestingAccount());189 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});190 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());191192 193 const newToken = await collectionB.mintToken(bob);194 await newToken.nest(bob, targetToken);195 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});196 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());197 });198199 200201 itSub('NFT: allows an Owner to nest/unnest their token', async ({helper}) => {202 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});203 await collection.addToAllowList(alice, {Substrate: charlie.address});204 const targetToken = await collection.mintToken(charlie);205 await collection.addToAllowList(alice, targetToken.nestingAccount());206207 208 const nestedToken = await collection.mintToken(charlie, targetToken.nestingAccount());209 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});210 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());211212 213 const newToken = await collection.mintToken(charlie);214 await newToken.nest(charlie, targetToken);215 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});216 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());217 });218219 itSub('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {220 const collectionA = await helper.nft.mintCollection(alice);221 const collectionB = await helper.nft.mintCollection(alice);222 223 const targetToken = await collectionA.mintToken(alice, {Substrate: charlie.address});224225 await collectionA.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionB.collectionId]}});226 await collectionA.addToAllowList(alice, {Substrate: charlie.address});227 await collectionA.addToAllowList(alice, targetToken.nestingAccount());228229 await collectionB.setPermissions(alice, {access: 'AllowList', mintMode: true});230 await collectionB.addToAllowList(alice, {Substrate: charlie.address});231 await collectionB.addToAllowList(alice, targetToken.nestingAccount());232233 234 const nestedToken = await collectionB.mintToken(charlie, targetToken.nestingAccount());235 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});236 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());237238 239 const newToken = await collectionB.mintToken(charlie);240 await newToken.nest(charlie, targetToken);241 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});242 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());243 });244245 246247 itSub('Fungible: allows an Owner to nest/unnest their token', async ({helper}) => {248 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});249 const collectionFT = await helper.ft.mintCollection(alice);250 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});251252 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});253 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());254255 await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});256 await collectionFT.addToAllowList(alice, {Substrate: charlie.address});257 await collectionFT.addToAllowList(alice, targetToken.nestingAccount());258259 260 await collectionFT.mint(charlie, 5n, targetToken.nestingAccount());261 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);262263 264 await collectionFT.mint(charlie, 5n);265 await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);266 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);267 });268269 itSub('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {270 const collectionNFT = await helper.nft.mintCollection(alice);271 const collectionFT = await helper.ft.mintCollection(alice);272 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});273274 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionFT.collectionId]}});275 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});276 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());277278 await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});279 await collectionFT.addToAllowList(alice, {Substrate: charlie.address});280 await collectionFT.addToAllowList(alice, targetToken.nestingAccount());281282 283 await collectionFT.mint(charlie, 5n, targetToken.nestingAccount());284 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);285286 287 await collectionFT.mint(charlie, 5n);288 await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);289 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);290 });291292 293294 itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token', [Pallets.ReFungible], async ({helper}) => {295 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});296 const collectionRFT = await helper.rft.mintCollection(alice);297 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});298299 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});300 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());301302 await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});303 await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});304 await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());305306 307 const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());308 expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);309310 311 const newToken = await collectionRFT.mintToken(charlie, 5n);312 await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);313 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);314 });315316 itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {317 const collectionNFT = await helper.nft.mintCollection(alice);318 const collectionRFT = await helper.rft.mintCollection(alice);319 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});320321 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionRFT.collectionId]}});322 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});323 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());324325 await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});326 await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});327 await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());328329 330 const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());331 expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);332333 334 const newToken = await collectionRFT.mintToken(charlie, 5n);335 await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);336 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);337 });338});339340describe('Negative Test: Nesting', () => {341 let alice: IKeyringPair;342 let bob: IKeyringPair;343344 before(async () => {345 await usingPlaygrounds(async (helper, privateKey) => {346 const donor = await privateKey({filename: __filename});347 [alice, bob] = await helper.arrange.createAccounts([100n, 50n], donor);348 });349 });350351 itSub('Disallows excessive token nesting', async ({helper}) => {352 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});353 let token = await collection.mintToken(alice);354355 const maxNestingLevel = 5;356357 358 for (let i = 0; i < maxNestingLevel; i++) {359 token = await collection.mintToken(alice, token.nestingAccount());360 }361362 363 await expect(collection.mintToken(alice, token.nestingAccount()))364 .to.be.rejectedWith(/structure\.DepthLimit/);365 expect(await token.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});366 expect(await token.getChildren()).to.be.length(0);367 });368369 370371 itSub('Admin (NFT): disallows an Admin to operate nesting when only TokenOwner is allowed', async ({helper}) => {372 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});373 await collection.addAdmin(alice, {Substrate: bob.address});374 const targetToken = await collection.mintToken(alice);375376 377 await expect(collection.mintToken(bob, targetToken.nestingAccount()))378 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);379380 381 const newToken = await collection.mintToken(bob);382 await expect(newToken.nest(bob, targetToken))383 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);384385 expect(await targetToken.getChildren()).to.be.length(0);386 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});387 });388389 itSub('Admin (NFT): disallows a Token Owner to operate nesting when only Admin is allowed', async ({helper}) => {390 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});391 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});392 await collection.addToAllowList(alice, {Substrate: bob.address});393 await collection.addToAllowList(alice, targetToken.nestingAccount());394395 396 await expect(collection.mintToken(bob, targetToken.nestingAccount()))397 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);398399 400 const newToken = await collection.mintToken(bob);401 await expect(newToken.nest(bob, targetToken))402 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);403404 expect(await targetToken.getChildren()).to.be.length(0);405 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});406 });407408 itSub('Admin (NFT): disallows an Admin to unnest someone else\'s token', async ({helper}) => {409 const collection = await helper.nft.mintCollection(alice, {limits: {ownerCanTransfer: true}, permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});410 411 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});412 await collection.addToAllowList(alice, {Substrate: bob.address});413 await collection.addToAllowList(alice, targetToken.nestingAccount());414415 416 const newToken = await collection.mintToken(bob);417 await expect(newToken.nest(alice, targetToken))418 .to.be.rejectedWith(/common\.NoPermission/);419420 421 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());422 await expect(nestedToken.unnest(alice, targetToken, {Substrate: bob.address}))423 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);424425 expect(await targetToken.getChildren()).to.be.length(1);426 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});427 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());428 });429430 itSub('Admin (NFT): disallows an Admin to nest a token from an unlisted collection (Restricted nesting)', async ({helper}) => {431 const collectionA = await helper.nft.mintCollection(alice);432 const collectionB = await helper.nft.mintCollection(alice);433 await collectionA.setPermissions(alice, {nesting: {collectionAdmin: true, restricted: [collectionA.collectionId]}});434 const targetToken = await collectionA.mintToken(alice);435436 437 await expect(collectionB.mintToken(alice, targetToken.nestingAccount()))438 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);439440 441 const newToken = await collectionB.mintToken(alice);442 await expect(newToken.nest(alice, targetToken))443 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);444445 expect(await targetToken.getChildren()).to.be.length(0);446 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});447 });448449 450451 itSub('NFT: disallows to nest token if nesting is disabled', async ({helper}) => {452 453 const collection = await helper.nft.mintCollection(alice);454 const targetToken = await collection.mintToken(alice);455456 457 await expect(collection.mintToken(alice, targetToken.nestingAccount()))458 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);459460 461 const newToken = await collection.mintToken(alice);462 await expect(newToken.nest(alice, targetToken))463 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);464465 expect(await targetToken.getChildren()).to.be.length(0);466 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});467 });468469 itSub('NFT: disallows a non-Owner to nest someone else\'s token', async ({helper}) => {470 const collection = await helper.nft.mintCollection(alice);471 const targetToken = await collection.mintToken(alice);472473 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});474 await collection.addToAllowList(alice, {Substrate: bob.address});475 await collection.addToAllowList(alice, targetToken.nestingAccount());476477 478 const newToken = await collection.mintToken(alice);479 await expect(newToken.nest(bob, targetToken)).to.be.rejectedWith(/common\.NoPermission/);480481 expect(await targetToken.getChildren()).to.be.length(0);482 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});483 });484485 itSub('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async ({helper}) => {486 const collection = await helper.nft.mintCollection(alice);487 const targetToken = await collection.mintToken(alice);488489 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});490 await collection.addToAllowList(alice, {Substrate: bob.address});491 await collection.addToAllowList(alice, targetToken.nestingAccount());492493 const collectionB = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true}});494 await collectionB.addToAllowList(alice, {Substrate: bob.address});495 await collectionB.addToAllowList(alice, targetToken.nestingAccount());496497 498 const newToken = await collectionB.mintToken(alice);499 await expect(newToken.nest(bob, targetToken)).to.be.rejectedWith(/common\.NoPermission/);500501 expect(await targetToken.getChildren()).to.be.length(0);502 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});503 });504505 itSub('NFT: disallows to nest token in an unlisted collection', async ({helper}) => {506 507 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: []}}});508 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});509510 await collection.addToAllowList(alice, {Substrate: bob.address});511 await collection.addToAllowList(alice, targetToken.nestingAccount());512513 514 await expect(collection.mintToken(bob, targetToken.nestingAccount()))515 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);516 });517518 519520 itSub('Fungible: disallows to nest token if nesting is disabled', async ({helper}) => {521 const collectionNFT = await helper.nft.mintCollection(alice);522 const collectionFT = await helper.ft.mintCollection(alice);523 const targetToken = await collectionNFT.mintToken(alice);524525 526 await expect(collectionFT.mint(alice, 5n, targetToken.nestingAccount()))527 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);528529 530 await collectionFT.mint(alice, 5n);531 await expect(collectionFT.transfer(alice, targetToken.nestingAccount(), 2n))532 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);533 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);534 });535536 itSub('Fungible: disallows a non-Owner to unnest someone else\'s token', async ({helper}) => {537 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true, tokenOwner: true}}});538 const collectionFT = await helper.ft.mintCollection(alice);539 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});540541 542 await collectionFT.mint(alice, 5n, targetToken.nestingAccount());543544 545 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))546 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);547 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);548 });549550 itSub('Fungible: disallows a non-Owner to unnest someone else\'s token (Restricted nesting)', async ({helper}) => {551 const collectionNFT = await helper.nft.mintCollection(alice);552 const collectionFT = await helper.ft.mintCollection(alice);553 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});554555 await collectionNFT.setPermissions(alice, {nesting: {collectionAdmin: true, tokenOwner: true, restricted: [collectionFT.collectionId]}});556557 558 await collectionFT.mint(alice, 5n, targetToken.nestingAccount());559560 561 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))562 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);563 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);564 });565566 itSub('Fungible: disallows to nest token in an unlisted collection', async ({helper}) => {567 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true, tokenOwner: true, restricted: []}}});568 const collectionFT = await helper.ft.mintCollection(alice);569 const targetToken = await collectionNFT.mintToken(alice);570571 572 await expect(collectionFT.mint(alice, 5n, targetToken.nestingAccount()))573 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);574575 576 await collectionFT.mint(alice, 5n);577 await expect(collectionFT.transfer(alice, targetToken.nestingAccount(), 1n))578 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);579580 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);581 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);582 });583584 585586 itSub.ifWithPallets('ReFungible: disallows to nest token if nesting is disabled', [Pallets.ReFungible], async ({helper}) => {587 const collectionNFT = await helper.nft.mintCollection(alice);588 const collectionRFT = await helper.rft.mintCollection(alice);589 const targetToken = await collectionNFT.mintToken(alice);590591 592 await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))593 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);594595 596 const token = await collectionRFT.mintToken(alice, 5n);597 await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))598 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);599 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);600 });601602 itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token', [Pallets.ReFungible], async ({helper}) => {603 const collectionNFT = await helper.nft.mintCollection(alice);604 const collectionRFT = await helper.rft.mintCollection(alice);605 const targetToken = await collectionNFT.mintToken(alice);606607 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});608 await collectionNFT.addToAllowList(alice, {Substrate: bob.address});609 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());610611 612 const newToken = await collectionRFT.mintToken(alice);613 await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);614615 expect(await targetToken.getChildren()).to.be.length(0);616 expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);617618 619 await newToken.transfer(alice, targetToken.nestingAccount());620621 622 await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))623 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);624 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);625 });626627 itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {628 const collectionNFT = await helper.nft.mintCollection(alice);629 const collectionRFT = await helper.rft.mintCollection(alice);630 const targetToken = await collectionNFT.mintToken(alice);631632 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: [collectionRFT.collectionId]}});633 await collectionNFT.addToAllowList(alice, {Substrate: bob.address});634 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());635636 637 const newToken = await collectionRFT.mintToken(alice);638 await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);639640 expect(await targetToken.getChildren()).to.be.length(0);641 expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);642643 644 await newToken.transfer(alice, targetToken.nestingAccount());645646 647 await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))648 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);649 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);650 });651652 itSub.ifWithPallets('ReFungible: disallows to nest token to an unlisted collection', [Pallets.ReFungible], async ({helper}) => {653 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true, restricted: []}}});654 const collectionRFT = await helper.rft.mintCollection(alice);655 const targetToken = await collectionNFT.mintToken(alice);656657 658 await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))659 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);660661 662 const token = await collectionRFT.mintToken(alice, 5n);663 await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))664 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);665 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);666 });667});