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 queryCollectionExpectSuccess,16 getCreatedCollectionCount,17} from './util/helpers';1819chai.use(chaiAsPromised);20const expect = chai.expect;2122let alice: IKeyringPair;23let bob: IKeyringPair;24let schema: any;25let largeSchema: any;2627before(async () => {28 await usingApi(async () => {29 const keyring = new Keyring({type: 'sr25519'});30 alice = keyring.addFromUri('//Alice');31 bob = keyring.addFromUri('//Bob');32 schema = '0x31';33 largeSchema = new Array(4097).fill(0xff);3435 });36});37describe('Integration Test ext. setVariableOnChainSchema()', () => {3839 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {40 await usingApi(async (api) => {41 const collectionId = await createCollectionExpectSuccess();42 const collection = await queryCollectionExpectSuccess(api, collectionId);43 expect(collection.owner.toString()).to.be.eq(alice.address);44 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);45 await submitTransactionAsync(alice, setSchema);46 });47 });4849 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {50 await usingApi(async (api) => {51 const collectionId = await createCollectionExpectSuccess();52 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);53 await submitTransactionAsync(alice, setSchema);54 const collection = await queryCollectionExpectSuccess(api, collectionId);55 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);5657 });58 });59});6061describe('Integration Test ext. collection admin setVariableOnChainSchema()', () => {6263 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {64 await usingApi(async (api) => {65 const collectionId = await createCollectionExpectSuccess();66 const collection = await queryCollectionExpectSuccess(api, collectionId);67 expect(collection.owner.toString()).to.be.eq(alice.address);68 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);69 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);70 await submitTransactionAsync(bob, setSchema);71 });72 });7374 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {75 await usingApi(async (api) => {76 const collectionId = await createCollectionExpectSuccess();77 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);78 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);79 await submitTransactionAsync(bob, setSchema);80 const collection = await queryCollectionExpectSuccess(api, collectionId);81 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);8283 });84 });85});8687describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {8889 it('Set a non-existent collection', async () => {90 await usingApi(async (api) => {91 92 const collectionId = await getCreatedCollectionCount(api) + 1;93 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);94 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;95 });96 });9798 it('Set a previously deleted collection', async () => {99 await usingApi(async (api) => {100 const collectionId = await createCollectionExpectSuccess();101 await destroyCollectionExpectSuccess(collectionId);102 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);103 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;104 });105 });106107 it('Set invalid data in schema (size too large:> 1024b)', async () => {108 await usingApi(async (api) => {109 const collectionId = await createCollectionExpectSuccess();110 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, largeSchema);111 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;112 });113 });114115 it('Execute method not on behalf of the collection owner', async () => {116 await usingApi(async (api) => {117 const collectionId = await createCollectionExpectSuccess();118 const collection = await queryCollectionExpectSuccess(api, collectionId);119 expect(collection.owner.toString()).to.be.eq(alice.address);120 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);121 await expect(submitTransactionExpectFailAsync(bob, setSchema)).to.be.rejected;122 });123 });124125});