123456import { 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 Schema: any;23let largeSchema: 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 Schema = '0x31';31 largeSchema = new Array(4097).fill(0xff);3233 });34});35describe('Integration Test ext. setVariableOnChainSchema()', () => {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 setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);43 await submitTransactionAsync(Alice, setSchema);44 });45 });4647 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {48 await usingApi(async (api) => {49 const collectionId = await createCollectionExpectSuccess();50 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);51 await submitTransactionAsync(Alice, setSchema);52 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();53 expect(collection.VariableOnChainSchema.toString()).to.be.eq(Schema);5455 });56 });57});5859describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {6061 it('Set a non-existent collection', async () => {62 await usingApi(async (api) => {63 64 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;65 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);66 await expect(submitTransactionExpectFailAsync(Alice, setSchema)).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 setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);75 await expect(submitTransactionExpectFailAsync(Alice, setSchema)).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 setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, largeSchema);83 await expect(submitTransactionExpectFailAsync(Alice, setSchema)).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 setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);93 await expect(submitTransactionExpectFailAsync(Bob, setSchema)).to.be.rejected;94 });95 });9697});