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

difftreelog

source

tests/src/setMintPermission.test.ts5.2 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 {itSub, usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Integration Test setMintPermission', () => {26  let alice: IKeyringPair;27  let bob: IKeyringPair;2829  before(async () => {30    await usingPlaygrounds(async (helper, privateKey) => {31      const donor = privateKey('//Alice');32      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);33    });34  });3536  itSub('ensure allow-listed non-privileged address can mint tokens', async ({helper}) => {37    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-1', description: '', tokenPrefix: 'SMP'});38    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});39    await collection.addToAllowList(alice, {Substrate: bob.address});4041    await expect(collection.mintToken(bob, {Substrate: bob.address})).to.not.be.rejected;42  });4344  itSub('can be enabled twice', async ({helper}) => {45    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-2', description: '', tokenPrefix: 'SMP'});46    expect((await collection.getData())?.raw.permissions.access).to.not.equal('AllowList');4748    await collection.setPermissions(alice, {mintMode: true});49    await collection.setPermissions(alice, {mintMode: true});50    expect((await collection.getData())?.raw.permissions.mintMode).to.be.true;51  });5253  itSub('can be disabled twice', async ({helper}) => {54    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-3', description: '', tokenPrefix: 'SMP'});55    expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');5657    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});58    expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');59    expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);6061    await collection.setPermissions(alice, {access: 'Normal', mintMode: false});62    await collection.setPermissions(alice, {access: 'Normal', mintMode: false});63    expect((await collection.getData())?.raw.permissions.access).to.equal('Normal');64    expect((await collection.getData())?.raw.permissions.mintMode).to.equal(false);65  });6667  itSub('Collection admin success on set', async ({helper}) => {68    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-4', description: '', tokenPrefix: 'SMP'});69    await collection.addAdmin(alice, {Substrate: bob.address});70    await collection.setPermissions(bob, {access: 'AllowList', mintMode: true});71    72    expect((await collection.getData())?.raw.permissions.access).to.equal('AllowList');73    expect((await collection.getData())?.raw.permissions.mintMode).to.equal(true);74  });75});7677describe('Negative Integration Test setMintPermission', () => {78  let alice: IKeyringPair;79  let bob: IKeyringPair;8081  before(async () => {82    await usingPlaygrounds(async (helper, privateKey) => {83      const donor = privateKey('//Alice');84      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);85    });86  });8788  itSub('fails on not existing collection', async ({helper}) => {89    const collectionId = (1 << 32) - 1;90    await expect(helper.collection.setPermissions(alice, collectionId, {mintMode: true}))91      .to.be.rejectedWith(/common\.CollectionNotFound/);92  });9394  itSub('fails on removed collection', async ({helper}) => {95    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-1', tokenPrefix: 'SMP'});96    await collection.burn(alice);9798    await expect(collection.setPermissions(alice, {mintMode: true}))99      .to.be.rejectedWith(/common\.CollectionNotFound/);100  });101102  itSub('fails when non-owner tries to set mint status', async ({helper}) => {103    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-2', tokenPrefix: 'SMP'});104105    await expect(collection.setPermissions(bob, {mintMode: true}))106      .to.be.rejectedWith(/common\.NoPermission/);107  });108109  itSub('ensure non-allow-listed non-privileged address can\'t mint tokens', async ({helper}) => {110    const collection = await helper.nft.mintCollection(alice, {name: 'SetMintPermission-Neg-3', tokenPrefix: 'SMP'});111    await collection.setPermissions(alice, {mintMode: true});112113    await expect(collection.mintToken(bob, {Substrate: bob.address}))114      .to.be.rejectedWith(/common\.AddressNotInAllowlist/);115  });116});