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

difftreelog

source

tests/src/setSchemaVersion.test.ts4.6 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#setschemaversion7import { 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,15  destroyCollectionExpectSuccess,16  getCreatedCollectionCount,17  getCreateItemResult,18  getDetailedCollectionInfo,19} from './util/helpers';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324let alice: IKeyringPair;25let collectionIdForTesting: number;2627/*281. We create collection.292. Save just created collection id.303. Use this id for setSchemaVersion.31*/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('setSchemaVersion 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 setSchemaVersion with image url and unique ', async () => {56    await usingApi(async (api: ApiPromise) => {57      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');58      const events = await submitTransactionAsync(alice, tx);59      const result = getCreateItemResult(events);60      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;61      // tslint:disable-next-line:no-unused-expression62      expect(result.success).to.be.true;63      // tslint:disable-next-line:no-unused-expression64      expect(collectionInfo).to.be.exist;65      // tslint:disable-next-line:no-unused-expression66      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');67    });68  });6970  it('validate schema version with just entered data', async () => {71    await usingApi(async (api: ApiPromise) => {72      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');73      const events = await submitTransactionAsync(alice, tx);74      const result = getCreateItemResult(events);75      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;76      // tslint:disable-next-line:no-unused-expression77      expect(result.success).to.be.true;78      // tslint:disable-next-line:no-unused-expression79      expect(collectionInfo).to.be.exist;80      // tslint:disable-next-line:no-unused-expression81      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('ImageURL');82    });83  });84});8586describe('setSchemaVersion negative', () => {87  let tx;88  before(async () => {89    await usingApi(async () => {90      const keyring = new Keyring({ type: 'sr25519' });91      alice = keyring.addFromUri('//Alice');92    });93  });94  it('execute setSchemaVersion for not exists collection', async () => {95    await usingApi(async (api: ApiPromise) => {96      const collectionCount = await getCreatedCollectionCount(api);97      const nonExistedCollectionId = collectionCount + 1;98      tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');99      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;100    });101  });102103  it('execute setSchemaVersion with not correct schema version', async () => {104    await usingApi(async (api: ApiPromise) => {105      const consoleError = console.error;106      console.error = (message: string) => {};107      try {108        tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');109        await submitTransactionAsync(alice, tx);110      } catch (e) {111        // tslint:disable-next-line:no-unused-expression112        expect(e).to.be.exist;113      } finally {114        console.error = consoleError;115      }116    });117  });118119  it('execute setSchemaVersion for deleted collection', async () => {120    await usingApi(async (api: ApiPromise) => {121      await destroyCollectionExpectSuccess(collectionIdForTesting);122      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');123      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;124    });125  });126});