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 addCollectionAdminExpectSuccess,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.eq(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('Integration Test ext. collection admin setVariableOnChainSchema()', () => {6061 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {62 await usingApi(async (api) => {63 const collectionId = await createCollectionExpectSuccess();64 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();65 expect(collection.owner).to.be.eq(Alice.address);66 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);67 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);68 await submitTransactionAsync(Bob, setSchema);69 });70 });7172 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {73 await usingApi(async (api) => {74 const collectionId = await createCollectionExpectSuccess();75 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob);76 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);77 await submitTransactionAsync(Bob, setSchema);78 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();79 expect(collection.variableOnChainSchema.toString()).to.be.eq(Schema);8081 });82 });83});8485describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {8687 it('Set a non-existent collection', async () => {88 await usingApi(async (api) => {89 90 const collectionId = parseInt((await api.query.nft.createdCollectionCount()).toString()) + 1;91 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);92 await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;93 });94 });9596 it('Set a previously deleted collection', async () => {97 await usingApi(async (api) => {98 const collectionId = await createCollectionExpectSuccess();99 await destroyCollectionExpectSuccess(collectionId);100 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);101 await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;102 });103 });104105 it('Set invalid data in schema (size too large:> 1024b)', async () => {106 await usingApi(async (api) => {107 const collectionId = await createCollectionExpectSuccess();108 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, largeSchema);109 await expect(submitTransactionExpectFailAsync(Alice, setSchema)).to.be.rejected;110 });111 });112113 it('Execute method not on behalf of the collection owner', async () => {114 await usingApi(async (api) => {115 const collectionId = await createCollectionExpectSuccess();116 const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();117 expect(collection.owner).to.be.eq(Alice.address);118 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, Schema);119 await expect(submitTransactionExpectFailAsync(Bob, setSchema)).to.be.rejected;120 });121 });122123});