git.delta.rocks / unique-network / refs/commits / 9cb35ec055ed

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 usingApi from './substrate/substrate-api';19import {20  addToAllowListExpectSuccess,21  createCollectionExpectSuccess,22  createItemExpectFailure,23  createItemExpectSuccess,24  destroyCollectionExpectSuccess,25  enableAllowListExpectSuccess,26  findNotExistingCollection,27  setMintPermissionExpectFailure,28  setMintPermissionExpectSuccess,29  addCollectionAdminExpectSuccess,30} from './util/helpers';3132describe('Integration Test setMintPermission', () => {33  let alice: IKeyringPair;34  let bob: IKeyringPair;3536  before(async () => {37    await usingApi(async (api, privateKeyWrapper) => {38      alice = privateKeyWrapper('//Alice');39      bob = privateKeyWrapper('//Bob');40    });41  });4243  it('ensure allow-listed non-privileged address can mint tokens', async () => {44    await usingApi(async () => {45      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});46      await enableAllowListExpectSuccess(alice, collectionId);47      await setMintPermissionExpectSuccess(alice, collectionId, true);48      await addToAllowListExpectSuccess(alice, collectionId, bob.address);4950      await createItemExpectSuccess(bob, collectionId, 'NFT');51    });52  });5354  it('can be enabled twice', async () => {55    await usingApi(async () => {56      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});57      await setMintPermissionExpectSuccess(alice, collectionId, true);58      await setMintPermissionExpectSuccess(alice, collectionId, true);59    });60  });6162  it('can be disabled twice', async () => {63    await usingApi(async () => {64      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});65      await setMintPermissionExpectSuccess(alice, collectionId, true);66      await setMintPermissionExpectSuccess(alice, collectionId, false);67      await setMintPermissionExpectSuccess(alice, collectionId, false);68    });69  });7071  it('Collection admin success on set', async () => {72    await usingApi(async () => {73      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});74      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);75      await setMintPermissionExpectSuccess(bob, collectionId, true);76    });77  });78});7980describe('Negative Integration Test setMintPermission', () => {81  let alice: IKeyringPair;82  let bob: IKeyringPair;8384  before(async () => {85    await usingApi(async (api, privateKeyWrapper) => {86      alice = privateKeyWrapper('//Alice');87      bob = privateKeyWrapper('//Bob');88    });89  });9091  it('fails on not existing collection', async () => {92    await usingApi(async (api) => {93      const nonExistingCollection = await findNotExistingCollection(api);94      await setMintPermissionExpectFailure(alice, nonExistingCollection, true);95    });96  });9798  it('fails on removed collection', async () => {99    await usingApi(async () => {100      const removedCollectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});101      await destroyCollectionExpectSuccess(removedCollectionId);102103      await setMintPermissionExpectFailure(alice, removedCollectionId, true);104    });105  });106107  it('fails when not collection owner tries to set mint status', async () => {108    const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});109    await enableAllowListExpectSuccess(alice, collectionId);110    await setMintPermissionExpectFailure(bob, collectionId, true);111  });112113  it('ensure non-allow-listed non-privileged address can\'t mint tokens', async () => {114    await usingApi(async () => {115      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});116      await enableAllowListExpectSuccess(alice, collectionId);117      await setMintPermissionExpectSuccess(alice, collectionId, true);118119      await createItemExpectFailure(bob, collectionId, 'NFT');120    });121  });122});