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

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      31      const collectionInfo = await collection.getData();32      expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);33      // first - add collection admin Bob34      await collection.addAdmin(alice, {Substrate: bob.address});3536      const adminListAfterAddAdmin = await collection.getAdmins();37      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});3839      // then remove bob from admins of collection40      await collection.removeAdmin(alice, {Substrate: bob.address});4142      const adminListAfterRemoveAdmin = await collection.getAdmins();43      expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});44    });45  });4647  it('Remove admin from collection that has no admins', async () => {48    await usingPlaygrounds(async (helper, privateKey) => {49      const alice = privateKey('//Alice');50      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});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('Unable to remove collection admin');56      await collection.removeAdmin(alice, {Substrate: alice.address});57    });58  });59});6061describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {62  it('Can\'t remove collection admin from not existing collection', async () => {63    await usingPlaygrounds(async (helper, privateKey) => {64      // tslint:disable-next-line: no-bitwise65      const collectionId = (1 << 32) - 1;66      const alice = privateKey('//Alice');67      const bob = privateKey('//Bob');6869      await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejected;7071      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)72      await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});73    });74  });7576  it('Can\'t remove collection admin from deleted collection', async () => {77    await usingPlaygrounds(async (helper, privateKey) => {78      const alice = privateKey('//Alice');79      const bob = privateKey('//Bob');80      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});8182      expect(await collection.burn(alice)).to.be.true;8384      await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address})).to.be.rejected;8586      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)87      await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});88    });89  });9091  it('Regular user can\'t remove collection admin', async () => {92    await usingPlaygrounds(async (helper, privateKey) => {93      const alice = privateKey('//Alice');94      const bob = privateKey('//Bob');95      const charlie = privateKey('//Charlie');96      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});9798      await collection.addAdmin(alice, {Substrate: bob.address});99100      await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;101102      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)103      await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});104    });105  });106107  it('Admin can\'t remove collection admin.', async () => {108    await usingPlaygrounds(async (helper, privateKey) => {109      const alice = privateKey('//Alice');110      const bob = privateKey('//Bob');111      const charlie = privateKey('//Charlie');112      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});113      114      await collection.addAdmin(alice, {Substrate: bob.address});115      await collection.addAdmin(alice, {Substrate: charlie.address});116117      const adminListAfterAddAdmin = await collection.getAdmins();118      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});119      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});120121      await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;122123      const adminListAfterRemoveAdmin = await collection.getAdmins();124      expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});125      expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});126    });127  });128});