git.delta.rocks / unique-network / refs/commits / 9cb35ec055ed

difftreelog

source

tests/src/removeCollectionAdmin.test.ts6.1 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 {usingPlaygrounds} from './util/playgrounds';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {25  it('Remove collection admin.', async () => {26    await usingPlaygrounds(async (helper, privateKey) => {27      const alice = privateKey('//Alice');28      const bob = privateKey('//Bob');29      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});30      const collectionInfo = await collection.getData();31      expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);32      // first - add collection admin Bob33      await collection.addAdmin(alice, {Substrate: bob.address});3435      const adminListAfterAddAdmin = await collection.getAdmins();36      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});3738      // then remove bob from admins of collection39      await collection.removeAdmin(alice, {Substrate: bob.address});4041      const adminListAfterRemoveAdmin = await collection.getAdmins();42      expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});43    });44  });4546  it('Remove admin from collection that has no admins', async () => {47    await usingPlaygrounds(async (helper, privateKey) => {48      const alice = privateKey('//Alice');49      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});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('Unable to remove collection admin');55      await collection.removeAdmin(alice, {Substrate: alice.address});56    });57  });58});5960describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {61  it('Can\'t remove collection admin from not existing collection', async () => {62    await usingPlaygrounds(async (helper, privateKey) => {63      // tslint:disable-next-line: no-bitwise64      const collectionId = (1 << 32) - 1;65      const alice = privateKey('//Alice');66      const bob = privateKey('//Bob');6768      await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejected;6970      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)71      await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});72    });73  });7475  it('Can\'t remove collection admin from deleted collection', async () => {76    await usingPlaygrounds(async (helper, privateKey) => {77      const alice = privateKey('//Alice');78      const bob = privateKey('//Bob');79      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});8081      expect(await collection.burn(alice)).to.be.true;8283      await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address})).to.be.rejected;8485      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)86      await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});87    });88  });8990  it('Regular user can\'t remove collection admin', async () => {91    await usingPlaygrounds(async (helper, privateKey) => {92      const alice = privateKey('//Alice');93      const bob = privateKey('//Bob');94      const charlie = privateKey('//Charlie');95      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});9697      await collection.addAdmin(alice, {Substrate: bob.address});9899      await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;100101      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)102      await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});103    });104  });105106  it('Admin can\'t remove collection admin.', async () => {107    await usingPlaygrounds(async (helper, privateKey) => {108      const alice = privateKey('//Alice');109      const bob = privateKey('//Bob');110      const charlie = privateKey('//Charlie');111      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});112      113      await collection.addAdmin(alice, {Substrate: bob.address});114      await collection.addAdmin(alice, {Substrate: charlie.address});115116      const adminListAfterAddAdmin = await collection.getAdmins();117      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});118      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});119120      await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;121122      const adminListAfterRemoveAdmin = await collection.getAdmins();123      expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});124      expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});125    });126  });127});