1234567891011121314151617import {Keyring} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';19import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';21import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';22import {23 createCollectionExpectSuccess,24 destroyCollectionExpectSuccess,25 addCollectionAdminExpectSuccess,26 queryCollectionExpectSuccess,27 getCreatedCollectionCount,28} from './util/helpers';2930chai.use(chaiAsPromised);31const expect = chai.expect;3233let alice: IKeyringPair;34let bob: IKeyringPair;35let schema: any;36let largeSchema: any;3738before(async () => {39 await usingApi(async () => {40 const keyring = new Keyring({type: 'sr25519'});41 alice = keyring.addFromUri('//Alice');42 bob = keyring.addFromUri('//Bob');43 schema = '0x31';44 largeSchema = new Array(1024 * 1024 + 10).fill(0xff);45 });46});47describe('Integration Test ext. setConstOnChainSchema()', () => {4849 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {50 await usingApi(async (api) => {51 const collectionId = await createCollectionExpectSuccess();52 const collection = await queryCollectionExpectSuccess(api, collectionId);53 expect(collection.owner.toString()).to.be.eq(alice.address);54 const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);55 await submitTransactionAsync(alice, setSchema);56 });57 });5859 it('Collection admin can set the scheme', async () => {60 await usingApi(async (api) => {61 const collectionId = await createCollectionExpectSuccess();62 const collection = await queryCollectionExpectSuccess(api, collectionId);63 expect(collection.owner.toString()).to.be.eq(alice.address);64 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);65 const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);66 await submitTransactionAsync(bob, setSchema);67 });68 });6970 it('Checking collection data using the ConstOnChainSchema parameter', async () => {71 await usingApi(async (api) => {72 const collectionId = await createCollectionExpectSuccess();73 const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);74 await submitTransactionAsync(alice, setSchema);75 const collection = await queryCollectionExpectSuccess(api, collectionId);76 expect(collection.constOnChainSchema.toString()).to.be.eq(schema);77 });78 });79});8081describe('Negative Integration Test ext. setConstOnChainSchema()', () => {8283 it('Set a non-existent collection', async () => {84 await usingApi(async (api) => {85 86 const collectionId = await getCreatedCollectionCount(api) + 1;87 const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);88 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;89 });90 });9192 it('Set a previously deleted collection', async () => {93 await usingApi(async (api) => {94 const collectionId = await createCollectionExpectSuccess();95 await destroyCollectionExpectSuccess(collectionId);96 const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);97 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;98 });99 });100101 it('Set invalid data in schema (size too large:> 1MB)', async () => {102 await usingApi(async (api) => {103 const collectionId = await createCollectionExpectSuccess();104 const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, largeSchema);105 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;106 });107 });108109 it('Execute method not on behalf of the collection owner', async () => {110 await usingApi(async (api) => {111 const collectionId = await createCollectionExpectSuccess();112 const collection = await queryCollectionExpectSuccess(api, collectionId);113 expect(collection.owner.toString()).to.be.eq(alice.address);114 const setSchema = api.tx.unique.setConstOnChainSchema(collectionId, schema);115 await expect(submitTransactionExpectFailAsync(bob, setSchema)).to.be.rejected;116 });117 });118119});