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

difftreelog

source

js-packages/tests/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 type {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util/index.js';19import {NON_EXISTENT_COLLECTION_ID} from '@unique/playgrounds/types.js';2021describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {22  let alice: IKeyringPair;23  let bob: IKeyringPair;2425  before(async () => {26    await usingPlaygrounds(async (helper, privateKey) => {27      const donor = await privateKey({url: import.meta.url});28      [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);29    });30  });3132  itSub('Remove collection admin', async ({helper}) => {33    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-1', tokenPrefix: 'RCA'});34    const collectionInfo = await collection.getData();35    expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);36    // first - add collection admin Bob37    await collection.addAdmin(alice, {Substrate: bob.address});3839    const adminListAfterAddAdmin = await collection.getAdmins();40    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});4142    // then remove bob from admins of collection43    await collection.removeAdmin(alice, {Substrate: bob.address});4445    const adminListAfterRemoveAdmin = await collection.getAdmins();46    expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: bob.address});47  });4849  itSub('Remove admin from collection that has no admins', async ({helper}) => {50    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-2', tokenPrefix: 'RCA'});5152    const adminListBeforeAddAdmin = await collection.getAdmins();53    expect(adminListBeforeAddAdmin).to.have.lengthOf(0);5455    await expect(collection.removeAdmin(alice, {Substrate: alice.address})).to.be.rejectedWith('common.UserIsNotCollectionAdmin');56  });57});5859describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {60  let alice: IKeyringPair;61  let bob: IKeyringPair;62  let charlie: IKeyringPair;6364  before(async () => {65    await usingPlaygrounds(async (helper, privateKey) => {66      const donor = await privateKey({url: import.meta.url});67      [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);68    });69  });7071  itSub('Can\'t remove collection admin from not existing collection', async ({helper}) => {72    const collectionId = NON_EXISTENT_COLLECTION_ID;7374    await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address}))75      .to.be.rejectedWith(/common\.CollectionNotFound/);76  });7778  itSub('Can\'t remove collection admin from deleted collection', async ({helper}) => {79    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-2', tokenPrefix: 'RCA'});8081    expect(await collection.burn(alice)).to.be.true;8283    await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address}))84      .to.be.rejectedWith(/common\.CollectionNotFound/);85  });8687  itSub('Regular user can\'t remove collection admin', async ({helper}) => {88    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-3', tokenPrefix: 'RCA'});8990    await collection.addAdmin(alice, {Substrate: bob.address});9192    await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))93      .to.be.rejectedWith(/common\.NoPermission/);94  });9596  itSub('Admin can\'t remove collection admin.', async ({helper}) => {97    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-4', tokenPrefix: 'RCA'});9899    await collection.addAdmin(alice, {Substrate: bob.address});100    await collection.addAdmin(alice, {Substrate: charlie.address});101102    const adminListAfterAddAdmin = await collection.getAdmins();103    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});104    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: charlie.address});105106    await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))107      .to.be.rejectedWith(/common\.NoPermission/);108109    const adminListAfterRemoveAdmin = await collection.getAdmins();110    expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: bob.address});111    expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: charlie.address});112  });113});