1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import privateKey from './substrate/privateKey';21import usingApi from './substrate/substrate-api';22import {23 createCollectionExpectSuccess,24 destroyCollectionExpectSuccess,25 findNotExistingCollection,26 queryCollectionExpectSuccess,27 setOffchainSchemaExpectFailure,28 setOffchainSchemaExpectSuccess,29 addCollectionAdminExpectSuccess,30} from './util/helpers';3132chai.use(chaiAsPromised);33const expect = chai.expect;3435const DATA = [1, 2, 3, 4];3637describe('Integration Test setOffchainSchema', () => {38 let alice: IKeyringPair;39 let bob: IKeyringPair;4041 before(async () => {42 await usingApi(async () => {43 alice = privateKey('//Alice');44 bob = privateKey('//Bob');45 });46 });4748 it('execute setOffchainSchema, verify data was set', async () => {49 await usingApi(async api => {50 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});51 await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);52 const collection = await queryCollectionExpectSuccess(api, collectionId);5354 expect('0x' + Buffer.from(collection.offchainSchema).toString('hex')).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));55 });56 });5758 it('execute setOffchainSchema (collection admin), verify data was set', async () => {59 await usingApi(async api => {60 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});61 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);62 await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);63 const collection = await queryCollectionExpectSuccess(api, collectionId);6465 expect('0x' + Buffer.from(collection.offchainSchema).toString('hex')).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));66 });67 });68});6970describe('Negative Integration Test setOffchainSchema', () => {71 let alice: IKeyringPair;72 let bob: IKeyringPair;7374 let validCollectionId: number;7576 before(async () => {77 await usingApi(async () => {78 alice = privateKey('//Alice');79 bob = privateKey('//Bob');8081 validCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});82 });83 });8485 it('fails on not existing collection id', async () => {86 const nonExistingCollectionId = await usingApi(findNotExistingCollection);8788 await setOffchainSchemaExpectFailure(alice, nonExistingCollectionId, DATA);89 });9091 it('fails on destroyed collection id', async () => {92 const destroyedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});93 await destroyCollectionExpectSuccess(destroyedCollectionId);9495 await setOffchainSchemaExpectFailure(alice, destroyedCollectionId, DATA);96 });9798 it('fails on too long data', async () => {99 const tooLongData = new Array(8 * 1024 + 10).fill(0xff);100101 await setOffchainSchemaExpectFailure(alice, validCollectionId, tooLongData);102 });103104 it('fails on execution by non-owner', async () => {105 await setOffchainSchemaExpectFailure(bob, validCollectionId, DATA);106 });107});