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

difftreelog

source

tests/src/removeCollectionAdmin.test.ts5.0 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 removeCollectionAdmin(collection_id, account_id):', () => {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([20n, 10n], donor);33    });34  });3536  itSub('Remove collection admin', async ({helper}) => {37    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-1', tokenPrefix: 'RCA'});38    const collectionInfo = await collection.getData();39    expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);40    // first - add collection admin Bob41    await collection.addAdmin(alice, {Substrate: bob.address});4243    const adminListAfterAddAdmin = await collection.getAdmins();44    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});4546    // then remove bob from admins of collection47    await collection.removeAdmin(alice, {Substrate: bob.address});4849    const adminListAfterRemoveAdmin = await collection.getAdmins();50    expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: bob.address});51  });5253  itSub('Remove admin from collection that has no admins', async ({helper}) => {54    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-2', tokenPrefix: 'RCA'});5556    const adminListBeforeAddAdmin = await collection.getAdmins();57    expect(adminListBeforeAddAdmin).to.have.lengthOf(0);5859    await collection.removeAdmin(alice, {Substrate: alice.address});60  });61});6263describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {64  let alice: IKeyringPair;65  let bob: IKeyringPair;66  let charlie: IKeyringPair;6768  before(async () => {69    await usingPlaygrounds(async (helper, privateKey) => {70      const donor = privateKey('//Alice');71      [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);72    });73  });7475  itSub('Can\'t remove collection admin from not existing collection', async ({helper}) => {76    const collectionId = (1 << 32) - 1;7778    await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address}))79      .to.be.rejectedWith(/common\.CollectionNotFound/);80  });8182  itSub('Can\'t remove collection admin from deleted collection', async ({helper}) => {83    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-2', tokenPrefix: 'RCA'});8485    expect(await collection.burn(alice)).to.be.true;8687    await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address}))88      .to.be.rejectedWith(/common\.CollectionNotFound/);89  });9091  itSub('Regular user can\'t remove collection admin', async ({helper}) => {92    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-3', tokenPrefix: 'RCA'});9394    await collection.addAdmin(alice, {Substrate: bob.address});9596    await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))97      .to.be.rejectedWith(/common\.NoPermission/);98  });99100  itSub('Admin can\'t remove collection admin.', async ({helper}) => {101    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-4', tokenPrefix: 'RCA'});102    103    await collection.addAdmin(alice, {Substrate: bob.address});104    await collection.addAdmin(alice, {Substrate: charlie.address});105106    const adminListAfterAddAdmin = await collection.getAdmins();107    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});108    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: charlie.address});109110    await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))111      .to.be.rejectedWith(/common\.NoPermission/);112113    const adminListAfterRemoveAdmin = await collection.getAdmins();114    expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: bob.address});115    expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: charlie.address});116  });117});