git.delta.rocks / unique-network / refs/commits / 5b368f35ddd7

difftreelog

source

tests/src/setConstOnChainSchema.test.ts4.2 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//56import {Keyring} from '@polkadot/api';7import {IKeyringPair} from '@polkadot/types/types';8import chai from 'chai';9import chaiAsPromised from 'chai-as-promised';10import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';11import {12  createCollectionExpectSuccess,13  destroyCollectionExpectSuccess,14  addCollectionAdminExpectSuccess,15  queryCollectionExpectSuccess,16  getCreatedCollectionCount,17} from './util/helpers';1819chai.use(chaiAsPromised);20const expect = chai.expect;2122let alice: IKeyringPair;23let bob: IKeyringPair;24let shema: any;25let largeShema: any;2627before(async () => {28  await usingApi(async () => {29    const keyring = new Keyring({type: 'sr25519'});30    alice = keyring.addFromUri('//Alice');31    bob = keyring.addFromUri('//Bob');32    shema = '0x31';33    largeShema = new Array(4097).fill(0xff);3435  });36});37describe('Integration Test ext. setConstOnChainSchema()', () => {3839  it('Run extrinsic with parameters of the collection id, set the scheme', async () => {40    await usingApi(async (api) => {41      const collectionId = await createCollectionExpectSuccess();42      const collection = await queryCollectionExpectSuccess(api, collectionId);43      expect(collection.owner.toString()).to.be.eq(alice.address);44      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);45      await submitTransactionAsync(alice, setShema);46    });47  });4849  it('Collection admin can set the scheme', async () => {50    await usingApi(async (api) => {51      const collectionId = await createCollectionExpectSuccess();52      const collection = await queryCollectionExpectSuccess(api, collectionId);53      expect(collection.owner.toString()).to.be.eq(alice.address);54      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);55      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);56      await submitTransactionAsync(bob, setShema);57    });58  });5960  it('Checking collection data using the ConstOnChainSchema parameter', async () => {61    await usingApi(async (api) => {62      const collectionId = await createCollectionExpectSuccess();63      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);64      await submitTransactionAsync(alice, setShema);65      const collection = await queryCollectionExpectSuccess(api, collectionId);66      expect(collection.constOnChainSchema.toString()).to.be.eq(shema);67    });68  });69});7071describe('Negative Integration Test ext. setConstOnChainSchema()', () => {7273  it('Set a non-existent collection', async () => {74    await usingApi(async (api) => {75      // tslint:disable-next-line: radix76      const collectionId = await getCreatedCollectionCount(api) + 1;77      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);78      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;79    });80  });8182  it('Set a previously deleted collection', async () => {83    await usingApi(async (api) => {84      const collectionId = await createCollectionExpectSuccess();85      await destroyCollectionExpectSuccess(collectionId);86      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);87      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;88    });89  });9091  it('Set invalid data in schema (size too large:> 1024b)', async () => {92    await usingApi(async (api) => {93      const collectionId = await createCollectionExpectSuccess();94      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, largeShema);95      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;96    });97  });9899  it('Execute method not on behalf of the collection owner', async () => {100    await usingApi(async (api) => {101      const collectionId = await createCollectionExpectSuccess();102      const collection = await queryCollectionExpectSuccess(api, collectionId);103      expect(collection.owner.toString()).to.be.eq(alice.address);104      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);105      await expect(submitTransactionExpectFailAsync(bob, setShema)).to.be.rejected;106    });107  });108109});