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

difftreelog

source

tests/src/removeCollectionAdmin.test.ts3.6 KiBsourcehistory
1import { ApiPromise } from '@polkadot/api';2import BN from 'bn.js';3import chai from 'chai';4import chaiAsPromised from 'chai-as-promised';5import privateKey from './substrate/privateKey';6import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';7import {createCollectionExpectSuccess, destroyCollectionExpectSuccess} from './util/helpers';89chai.use(chaiAsPromised);10const expect = chai.expect;1112describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {13  it('Remove collection admin.', async () => {14    await usingApi(async (api: ApiPromise) => {15      const collectionId = await createCollectionExpectSuccess();16      const Alice = privateKey('//Alice');17      const Bob = privateKey('//Bob');18      const collection: any = (await api.query.nft.collection(collectionId));19      expect(collection.Owner.toString()).to.be.eq(Alice.address);20      // first - add collection admin Bob21      const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);22      await submitTransactionAsync(Alice, addAdminTx);2324      const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));25      expect(adminListAfterAddAdmin).to.be.contains(Bob.address);2627      // then remove bob from admins of collection28      const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);29      await submitTransactionAsync(Alice, removeAdminTx);3031      const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId));32      expect(adminListAfterRemoveAdmin).not.to.be.contains(Bob.address);33    });34  });35});3637describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {38  it('Can\'t remove collection admin from not existing collection', async () => {39    await usingApi(async (api: ApiPromise) => {40      // tslint:disable-next-line: no-bitwise41      const collectionId = (1 << 32) - 1;42      const alice = privateKey('//Alice');43      const bob = privateKey('//Bob');4445      const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, bob.address);46      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;4748      // Verifying that nothing bad happened (network is live, new collections can be created, etc.)49      await createCollectionExpectSuccess();50    });51  });5253  it('Can\'t remove collection admin from deleted collection', async () => {54    await usingApi(async (api: ApiPromise) => {55      // tslint:disable-next-line: no-bitwise56      const collectionId = await createCollectionExpectSuccess();57      const Alice = privateKey('//Alice');58      const Bob = privateKey('//Bob');5960      await destroyCollectionExpectSuccess(collectionId);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('Remove admin from collection that has no admins', async () => {71    await usingApi(async (api: ApiPromise) => {72      const Alice = privateKey('//Alice');73      const collectionId = await createCollectionExpectSuccess();7475      const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));76      expect(adminListBeforeAddAdmin).to.have.lengthOf(0);7778      const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);79      await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;80    });81  });82});