git.delta.rocks / unique-network / refs/commits / 76f773049e63

difftreelog

source

tests/src/createItem.test.ts4.5 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 {default as usingApi} from './substrate/substrate-api';18import chai from 'chai';19import {Keyring} from '@polkadot/api';20import {IKeyringPair} from '@polkadot/types/types';21import {22  createCollectionExpectSuccess,23  createItemExpectSuccess,24  addCollectionAdminExpectSuccess,25} from './util/helpers';2627const expect = chai.expect;28let alice: IKeyringPair;29let bob: IKeyringPair;3031describe('integration test: ext. createItem():', () => {32  before(async () => {33    await usingApi(async () => {34      const keyring = new Keyring({type: 'sr25519'});35      alice = keyring.addFromUri('//Alice');36      bob = keyring.addFromUri('//Bob');37    });38  });3940  it('Create new item in NFT collection', async () => {41    const createMode = 'NFT';42    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});43    await createItemExpectSuccess(alice, newCollectionID, createMode);44  });45  it('Create new item in Fungible collection', async () => {46    const createMode = 'Fungible';47    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});48    await createItemExpectSuccess(alice, newCollectionID, createMode);49  });50  it('Create new item in ReFungible collection', async () => {51    const createMode = 'ReFungible';52    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});53    await createItemExpectSuccess(alice, newCollectionID, createMode);54  });55  it('Create new item in NFT collection with collection admin permissions', async () => {56    const createMode = 'NFT';57    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});58    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);59    await createItemExpectSuccess(bob, newCollectionID, createMode);60  });61  it('Create new item in Fungible collection with collection admin permissions', async () => {62    const createMode = 'Fungible';63    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});64    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);65    await createItemExpectSuccess(bob, newCollectionID, createMode);66  });67  it('Create new item in ReFungible collection with collection admin permissions', async () => {68    const createMode = 'ReFungible';69    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});70    await addCollectionAdminExpectSuccess(alice, newCollectionID, bob.address);71    await createItemExpectSuccess(bob, newCollectionID, createMode);72  });73});7475describe('Negative integration test: ext. createItem():', () => {76  before(async () => {77    await usingApi(async () => {78      const keyring = new Keyring({type: 'sr25519'});79      alice = keyring.addFromUri('//Alice');80      bob = keyring.addFromUri('//Bob');81    });82  });8384  it('Regular user cannot create new item in NFT collection', async () => {85    const createMode = 'NFT';86    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});87    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;88  });89  it('Regular user cannot create new item in Fungible collection', async () => {90    const createMode = 'Fungible';91    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});92    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;93  });94  it('Regular user cannot create new item in ReFungible collection', async () => {95    const createMode = 'ReFungible';96    const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});97    await expect(createItemExpectSuccess(bob, newCollectionID, createMode)).to.be.rejected;98  });99});