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

difftreelog

source

tests/src/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 {IKeyringPair} from '@polkadot/types/types';19import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';21import {itSub, usingPlaygrounds} from './util/playgrounds';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526const accountTokenOwnershipLimit = 0;27const sponsoredDataSize = 0;28const sponsorTransferTimeout = 1;29const tokenLimit = 10;3031describe('setCollectionLimits positive', () => {32  let alice: IKeyringPair;33  let bob: IKeyringPair;3435  before(async () => {36    await usingPlaygrounds(async (helper, privateKey) => {37      const donor = privateKey('//Alice');38      [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);39    });40  });4142  itSub('execute setCollectionLimits with predefined params', async ({helper}) => {43    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-1', tokenPrefix: 'SCL'});4445    await collection.setLimits(46      alice,47      {48        accountTokenOwnershipLimit,49        sponsoredDataSize,50        tokenLimit,51        sponsorTransferTimeout,52        ownerCanTransfer: true,53        ownerCanDestroy: true,54      },55    );5657    // get collection limits defined previously58    const collectionInfo = await collection.getEffectiveLimits();5960    expect(collectionInfo.accountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);61    expect(collectionInfo.sponsoredDataSize).to.be.equal(sponsoredDataSize);62    expect(collectionInfo.tokenLimit).to.be.equal(tokenLimit);63    expect(collectionInfo.sponsorTransferTimeout).to.be.equal(sponsorTransferTimeout);64    expect(collectionInfo.ownerCanTransfer).to.be.true;65    expect(collectionInfo.ownerCanDestroy).to.be.true;66  });6768  itSub('Set the same token limit twice', async ({helper}) => {69    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-2', tokenPrefix: 'SCL'});7071    const collectionLimits = {72      accountTokenOwnershipLimit,73      sponsoredDataSize,74      tokenLimit,75      sponsorTransferTimeout,76      ownerCanTransfer: true,77      ownerCanDestroy: true,78    };7980    await collection.setLimits(alice, collectionLimits);8182    const collectionInfo1 = await collection.getEffectiveLimits();83      84    expect(collectionInfo1.tokenLimit).to.be.equal(tokenLimit);8586    await collection.setLimits(alice, collectionLimits);87    const collectionInfo2 = await collection.getEffectiveLimits();88    expect(collectionInfo2.tokenLimit).to.be.equal(tokenLimit);89  });9091  itSub('execute setCollectionLimits from admin collection', async ({helper}) => {92    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-3', tokenPrefix: 'SCL'});93    await collection.addAdmin(alice, {Substrate: bob.address});9495    const collectionLimits = {96      accountTokenOwnershipLimit,97      sponsoredDataSize,98      // sponsoredMintSize,99      tokenLimit,100    };101102    await expect(collection.setLimits(alice, collectionLimits)).to.not.be.rejected;103  });104});105106describe('setCollectionLimits negative', () => {107  let alice: IKeyringPair;108  let bob: IKeyringPair;109110  before(async () => {111    await usingPlaygrounds(async (helper, privateKey) => {112      const donor = privateKey('//Alice');113      [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);114    });115  });116  117  itSub('execute setCollectionLimits for not exists collection', async ({helper}) => {118    const nonExistentCollectionId = (1 << 32) - 1;119    await expect(helper.collection.setLimits(120      alice,121      nonExistentCollectionId,122      {123        accountTokenOwnershipLimit,124        sponsoredDataSize,125        // sponsoredMintSize,126        tokenLimit,127      },128    )).to.be.rejectedWith(/common\.CollectionNotFound/);129  });130131  itSub('execute setCollectionLimits from user who is not owner of this collection', async ({helper}) => {132    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-1', tokenPrefix: 'SCL'});133134    await expect(collection.setLimits(bob, {135      accountTokenOwnershipLimit,136      sponsoredDataSize,137      // sponsoredMintSize,138      tokenLimit,139    })).to.be.rejectedWith(/common\.NoPermission/);140  });141142  itSub('fails when trying to enable OwnerCanTransfer after it was disabled', async ({helper}) => {143    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-2', tokenPrefix: 'SCL'});144145    await collection.setLimits(alice, {146      accountTokenOwnershipLimit,147      sponsoredDataSize,148      tokenLimit,149      sponsorTransferTimeout,150      ownerCanTransfer: false,151      ownerCanDestroy: true,152    });153154    await expect(collection.setLimits(alice, {155      accountTokenOwnershipLimit,156      sponsoredDataSize,157      tokenLimit,158      sponsorTransferTimeout,159      ownerCanTransfer: true,160      ownerCanDestroy: true,161    })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);162  });163164  itSub('fails when trying to enable OwnerCanDestroy after it was disabled', async ({helper}) => {165    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-3', tokenPrefix: 'SCL'});166167    await collection.setLimits(alice, {168      accountTokenOwnershipLimit,169      sponsoredDataSize,170      tokenLimit,171      sponsorTransferTimeout,172      ownerCanTransfer: true,173      ownerCanDestroy: false,174    });175176    await expect(collection.setLimits(alice, {177      accountTokenOwnershipLimit,178      sponsoredDataSize,179      tokenLimit,180      sponsorTransferTimeout,181      ownerCanTransfer: true,182      ownerCanDestroy: true,183    })).to.be.rejectedWith(/common\.OwnerPermissionsCantBeReverted/);184  });185186  itSub('Setting the higher token limit fails', async ({helper}) => {187    const collection = await helper.nft.mintCollection(alice, {name: 'SetCollectionLimits-Neg-4', tokenPrefix: 'SCL'});188      189    const collectionLimits = {190      accountTokenOwnershipLimit: accountTokenOwnershipLimit,191      sponsoredMintSize: sponsoredDataSize,192      tokenLimit: tokenLimit,193      sponsorTransferTimeout,194      ownerCanTransfer: true,195      ownerCanDestroy: true,196    };197198    // The first time199    await collection.setLimits(alice, collectionLimits);200201    // The second time - higher token limit202    collectionLimits.tokenLimit += 1;203    await expect(collection.setLimits(alice, collectionLimits)).to.be.rejectedWith(/common\.CollectionTokenLimitExceeded/);204  });205});