git.delta.rocks / unique-network / refs/commits / 74ad9c34019c

difftreelog

tests: add tests for restriction disabling

Yaroslav Bolyukin2021-02-19parent: #94a4122.patch.diff
in: master

1 file changed

modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
before · tests/src/setCollectionLimits.test.ts
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});
after · tests/src/setCollectionLimits.test.ts
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});