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

difftreelog

source

tests/src/addCollectionAdmin.test.ts6.6 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 chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425let donor: IKeyringPair;2627before(async () => {28  await usingPlaygrounds(async (_, privateKeyWrapper) => {29    donor = privateKeyWrapper('//Alice');30  });31});3233describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {34  it('Add collection admin.', async () => {35    await usingPlaygrounds(async (helper) => {36      const [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);37      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});3839      const collection = await helper.collection.getData(collectionId);40      expect(collection!.normalizedOwner!).to.be.equal(alice.address);4142      await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});4344      const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);45      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});46    });47  });48});4950describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {51  it("Not owner can't add collection admin.", async () => {52    await usingPlaygrounds(async (helper) => {53      const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);54      const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});5556      const collection = await helper.collection.getData(collectionId);57      expect(collection?.normalizedOwner).to.be.equal(alice.address);5859      const changeAdminTxBob = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: bob.address});60      const changeAdminTxCharlie = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: charlie.address});61      await expect(changeAdminTxCharlie()).to.be.rejected;62      await expect(changeAdminTxBob()).to.be.rejected;6364      const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);65      expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: charlie.address});66      expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: bob.address});67    });68  });6970  it("Admin can't add collection admin.", async () => {71    await usingPlaygrounds(async (helper) => {72      const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);73      const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});7475      await collection.addAdmin(alice, {Substrate: bob.address});7677      const adminListAfterAddAdmin = await collection.getAdmins();78      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});7980      const changeAdminTxCharlie = async () => collection.addAdmin(bob, {Substrate: charlie.address});81      await expect(changeAdminTxCharlie()).to.be.rejected;8283      const adminListAfterAddNewAdmin = await collection.getAdmins();84      expect(adminListAfterAddNewAdmin).to.be.deep.contains({Substrate: bob.address});85      expect(adminListAfterAddNewAdmin).to.be.not.deep.contains({Substrate: charlie.address});86    });87  });8889  it("Can't add collection admin of not existing collection.", async () => {90    await usingPlaygrounds(async (helper) => {91      const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);92      // tslint:disable-next-line: no-bitwise93      const collectionId = (1 << 32) - 1;9495      const addAdminTx = async () => helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});96      await expect(addAdminTx()).to.be.rejected;9798      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)99      await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});100    });101  });102103  it("Can't add an admin to a destroyed collection.", async () => {104    await usingPlaygrounds(async (helper) => {105      const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);106      const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});107108      await collection.burn(alice);109      const addAdminTx = async () => collection.addAdmin(alice, {Substrate: bob.address});110      await expect(addAdminTx()).to.be.rejected;111112      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)113      await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});114    });115  });116117  it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {118    await usingPlaygrounds(async (helper) => {119      const [alice, ...accounts] = await helper.arrange.createAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);120      const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});121122      const chainAdminLimit = (helper.api!.consts.common.collectionAdminsLimit as any).toNumber();123      expect(chainAdminLimit).to.be.equal(5);124125      for (let i = 0; i < chainAdminLimit; i++) {126        await collection.addAdmin(alice, {Substrate: accounts[i].address});127        const adminListAfterAddAdmin = await collection.getAdmins();128        expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: accounts[i].address});129      }130131      const addExtraAdminTx = async () => collection.addAdmin(alice, {Substrate: accounts[chainAdminLimit].address});132      await expect(addExtraAdminTx()).to.be.rejected;133    });134  });135});