123456import {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, getAdminList, normalizeAccountId} 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 = (await api.query.common.collectionById(collectionId)).unwrap();23 expect(collection.owner.toString()).to.be.deep.eq(alice.address);24 25 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));26 await submitTransactionAsync(alice, addAdminTx);2728 const adminListAfterAddAdmin = await getAdminList(api, collectionId);29 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));3031 32 const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));33 await submitTransactionAsync(alice, removeAdminTx);3435 const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);36 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));37 });38 });3940 it('Remove collection admin by admin.', async () => {41 await usingApi(async (api: ApiPromise) => {42 const collectionId = await createCollectionExpectSuccess();43 const alice = privateKey('//Alice');44 const bob = privateKey('//Bob');45 const charlie = privateKey('//Charlie');46 const collection = (await api.query.common.collectionById(collectionId)).unwrap();47 expect(collection.owner.toString()).to.be.eq(alice.address);48 49 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));50 await submitTransactionAsync(alice, addAdminTx);5152 const addAdminTx2 = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));53 await submitTransactionAsync(alice, addAdminTx2);5455 const adminListAfterAddAdmin = await getAdminList(api, collectionId);56 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));5758 59 const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));60 await submitTransactionAsync(charlie, removeAdminTx);6162 const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);63 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));64 });65 });6667 it('Remove admin from collection that has no admins', async () => {68 await usingApi(async (api: ApiPromise) => {69 const alice = privateKey('//Alice');70 const collectionId = await createCollectionExpectSuccess();7172 const adminListBeforeAddAdmin = await getAdminList(api, collectionId);73 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);7475 const tx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(alice.address));76 await submitTransactionAsync(alice, tx);77 });78 });79});8081describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {82 it('Can\'t remove collection admin from not existing collection', async () => {83 await usingApi(async (api: ApiPromise) => {84 85 const collectionId = (1 << 32) - 1;86 const alice = privateKey('//Alice');87 const bob = privateKey('//Bob');8889 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));90 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;9192 93 await createCollectionExpectSuccess();94 });95 });9697 it('Can\'t remove collection admin from deleted collection', async () => {98 await usingApi(async (api: ApiPromise) => {99 100 const collectionId = await createCollectionExpectSuccess();101 const alice = privateKey('//Alice');102 const bob = privateKey('//Bob');103104 await destroyCollectionExpectSuccess(collectionId);105106 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));107 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;108109 110 await createCollectionExpectSuccess();111 });112 });113114 it('Regular user Can\'t remove collection admin', async () => {115 await usingApi(async (api: ApiPromise) => {116 const collectionId = await createCollectionExpectSuccess();117 const alice = privateKey('//Alice');118 const bob = privateKey('//Bob');119 const charlie = privateKey('//Charlie');120121 const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));122 await submitTransactionAsync(alice, addAdminTx);123124 const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));125 await expect(submitTransactionExpectFailAsync(charlie, changeOwnerTx)).to.be.rejected;126127 128 await createCollectionExpectSuccess();129 });130 });131});