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 shema: any;25let largeShema: 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 shema = '0x31';33 largeShema = new Array(1024 * 1024 + 10).fill(0xff);34 });35});36describe('Integration Test ext. setConstOnChainSchema()', () => {3738 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {39 await usingApi(async (api) => {40 const collectionId = await createCollectionExpectSuccess();41 const collection = await queryCollectionExpectSuccess(api, collectionId);42 expect(collection.owner.toString()).to.be.eq(alice.address);43 const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);44 await submitTransactionAsync(alice, setShema);45 });46 });4748 it('Collection admin can set the scheme', async () => {49 await usingApi(async (api) => {50 const collectionId = await createCollectionExpectSuccess();51 const collection = await queryCollectionExpectSuccess(api, collectionId);52 expect(collection.owner.toString()).to.be.eq(alice.address);53 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);54 const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);55 await submitTransactionAsync(bob, setShema);56 });57 });5859 it('Checking collection data using the ConstOnChainSchema parameter', async () => {60 await usingApi(async (api) => {61 const collectionId = await createCollectionExpectSuccess();62 const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);63 await submitTransactionAsync(alice, setShema);64 const collection = await queryCollectionExpectSuccess(api, collectionId);65 expect(collection.constOnChainSchema.toString()).to.be.eq(shema);66 });67 });68});6970describe('Negative Integration Test ext. setConstOnChainSchema()', () => {7172 it('Set a non-existent collection', async () => {73 await usingApi(async (api) => {74 75 const collectionId = await getCreatedCollectionCount(api) + 1;76 const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);77 await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;78 });79 });8081 it('Set a previously deleted collection', async () => {82 await usingApi(async (api) => {83 const collectionId = await createCollectionExpectSuccess();84 await destroyCollectionExpectSuccess(collectionId);85 const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);86 await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;87 });88 });8990 it('Set invalid data in schema (size too large:> 1MB)', async () => {91 await usingApi(async (api) => {92 const collectionId = await createCollectionExpectSuccess();93 const setShema = api.tx.unique.setConstOnChainSchema(collectionId, largeShema);94 await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;95 });96 });9798 it('Execute method not on behalf of the collection owner', async () => {99 await usingApi(async (api) => {100 const collectionId = await createCollectionExpectSuccess();101 const collection = await queryCollectionExpectSuccess(api, collectionId);102 expect(collection.owner.toString()).to.be.eq(alice.address);103 const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);104 await expect(submitTransactionExpectFailAsync(bob, setShema)).to.be.rejected;105 });106 });107108});