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

difftreelog

source

tests/src/setSchemaVersion.test.ts5.8 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  addCollectionAdminExpectSuccess,20} from './util/helpers';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425let alice: IKeyringPair;26let bob: IKeyringPair;27let collectionIdForTesting: number;2829/*301. We create collection.312. Save just created collection id.323. Use this id for setSchemaVersion.33*/3435describe('hooks', () => {36  before(async () => {37    await usingApi(async () => {38      const keyring = new Keyring({ type: 'sr25519' });39      alice = keyring.addFromUri('//Alice');40    });41  });42  it('choose or create collection for testing', async () => {43    await usingApi(async () => {44      collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});45    });46  });47});4849describe('setSchemaVersion positive', () => {50  let tx;51  before(async () => {52    await usingApi(async () => {53      const keyring = new Keyring({ type: 'sr25519' });54      alice = keyring.addFromUri('//Alice');55    });56  });57  it('execute setSchemaVersion with image url and unique ', async () => {58    await usingApi(async (api: ApiPromise) => {59      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');60      const events = await submitTransactionAsync(alice, tx);61      const result = getCreateItemResult(events);62      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;63      // tslint:disable-next-line:no-unused-expression64      expect(result.success).to.be.true;65      // tslint:disable-next-line:no-unused-expression66      expect(collectionInfo).to.be.exist;67      // tslint:disable-next-line:no-unused-expression68      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');69    });70  });71});7273describe('Collection admin setSchemaVersion positive', () => {74  let tx;75  before(async () => {76    await usingApi(async () => {77      const keyring = new Keyring({ type: 'sr25519' });78      alice = keyring.addFromUri('//Alice');79      bob = keyring.addFromUri('//Bob');80      await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob);81    });82  });83  it('execute setSchemaVersion with image url and unique ', async () => {84    await usingApi(async (api: ApiPromise) => {85      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');86      const events = await submitTransactionAsync(bob, tx);87      const result = getCreateItemResult(events);88      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;89      // tslint:disable-next-line:no-unused-expression90      expect(result.success).to.be.true;91      // tslint:disable-next-line:no-unused-expression92      expect(collectionInfo).to.be.exist;93      // tslint:disable-next-line:no-unused-expression94      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');95    });96  });9798  it('validate schema version with just entered data', async () => {99    await usingApi(async (api: ApiPromise) => {100      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');101      const events = await submitTransactionAsync(bob, tx);102      const result = getCreateItemResult(events);103      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting) as ICollectionInterface;104      // tslint:disable-next-line:no-unused-expression105      expect(result.success).to.be.true;106      // tslint:disable-next-line:no-unused-expression107      expect(collectionInfo).to.be.exist;108      // tslint:disable-next-line:no-unused-expression109      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('ImageURL');110    });111  });112});113114describe('setSchemaVersion negative', () => {115  let tx;116  before(async () => {117    await usingApi(async () => {118      const keyring = new Keyring({ type: 'sr25519' });119      alice = keyring.addFromUri('//Alice');120    });121  });122  it('execute setSchemaVersion for not exists collection', async () => {123    await usingApi(async (api: ApiPromise) => {124      const collectionCount = await getCreatedCollectionCount(api);125      const nonExistedCollectionId = collectionCount + 1;126      tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');127      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;128    });129  });130131  it('execute setSchemaVersion with not correct schema version', async () => {132    await usingApi(async (api: ApiPromise) => {133      const consoleError = console.error;134      console.error = () => {};135      try {136        tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');137        await submitTransactionAsync(alice, tx);138      } catch (e) {139        // tslint:disable-next-line:no-unused-expression140        expect(e).to.be.exist;141      } finally {142        console.error = consoleError;143      }144    });145  });146147  it('execute setSchemaVersion for deleted collection', async () => {148    await usingApi(async (api: ApiPromise) => {149      await destroyCollectionExpectSuccess(collectionIdForTesting);150      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');151      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;152    });153  });154});