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

difftreelog

source

tests/src/setMintPermission.test.ts5.1 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 {itSub, usingPlaygrounds, expect} from './util/playgrounds';1920describe('Integration Test setMintPermission', () => {21  let alice: IKeyringPair;22  let bob: IKeyringPair;2324  before(async () => {25    await usingPlaygrounds(async (helper, privateKey) => {26      const donor = privateKey('//Alice');27      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);28    });29  });3031  itSub('ensure allow-listed non-privileged address can mint tokens', async ({helper}) => {32    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-1', description: '', tokenPrefix: 'SMP'});33    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});34    await collection.addToAllowList(alice, {Substrate: bob.address});3536    await expect(collection.mintToken(bob, {Substrate: bob.address})).to.not.be.rejected;37  });3839  itSub('can be enabled twice', async ({helper}) => {40    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-2', description: '', tokenPrefix: 'SMP'});41    expect((await collection.getData())?.raw.permissions.access).to.not.equal('AllowList');4243    await collection.setPermissions(alice, {mintMode: true});44    await collection.setPermissions(alice, {mintMode: true});45    expect((await collection.getData())?.raw.permissions.mintMode).to.be.true;46  });4748  itSub('can be disabled twice', async ({helper}) => {49    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-3', description: '', tokenPrefix: 'SMP'});50    expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');5152    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});53    expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');54    expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);5556    await collection.setPermissions(alice, {access: 'Normal', mintMode: false});57    await collection.setPermissions(alice, {access: 'Normal', mintMode: false});58    expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');59    expect((await collection.getData())?.raw.permissions.mintMode).to.equal(false);60  });6162  itSub('Collection admin success on set', async ({helper}) => {63    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-4', description: '', tokenPrefix: 'SMP'});64    await collection.addAdmin(alice, {Substrate: bob.address});65    await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});66    67    expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');68    expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);69  });70});7172describe('Negative Integration Test setMintPermission', () => {73  let alice: IKeyringPair;74  let bob: IKeyringPair;7576  before(async () => {77    await usingPlaygrounds(async (helper, privateKey) => {78      const donor = privateKey('//Alice');79      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);80    });81  });8283  itSub('fails on not existing collection', async ({helper}) => {84    const collectionId = (1 << 32) - 1;85    await expect(helper.collection.setPermissions(alice, collectionId, {mintMode: true}))86      .to.be.rejectedWith(/common\.CollectionNotFound/);87  });8889  itSub('fails on removed collection', async ({helper}) => {90    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-1', tokenPrefix: 'SMP'});91    await collection.burn(alice);9293    await expect(collection.setPermissions(alice, {mintMode: true}))94      .to.be.rejectedWith(/common\.CollectionNotFound/);95  });9697  itSub('fails when non-owner tries to set mint status', async ({helper}) => {98    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-2', tokenPrefix: 'SMP'});99100    await expect(collection.setPermissions(bob, {mintMode: true}))101      .to.be.rejectedWith(/common\.NoPermission/);102  });103104  itSub('ensure non-allow-listed non-privileged address can\'t mint tokens', async ({helper}) => {105    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-3', tokenPrefix: 'SMP'});106    await collection.setPermissions(alice, {mintMode: true});107108    await expect(collection.mintToken(bob, {Substrate: bob.address}))109      .to.be.rejectedWith(/common\.AddressNotInAllowlist/);110  });111});