git.delta.rocks / unique-network / refs/commits / 49640f3b718a

difftreelog

source

tests/src/setSchemaVersion.test.ts4.8 KiBsourcehistory
1// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits2import { ApiPromise, Keyring } from '@polkadot/api';3import { IKeyringPair } from '@polkadot/types/types';4import BN from 'bn.js';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';7import usingApi, { submitTransactionAsync } from './substrate/substrate-api';8import { ICollectionInterface } from './types';9import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, getCreateItemResult } from './util/helpers';1011chai.use(chaiAsPromised);12const expect = chai.expect;1314let alice: IKeyringPair;15let collectionIdForTesting: number;1617/*181. We create collection.192. Save just created collection id.203. Use this id for setSchemaVersion.21*/2223const getDetailedCollectionInfo = async (api: ApiPromise, collectionId: number)24  : Promise<ICollectionInterface | null> => {25  return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;26};2728const getCreatedCollectionCount = async (api: ApiPromise): Promise<number> => {29  // set global object - collectionsCount30  return (await api.query.nft.createdCollectionCount() as unknown as BN).toNumber();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: '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);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);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      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  });107108  it('execute setSchemaVersion with not correct schema version', async () => {109    await usingApi(async (api: ApiPromise) => {110      try {111        tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');112        await submitTransactionAsync(alice, tx);113      } catch (e) {114        // tslint:disable-next-line:no-unused-expression115        expect(e).to.be.exist;116      }117    });118  });119120  it('execute setSchemaVersion for deleted collection', async () => {121    await usingApi(async (api: ApiPromise) => {122      await destroyCollectionExpectSuccess(collectionIdForTesting);123      try {124        tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');125        await submitTransactionAsync(alice, tx);126      } catch (e) {127        // tslint:disable-next-line:no-unused-expression128        expect(e).to.be.exist;129      }130    });131  });132});