123456789101112131415161718import {IKeyringPair} from '@polkadot/types/types';19import {itSub, usingPlaygrounds, expect} from './util/playgrounds';2021const accountTokenOwnershipLimit = 0;22const sponsoredDataSize = 0;23const sponsorTransferTimeout = 1;24const tokenLimit = 10;2526describe('setCollectionLimits positive', () => {27 let alice: IKeyringPair;28 let bob: IKeyringPair;2930 before(async () => {31 await usingPlaygrounds(async (helper, privateKey) => {32 const donor = privateKey('//Alice');33 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);34 });35 });3637 itSub('execute setCollectionLimits with predefined params', async ({helper}) => {38 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-1', tokenPrefix: 'SCL'});3940 await collection.setLimits(41 alice,42 {43 accountTokenOwnershipLimit,44 sponsoredDataSize,45 tokenLimit,46 sponsorTransferTimeout,47 ownerCanTransfer: true,48 ownerCanDestroy: true,49 },50 );5152 53 const collectionInfo = await collection.getEffectiveLimits();5455 expect(collectionInfo.accountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);56 expect(collectionInfo.sponsoredDataSize).to.be.equal(sponsoredDataSize);57 expect(collectionInfo.tokenLimit).to.be.equal(tokenLimit);58 expect(collectionInfo.sponsorTransferTimeout).to.be.equal(sponsorTransferTimeout);59 expect(collectionInfo.ownerCanTransfer).to.be.true;60 expect(collectionInfo.ownerCanDestroy).to.be.true;61 });6263 itSub('Set the same token limit twice', async ({helper}) => {64 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-2', tokenPrefix: 'SCL'});6566 const collectionLimits = {67 accountTokenOwnershipLimit,68 sponsoredDataSize,69 tokenLimit,70 sponsorTransferTimeout,71 ownerCanTransfer: true,72 ownerCanDestroy: true,73 };7475 await collection.setLimits(alice, collectionLimits);7677 const collectionInfo1 = await collection.getEffectiveLimits();78 79 expect(collectionInfo1.tokenLimit).to.be.equal(tokenLimit);8081 await collection.setLimits(alice, collectionLimits);82 const collectionInfo2 = await collection.getEffectiveLimits();83 expect(collectionInfo2.tokenLimit).to.be.equal(tokenLimit);84 });8586 itSub('execute setCollectionLimits from admin collection', async ({helper}) => {87 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-3', tokenPrefix: 'SCL'});88 await collection.addAdmin(alice, {Substrate: bob.address});8990 const collectionLimits = {91 accountTokenOwnershipLimit,92 sponsoredDataSize,93 94 tokenLimit,95 };9697 await expect(collection.setLimits(alice, collectionLimits)).to.not.be.rejected;98 });99});100101describe('setCollectionLimits negative', () => {102 let alice: IKeyringPair;103 let bob: IKeyringPair;104105 before(async () => {106 await usingPlaygrounds(async (helper, privateKey) => {107 const donor = privateKey('//Alice');108 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);109 });110 });111 112 itSub('execute setCollectionLimits for not exists collection', async ({helper}) => {113 const nonExistentCollectionId = (1 << 32) - 1;114 await expect(helper.collection.setLimits(115 alice,116 nonExistentCollectionId,117 {118 accountTokenOwnershipLimit,119 sponsoredDataSize,120 121 tokenLimit,122 },123 )).to.be.rejectedWith(/common\.CollectionNotFound/);124 });125126 itSub('execute setCollectionLimits from user who is not owner of this collection', async ({helper}) => {127 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-1', tokenPrefix: 'SCL'});128129 await expect(collection.setLimits(bob, {130 accountTokenOwnershipLimit,131 sponsoredDataSize,132 133 tokenLimit,134 })).to.be.rejectedWith(/common\.NoPermission/);135 });136137 itSub('fails when trying to enable OwnerCanTransfer after it was disabled', async ({helper}) => {138 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-2', tokenPrefix: 'SCL'});139140 await collection.setLimits(alice, {141 accountTokenOwnershipLimit,142 sponsoredDataSize,143 tokenLimit,144 sponsorTransferTimeout,145 ownerCanTransfer: false,146 ownerCanDestroy: true,147 });148149 await expect(collection.setLimits(alice, {150 accountTokenOwnershipLimit,151 sponsoredDataSize,152 tokenLimit,153 sponsorTransferTimeout,154 ownerCanTransfer: true,155 ownerCanDestroy: true,156 })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);157 });158159 itSub('fails when trying to enable OwnerCanDestroy after it was disabled', async ({helper}) => {160 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-3', tokenPrefix: 'SCL'});161162 await collection.setLimits(alice, {163 accountTokenOwnershipLimit,164 sponsoredDataSize,165 tokenLimit,166 sponsorTransferTimeout,167 ownerCanTransfer: true,168 ownerCanDestroy: false,169 });170171 await expect(collection.setLimits(alice, {172 accountTokenOwnershipLimit,173 sponsoredDataSize,174 tokenLimit,175 sponsorTransferTimeout,176 ownerCanTransfer: true,177 ownerCanDestroy: true,178 })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);179 });180181 itSub('Setting the higher token limit fails', async ({helper}) => {182 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-4', tokenPrefix: 'SCL'});183 184 const collectionLimits = {185 accountTokenOwnershipLimit: accountTokenOwnershipLimit,186 sponsoredMintSize: sponsoredDataSize,187 tokenLimit: tokenLimit,188 sponsorTransferTimeout,189 ownerCanTransfer: true,190 ownerCanDestroy: true,191 };192193 194 await collection.setLimits(alice, collectionLimits);195196 197 collectionLimits.tokenLimit += 1;198 await expect(collection.setLimits(alice, collectionLimits)).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);199 });200});