git.delta.rocks / unique-network / refs/commits / 5192a06a09ff

difftreelog

source

tests/src/setOffchainSchema.test.ts3.0 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  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    const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });39    await setOffchainSchemaExpectSuccess(alice, collectionId, DATA);40    const collection = await queryCollectionExpectSuccess(collectionId);4142    expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));43  });4445  it('execute setOffchainSchema (collection admin), verify data was set', async () => {46    const collectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });47    await addCollectionAdminExpectSuccess(alice, collectionId, bob);48    await setOffchainSchemaExpectSuccess(bob, collectionId, DATA);49    const collection = await queryCollectionExpectSuccess(collectionId);5051    expect(collection.OffchainSchema).to.be.equal('0x' + Buffer.from(DATA).toString('hex'));52  });53});5455describe('Negative Integration Test setOffchainSchema', () => {56  let alice: IKeyringPair;57  let bob: IKeyringPair;5859  let validCollectionId: number;6061  before(async () => {62    await usingApi(async () => {63      alice = privateKey('//Alice');64      bob = privateKey('//Bob');6566      validCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });67    });68  });6970  it('fails on not existing collection id', async () => {71    const nonExistingCollectionId = await usingApi(findNotExistingCollection);7273    await setOffchainSchemaExpectFailure(alice, nonExistingCollectionId, DATA);74  });7576  it('fails on destroyed collection id', async () => {77    const destroyedCollectionId = await createCollectionExpectSuccess({ mode: { type: 'NFT' } });78    await destroyCollectionExpectSuccess(destroyedCollectionId);7980    await setOffchainSchemaExpectFailure(alice, destroyedCollectionId, DATA);81  });8283  it('fails on too long data', async () => {84    const tooLongData = new Array(4097).fill(0xff);8586    await setOffchainSchemaExpectFailure(alice, validCollectionId, tooLongData);87  });8889  it('fails on execution by non-owner', async () => {90    await setOffchainSchemaExpectFailure(bob, validCollectionId, DATA);91  });92});