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

difftreelog

source

tests/src/removeCollectionAdmin.test.ts3.7 KiBsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import { ApiPromise } from '@polkadot/api';7import chai from 'chai';8import chaiAsPromised from 'chai-as-promised';9import privateKey from './substrate/privateKey';10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';11import {createCollectionExpectSuccess, destroyCollectionExpectSuccess} from './util/helpers';1213chai.use(chaiAsPromised);14const expect = chai.expect;1516describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {17  it('Remove collection admin.', async () => {18    await usingApi(async (api: ApiPromise) => {19      const collectionId = await createCollectionExpectSuccess();20      const Alice = privateKey('//Alice');21      const Bob = privateKey('//Bob');22      const collection: any = (await api.query.nft.collectionById(collectionId)).toJSON();23      expect(collection.Owner.toString()).to.be.eq(Alice.address);24      // first - add collection admin Bob25      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);26      await submitTransactionAsync(Alice, addAdminTx);2728      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));29      expect(adminListAfterAddAdmin).to.be.contains(Bob.address);3031      // then remove bob from admins of collection32      const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);33      await submitTransactionAsync(Alice, removeAdminTx);3435      const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId));36      expect(adminListAfterRemoveAdmin).not.to.be.contains(Bob.address);37    });38  });3940  it('Remove admin from collection that has no admins', async () => {41    await usingApi(async (api: ApiPromise) => {42      const Alice = privateKey('//Alice');43      const collectionId = await createCollectionExpectSuccess();4445      const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));46      expect(adminListBeforeAddAdmin).to.have.lengthOf(0);4748      const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);49      await submitTransactionAsync(Alice, tx);50    });51  });52});5354describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {55  it('Can\'t remove collection admin from not existing collection', async () => {56    await usingApi(async (api: ApiPromise) => {57      // tslint:disable-next-line: no-bitwise58      const collectionId = (1 << 32) - 1;59      const alice = privateKey('//Alice');60      const bob = privateKey('//Bob');6162      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, bob.address);63      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;6465      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)66      await createCollectionExpectSuccess();67    });68  });6970  it('Can\'t remove collection admin from deleted collection', async () => {71    await usingApi(async (api: ApiPromise) => {72      // tslint:disable-next-line: no-bitwise73      const collectionId = await createCollectionExpectSuccess();74      const Alice = privateKey('//Alice');75      const Bob = privateKey('//Bob');7677      await destroyCollectionExpectSuccess(collectionId);7879      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);80      await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;8182      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)83      await createCollectionExpectSuccess();84    });85  });86});