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

difftreelog

setSchema test scenarios

kpozdnikin2020-12-30parent: #aa7dc42.patch.diff
in: master

1 file changed

modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
before · tests/src/setSchemaVersion.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 BN from 'bn.js';5import chai from 'chai';6import chaiAsPromised from 'chai-as-promised';7import privateKey from './substrate/privateKey';8import promisifySubstrate from './substrate/promisify-substrate';9import usingApi, { submitTransactionAsync } from './substrate/substrate-api';10import { ICollectionInterface } from './types';11import { createCollectionExpectSuccess, destroyCollectionExpectSuccess, getCreateItemResult } from './util/helpers';1213chai.use(chaiAsPromised);14const expect = chai.expect;1516let alice: IKeyringPair;17let collectionIdForTesting: number;1819/*201. We create collection.212. Save just created collection id.223. Use this id for setSchemaVersion.23*/2425async function getDetailedCollectionInfo(api: ApiPromise, collectionId: number)26  : Promise<ICollectionInterface | null> {27  return await api.query.nft.collection(collectionId) as unknown as ICollectionInterface;28}2930async function getCollectionCount(api: ApiPromise): Promise<number> {31  // set global object - collectionsCount32  return (await api.query.nft.collectionCount() as unknown as BN).toNumber();33}3435function utf8Decoder(name: [Uint8Array]) {36  const collectionNameArr = Array.prototype.slice.call(name);37  return String.fromCharCode(...collectionNameArr);38}3940describe('hooks', () => {41  before(async () => {42    await usingApi(async (api) => {43      const keyring = new Keyring({ type: 'sr25519' });44      alice = keyring.addFromUri('//Alice');45    });46  });47  it('choose or create collection for testing', async () => {48    await usingApi(async (api: ApiPromise) => {49      const newCollectionId = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});50      console.log('newCollectionId', newCollectionId);51      collectionIdForTesting = newCollectionId;52    });53  });54});5556describe('setSchemaVersion positive', () => {57  let tx;58  before(async () => {59    await usingApi(async (api) => {60      const keyring = new Keyring({ type: 'sr25519' });61      alice = keyring.addFromUri('//Alice');62    });63  });64  it('execute setSchemaVersion with image url and unique ', async () => {65    await usingApi(async (api: ApiPromise) => {66      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Unique');67      const events = await submitTransactionAsync(alice, tx);68      const result = getCreateItemResult(events);69      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);70      // tslint:disable-next-line:no-unused-expression71      expect(result.success).to.be.true;72      // tslint:disable-next-line:no-unused-expression73      expect(collectionInfo).to.be.exist;74      // tslint:disable-next-line:no-unused-expression75      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('Unique');76    });77  });7879  it('validate schema version with just entered data', async () => {80    await usingApi(async (api: ApiPromise) => {81      tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');82      const events = await submitTransactionAsync(alice, tx);83      const result = getCreateItemResult(events);84      const collectionInfo = await getDetailedCollectionInfo(api, collectionIdForTesting);85      // tslint:disable-next-line:no-unused-expression86      expect(result.success).to.be.true;87      // tslint:disable-next-line:no-unused-expression88      expect(collectionInfo).to.be.exist;89      // tslint:disable-next-line:no-unused-expression90      expect(collectionInfo ? collectionInfo.SchemaVersion.toString() : '').to.be.equal('ImageURL');91    });92  });93});9495describe('setSchemaVersion negative', () => {96  let tx;97  before(async () => {98    await usingApi(async (api) => {99      const keyring = new Keyring({ type: 'sr25519' });100      alice = keyring.addFromUri('//Alice');101    });102  });103  it('execute setSchemaVersion for not exists collection', async () => {104    await usingApi(async (api: ApiPromise) => {105      const collectionCount = await getCollectionCount(api);106      const nonExistedCollectionId = collectionCount + 1;107      tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');108      try {109        await submitTransactionAsync(alice, tx);110      } catch (e) {111        // tslint:disable-next-line:no-unused-expression112        expect(e).to.be.exist;113      }114    });115  });116117  it('execute setSchemaVersion with not correct schema version', async () => {118    await usingApi(async (api: ApiPromise) => {119      try {120        tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'Test');121        await submitTransactionAsync(alice, tx);122      } catch (e) {123        // tslint:disable-next-line:no-unused-expression124        expect(e).to.be.exist;125      }126    });127  });128129  it('execute setSchemaVersion for deleted collection', async () => {130    await usingApi(async (api: ApiPromise) => {131      const collectionCount = await getCollectionCount(api);132      await destroyCollectionExpectSuccess(collectionCount);133      try {134        tx = api.tx.nft.setSchemaVersion(collectionCount, 'ImageURL');135        await submitTransactionAsync(alice, tx);136      } catch (e) {137        // tslint:disable-next-line:no-unused-expression138        expect(e).to.be.exist;139      }140    });141  });142});
after · tests/src/setSchemaVersion.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 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});