git.delta.rocks / unique-network / refs/commits / 4b68421a192f

difftreelog

source

tests/src/setCollectionLimits.test.ts5.3 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 tokenLimit = 0;3233describe('hooks', () => {34  before(async () => {35    await usingApi(async () => {36      const keyring = new Keyring({ type: 'sr25519' });37      alice = keyring.addFromUri('//Alice');38    });39  });40  it('choose or create collection for testing', async () => {41    await usingApi(async () => {42      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});43    });44  });45});4647describe('setCollectionLimits positive', () => {48  let tx;49  before(async () => {50    await usingApi(async () => {51      const keyring = new Keyring({ type: 'sr25519' });52      alice = keyring.addFromUri('//Alice');53    });54  });55  it('execute setCollectionLimits with predefined params ', async () => {56    await usingApi(async (api: ApiPromise) => {57      tx = api.tx.nft.setCollectionLimits(58        collectionIdForTesting,59        {60          accountTokenOwnershipLimit,61          sponsoredDataSize,62          sponsoredMintSize,63          tokenLimit,64        },65      );66      const events = await submitTransactionAsync(alice, tx);67      const result = getCreateItemResult(events);68      // tslint:disable-next-line:no-unused-expression69      expect(result.success).to.be.true;70    });71  });72  it('get collection limits defined in previous test', async () => {73    await usingApi(async (api: ApiPromise) => {74      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;75      expect(collectionInfo.Limits.AccountTokenOwnershipLimit.toNumber()).to.be.equal(accountTokenOwnershipLimit);76      expect(collectionInfo.Limits.SponsoredMintSize.toNumber()).to.be.equal(sponsoredMintSize);77      expect(collectionInfo.Limits.TokenLimit.toNumber()).to.be.equal(tokenLimit);78      expect(collectionInfo.Limits.SponsorTimeout.toNumber()).to.be.equal(sponsoredDataSize);79    });80  });81});8283describe('setCollectionLimits negative', () => {84  let tx;85  before(async () => {86    await usingApi(async () => {87      const keyring = new Keyring({ type: 'sr25519' });88      alice = keyring.addFromUri('//Alice');89      bob = keyring.addFromUri('//Bob');90    });91  });92  it('execute setCollectionLimits for not exists collection', async () => {93    await usingApi(async (api: ApiPromise) => {94      const collectionCount = await getCreatedCollectionCount(api);95      const nonExistedCollectionId = collectionCount + 1;96      tx = api.tx.nft.setCollectionLimits(97        nonExistedCollectionId,98        {99          accountTokenOwnershipLimit,100          sponsoredDataSize,101          sponsoredMintSize,102          tokenLimit,103        },104      );105      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;106    });107  });108  it('execute setCollectionLimits from user who is not owner of this collection', async () => {109    await usingApi(async (api: ApiPromise) => {110      tx = api.tx.nft.setCollectionLimits(111        collectionIdForTesting,112        {113          accountTokenOwnershipLimit,114          sponsoredDataSize,115          sponsoredMintSize,116          tokenLimit,117        },118      );119      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;120    });121  });122  it('execute setCollectionLimits with incorrect limits', async () => {123    await usingApi(async (api: ApiPromise) => {124      tx = api.tx.nft.setCollectionLimits(125        collectionIdForTesting,126        {127          accountTokenOwnershipLimit: 'awdawd',128          sponsorTransferTimeout: 'awd',129          sponsoredDataSize: '12312312312312312',130          tokenLimit: '-100',131        },132      );133      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;134    });135  });136137  it('fails when trying to enable OwnerCanTransfer after it was disabled', async () => {138    const collectionId = await createCollectionExpectSuccess();139    await setCollectionLimitsExpectSuccess(alice, collectionId, { OwnerCanTransfer: false });140    await setCollectionLimitsExpectFailure(alice, collectionId, { OwnerCanTransfer: true });141  });142143  it('fails when trying to enable OwnerCanDestroy after it was disabled', async () => {144    const collectionId = await createCollectionExpectSuccess();145    await setCollectionLimitsExpectSuccess(alice, collectionId, { OwnerCanDestroy: false });146    await setCollectionLimitsExpectFailure(alice, collectionId, { OwnerCanDestroy: true });147  });148});