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(8 * 1024 + 10).fill(0xff);4546 });47});48describe('Integration Test ext. setVariableOnChainSchema()', () => {4950 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {51 await usingApi(async (api) => {52 const collectionId = await createCollectionExpectSuccess();53 const collection = await queryCollectionExpectSuccess(api, collectionId);54 expect(collection.owner.toString()).to.be.eq(alice.address);55 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);56 await submitTransactionAsync(alice, setSchema);57 });58 });5960 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {61 await usingApi(async (api) => {62 const collectionId = await createCollectionExpectSuccess();63 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);64 await submitTransactionAsync(alice, setSchema);65 const collection = await queryCollectionExpectSuccess(api, collectionId);66 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);6768 });69 });70});7172describe('Integration Test ext. collection admin setVariableOnChainSchema()', () => {7374 it('Run extrinsic with parameters of the collection id, set the scheme', async () => {75 await usingApi(async (api) => {76 const collectionId = await createCollectionExpectSuccess();77 const collection = await queryCollectionExpectSuccess(api, collectionId);78 expect(collection.owner.toString()).to.be.eq(alice.address);79 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);80 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);81 await submitTransactionAsync(bob, setSchema);82 });83 });8485 it('Checking collection data using the setVariableOnChainSchema parameter', async () => {86 await usingApi(async (api) => {87 const collectionId = await createCollectionExpectSuccess();88 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);89 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);90 await submitTransactionAsync(bob, setSchema);91 const collection = await queryCollectionExpectSuccess(api, collectionId);92 expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);9394 });95 });96});9798describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {99100 it('Set a non-existent collection', async () => {101 await usingApi(async (api) => {102 103 const collectionId = await getCreatedCollectionCount(api) + 1;104 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);105 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;106 });107 });108109 it('Set a previously deleted collection', async () => {110 await usingApi(async (api) => {111 const collectionId = await createCollectionExpectSuccess();112 await destroyCollectionExpectSuccess(collectionId);113 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);114 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;115 });116 });117118 it('Set invalid data in schema (size too large:> 8kB)', async () => {119 await usingApi(async (api) => {120 const collectionId = await createCollectionExpectSuccess();121 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, largeSchema);122 await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;123 });124 });125126 it('Execute method not on behalf of the collection owner', async () => {127 await usingApi(async (api) => {128 const collectionId = await createCollectionExpectSuccess();129 const collection = await queryCollectionExpectSuccess(api, collectionId);130 expect(collection.owner.toString()).to.be.eq(alice.address);131 const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);132 await expect(submitTransactionExpectFailAsync(bob, setSchema)).to.be.rejected;133 });134 });135136});