git.delta.rocks / unique-network / refs/commits / 5e8916aa3a6c

difftreelog

source

tests/src/setConstOnChainSchema.test.ts4.8 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {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 shema: any;36let largeShema: 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    shema = '0x31';44    largeShema = new Array(1024 * 1024 + 10).fill(0xff);45  });46});47describe('Integration Test ext. setConstOnChainSchema()', () => {4849  it('Run extrinsic with parameters of the collection id, set the scheme', async () => {50    await usingApi(async (api) => {51      const collectionId = await createCollectionExpectSuccess();52      const collection = await queryCollectionExpectSuccess(api, collectionId);53      expect(collection.owner.toString()).to.be.eq(alice.address);54      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);55      await submitTransactionAsync(alice, setShema);56    });57  });5859  it('Collection admin can set the scheme', async () => {60    await usingApi(async (api) => {61      const collectionId = await createCollectionExpectSuccess();62      const collection = await queryCollectionExpectSuccess(api, collectionId);63      expect(collection.owner.toString()).to.be.eq(alice.address);64      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);65      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);66      await submitTransactionAsync(bob, setShema);67    });68  });6970  it('Checking collection data using the ConstOnChainSchema parameter', async () => {71    await usingApi(async (api) => {72      const collectionId = await createCollectionExpectSuccess();73      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);74      await submitTransactionAsync(alice, setShema);75      const collection = await queryCollectionExpectSuccess(api, collectionId);76      expect(collection.constOnChainSchema.toString()).to.be.eq(shema);77    });78  });79});8081describe('Negative Integration Test ext. setConstOnChainSchema()', () => {8283  it('Set a non-existent collection', async () => {84    await usingApi(async (api) => {85      // tslint:disable-next-line: radix86      const collectionId = await getCreatedCollectionCount(api) + 1;87      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);88      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;89    });90  });9192  it('Set a previously deleted collection', async () => {93    await usingApi(async (api) => {94      const collectionId = await createCollectionExpectSuccess();95      await destroyCollectionExpectSuccess(collectionId);96      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);97      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;98    });99  });100101  it('Set invalid data in schema (size too large:> 1MB)', async () => {102    await usingApi(async (api) => {103      const collectionId = await createCollectionExpectSuccess();104      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, largeShema);105      await expect(submitTransactionExpectFailAsync(alice, setShema)).to.be.rejected;106    });107  });108109  it('Execute method not on behalf of the collection owner', async () => {110    await usingApi(async (api) => {111      const collectionId = await createCollectionExpectSuccess();112      const collection = await queryCollectionExpectSuccess(api, collectionId);113      expect(collection.owner.toString()).to.be.eq(alice.address);114      const setShema = api.tx.unique.setConstOnChainSchema(collectionId, shema);115      await expect(submitTransactionExpectFailAsync(bob, setShema)).to.be.rejected;116    });117  });118119});