git.delta.rocks / unique-network / refs/commits / 172f80a3eea4

difftreelog

source

tests/src/setCollectionLimits.test.ts6.1 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits7import { ApiPromise, Keyring } from '@polkadot/api';8import { IKeyringPair } from '@polkadot/types/types';9import chai from 'chai';10import chaiAsPromised from 'chai-as-promised';11import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';12import { ICollectionInterface } from './types';13import {14  createCollectionExpectSuccess, getCreatedCollectionCount,15  getCreateItemResult,16  getDetailedCollectionInfo,17  setCollectionLimitsExpectFailure,18  setCollectionLimitsExpectSuccess,19} from './util/helpers';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324let alice: IKeyringPair;25let bob: IKeyringPair;26let collectionIdForTesting: number;2728const accountTokenOwnershipLimit = 0;29const sponsoredDataSize = 0;30const sponsoredMintSize = 0;31const sponsorTimeout = 1;32const tokenLimit = 1;3334describe('setCollectionLimits positive', () => {35  let tx;36  before(async () => {37    await usingApi(async () => {38      const keyring = new Keyring({ type: 'sr25519' });39      alice = keyring.addFromUri('//Alice');40      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});41    });42  });43  it('execute setCollectionLimits with predefined params ', async () => {44    await usingApi(async (api: ApiPromise) => {45      tx = api.tx.nft.setCollectionLimits(46        collectionIdForTesting,47        {48          AccountTokenOwnershipLimit: accountTokenOwnershipLimit,49          SponsoredMintSize: sponsoredDataSize,50          TokenLimit: tokenLimit,51          SponsorTimeout: sponsorTimeout,52          OwnerCanTransfer: true,53          OwnerCanDestroy: true54        },55      );56      const events = await submitTransactionAsync(alice, tx);57      const result = getCreateItemResult(events);5859      // get collection limits defined previously60      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;6162      // tslint:disable-next-line:no-unused-expression63      expect(result.success).to.be.true;64      expect(collectionInfo.Limits.AccountTokenOwnershipLimit).to.be.equal(accountTokenOwnershipLimit);65      expect(collectionInfo.Limits.SponsoredDataSize).to.be.equal(sponsoredDataSize);66      expect(collectionInfo.Limits.TokenLimit).to.be.equal(tokenLimit);67      expect(collectionInfo.Limits.SponsorTimeout).to.be.equal(sponsorTimeout);68      expect(collectionInfo.Limits.OwnerCanTransfer).to.be.true;69      expect(collectionInfo.Limits.OwnerCanDestroy).to.be.true;70    });71  });72});7374describe('setCollectionLimits negative', () => {75  let tx;76  before(async () => {77    await usingApi(async () => {78      const keyring = new Keyring({ type: 'sr25519' });79      alice = keyring.addFromUri('//Alice');80      bob = keyring.addFromUri('//Bob');81      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});82    });83  });84  it('execute setCollectionLimits for not exists collection', async () => {85    await usingApi(async (api: ApiPromise) => {86      const collectionCount = await getCreatedCollectionCount(api);87      const nonExistedCollectionId = collectionCount + 1;88      tx = api.tx.nft.setCollectionLimits(89        nonExistedCollectionId,90        {91          accountTokenOwnershipLimit,92          sponsoredDataSize,93          sponsoredMintSize,94          tokenLimit,95        },96      );97      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;98    });99  });100  it('execute setCollectionLimits from user who is not owner of this collection', async () => {101    await usingApi(async (api: ApiPromise) => {102      tx = api.tx.nft.setCollectionLimits(103        collectionIdForTesting,104        {105          accountTokenOwnershipLimit,106          sponsoredDataSize,107          sponsoredMintSize,108          tokenLimit,109        },110      );111      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;112    });113  });114  it('execute setCollectionLimits with incorrect limits', async () => {115    await usingApi(async (api: ApiPromise) => {116      tx = api.tx.nft.setCollectionLimits(117        collectionIdForTesting,118        {119          accountTokenOwnershipLimit: 'awdawd',120          sponsorTransferTimeout: 'awd',121          sponsoredDataSize: '12312312312312312',122          tokenLimit: '-100',123        },124      );125      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;126    });127  });128129  it('fails when trying to enable OwnerCanTransfer after it was disabled', async () => {130    const collectionId = await createCollectionExpectSuccess();131    await setCollectionLimitsExpectSuccess(alice, collectionId, { 132      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,133      SponsoredMintSize: sponsoredDataSize,134      TokenLimit: tokenLimit,135      SponsorTimeout: sponsorTimeout,136      OwnerCanTransfer: false,137      OwnerCanDestroy: true138    });139    await setCollectionLimitsExpectFailure(alice, collectionId, { 140      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,141      SponsoredMintSize: sponsoredDataSize,142      TokenLimit: tokenLimit,143      SponsorTimeout: sponsorTimeout,144      OwnerCanTransfer: true,145      OwnerCanDestroy: true146    });147  });148149  it('fails when trying to enable OwnerCanDestroy after it was disabled', async () => {150    const collectionId = await createCollectionExpectSuccess();151    await setCollectionLimitsExpectSuccess(alice, collectionId, {152      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,153      SponsoredMintSize: sponsoredDataSize,154      TokenLimit: tokenLimit,155      SponsorTimeout: sponsorTimeout,156      OwnerCanTransfer: true,157      OwnerCanDestroy: false158    });159    await setCollectionLimitsExpectFailure(alice, collectionId, { 160      AccountTokenOwnershipLimit: accountTokenOwnershipLimit,161      SponsoredMintSize: sponsoredDataSize,162      TokenLimit: tokenLimit,163      SponsorTimeout: sponsorTimeout,164      OwnerCanTransfer: true,165      OwnerCanDestroy: true166    });167  });168});