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, 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: any = (await api.query.nft.collectionById(collectionId)).toJSON();23 expect(collection.Owner).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: any = (await api.query.nft.adminList(collectionId)).toJSON();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: any = (await api.query.nft.adminList(collectionId)).toJSON;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: any = (await api.query.nft.collectionById(collectionId)).toJSON();47 expect(collection.Owner).to.be.deep.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: any = (await api.query.nft.adminList(collectionId)).toJSON();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: any = (await api.query.nft.adminList(collectionId)).toJSON;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: any = (await api.query.nft.adminList(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});