git.delta.rocks / unique-network / refs/commits / 22b5fa633f47

difftreelog

source

tests/src/setCollectionLimits.test.ts4.5 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} from './util/helpers';1819chai.use(chaiAsPromised);20const expect = chai.expect;2122let alice: IKeyringPair;23let bob: IKeyringPair;24let collectionIdForTesting: number;2526const accountTokenOwnershipLimit = 0;27const sponsoredDataSize = 0;28const sponsoredMintSize = 0;29const tokenLimit = 0;3031describe('hooks', () => {32  before(async () => {33    await usingApi(async () => {34      const keyring = new Keyring({ type: 'sr25519' });35      alice = keyring.addFromUri('//Alice');36    });37  });38  it('choose or create collection for testing', async () => {39    await usingApi(async () => {40      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});41    });42  });43});4445describe('setCollectionLimits positive', () => {46  let tx;47  before(async () => {48    await usingApi(async () => {49      const keyring = new Keyring({ type: 'sr25519' });50      alice = keyring.addFromUri('//Alice');51    });52  });53  it('execute setCollectionLimits with predefined params ', async () => {54    await usingApi(async (api: ApiPromise) => {55      tx = api.tx.nft.setCollectionLimits(56        collectionIdForTesting,57        {58          accountTokenOwnershipLimit,59          sponsoredDataSize,60          sponsoredMintSize,61          tokenLimit,62        },63      );64      const events = await submitTransactionAsync(alice, tx);65      const result = getCreateItemResult(events);66      // tslint:disable-next-line:no-unused-expression67      expect(result.success).to.be.true;68    });69  });70  it('get collection limits defined in previous test', async () => {71    await usingApi(async (api: ApiPromise) => {72      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;73      expect(collectionInfo.Limits.AccountTokenOwnershipLimit.toNumber()).to.be.equal(accountTokenOwnershipLimit);74      expect(collectionInfo.Limits.SponsoredMintSize.toNumber()).to.be.equal(sponsoredMintSize);75      expect(collectionInfo.Limits.TokenLimit.toNumber()).to.be.equal(tokenLimit);76      expect(collectionInfo.Limits.SponsorTimeout.toNumber()).to.be.equal(sponsoredDataSize);77    });78  });79});8081describe('setCollectionLimits negative', () => {82  let tx;83  before(async () => {84    await usingApi(async () => {85      const keyring = new Keyring({ type: 'sr25519' });86      alice = keyring.addFromUri('//Alice');87      bob = keyring.addFromUri('//Bob');88    });89  });90  it('execute setCollectionLimits for not exists collection', async () => {91    await usingApi(async (api: ApiPromise) => {92      const collectionCount = await getCreatedCollectionCount(api);93      const nonExistedCollectionId = collectionCount + 1;94      tx = api.tx.nft.setCollectionLimits(95        nonExistedCollectionId,96        {97          accountTokenOwnershipLimit,98          sponsoredDataSize,99          sponsoredMintSize,100          tokenLimit,101        },102      );103      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;104    });105  });106  it('execute setCollectionLimits from user who is not owner of this collection', async () => {107    await usingApi(async (api: ApiPromise) => {108      tx = api.tx.nft.setCollectionLimits(109        collectionIdForTesting,110        {111          accountTokenOwnershipLimit,112          sponsoredDataSize,113          sponsoredMintSize,114          tokenLimit,115        },116      );117      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;118    });119  });120  it('execute setCollectionLimits with incorrect limits', async () => {121    await usingApi(async (api: ApiPromise) => {122      tx = api.tx.nft.setCollectionLimits(123        collectionIdForTesting,124        {125          accountTokenOwnershipLimit: 'awdawd',126          sponsorTransferTimeout: 'awd',127          sponsoredDataSize: '12312312312312312',128          tokenLimit: '-100',129        },130      );131      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;132    });133  });134});