git.delta.rocks / unique-network / refs/commits / 30e1ae5f0b65

difftreelog

source

tests/src/setOffchainSchema.test.ts2.4 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import { 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} from './util/helpers';1920chai.use(chaiAsPromised);21const expect = chai.expect;2223const DATA = [1, 2, 3, 4];2425describe('Integration Test setOffchainSchema', () => {26  let alice: IKeyringPair;2728  before(async () => {29    await usingApi(async () => {30      alice = privateKey('//Alice');31    });32  });3334  it('execute setOffchainSchema, verify data was set', async () => {35    const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });36    await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);37    const collection = await queryCollectionExpectSuccess(collectionId);3839    expect(Array.from(collection.OffchainSchema)).to.be.deep.equal(DATA);40  });41});4243describe('Negative Integration Test setOffchainSchema', () => {44  let alice: IKeyringPair;45  let bob: IKeyringPair;4647  let validCollectionId: number;4849  before(async () => {50    await usingApi(async () => {51      alice = privateKey('//Alice');52      bob = privateKey('//Bob');5354      validCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });55    });56  });5758  it('fails on not existing collection id', async () => {59    const nonExistingCollectionId = await usingApi(findNotExistingCollection);6061    await setOffchainSchemaExpectFailure(alice, nonExistingCollectionId, DATA);62  });6364  it('fails on destroyed collection id', async () => {65    const destroyedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });66    await destroyCollectionExpectSuccess(destroyedCollectionId);6768    await setOffchainSchemaExpectFailure(alice, destroyedCollectionId, DATA);69  });7071  it('fails on too long data', async () => {72    const tooLongData = new Array(4097).fill(0xff);7374    await setOffchainSchemaExpectFailure(alice, validCollectionId, tooLongData);75  });7677  it('fails on execution by non-owner', async () => {78    await setOffchainSchemaExpectFailure(bob, validCollectionId, DATA);79  });80});