git.delta.rocks / unique-network / refs/commits / 9812643539bc

difftreelog

source

tests/src/removeCollectionAdmin.test.ts4.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 {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util';1920describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {21  let alice: IKeyringPair;22  let bob: IKeyringPair;2324  before(async () => {25    await usingPlaygrounds(async (helper, privateKey) => {26      const donor = await privateKey({url: import.meta.url});27      [alice, bob] = await helper.arrange.createAccounts([20n, 10n], donor);28    });29  });3031  itSub('Remove collection admin', async ({helper}) => {32    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-1', tokenPrefix: 'RCA'});33    const collectionInfo = await collection.getData();34    expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);35    // first - add collection admin Bob36    await collection.addAdmin(alice, {Substrate: bob.address});3738    const adminListAfterAddAdmin = await collection.getAdmins();39    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});4041    // then remove bob from admins of collection42    await collection.removeAdmin(alice, {Substrate: bob.address});4344    const adminListAfterRemoveAdmin = await collection.getAdmins();45    expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: bob.address});46  });4748  itSub('Remove admin from collection that has no admins', async ({helper}) => {49    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-2', tokenPrefix: 'RCA'});5051    const adminListBeforeAddAdmin = await collection.getAdmins();52    expect(adminListBeforeAddAdmin).to.have.lengthOf(0);5354    await expect(collection.removeAdmin(alice, {Substrate: alice.address})).to.be.rejectedWith('common.UserIsNotCollectionAdmin');55  });56});5758describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {59  let alice: IKeyringPair;60  let bob: IKeyringPair;61  let charlie: IKeyringPair;6263  before(async () => {64    await usingPlaygrounds(async (helper, privateKey) => {65      const donor = await privateKey({url: import.meta.url});66      [alice, bob, charlie] = await helper.arrange.createAccounts([20n, 10n, 10n], donor);67    });68  });6970  itSub('Can\'t remove collection admin from not existing collection', async ({helper}) => {71    const collectionId = (1 << 32) - 1;7273    await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address}))74      .to.be.rejectedWith(/common\.CollectionNotFound/);75  });7677  itSub('Can\'t remove collection admin from deleted collection', async ({helper}) => {78    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-2', tokenPrefix: 'RCA'});7980    expect(await collection.burn(alice)).to.be.true;8182    await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address}))83      .to.be.rejectedWith(/common\.CollectionNotFound/);84  });8586  itSub('Regular user can\'t remove collection admin', async ({helper}) => {87    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-3', tokenPrefix: 'RCA'});8889    await collection.addAdmin(alice, {Substrate: bob.address});9091    await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))92      .to.be.rejectedWith(/common\.NoPermission/);93  });9495  itSub('Admin can\'t remove collection admin.', async ({helper}) => {96    const collection = await helper.nft.mintCollection(alice, {name: 'RemoveCollectionAdmin-Neg-4', tokenPrefix: 'RCA'});9798    await collection.addAdmin(alice, {Substrate: bob.address});99    await collection.addAdmin(alice, {Substrate: charlie.address});100101    const adminListAfterAddAdmin = await collection.getAdmins();102    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});103    expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: charlie.address});104105    await expect(collection.removeAdmin(charlie, {Substrate: bob.address}))106      .to.be.rejectedWith(/common\.NoPermission/);107108    const adminListAfterRemoveAdmin = await collection.getAdmins();109    expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: bob.address});110    expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: charlie.address});111  });112});