git.delta.rocks / unique-network / refs/commits / 35f0b49c19be

difftreelog

source

tests/src/setConstOnChainSchema.test.ts3.7 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  normalizeAccountId,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 (api) => {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.deep.eq(normalizeAccountId(Alice.address));42      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);43      await submitTransactionAsync(Alice, setShema);44    });45  });4647  it('Checking collection data using the ConstOnChainSchema parameter', async () => {48      await usingApi(async (api) => {49        const collectionId = await createCollectionExpectSuccess();50        const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);51        await submitTransactionAsync(Alice, setShema);52        const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();53        expect(collection.ConstOnChainSchema.toString()).to.be.eq(Shema);5455    });56  });57});5859describe('Negative Integration Test ext. setConstOnChainSchema()', () => {6061  it('Set a non-existent collection', async () => {62    await usingApi(async (api) => {63      // tslint:disable-next-line: radix64      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;65      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);66      await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;67    });68  });6970  it('Set a previously deleted collection', async () => {71    await usingApi(async (api) => {72      const collectionId = await createCollectionExpectSuccess();73      await destroyCollectionExpectSuccess(collectionId);74      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);75      await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;76    });77  });7879  it('Set invalid data in schema (size too large:> 1024b)', async () => {80    await usingApi(async (api) => {81      const collectionId = await createCollectionExpectSuccess();82      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, largeShema);83      await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;84    });85  });8687  it('Execute method not on behalf of the collection owner', async () => {88    await usingApi(async (api) => {89      const collectionId = await createCollectionExpectSuccess();90      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();91      expect(collection.Owner).to.be.deep.eq(normalizeAccountId(Alice.address));92      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);93      await expect(submitTransactionExpectFailAsync(Bob, setShema)).to.be.rejected;94    });95  });9697});