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

difftreelog

source

tests/src/setCollectionLimits.test.ts6.9 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 {IKeyringPair} from '@polkadot/types/types';19import {itSub, usingPlaygrounds, expect} from './util';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 = await privateKey({filename: __filename});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    // get collection limits defined previously53    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      // sponsoredMintSize,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 = await privateKey({filename: __filename});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        // sponsoredMintSize,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      // sponsoredMintSize,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    // The first time194    await collection.setLimits(alice, collectionLimits);195196    // The second time - higher token limit197    collectionLimits.tokenLimit += 1;198    await expect(collection.setLimits(alice, collectionLimits)).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);199  });200});