git.delta.rocks / unique-network / refs/commits / 6bc9f6eef346

difftreelog

source

tests/src/removeFromAllowList.test.ts5.9 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 chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi} from './substrate/substrate-api';20import {21  createCollectionExpectSuccess,22  destroyCollectionExpectSuccess,23  enableAllowListExpectSuccess,24  addToAllowListExpectSuccess,25  removeFromAllowListExpectSuccess,26  isAllowlisted,27  findNotExistingCollection,28  removeFromAllowListExpectFailure,29  disableAllowListExpectSuccess,30  normalizeAccountId,31  addCollectionAdminExpectSuccess,32} from './util/helpers';33import {IKeyringPair} from '@polkadot/types/types';3435chai.use(chaiAsPromised);36const expect = chai.expect;3738describe('Integration Test removeFromAllowList', () => {39  let alice: IKeyringPair;40  let bob: IKeyringPair;4142  before(async () => {43    await usingApi(async (api, privateKeyWrapper) => {44      alice = privateKeyWrapper('//Alice');45      bob = privateKeyWrapper('//Bob');46    });47  });4849  it('ensure bob is not in allowlist after removal', async () => {50    await usingApi(async api => {51      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});52      await enableAllowListExpectSuccess(alice, collectionId);53      await addToAllowListExpectSuccess(alice, collectionId, bob.address);5455      await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));56      expect(await isAllowlisted(api, collectionId, bob.address)).to.be.false;57    });58  });5960  it('allows removal from collection with unset allowlist status', async () => {61    await usingApi(async () => {62      const collectionWithoutAllowlistId = await createCollectionExpectSuccess();63      await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);64      await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);65      await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);6667      await removeFromAllowListExpectSuccess(alice, collectionWithoutAllowlistId, normalizeAccountId(bob.address));68    });69  });70});7172describe('Negative Integration Test removeFromAllowList', () => {73  let alice: IKeyringPair;74  let bob: IKeyringPair;7576  before(async () => {77    await usingApi(async (api, privateKeyWrapper) => {78      alice = privateKeyWrapper('//Alice');79      bob = privateKeyWrapper('//Bob');80    });81  });8283  it('fails on removal from not existing collection', async () => {84    await usingApi(async (api) => {85      const collectionId = await findNotExistingCollection(api);8687      await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));88    });89  });9091  it('fails on removal from removed collection', async () => {92    await usingApi(async () => {93      const collectionId = await createCollectionExpectSuccess();94      await enableAllowListExpectSuccess(alice, collectionId);95      await addToAllowListExpectSuccess(alice, collectionId, bob.address);96      await destroyCollectionExpectSuccess(collectionId);9798      await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));99    });100  });101});102103describe('Integration Test removeFromAllowList with collection admin permissions', () => {104  let alice: IKeyringPair;105  let bob: IKeyringPair;106  let charlie: IKeyringPair;107108  before(async () => {109    await usingApi(async (api, privateKeyWrapper) => {110      alice = privateKeyWrapper('//Alice');111      bob = privateKeyWrapper('//Bob');112      charlie = privateKeyWrapper('//Charlie');113    });114  });115116  it('ensure address is not in allowlist after removal', async () => {117    await usingApi(async api => {118      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});119      await enableAllowListExpectSuccess(alice, collectionId);120      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);121      await addToAllowListExpectSuccess(alice, collectionId, charlie.address);122      await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));123      expect(await isAllowlisted(api, collectionId, charlie.address)).to.be.false;124    });125  });126127  it('Collection admin allowed to remove from allowlist with unset allowlist status', async () => {128    await usingApi(async () => {129      const collectionWithoutAllowlistId = await createCollectionExpectSuccess();130      await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);131      await addCollectionAdminExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);132      await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);133      await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);134      await removeFromAllowListExpectSuccess(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));135    });136  });137138  it('Regular user can`t remove from allowlist', async () => {139    await usingApi(async () => {140      const collectionWithoutAllowlistId = await createCollectionExpectSuccess();141      await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);142      await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);143      await removeFromAllowListExpectFailure(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));144    });145  });146});