123456789101112131415161718import type {IKeyringPair} from '@polkadot/types/types';19import {itSub, usingPlaygrounds, expect} from './util/index.js';20import {NON_EXISTENT_COLLECTION_ID} from '@unique/playgrounds/src/types.js';2122const accountTokenOwnershipLimit = 0;23const sponsoredDataSize = 0;24const sponsorTransferTimeout = 1;25const tokenLimit = 10;2627describe('setCollectionLimits positive', () => {28 let alice: IKeyringPair;29 let bob: IKeyringPair;3031 before(async () => {32 await usingPlaygrounds(async (helper, privateKey) => {33 const donor = await privateKey({url: import.meta.url});34 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);35 });36 });3738 itSub('execute setCollectionLimits with predefined params', async ({helper}) => {39 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-1', tokenPrefix: 'SCL'});4041 await collection.setLimits(42 alice,43 {44 accountTokenOwnershipLimit,45 sponsoredDataSize,46 tokenLimit,47 sponsorTransferTimeout,48 ownerCanTransfer: true,49 ownerCanDestroy: true,50 },51 );5253 54 const collectionInfo = await collection.getEffectiveLimits();5556 expect(collectionInfo.accountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);57 expect(collectionInfo.sponsoredDataSize).to.be.equal(sponsoredDataSize);58 expect(collectionInfo.tokenLimit).to.be.equal(tokenLimit);59 expect(collectionInfo.sponsorTransferTimeout).to.be.equal(sponsorTransferTimeout);60 expect(collectionInfo.ownerCanTransfer).to.be.true;61 expect(collectionInfo.ownerCanDestroy).to.be.true;62 });6364 itSub('Set the same token limit twice', async ({helper}) => {65 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-2', tokenPrefix: 'SCL'});6667 const collectionLimits = {68 accountTokenOwnershipLimit,69 sponsoredDataSize,70 tokenLimit,71 sponsorTransferTimeout,72 ownerCanTransfer: true,73 ownerCanDestroy: true,74 };7576 await collection.setLimits(alice, collectionLimits);7778 const collectionInfo1 = await collection.getEffectiveLimits();7980 expect(collectionInfo1.tokenLimit).to.be.equal(tokenLimit);8182 await collection.setLimits(alice, collectionLimits);83 const collectionInfo2 = await collection.getEffectiveLimits();84 expect(collectionInfo2.tokenLimit).to.be.equal(tokenLimit);85 });8687 itSub('execute setCollectionLimits from admin collection', async ({helper}) => {88 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-3', tokenPrefix: 'SCL'});89 await collection.addAdmin(alice, {Substrate: bob.address});9091 const collectionLimits = {92 accountTokenOwnershipLimit,93 sponsoredDataSize,94 95 tokenLimit,96 };9798 await expect(collection.setLimits(alice, collectionLimits)).to.not.be.rejected;99 });100});101102describe('setCollectionLimits negative', () => {103 let alice: IKeyringPair;104 let bob: IKeyringPair;105106 before(async () => {107 await usingPlaygrounds(async (helper, privateKey) => {108 const donor = await privateKey({url: import.meta.url});109 [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);110 });111 });112113 itSub('execute setCollectionLimits for not exists collection', async ({helper}) => {114 const nonExistentCollectionId = NON_EXISTENT_COLLECTION_ID;115 await expect(helper.collection.setLimits(116 alice,117 nonExistentCollectionId,118 {119 accountTokenOwnershipLimit,120 sponsoredDataSize,121 122 tokenLimit,123 },124 )).to.be.rejectedWith(/common\.CollectionNotFound/);125 });126127 itSub('execute setCollectionLimits from user who is not owner of this collection', async ({helper}) => {128 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-1', tokenPrefix: 'SCL'});129130 await expect(collection.setLimits(bob, {131 accountTokenOwnershipLimit,132 sponsoredDataSize,133 134 tokenLimit,135 })).to.be.rejectedWith(/common\.NoPermission/);136 });137138 itSub('fails when trying to enable OwnerCanTransfer after it was disabled', async ({helper}) => {139 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-2', tokenPrefix: 'SCL'});140141 await collection.setLimits(alice, {142 accountTokenOwnershipLimit,143 sponsoredDataSize,144 tokenLimit,145 sponsorTransferTimeout,146 ownerCanTransfer: false,147 ownerCanDestroy: true,148 });149150 await expect(collection.setLimits(alice, {151 accountTokenOwnershipLimit,152 sponsoredDataSize,153 tokenLimit,154 sponsorTransferTimeout,155 ownerCanTransfer: true,156 ownerCanDestroy: true,157 })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);158 });159160 itSub('fails when trying to enable OwnerCanDestroy after it was disabled', async ({helper}) => {161 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-3', tokenPrefix: 'SCL'});162163 await collection.setLimits(alice, {164 accountTokenOwnershipLimit,165 sponsoredDataSize,166 tokenLimit,167 sponsorTransferTimeout,168 ownerCanTransfer: true,169 ownerCanDestroy: false,170 });171172 await expect(collection.setLimits(alice, {173 accountTokenOwnershipLimit,174 sponsoredDataSize,175 tokenLimit,176 sponsorTransferTimeout,177 ownerCanTransfer: true,178 ownerCanDestroy: true,179 })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);180 });181182 itSub('Setting the higher token limit fails', async ({helper}) => {183 const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-4', tokenPrefix: 'SCL'});184185 const collectionLimits = {186 accountTokenOwnershipLimit: accountTokenOwnershipLimit,187 sponsoredMintSize: sponsoredDataSize,188 tokenLimit: tokenLimit,189 sponsorTransferTimeout,190 ownerCanTransfer: true,191 ownerCanDestroy: true,192 };193194 195 await collection.setLimits(alice, collectionLimits);196197 198 collectionLimits.tokenLimit += 1;199 await expect(collection.setLimits(alice, collectionLimits)).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);200 });201});