git.delta.rocks / unique-network / refs/commits / cc9eeb2f3b2c

difftreelog

source

js-packages/tests/setCollectionLimits.test.ts7.0 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits18import type {IKeyringPair} from '@polkadot/types/types';19import {itSub, usingPlaygrounds, expect} from './util/index.js';20import {NON_EXISTENT_COLLECTION_ID} from '@unique/playgrounds/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    // get collection limits defined previously54    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      // sponsoredMintSize,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        // sponsoredMintSize,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      // sponsoredMintSize,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    // The first time195    await collection.setLimits(alice, collectionLimits);196197    // The second time - higher token limit198    collectionLimits.tokenLimit += 1;199    await expect(collection.setLimits(alice, collectionLimits)).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);200  });201});