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 = (await api.query.common.collectionById(collectionId)).unwrap();41 expect(collection.owner.toString()).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 = (await api.query.common.collectionById(collectionId)).unwrap();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 = (await api.query.common.collectionById(collectionId)).unwrap();65 expect(collection.owner.toString()).to.be.eq(alice.address);66 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);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.address);76 const setSchema = api.tx.nft.setVariableOnChainSchema(collectionId, schema);77 await submitTransactionAsync(bob, setSchema);78 const collection = (await api.query.common.collectionById(collectionId)).unwrap();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 = (await api.query.common.createdCollectionCount()).toNumber() + 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 = (await api.query.common.collectionById(collectionId)).unwrap();117 expect(collection.owner.toString()).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});