git.delta.rocks / unique-network / refs/commits / 09636be4bace

difftreelog

source

tests/src/setConstOnChainSchema.test.ts3.5 KiBsourcehistory
1import { Keyring } from '@polkadot/api';2import { IKeyringPair } from '@polkadot/types/types';3import chai from 'chai';4import chaiAsPromised from 'chai-as-promised';5import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';6import {7  createCollectionExpectSuccess,8  destroyCollectionExpectSuccess,9} from './util/helpers';1011chai.use(chaiAsPromised);12const expect = chai.expect;1314let Alice: IKeyringPair;15let Bob: IKeyringPair;16let Shema: any;17let largeShema: any;1819before(async () => {20  await usingApi(async (api) => {21    const keyring = new Keyring({ type: 'sr25519' });22    Alice = keyring.addFromUri('//Alice');23    Bob = keyring.addFromUri('//Bob');24    Shema = '0x31';25    largeShema = new Array(4097).fill(0xff);2627  });28});29describe('Integration Test ext. setConstOnChainSchema()', () => {3031  it('Run extrinsic with parameters of the collection id, set the scheme', async () => {32      await usingApi(async (api) => {33      const collectionId = await createCollectionExpectSuccess();34      const collection: any = (await api.query.nft.collection(collectionId));35      expect(collection.Owner.toString()).to.be.eq(Alice.address);36      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);37      await submitTransactionAsync(Alice, setShema);38    });39  });4041  it('Checking collection data using the ConstOnChainSchema parameter', async () => {42      await usingApi(async (api) => {43        const collectionId = await createCollectionExpectSuccess();44        const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);45        await submitTransactionAsync(Alice, setShema);46        const collection: any = (await api.query.nft.collection(collectionId));47        expect(collection.ConstOnChainSchema.toString()).to.be.eq(Shema);4849    });50  });51});5253describe('Negative Integration Test ext. setConstOnChainSchema()', () => {5455  it('Set a non-existent collection', async () => {56    await usingApi(async (api) => {57      // tslint:disable-next-line: radix58      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;59      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);60      await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;61    });62  });6364  it('Set a previously deleted collection', async () => {65    await usingApi(async (api) => {66      const collectionId = await createCollectionExpectSuccess();67      await destroyCollectionExpectSuccess(collectionId);68      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);69      await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;70    });71  });7273  it('Set invalid data in schema (size too large:> 1024b)', async () => {74    await usingApi(async (api) => {75      const collectionId = await createCollectionExpectSuccess();76      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, largeShema);77      await expect(submitTransactionExpectFailAsync(Alice, setShema)).to.be.rejected;78    });79  });8081  it('Execute method not on behalf of the collection owner', async () => {82    await usingApi(async (api) => {83      const collectionId = await createCollectionExpectSuccess();84      const collection: any = (await api.query.nft.collection(collectionId));85      expect(collection.Owner.toString()).to.be.eq(Alice.address);86      const setShema = api.tx.nft.setConstOnChainSchema(collectionId, Shema);87      await expect(submitTransactionExpectFailAsync(Bob, setShema)).to.be.rejected;88    });89  });9091});