1234567891011121314151617import {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 36 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 43 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 60 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 70 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 96 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 104 await createCollectionExpectSuccess();105 });106 });107108 it('Can\'t remove collection admin from deleted collection', async () => {109 await usingApi(async (api: ApiPromise) => {110 111 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 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 139 await createCollectionExpectSuccess();140 });141 });142});