git.delta.rocks / unique-network / refs/commits / 555e682e0063

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 = (await api.query.common.collectionById(collectionId)).unwrap();41      expect(collection.owner.toString()).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 = (await api.query.common.collectionById(collectionId)).unwrap();51      expect(collection.owner.toString()).to.be.eq(alice.address);52      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);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 = (await api.query.common.collectionById(collectionId)).unwrap();64      expect(collection.constOnChainSchema.toString()).to.be.eq(shema);65    });66  });67});6869describe('Negative Integration Test ext. setConstOnChainSchema()', () => {7071  it('Set a non-existent collection', async () => {72    await usingApi(async (api) => {73      // tslint:disable-next-line: radix74      const collectionId = (await api.query.common.createdCollectionCount()).toNumber() + 1;75      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);76      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;77    });78  });7980  it('Set a previously deleted collection', async () => {81    await usingApi(async (api) => {82      const collectionId = await createCollectionExpectSuccess();83      await destroyCollectionExpectSuccess(collectionId);84      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);85      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;86    });87  });8889  it('Set invalid data in schema (size too large:> 1024b)', async () => {90    await usingApi(async (api) => {91      const collectionId = await createCollectionExpectSuccess();92      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, largeShema);93      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;94    });95  });9697  it('Execute method not on behalf of the collection owner', async () => {98    await usingApi(async (api) => {99      const collectionId = await createCollectionExpectSuccess();100      const collection = (await api.query.common.collectionById(collectionId)).unwrap();101      expect(collection.owner.toString()).to.be.eq(alice.address);102      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, shema);103      await expect(submitTransactionExpectFailAsync(bob, setShema)).to.be.rejected;104    });105  });106107});