git.delta.rocks / unique-network / refs/commits / 3ee9e950e03f

difftreelog

source

tests/src/mintModes.test.ts6.3 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  enableAllowListExpectSuccess,26  setMintPermissionExpectSuccess,27  addCollectionAdminExpectSuccess,28  disableAllowListExpectSuccess,29} from './util/helpers';3031describe('Integration Test public minting', () => {32  let alice: IKeyringPair;33  let bob: IKeyringPair;3435  before(async () => {36    await usingApi(async () => {37      alice = privateKey('//Alice');38      bob = privateKey('//Bob');39    });40  });4142  it('If the AllowList mode is enabled, then the address added to the allowlist and not the owner or administrator can create tokens', async () => {43    await usingApi(async () => {44      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});45      await enableAllowListExpectSuccess(alice, collectionId);46      await setMintPermissionExpectSuccess(alice, collectionId, true);47      await addToAllowListExpectSuccess(alice, collectionId, bob.address);4849      await createItemExpectSuccess(bob, collectionId, 'NFT');50    });51  });5253  it('If the AllowList mode is enabled, address not included in allowlist that is regular user cannot create tokens', async () => {54    await usingApi(async () => {55      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});56      await enableAllowListExpectSuccess(alice, collectionId);57      await setMintPermissionExpectSuccess(alice, collectionId, true);58      await createItemExpectFailure(bob, collectionId, 'NFT');59    });60  });6162  it('If the AllowList mode is enabled, address not included in allowlist that is admin can create tokens', async () => {63    await usingApi(async () => {64      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});65      await enableAllowListExpectSuccess(alice, collectionId);66      await setMintPermissionExpectSuccess(alice, collectionId, true);67      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);68      await createItemExpectSuccess(bob, collectionId, 'NFT');69    });70  });7172  it('If the AllowList mode is enabled, address not included in allowlist that is owner can create tokens', async () => {73    await usingApi(async () => {74      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});75      await enableAllowListExpectSuccess(alice, collectionId);76      await setMintPermissionExpectSuccess(alice, collectionId, true);77      await createItemExpectSuccess(alice, collectionId, 'NFT');78    });79  });8081  it('If the AllowList mode is disabled, owner can create tokens', async () => {82    await usingApi(async () => {83      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});84      await disableAllowListExpectSuccess(alice, collectionId);85      await setMintPermissionExpectSuccess(alice, collectionId, true);86      await createItemExpectSuccess(alice, collectionId, 'NFT');87    });88  });8990  it('If the AllowList mode is disabled, collection admin can create tokens', async () => {91    await usingApi(async () => {92      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});93      await disableAllowListExpectSuccess(alice, collectionId);94      await setMintPermissionExpectSuccess(alice, collectionId, true);95      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);96      await createItemExpectSuccess(bob, collectionId, 'NFT');97    });98  });99100  it('If the AllowList mode is disabled, regular user can`t create tokens', async () => {101    await usingApi(async () => {102      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});103      await disableAllowListExpectSuccess(alice, collectionId);104      await setMintPermissionExpectSuccess(alice, collectionId, true);105      await createItemExpectFailure(bob, collectionId, 'NFT');106    });107  });108});109110describe('Integration Test private minting', () => {111  let alice: IKeyringPair;112  let bob: IKeyringPair;113114  before(async () => {115    await usingApi(async () => {116      alice = privateKey('//Alice');117      bob = privateKey('//Bob');118    });119  });120121  it('Address that is the not owner or not admin cannot create tokens', async () => {122    await usingApi(async () => {123      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});124      await enableAllowListExpectSuccess(alice, collectionId);125      await setMintPermissionExpectSuccess(alice, collectionId, false);126      await addToAllowListExpectSuccess(alice, collectionId, bob.address);127      await createItemExpectFailure(bob, collectionId, 'NFT');128    });129  });130131  it('Address that is collection owner can create tokens', async () => {132    await usingApi(async () => {133      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});134      await disableAllowListExpectSuccess(alice, collectionId);135      await setMintPermissionExpectSuccess(alice, collectionId, false);136      await createItemExpectSuccess(alice, collectionId, 'NFT');137    });138  });139140  it('Address that is admin can create tokens', async () => {141    await usingApi(async () => {142      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});143      await disableAllowListExpectSuccess(alice, collectionId);144      await setMintPermissionExpectSuccess(alice, collectionId, false);145      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);146      await createItemExpectSuccess(bob, collectionId, 'NFT');147    });148  });149});