git.delta.rocks / unique-network / refs/commits / 6d585f930166

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 {default as usingApi} from './substrate/substrate-api';21import {createCollectionExpectSuccess,22  destroyCollectionExpectSuccess,23  destroyCollectionExpectFailure,24  setCollectionLimitsExpectSuccess,25  addCollectionAdminExpectSuccess,26  getCreatedCollectionCount,27  createItemExpectSuccess,28} from './util/helpers';2930chai.use(chaiAsPromised);3132describe('integration test: ext. destroyCollection():', () => {33  it('NFT collection can be destroyed', async () => {34    const collectionId = await createCollectionExpectSuccess();35    await destroyCollectionExpectSuccess(collectionId);36  });37  it('Fungible collection can be destroyed', async () => {38    const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});39    await destroyCollectionExpectSuccess(collectionId);40  });41  it('ReFungible collection can be destroyed', async () => {42    const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});43    await destroyCollectionExpectSuccess(collectionId);44  });45});4647describe('(!negative test!) integration test: ext. destroyCollection():', () => {48  let alice: IKeyringPair;49  let bob: IKeyringPair;5051  before(async () => {52    await usingApi(async (api, privateKeyWrapper) => {53      alice = privateKeyWrapper('//Alice');54      bob = privateKeyWrapper('//Bob');55    });56  });5758  it('(!negative test!) Destroy a collection that never existed', async () => {59    await usingApi(async (api) => {60      // Find the collection that never existed61      const collectionId = await getCreatedCollectionCount(api) + 1;62      await destroyCollectionExpectFailure(collectionId);63    });64  });65  it('(!negative test!) Destroy a collection that has already been destroyed', async () => {66    const collectionId = await createCollectionExpectSuccess();67    await destroyCollectionExpectSuccess(collectionId);68    await destroyCollectionExpectFailure(collectionId);69  });70  it('(!negative test!) Destroy a collection using non-owner account', async () => {71    const collectionId = await createCollectionExpectSuccess();72    await destroyCollectionExpectFailure(collectionId, '//Bob');73    await destroyCollectionExpectSuccess(collectionId, '//Alice');74  });75  it('(!negative test!) Destroy a collection using collection admin account', async () => {76    const collectionId = await createCollectionExpectSuccess();77    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);78    await destroyCollectionExpectFailure(collectionId, '//Bob');79  });80  it('fails when OwnerCanDestroy == false', async () => {81    const collectionId = await createCollectionExpectSuccess();82    await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanDestroy: false});8384    await destroyCollectionExpectFailure(collectionId, '//Alice');85  });86  it('fails when a collection still has a token', async () => {87    const collectionId = await createCollectionExpectSuccess();88    await createItemExpectSuccess(alice, collectionId, 'NFT');8990    await destroyCollectionExpectFailure(collectionId, '//Alice');91  });92});