git.delta.rocks / unique-network / refs/commits / 6069e8a874a9

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 {IKeyringPair} from '@polkadot/types/types';20import {itSub, usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Integration Test removeFromAllowList', () => {26  let alice: IKeyringPair;27  let bob: IKeyringPair;2829  before(async () => {30    await usingPlaygrounds(async (helper, privateKey) => {31      const donor = privateKey('//Alice');32      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);33    });34  });3536  itSub('ensure bob is not in allowlist after removal', async ({helper}) => {37    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-1', tokenPrefix: 'RFAL'});3839    const collectionInfo = await collection.getData();40    expect(collectionInfo!.raw.permissions.access).to.not.equal('AllowList');4142    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});43    await collection.addToAllowList(alice, {Substrate: bob.address});44    expect(await collection.getAllowList()).to.deep.contains({Substrate: bob.address});45    46    await collection.removeFromAllowList(alice, {Substrate: bob.address});47    expect(await collection.getAllowList()).to.be.empty;48  });4950  itSub('allows removal from collection with unset allowlist status', async ({helper}) => {51    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-2', tokenPrefix: 'RFAL'});5253    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});54    await collection.addToAllowList(alice, {Substrate: bob.address});55    expect(await collection.getAllowList()).to.deep.contains({Substrate: bob.address});5657    await collection.setPermissions(alice, {access: 'Normal'});58    59    await collection.removeFromAllowList(alice, {Substrate: bob.address});60    expect(await collection.getAllowList()).to.be.empty;61  });62});6364describe('Negative Integration Test removeFromAllowList', () => {65  let alice: IKeyringPair;66  let bob: IKeyringPair;6768  before(async () => {69    await usingPlaygrounds(async (helper, privateKey) => {70      const donor = privateKey('//Alice');71      [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);72    });73  });7475  itSub('fails on removal from not existing collection', async ({helper}) => {76    const nonExistentCollectionId = (1 << 32) - 1;77    await expect(helper.collection.removeFromAllowList(alice, nonExistentCollectionId, {Substrate: alice.address}))78      .to.be.rejectedWith(/common\.CollectionNotFound/);79  });8081  itSub('fails on removal from removed collection', async ({helper}) => {82    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-3', tokenPrefix: 'RFAL'});83    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});84    await collection.addToAllowList(alice, {Substrate: bob.address});8586    await collection.burn(alice);87    await expect(collection.removeFromAllowList(alice, {Substrate: bob.address}))88      .to.be.rejectedWith(/common\.CollectionNotFound/);89  });90});9192describe('Integration Test removeFromAllowList with collection admin permissions', () => {93  let alice: IKeyringPair;94  let bob: IKeyringPair;95  let charlie: IKeyringPair;9697  before(async () => {98    await usingPlaygrounds(async (helper, privateKey) => {99      const donor = privateKey('//Alice');100      [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);101    });102  });103104  itSub('ensure address is not in allowlist after removal', async ({helper}) => {105    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-4', tokenPrefix: 'RFAL'});106    107    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});108    await collection.addAdmin(alice, {Substrate: bob.address});109110    await collection.addToAllowList(bob, {Substrate: charlie.address});111    await collection.removeFromAllowList(bob, {Substrate: charlie.address});112113    expect(await collection.getAllowList()).to.be.empty;114  });115116  itSub('Collection admin allowed to remove from allowlist with unset allowlist status', async ({helper}) => {117    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-5', tokenPrefix: 'RFAL'});118119    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});120    await collection.addAdmin(alice, {Substrate: bob.address});121    await collection.addToAllowList(alice, {Substrate: charlie.address});122123    await collection.setPermissions(bob, {access: 'Normal'});124    await collection.removeFromAllowList(bob, {Substrate: charlie.address});125126    expect(await collection.getAllowList()).to.be.empty;127  });128129  itSub('Regular user can`t remove from allowlist', async ({helper}) => {130    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveFromAllowList-6', tokenPrefix: 'RFAL'});131132    await collection.setPermissions(alice, {access: 'AllowList', mintMode: true});133    await collection.addToAllowList(alice, {Substrate: charlie.address});134135    await expect(collection.removeFromAllowList(bob, {Substrate: charlie.address}))136      .to.be.rejectedWith(/common\.NoPermission/);137    expect(await collection.getAllowList()).to.deep.contain({Substrate: charlie.address});138  });139});