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

difftreelog

tests fixes

kpozdnikin2021-01-11parent: #a013b67.patch.diff
in: master

2 files changed

modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
before · tests/src/setCollectionLimits.test.ts
1// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits2import { ApiPromise, Keyring } from '@polkadot/api';3import { IKeyringPair } from '@polkadot/types/types';4import chai from 'chai';5import chaiAsPromised from 'chai-as-promised';6import usingApi, { submitTransactionAsync } from './substrate/substrate-api';7import { ICollectionInterface } from './types';8import {9  createCollectionExpectSuccess, getCreatedCollectionCount,10  getCreateItemResult,11  getDetailedCollectionInfo,12} from './util/helpers';1314chai.use(chaiAsPromised);15const expect = chai.expect;1617let alice: IKeyringPair;18let bob: IKeyringPair;19let collectionIdForTesting: number;2021const accountTokenOwnershipLimit = 0;22const sponsoredDataSize = 0;23const sponsoredMintSize = 0;24const tokenLimit = 0;2526describe('hooks', () => {27  before(async () => {28    await usingApi(async () => {29      const keyring = new Keyring({ type: 'sr25519' });30      alice = keyring.addFromUri('//Alice');31    });32  });33  it('choose or create collection for testing', async () => {34    await usingApi(async () => {35      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});36      console.log('collectionIdForTesting', collectionIdForTesting);37    });38  });39});4041describe('setCollectionLimits positive', () => {42  let tx;43  before(async () => {44    await usingApi(async () => {45      const keyring = new Keyring({ type: 'sr25519' });46      alice = keyring.addFromUri('//Alice');47    });48  });49  it('execute setCollectionLimits with predefined params ', async () => {50    await usingApi(async (api: ApiPromise) => {51      tx = api.tx.nft.setCollectionLimits(52        collectionIdForTesting,53        {54          accountTokenOwnershipLimit,55          sponsoredDataSize,56          sponsoredMintSize,57          tokenLimit,58        },59      );60      const events = await submitTransactionAsync(alice, tx);61      const result = getCreateItemResult(events);62      // tslint:disable-next-line:no-unused-expression63      expect(result.success).to.be.true;64    });65  });66  it('get collection limits defined in previous test', async () => {67    await usingApi(async (api: ApiPromise) => {68      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;69      expect(collectionInfo.Limits.AccountTokenOwnershipLimit.toNumber()).to.be.equal(accountTokenOwnershipLimit);70      expect(collectionInfo.Limits.SponsoredMintSize.toNumber()).to.be.equal(sponsoredMintSize);71      expect(collectionInfo.Limits.TokenLimit.toNumber()).to.be.equal(tokenLimit);72      expect(collectionInfo.Limits.SponsorTimeout.toNumber()).to.be.equal(sponsoredDataSize);73    });74  });75});7677describe('setCollectionLimits negative', () => {78  let tx;79  before(async () => {80    await usingApi(async () => {81      const keyring = new Keyring({ type: 'sr25519' });82      alice = keyring.addFromUri('//Alice');83      bob = keyring.addFromUri('//Bob');84    });85  });86  it('execute setCollectionLimits for not exists collection', async () => {87    await usingApi(async (api: ApiPromise) => {88      const collectionCount = await getCreatedCollectionCount(api);89      const nonExistedCollectionId = collectionCount + 1;90      tx = api.tx.nft.setCollectionLimits(91        nonExistedCollectionId,92        {93          accountTokenOwnershipLimit,94          sponsoredDataSize,95          sponsoredMintSize,96          tokenLimit,97        },98      );99      try {100        await submitTransactionAsync(alice, tx);101      } catch (e) {102        // tslint:disable-next-line:no-unused-expression103        expect(e).to.be.exist;104      }105    });106  });107  it('execute setCollectionLimits from user who is not owner of this collection', async () => {108    await usingApi(async (api: ApiPromise) => {109      tx = api.tx.nft.setCollectionLimits(110        collectionIdForTesting,111        {112          accountTokenOwnershipLimit,113          sponsoredDataSize,114          sponsoredMintSize,115          tokenLimit,116        },117      );118      try {119        await submitTransactionAsync(bob, tx);120      } catch (e) {121        // tslint:disable-next-line:no-unused-expression122        expect(e).to.be.exist;123      }124    });125  });126  it('execute setCollectionLimits with incorrect limits', async () => {127    await usingApi(async (api: ApiPromise) => {128      tx = api.tx.nft.setCollectionLimits(129        collectionIdForTesting,130        {131          accountTokenOwnershipLimit: 'awdawd',132          sponsorTransferTimeout: 'awd',133          sponsoredDataSize: '12312312312312312',134          tokenLimit: '-100',135        },136      );137      try {138        await submitTransactionAsync(alice, tx);139      } catch (e) {140        // tslint:disable-next-line:no-unused-expression141        expect(e).to.be.exist;142      }143    });144  });145});
after · tests/src/setCollectionLimits.test.ts
1// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits2import { ApiPromise, Keyring } from '@polkadot/api';3import { IKeyringPair } from '@polkadot/types/types';4import chai from 'chai';5import chaiAsPromised from 'chai-as-promised';6import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';7import { ICollectionInterface } from './types';8import {9  createCollectionExpectSuccess, getCreatedCollectionCount,10  getCreateItemResult,11  getDetailedCollectionInfo,12} from './util/helpers';1314chai.use(chaiAsPromised);15const expect = chai.expect;1617let alice: IKeyringPair;18let bob: IKeyringPair;19let collectionIdForTesting: number;2021const accountTokenOwnershipLimit = 0;22const sponsoredDataSize = 0;23const sponsoredMintSize = 0;24const tokenLimit = 0;2526describe('hooks', () => {27  before(async () => {28    await usingApi(async () => {29      const keyring = new Keyring({ type: 'sr25519' });30      alice = keyring.addFromUri('//Alice');31    });32  });33  it('choose or create collection for testing', async () => {34    await usingApi(async () => {35      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});36    });37  });38});3940describe('setCollectionLimits positive', () => {41  let tx;42  before(async () => {43    await usingApi(async () => {44      const keyring = new Keyring({ type: 'sr25519' });45      alice = keyring.addFromUri('//Alice');46    });47  });48  it('execute setCollectionLimits with predefined params ', async () => {49    await usingApi(async (api: ApiPromise) => {50      tx = api.tx.nft.setCollectionLimits(51        collectionIdForTesting,52        {53          accountTokenOwnershipLimit,54          sponsoredDataSize,55          sponsoredMintSize,56          tokenLimit,57        },58      );59      const events = await submitTransactionAsync(alice, tx);60      const result = getCreateItemResult(events);61      // tslint:disable-next-line:no-unused-expression62      expect(result.success).to.be.true;63    });64  });65  it('get collection limits defined in previous test', async () => {66    await usingApi(async (api: ApiPromise) => {67      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;68      expect(collectionInfo.Limits.AccountTokenOwnershipLimit.toNumber()).to.be.equal(accountTokenOwnershipLimit);69      expect(collectionInfo.Limits.SponsoredMintSize.toNumber()).to.be.equal(sponsoredMintSize);70      expect(collectionInfo.Limits.TokenLimit.toNumber()).to.be.equal(tokenLimit);71      expect(collectionInfo.Limits.SponsorTimeout.toNumber()).to.be.equal(sponsoredDataSize);72    });73  });74});7576describe('setCollectionLimits negative', () => {77  let tx;78  before(async () => {79    await usingApi(async () => {80      const keyring = new Keyring({ type: 'sr25519' });81      alice = keyring.addFromUri('//Alice');82      bob = keyring.addFromUri('//Bob');83    });84  });85  it('execute setCollectionLimits for not exists collection', async () => {86    await usingApi(async (api: ApiPromise) => {87      const collectionCount = await getCreatedCollectionCount(api);88      const nonExistedCollectionId = collectionCount + 1;89      tx = api.tx.nft.setCollectionLimits(90        nonExistedCollectionId,91        {92          accountTokenOwnershipLimit,93          sponsoredDataSize,94          sponsoredMintSize,95          tokenLimit,96        },97      );98      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;99    });100  });101  it('execute setCollectionLimits from user who is not owner of this collection', async () => {102    await usingApi(async (api: ApiPromise) => {103      tx = api.tx.nft.setCollectionLimits(104        collectionIdForTesting,105        {106          accountTokenOwnershipLimit,107          sponsoredDataSize,108          sponsoredMintSize,109          tokenLimit,110        },111      );112      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;113    });114  });115  it('execute setCollectionLimits with incorrect limits', async () => {116    await usingApi(async (api: ApiPromise) => {117      tx = api.tx.nft.setCollectionLimits(118        collectionIdForTesting,119        {120          accountTokenOwnershipLimit: 'awdawd',121          sponsorTransferTimeout: 'awd',122          sponsoredDataSize: '12312312312312312',123          tokenLimit: '-100',124        },125      );126      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;127    });128  });129});
modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
--- a/tests/src/setSchemaVersion.test.ts
+++ b/tests/src/setSchemaVersion.test.ts
@@ -4,7 +4,7 @@
 import BN from 'bn.js';
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import usingApi, { submitTransactionAsync } from './substrate/substrate-api';
+import usingApi, {submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
 import { ICollectionInterface } from './types';
 import {
   createCollectionExpectSuccess,
@@ -92,12 +92,13 @@
       const collectionCount = await getCreatedCollectionCount(api);
       const nonExistedCollectionId = collectionCount + 1;
       tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');
-      try {
+      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
+      /*try {
         await submitTransactionAsync(alice, tx);
       } catch (e) {
         // tslint:disable-next-line:no-unused-expression
         expect(e).to.be.exist;
-      }
+      }*/
     });
   });
 
@@ -116,13 +117,15 @@
   it('execute setSchemaVersion for deleted collection', async () => {
     await usingApi(async (api: ApiPromise) => {
       await destroyCollectionExpectSuccess(collectionIdForTesting);
-      try {
+      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');
+      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
+      /*try {
         tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');
         await submitTransactionAsync(alice, tx);
       } catch (e) {
         // tslint:disable-next-line:no-unused-expression
         expect(e).to.be.exist;
-      }
+      }*/
     });
   });
 });