123456import {IKeyringPair} from '@polkadot/types/types';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import usingApi from './substrate/substrate-api';11import {12 createCollectionExpectSuccess,13 destroyCollectionExpectSuccess,14 findNotExistingCollection,15 queryCollectionExpectSuccess,16 setOffchainSchemaExpectFailure,17 setOffchainSchemaExpectSuccess,18 addCollectionAdminExpectSuccess,19} from './util/helpers';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324const DATA = [1, 2, 3, 4];2526describe('Integration Test setOffchainSchema', () => {27 let alice: IKeyringPair;28 let bob: IKeyringPair;2930 before(async () => {31 await usingApi(async () => {32 alice = privateKey('//Alice');33 bob = privateKey('//Bob');34 });35 });3637 it('execute setOffchainSchema, verify data was set', async () => {38 await usingApi(async api => {39 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});40 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);41 const collection = await queryCollectionExpectSuccess(api, collectionId);4243 expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));44 });45 });4647 it('execute setOffchainSchema (collection admin), verify data was set', async () => {48 await usingApi(async api => {49 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});50 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);51 await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);52 const collection = await queryCollectionExpectSuccess(api, collectionId);5354 expect(collection.offchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));55 });56 });57});5859describe('Negative Integration Test setOffchainSchema', () => {60 let alice: IKeyringPair;61 let bob: IKeyringPair;6263 let validCollectionId: number;6465 before(async () => {66 await usingApi(async () => {67 alice = privateKey('//Alice');68 bob = privateKey('//Bob');6970 validCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});71 });72 });7374 it('fails on not existing collection id', async () => {75 const nonExistingCollectionId = await usingApi(findNotExistingCollection);7677 await setOffchainSchemaExpectFailure(alice, nonExistingCollectionId, DATA);78 });7980 it('fails on destroyed collection id', async () => {81 const destroyedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});82 await destroyCollectionExpectSuccess(destroyedCollectionId);8384 await setOffchainSchemaExpectFailure(alice, destroyedCollectionId, DATA);85 });8687 it('fails on too long data', async () => {88 const tooLongData = new Array(4097).fill(0xff);8990 await setOffchainSchemaExpectFailure(alice, validCollectionId, tooLongData);91 });9293 it('fails on execution by non-owner', async () => {94 await setOffchainSchemaExpectFailure(bob, validCollectionId, DATA);95 });96});