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

difftreelog

source

tests/src/removeCollectionAdmin.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 {ApiPromise} from '@polkadot/api';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import privateKey from './substrate/privateKey';21import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';22import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';2324chai.use(chaiAsPromised);25const expect = chai.expect;2627describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {28  it('Remove collection admin.', async () => {29    await usingApi(async (api: ApiPromise) => {30      const collectionId = await createCollectionExpectSuccess();31      const alice = privateKey('//Alice');32      const bob = privateKey('//Bob');33      const collection = await queryCollectionExpectSuccess(api, collectionId);34      expect(collection.owner.toString()).to.be.deep.eq(alice.address);35      // first - add collection admin Bob36      const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));37      await submitTransactionAsync(alice, addAdminTx);3839      const adminListAfterAddAdmin = await getAdminList(api, collectionId);40      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));4142      // then remove bob from admins of collection43      const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));44      await submitTransactionAsync(alice, removeAdminTx);4546      const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);47      expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));48    });49  });5051  it('Remove collection admin by admin.', async () => {52    await usingApi(async (api: ApiPromise) => {53      const collectionId = await createCollectionExpectSuccess();54      const alice = privateKey('//Alice');55      const bob = privateKey('//Bob');56      const charlie = privateKey('//Charlie');57      const collection = await queryCollectionExpectSuccess(api, collectionId);58      expect(collection.owner.toString()).to.be.eq(alice.address);59      // first - add collection admin Bob60      const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));61      await submitTransactionAsync(alice, addAdminTx);6263      const addAdminTx2 = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));64      await submitTransactionAsync(alice, addAdminTx2);6566      const adminListAfterAddAdmin = await getAdminList(api, collectionId);67      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));6869      // then remove bob from admins of collection70      const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));71      await submitTransactionAsync(charlie, removeAdminTx);7273      const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);74      expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));75    });76  });7778  it('Remove admin from collection that has no admins', async () => {79    await usingApi(async (api: ApiPromise) => {80      const alice = privateKey('//Alice');81      const collectionId = await createCollectionExpectSuccess();8283      const adminListBeforeAddAdmin = await getAdminList(api, collectionId);84      expect(adminListBeforeAddAdmin).to.have.lengthOf(0);8586      const tx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(alice.address));87      await submitTransactionAsync(alice, tx);88    });89  });90});9192describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {93  it('Can\'t remove collection admin from not existing collection', async () => {94    await usingApi(async (api: ApiPromise) => {95      // tslint:disable-next-line: no-bitwise96      const collectionId = (1 << 32) - 1;97      const alice = privateKey('//Alice');98      const bob = privateKey('//Bob');99100      const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));101      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;102103      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)104      await createCollectionExpectSuccess();105    });106  });107108  it('Can\'t remove collection admin from deleted collection', async () => {109    await usingApi(async (api: ApiPromise) => {110      // tslint:disable-next-line: no-bitwise111      const collectionId = await createCollectionExpectSuccess();112      const alice = privateKey('//Alice');113      const bob = privateKey('//Bob');114115      await destroyCollectionExpectSuccess(collectionId);116117      const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));118      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;119120      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)121      await createCollectionExpectSuccess();122    });123  });124125  it('Regular user Can\'t remove collection admin', async () => {126    await usingApi(async (api: ApiPromise) => {127      const collectionId = await createCollectionExpectSuccess();128      const alice = privateKey('//Alice');129      const bob = privateKey('//Bob');130      const charlie = privateKey('//Charlie');131132      const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));133      await submitTransactionAsync(alice, addAdminTx);134135      const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));136      await expect(submitTransactionExpectFailAsync(charlie, changeOwnerTx)).to.be.rejected;137138      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)139      await createCollectionExpectSuccess();140    });141  });142});