git.delta.rocks / unique-network / refs/commits / c35f6c8d35c5

difftreelog

source

tests/src/setVariableOnChainSchema.test.ts5.6 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 schema: any;36let largeSchema: 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    schema = '0x31';44    largeSchema = new Array(8 * 1024 + 10).fill(0xff);4546  });47});48describe('Integration Test ext. setVariableOnChainSchema()', () => {4950  it('Run extrinsic with parameters of the collection id, set the scheme', async () => {51    await usingApi(async (api) => {52      const collectionId = await createCollectionExpectSuccess();53      const collection = await queryCollectionExpectSuccess(api, collectionId);54      expect(collection.owner.toString()).to.be.eq(alice.address);55      const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);56      await submitTransactionAsync(alice, setSchema);57    });58  });5960  it('Checking collection data using the setVariableOnChainSchema parameter', async () => {61    await usingApi(async (api) => {62      const collectionId = await createCollectionExpectSuccess();63      const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);64      await submitTransactionAsync(alice, setSchema);65      const collection = await queryCollectionExpectSuccess(api, collectionId);66      expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);6768    });69  });70});7172describe('Integration Test ext. collection admin setVariableOnChainSchema()', () => {7374  it('Run extrinsic with parameters of the collection id, set the scheme', async () => {75    await usingApi(async (api) => {76      const collectionId = await createCollectionExpectSuccess();77      const collection = await queryCollectionExpectSuccess(api, collectionId);78      expect(collection.owner.toString()).to.be.eq(alice.address);79      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);80      const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);81      await submitTransactionAsync(bob, setSchema);82    });83  });8485  it('Checking collection data using the setVariableOnChainSchema parameter', async () => {86    await usingApi(async (api) => {87      const collectionId = await createCollectionExpectSuccess();88      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);89      const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);90      await submitTransactionAsync(bob, setSchema);91      const collection = await queryCollectionExpectSuccess(api, collectionId);92      expect(collection.variableOnChainSchema.toString()).to.be.eq(schema);9394    });95  });96});9798describe('Negative Integration Test ext. setVariableOnChainSchema()', () => {99100  it('Set a non-existent collection', async () => {101    await usingApi(async (api) => {102      // tslint:disable-next-line: radix103      const collectionId = await getCreatedCollectionCount(api) + 1;104      const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);105      await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;106    });107  });108109  it('Set a previously deleted collection', async () => {110    await usingApi(async (api) => {111      const collectionId = await createCollectionExpectSuccess();112      await destroyCollectionExpectSuccess(collectionId);113      const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);114      await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;115    });116  });117118  it('Set invalid data in schema (size too large:> 8kB)', async () => {119    await usingApi(async (api) => {120      const collectionId = await createCollectionExpectSuccess();121      const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, largeSchema);122      await expect(submitTransactionExpectFailAsync(alice, setSchema)).to.be.rejected;123    });124  });125126  it('Execute method not on behalf of the collection owner', async () => {127    await usingApi(async (api) => {128      const collectionId = await createCollectionExpectSuccess();129      const collection = await queryCollectionExpectSuccess(api, collectionId);130      expect(collection.owner.toString()).to.be.eq(alice.address);131      const setSchema = api.tx.unique.setVariableOnChainSchema(collectionId, schema);132      await expect(submitTransactionExpectFailAsync(bob, setSchema)).to.be.rejected;133    });134  });135136});