1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, Pallets, usingPlaygrounds} from '../../util';19import {UniqueNFTCollection, UniqueRFTCollection} from '../../util/playgrounds/unique';20import {itEth} from '../../eth/util';2122let alice: IKeyringPair;2324before(async () => {25 await usingPlaygrounds(async (helper, privateKey) => {26 const donor = await privateKey({filename: __filename});27 [alice] = await helper.arrange.createAccounts([50n], donor);28 });29});3031[32 {mode: 'nft' as const, requiredPallets: []},33 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},34].map(testCase => {35 itSub.ifWithPallets(`Owner cannot nest ${testCase.mode.toUpperCase()} if nesting not allowed`, testCase.requiredPallets, async ({helper}) => {36 37 const aliceNFTCollection = await helper.nft.mintCollection(alice);38 const targetToken = await aliceNFTCollection.mintToken(alice);3940 const collectionForNesting = await helper[testCase.mode].mintCollection(alice);4142 43 const nestingTx = testCase.mode === 'nft'44 ? (collectionForNesting as UniqueNFTCollection).mintToken(alice, targetToken.nestingAccount())45 : (collectionForNesting as UniqueRFTCollection).mintToken(alice, 10n, targetToken.nestingAccount());46 await expect(nestingTx).to.be.rejectedWith('common.UserIsNotAllowedToNest');4748 49 const nestedToken2 = await collectionForNesting.mintToken(alice);50 await expect(nestedToken2.nest(alice, targetToken)).to.be.rejectedWith('common.UserIsNotAllowedToNest');51 });52});5354itSub('Owner cannot nest FT if nesting not allowed', async ({helper}) => {55 56 const aliceNFTCollection = await helper.nft.mintCollection(alice);57 const targetToken = await aliceNFTCollection.mintToken(alice);5859 const collectionForNesting = await helper.ft.mintCollection(alice);6061 62 await expect(collectionForNesting.mint(alice, 100n, targetToken.nestingAccount())).to.be.rejectedWith('common.UserIsNotAllowedToNest');6364 65 await collectionForNesting.mint(alice, 100n);66 await expect(collectionForNesting.transfer(alice, targetToken.nestingAccount(), 50n)).to.be.rejectedWith('common.UserIsNotAllowedToNest');67});6869itSub.ifWithPallets('Cannot nest in non existing token', [Pallets.ReFungible], async ({helper}) => {70 const collection = await helper.nft.mintCollection(alice);71 72 await helper.collection.setPermissions(alice, collection.collectionId, {nesting: {collectionAdmin: true}});7374 75 const tokenFromNonExistingCollection = helper.nft.getTokenObject(9999999, 1);76 const tokenBurnt = await collection.mintToken(alice);77 await tokenBurnt.burn(alice);78 const tokenNotMintedYet = helper.nft.getTokenObject(collection.collectionId, 2);7980 81 const nftCollectionForNesting = await helper.nft.mintCollection(alice);82 const rftCollectionForNesting = await helper.rft.mintCollection(alice);83 const ftCollectionForNesting = await helper.ft.mintCollection(alice);8485 const testCases = [86 {token: tokenFromNonExistingCollection, error: 'CollectionNotFound'},87 {token: tokenBurnt, error: 'TokenNotFound'},88 {token: tokenNotMintedYet, error: 'TokenNotFound'},89 ];9091 for(const testCase of testCases) {92 93 await expect(nftCollectionForNesting.mintToken(alice, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);94 await expect(rftCollectionForNesting.mintToken(alice, 10n, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);95 await expect(ftCollectionForNesting.mint(alice, 10n, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);9697 98 const nft = await nftCollectionForNesting.mintToken(alice);99 const rft = await rftCollectionForNesting.mintToken(alice, 100n);100 const _ft = await ftCollectionForNesting.mint(alice, 100n);101 await expect(nft.transfer(alice, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);102 await expect(rft.transfer(alice, testCase.token.nestingAccount())).to.be.rejectedWith(testCase.error);103 await expect(ftCollectionForNesting.transfer(alice, testCase.token.nestingAccount(), 50n)).to.be.rejectedWith(testCase.error);104 }105});106107itEth.ifWithPallets('Cannot nest to collection address', [Pallets.ReFungible], async({helper}) => {108 const existingCollection = await helper.nft.mintCollection(alice);109 const existingCollectionAddress = helper.ethAddress.fromCollectionId(existingCollection.collectionId);110 const futureCollectionAddress = helper.ethAddress.fromCollectionId(99999999);111112 const nftCollectionForNesting = await helper.nft.mintCollection(alice);113114 115 await expect(nftCollectionForNesting.mintToken(alice, {Ethereum: existingCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');116 await expect(nftCollectionForNesting.mintToken(alice, {Ethereum: futureCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');117118 119 const nft = await nftCollectionForNesting.mintToken(alice);120 await expect(nft.transfer(alice, {Ethereum: existingCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');121 await expect(nft.transfer(alice, {Ethereum: futureCollectionAddress})).to.be.rejectedWith('CantNestTokenUnderCollection');122});123124itEth.ifWithPallets('Cannot nest in RFT or FT', [Pallets.ReFungible], async ({helper}) => {125 126 const rftCollection = await helper.rft.mintCollection(alice);127 const ftCollection = await helper.ft.mintCollection(alice);128129 const rftToken = await rftCollection.mintToken(alice);130 const _ftToken = await ftCollection.mint(alice, 100n);131132 const collectionForNesting = await helper.nft.mintCollection(alice);133134 135 await expect(collectionForNesting.mintToken(alice, rftToken.nestingAccount())).to.be.rejectedWith('refungible.RefungibleDisallowsNesting');136 await expect(collectionForNesting.mintToken(alice, {Ethereum: helper.ethAddress.fromTokenId(ftCollection.collectionId, 0)})).to.be.rejectedWith('fungible.FungibleDisallowsNesting');137138 139 const nestedToken2 = await collectionForNesting.mintToken(alice);140 await expect(nestedToken2.nest(alice, rftToken)).to.be.rejectedWith('refungible.RefungibleDisallowsNesting');141 await expect(ftCollection.transfer(alice, {Ethereum: helper.ethAddress.fromTokenId(ftCollection.collectionId, 0)})).to.be.rejectedWith('fungible.FungibleDisallowsNesting');142});