git.delta.rocks / unique-network / refs/commits / 219f5f01d1e5

difftreelog

source

tests/src/removeFromAllowList.test.ts5.8 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';34import privateKey from './substrate/privateKey';3536chai.use(chaiAsPromised);37const expect = chai.expect;3839describe('Integration Test removeFromAllowList', () => {40  let alice: IKeyringPair;41  let bob: IKeyringPair;4243  before(async () => {44    await usingApi(async () => {45      alice = privateKey('//Alice');46      bob = privateKey('//Bob');47    });48  });4950  it('ensure bob is not in allowlist after removal', async () => {51    await usingApi(async api => {52      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});53      await enableAllowListExpectSuccess(alice, collectionId);54      await addToAllowListExpectSuccess(alice, collectionId, bob.address);5556      await removeFromAllowListExpectSuccess(alice, collectionId, normalizeAccountId(bob.address));57      expect(await isAllowlisted(api, collectionId, bob.address)).to.be.false;58    });59  });6061  it('allows removal from collection with unset allowlist status', async () => {62    await usingApi(async () => {63      const collectionWithoutAllowlistId = await createCollectionExpectSuccess();64      await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);65      await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);66      await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);6768      await removeFromAllowListExpectSuccess(alice, collectionWithoutAllowlistId, normalizeAccountId(bob.address));69    });70  });71});7273describe('Negative Integration Test removeFromAllowList', () => {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 removal from not existing collection', async () => {85    await usingApi(async (api) => {86      const collectionId = await findNotExistingCollection(api);8788      await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));89    });90  });9192  it('fails on removal from removed collection', async () => {93    await usingApi(async () => {94      const collectionId = await createCollectionExpectSuccess();95      await enableAllowListExpectSuccess(alice, collectionId);96      await addToAllowListExpectSuccess(alice, collectionId, bob.address);97      await destroyCollectionExpectSuccess(collectionId);9899      await removeFromAllowListExpectFailure(alice, collectionId, normalizeAccountId(bob.address));100    });101  });102});103104describe('Integration Test removeFromAllowList with collection admin permissions', () => {105  let alice: IKeyringPair;106  let bob: IKeyringPair;107  let charlie: IKeyringPair;108109  before(async () => {110    await usingApi(async () => {111      alice = privateKey('//Alice');112      bob = privateKey('//Bob');113      charlie = privateKey('//Charlie');114    });115  });116117  it('ensure address is not in allowlist after removal', async () => {118    await usingApi(async api => {119      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});120      await enableAllowListExpectSuccess(alice, collectionId);121      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);122      await addToAllowListExpectSuccess(alice, collectionId, charlie.address);123      await removeFromAllowListExpectSuccess(bob, collectionId, normalizeAccountId(charlie.address));124      expect(await isAllowlisted(api, collectionId, charlie.address)).to.be.false;125    });126  });127128  it('Collection admin allowed to remove from allowlist with unset allowlist status', async () => {129    await usingApi(async () => {130      const collectionWithoutAllowlistId = await createCollectionExpectSuccess();131      await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);132      await addCollectionAdminExpectSuccess(alice, collectionWithoutAllowlistId, bob.address);133      await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);134      await disableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);135      await removeFromAllowListExpectSuccess(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));136    });137  });138139  it('Regular user can`t remove from allowlist', async () => {140    await usingApi(async () => {141      const collectionWithoutAllowlistId = await createCollectionExpectSuccess();142      await enableAllowListExpectSuccess(alice, collectionWithoutAllowlistId);143      await addToAllowListExpectSuccess(alice, collectionWithoutAllowlistId, charlie.address);144      await removeFromAllowListExpectFailure(bob, collectionWithoutAllowlistId, normalizeAccountId(charlie.address));145    });146  });147});