git.delta.rocks / unique-network / refs/commits / 4d135e3fe0d2

difftreelog

source

tests/src/destroyCollection.test.ts3.9 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 {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import privateKey from './substrate/privateKey';21import {default as usingApi} from './substrate/substrate-api';22import {createCollectionExpectSuccess,23  destroyCollectionExpectSuccess,24  destroyCollectionExpectFailure,25  setCollectionLimitsExpectSuccess,26  addCollectionAdminExpectSuccess,27  getCreatedCollectionCount,28  createItemExpectSuccess,29} from './util/helpers';3031chai.use(chaiAsPromised);3233describe('integration test: ext. destroyCollection():', () => {34  it('NFT collection can be destroyed', async () => {35    const collectionId = await createCollectionExpectSuccess();36    await destroyCollectionExpectSuccess(collectionId);37  });38  it('Fungible collection can be destroyed', async () => {39    const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});40    await destroyCollectionExpectSuccess(collectionId);41  });42  it('ReFungible collection can be destroyed', async () => {43    const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});44    await destroyCollectionExpectSuccess(collectionId);45  });46});4748describe('(!negative test!) integration test: ext. destroyCollection():', () => {49  let alice: IKeyringPair;50  let bob: IKeyringPair;5152  before(async () => {53    await usingApi(async () => {54      alice = privateKey('//Alice');55      bob = privateKey('//Bob');56    });57  });5859  it('(!negative test!) Destroy a collection that never existed', async () => {60    await usingApi(async (api) => {61      // Find the collection that never existed62      const collectionId = await getCreatedCollectionCount(api) + 1;63      await destroyCollectionExpectFailure(collectionId);64    });65  });66  it('(!negative test!) Destroy a collection that has already been destroyed', async () => {67    const collectionId = await createCollectionExpectSuccess();68    await destroyCollectionExpectSuccess(collectionId);69    await destroyCollectionExpectFailure(collectionId);70  });71  it('(!negative test!) Destroy a collection using non-owner account', async () => {72    const collectionId = await createCollectionExpectSuccess();73    await destroyCollectionExpectFailure(collectionId, '//Bob');74    await destroyCollectionExpectSuccess(collectionId, '//Alice');75  });76  it('(!negative test!) Destroy a collection using collection admin account', async () => {77    const collectionId = await createCollectionExpectSuccess();78    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);79    await destroyCollectionExpectFailure(collectionId, '//Bob');80  });81  it('fails when OwnerCanDestroy == false', async () => {82    const collectionId = await createCollectionExpectSuccess();83    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanDestroy: false});8485    await destroyCollectionExpectFailure(collectionId, '//Alice');86  });87  it('fails when a collection still has a token', async () => {88    const collectionId = await createCollectionExpectSuccess();89    await createItemExpectSuccess(alice, collectionId, 'NFT');9091    await destroyCollectionExpectFailure(collectionId, '//Alice');92  });93});