git.delta.rocks / unique-network / refs/commits / 02be24d6ef8a

difftreelog

source

tests/src/setMintPermission.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 privateKey from './substrate/privateKey';19import usingApi from './substrate/substrate-api';20import {21  addToAllowListExpectSuccess,22  createCollectionExpectSuccess,23  createItemExpectFailure,24  createItemExpectSuccess,25  destroyCollectionExpectSuccess,26  enableAllowListExpectSuccess,27  findNotExistingCollection,28  setMintPermissionExpectFailure,29  setMintPermissionExpectSuccess,30  addCollectionAdminExpectSuccess,31} from './util/helpers';3233describe('Integration Test setMintPermission', () => {34  let alice: IKeyringPair;35  let bob: IKeyringPair;3637  before(async () => {38    await usingApi(async () => {39      alice = privateKey('//Alice');40      bob = privateKey('//Bob');41    });42  });4344  it('ensure allow-listed non-privileged address can mint tokens', async () => {45    await usingApi(async () => {46      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});47      await enableAllowListExpectSuccess(alice, collectionId);48      await setMintPermissionExpectSuccess(alice, collectionId, true);49      await addToAllowListExpectSuccess(alice, collectionId, bob.address);5051      await createItemExpectSuccess(bob, collectionId, 'NFT');52    });53  });5455  it('can be enabled twice', async () => {56    await usingApi(async () => {57      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});58      await setMintPermissionExpectSuccess(alice, collectionId, true);59      await setMintPermissionExpectSuccess(alice, collectionId, true);60    });61  });6263  it('can be disabled twice', async () => {64    await usingApi(async () => {65      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});66      await setMintPermissionExpectSuccess(alice, collectionId, true);67      await setMintPermissionExpectSuccess(alice, collectionId, false);68      await setMintPermissionExpectSuccess(alice, collectionId, false);69    });70  });71});7273describe('Negative Integration Test setMintPermission', () => {74  let alice: IKeyringPair;75  let bob: IKeyringPair;7677  before(async () => {78    await usingApi(async () => {79      alice = privateKey('//Alice');80      bob = privateKey('//Bob');81    });82  });8384  it('fails on not existing collection', async () => {85    await usingApi(async (api) => {86      const nonExistingCollection = await findNotExistingCollection(api);87      await setMintPermissionExpectFailure(alice, nonExistingCollection, true);88    });89  });9091  it('fails on removed collection', async () => {92    await usingApi(async () => {93      const removedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});94      await destroyCollectionExpectSuccess(removedCollectionId);9596      await setMintPermissionExpectFailure(alice, removedCollectionId, true);97    });98  });99100  it('fails when not collection owner tries to set mint status', async () => {101    const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});102    await enableAllowListExpectSuccess(alice, collectionId);103    await setMintPermissionExpectFailure(bob, collectionId, true);104  });105106  it('Collection admin fails on set', async () => {107    await usingApi(async () => {108      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});109      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);110      await setMintPermissionExpectFailure(bob, collectionId, true);111    });112  });113114  it('ensure non-allow-listed non-privileged address can\'t mint tokens', async () => {115    await usingApi(async () => {116      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});117      await enableAllowListExpectSuccess(alice, collectionId);118      await setMintPermissionExpectSuccess(alice, collectionId, true);119120      await createItemExpectFailure(bob, collectionId, 'NFT');121    });122  });123});