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

difftreelog

source

tests/src/addToAllowList.test.ts5.4 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 usingApi, {submitTransactionExpectFailAsync} from './substrate/substrate-api';21import {22  addToAllowListExpectSuccess,23  createCollectionExpectSuccess,24  createItemExpectSuccess,25  destroyCollectionExpectSuccess,26  enablePublicMintingExpectSuccess,27  enableAllowListExpectSuccess,28  normalizeAccountId,29  addCollectionAdminExpectSuccess,30  addToAllowListExpectFail,31  getCreatedCollectionCount,32} from './util/helpers';3334chai.use(chaiAsPromised);35const expect = chai.expect;3637let alice: IKeyringPair;38let bob: IKeyringPair;39let charlie: IKeyringPair;4041describe('Integration Test ext. addToAllowList()', () => {4243  before(async () => {44    await usingApi(async (api, privateKeyWrapper) => {45      alice = privateKeyWrapper('//Alice');46      bob = privateKeyWrapper('//Bob');47    });48  });4950  it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {51    const collectionId = await createCollectionExpectSuccess();52    await addToAllowListExpectSuccess(alice, collectionId, bob.address);53  });5455  it('Allowlisted minting: list restrictions', async () => {56    const collectionId = await createCollectionExpectSuccess();57    await addToAllowListExpectSuccess(alice, collectionId, bob.address);58    await enableAllowListExpectSuccess(alice, collectionId);59    await enablePublicMintingExpectSuccess(alice, collectionId);60    await createItemExpectSuccess(bob, collectionId, 'NFT', bob.address);61  });62});6364describe('Negative Integration Test ext. addToAllowList()', () => {6566  it('Allow list an address in the collection that does not exist', async () => {67    await usingApi(async (api, privateKeyWrapper) => {68      // tslint:disable-next-line: no-bitwise69      const collectionId = await getCreatedCollectionCount(api) + 1;70      const bob = privateKeyWrapper('//Bob');7172      const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(bob.address));73      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;74    });75  });7677  it('Allow list an address in the collection that was destroyed', async () => {78    await usingApi(async (api, privateKeyWrapper) => {79      const alice = privateKeyWrapper('//Alice');80      const bob = privateKeyWrapper('//Bob');81      // tslint:disable-next-line: no-bitwise82      const collectionId = await createCollectionExpectSuccess();83      await destroyCollectionExpectSuccess(collectionId);84      const tx = api.tx.unique.addToAllowList(collectionId, normalizeAccountId(bob.address));85      await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;86    });87  });8889  it('Allow list an address in the collection that does not have allow list access enabled', async () => {90    await usingApi(async (api, privateKeyWrapper) => {91      const alice = privateKeyWrapper('//Alice');92      const ferdie = privateKeyWrapper('//Ferdie');93      const collectionId = await createCollectionExpectSuccess();94      await enableAllowListExpectSuccess(alice, collectionId);95      await enablePublicMintingExpectSuccess(alice, collectionId);96      const tx = api.tx.unique.createItem(collectionId, normalizeAccountId(ferdie.address), 'NFT');97      await expect(submitTransactionExpectFailAsync(ferdie, tx)).to.be.rejected;98    });99  });100101});102103describe('Integration Test ext. addToAllowList() with collection admin permissions:', () => {104105  before(async () => {106    await usingApi(async (api, privateKeyWrapper) => {107      alice = privateKeyWrapper('//Alice');108      bob = privateKeyWrapper('//Bob');109      charlie = privateKeyWrapper('//Charlie');110    });111  });112113  it('Negative. Add to the allow list by regular user', async () => {114    const collectionId = await createCollectionExpectSuccess();115    await addToAllowListExpectFail(bob, collectionId, charlie.address);116  });117118  it('Execute the extrinsic with parameters: Collection ID and address to add to the allow list', async () => {119    const collectionId = await createCollectionExpectSuccess();120    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);121    await addToAllowListExpectSuccess(bob, collectionId, charlie.address);122  });123124  it('Allowlisted minting: list restrictions', async () => {125    const collectionId = await createCollectionExpectSuccess();126    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);127    await addToAllowListExpectSuccess(bob, collectionId, charlie.address);128129    // allowed only for collection owner130    await enableAllowListExpectSuccess(alice, collectionId);131    await enablePublicMintingExpectSuccess(alice, collectionId);132133    await createItemExpectSuccess(charlie, collectionId, 'NFT', charlie.address);134  });135});