git.delta.rocks / unique-network / refs/commits / 1c142c5374ba

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} from './util/helpers';1617chai.use(chaiAsPromised);18const expect = chai.expect;1920let Alice: IKeyringPair;21let Bob: IKeyringPair;22let Shema: any;23let largeShema: any;2425before(async () => {26  await usingApi(async () => {27    const keyring = new Keyring({ type: 'sr25519' });28    Alice = keyring.addFromUri('//Alice');29    Bob = keyring.addFromUri('//Bob');30    Shema = '0x31';31    largeShema = new Array(4097).fill(0xff);3233  });34});35describe('Integration Test ext. setConstOnChainSchema()', () => {3637  it('Run extrinsic with parameters of the collection id, set the scheme', async () => {38    await usingApi(async (api) => {39      const collectionId = await createCollectionExpectSuccess();40      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();41      expect(collection.Owner).to.be.eq(Alice.address);42      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);43      await submitTransactionAsync(Alice, setShema);44    });45  });4647  it('Collection admin can set the scheme', async () => {48    await usingApi(async (api) => {49      const collectionId = await createCollectionExpectSuccess();50      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();51      expect(collection.Owner).to.be.eq(Alice.address);52      await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);53      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);54      await submitTransactionAsync(Bob, setShema);55    });56  });5758  it('Checking collection data using the ConstOnChainSchema parameter', async () => {59    await usingApi(async (api) => {60      const collectionId = await createCollectionExpectSuccess();61      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);62      await submitTransactionAsync(Alice, setShema);63      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();64      expect(collection.ConstOnChainSchema.toString()).to.be.eq(Shema);6566    });67  });68});6970describe('Negative Integration Test ext. setConstOnChainSchema()', () => {7172  it('Set a non-existent collection', async () => {73    await usingApi(async (api) => {74      // tslint:disable-next-line: radix75      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;76      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);77      await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;78    });79  });8081  it('Set a previously deleted collection', async () => {82    await usingApi(async (api) => {83      const collectionId = await createCollectionExpectSuccess();84      await destroyCollectionExpectSuccess(collectionId);85      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);86      await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;87    });88  });8990  it('Set invalid data in schema (size too large:> 1024b)', async () => {91    await usingApi(async (api) => {92      const collectionId = await createCollectionExpectSuccess();93      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, largeShema);94      await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;95    });96  });9798  it('Execute method not on behalf of the collection owner', async () => {99    await usingApi(async (api) => {100      const collectionId = await createCollectionExpectSuccess();101      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();102      expect(collection.Owner).to.be.eq(Alice.address);103      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);104      await expect(submitTransactionExpectFailAsync(Bob, setShema)).to.be.rejected;105    });106  });107108});