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

difftreelog

source

tests/src/destroyCollection.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 {IKeyringPair} from '@polkadot/types/types';18import {19  Pallets,20} from './util/helpers';21import {itSub, expect, usingPlaygrounds} from './util/playgrounds';2223describe('integration test: ext. destroyCollection():', () => {24  let alice: IKeyringPair;2526  before(async () => {27    await usingPlaygrounds(async (helper, privateKey) => {28      const donor = privateKey('//Alice');29      [alice] = await helper.arrange.createAccounts([100n], donor);30    });31  });3233  itSub('NFT collection can be destroyed', async ({helper}) => {34    const collection = await helper.nft.mintCollection(alice, {35      name: 'test',36      description: 'test',37      tokenPrefix: 'test',38    });39    await collection.burn(alice);40    expect(await collection.getData()).to.be.null;41  });42  itSub('Fungible collection can be destroyed', async ({helper}) => {43    const collection = await helper.ft.mintCollection(alice, {44      name: 'test',45      description: 'test',46      tokenPrefix: 'test',47    }, 0);48    await collection.burn(alice);49    expect(await collection.getData()).to.be.null;50  });51  itSub.ifWithPallets('ReFungible collection can be destroyed', [Pallets.ReFungible], async ({helper}) => {52    const collection = await helper.rft.mintCollection(alice, {53      name: 'test',54      description: 'test',55      tokenPrefix: 'test',56    });57    await collection.burn(alice);58    expect(await collection.getData()).to.be.null;59  });60});6162describe('(!negative test!) integration test: ext. destroyCollection():', () => {63  let alice: IKeyringPair;64  let bob: IKeyringPair;6566  before(async () => {67    await usingPlaygrounds(async (helper, privateKey) => {68      const donor = privateKey('//Alice');69      [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);70    });71  });7273  itSub('(!negative test!) Destroy a collection that never existed', async ({helper}) => {74    const collectionId = 1_000_000;75    await expect(helper.collection.burn(alice, collectionId)).to.be.rejectedWith(/common\.CollectionNotFound/);76  });77  itSub('(!negative test!) Destroy a collection that has already been destroyed', async ({helper}) => {78    const collection = await helper.nft.mintCollection(alice, {79      name: 'test',80      description: 'test',81      tokenPrefix: 'test',82    });83    await collection.burn(alice);84    await expect(collection.burn(alice)).to.be.rejectedWith(/common\.CollectionNotFound/);85  });86  itSub('(!negative test!) Destroy a collection using non-owner account', async ({helper}) => {87    const collection = await helper.nft.mintCollection(alice, {88      name: 'test',89      description: 'test',90      tokenPrefix: 'test',91    });92    await expect(collection.burn(bob)).to.be.rejectedWith(/common\.NoPermission/);93  });94  itSub('(!negative test!) Destroy a collection using collection admin account', async ({helper}) => {95    const collection = await helper.nft.mintCollection(alice, {96      name: 'test',97      description: 'test',98      tokenPrefix: 'test',99    });100    await collection.addAdmin(alice, {Substrate: bob.address});101    await expect(collection.burn(bob)).to.be.rejectedWith(/common\.NoPermission/);102  });103  itSub('fails when OwnerCanDestroy == false', async ({helper}) => {104    const collection = await helper.nft.mintCollection(alice, {105      name: 'test',106      description: 'test',107      tokenPrefix: 'test',108      limits: {109        ownerCanDestroy: false,110      },111    });112    await expect(collection.burn(alice)).to.be.rejectedWith(/common\.NoPermission/);113  });114  itSub('fails when a collection still has a token', async ({helper}) => {115    const collection = await helper.nft.mintCollection(alice, {116      name: 'test',117      description: 'test',118      tokenPrefix: 'test',119    });120    await collection.mintToken(alice, {Substrate: alice.address});121    await expect(collection.burn(alice)).to.be.rejectedWith(/common\.CantDestroyNotEmptyCollection/);122  });123});