git.delta.rocks / unique-network / refs/commits / cbd9f34df60f

difftreelog

source

tests/src/setVariableOnChainSchema.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} from './util/helpers';1516chai.use(chaiAsPromised);17const expect = chai.expect;1819let Alice: IKeyringPair;20let Bob: IKeyringPair;21let Schema: any;22let largeSchema: any;2324before(async () => {25  await usingApi(async (api) => {26    const keyring = new Keyring({ type: 'sr25519' });27    Alice = keyring.addFromUri('//Alice');28    Bob = keyring.addFromUri('//Bob');29    Schema = '0x31';30    largeSchema = new Array(4097).fill(0xff);3132  });33});34describe('Integration Test ext. setVariableOnChainSchema()', () => {3536  it('Run extrinsic with parameters of the collection id, set the scheme', async () => {37      await usingApi(async (api) => {38      const collectionId = await createCollectionExpectSuccess();39      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();40      expect(collection.Owner.toString()).to.be.eq(Alice.address);41      const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);42      await submitTransactionAsync(Alice, setSchema);43    });44  });4546  it('Checking collection data using the setVariableOnChainSchema parameter', async () => {47      await usingApi(async (api) => {48        const collectionId = await createCollectionExpectSuccess();49        const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);50        await submitTransactionAsync(Alice, setSchema);51        const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();52        expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);5354    });55  });56});5758describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {5960  it('Set a non-existent collection', async () => {61    await usingApi(async (api) => {62      // tslint:disable-next-line: radix63      const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;64      const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);65      await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;66    });67  });6869  it('Set a previously deleted collection', async () => {70    await usingApi(async (api) => {71      const collectionId = await createCollectionExpectSuccess();72      await destroyCollectionExpectSuccess(collectionId);73      const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);74      await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;75    });76  });7778  it('Set invalid data in schema (size too large:> 1024b)', async () => {79    await usingApi(async (api) => {80      const collectionId = await createCollectionExpectSuccess();81      const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, largeSchema);82      await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;83    });84  });8586  it('Execute method not on behalf of the collection owner', async () => {87    await usingApi(async (api) => {88      const collectionId = await createCollectionExpectSuccess();89      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();90      expect(collection.Owner.toString()).to.be.eq(Alice.address);91      const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);92      await expect(submitTransactionExpectFailAsync(Bob, setSchema)).to.be.rejected;93    });94  });9596});