1234567891011121314151617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {26 it('Remove collection admin.', async () => {27 await usingApi(async (api, privateKeyWrapper) => {28 const collectionId = await createCollectionExpectSuccess();29 const alice = privateKeyWrapper('//Alice');30 const bob = privateKeyWrapper('//Bob');31 const collection = await queryCollectionExpectSuccess(api, collectionId);32 expect(collection.owner.toString()).to.be.deep.eq(alice.address);33 34 const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));35 await submitTransactionAsync(alice, addAdminTx);3637 const adminListAfterAddAdmin = await getAdminList(api, collectionId);38 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));3940 41 const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));42 await submitTransactionAsync(alice, removeAdminTx);4344 const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);45 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));46 });47 });4849 it('Remove admin from collection that has no admins', async () => {50 await usingApi(async (api, privateKeyWrapper) => {51 const alice = privateKeyWrapper('//Alice');52 const collectionId = await createCollectionExpectSuccess();5354 const adminListBeforeAddAdmin = await getAdminList(api, collectionId);55 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);5657 const tx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(alice.address));58 await submitTransactionAsync(alice, tx);59 });60 });61});6263describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {64 it('Can\'t remove collection admin from not existing collection', async () => {65 await usingApi(async (api, privateKeyWrapper) => {66 67 const collectionId = (1 << 32) - 1;68 const alice = privateKeyWrapper('//Alice');69 const bob = privateKeyWrapper('//Bob');7071 const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));72 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;7374 75 await createCollectionExpectSuccess();76 });77 });7879 it('Can\'t remove collection admin from deleted collection', async () => {80 await usingApi(async (api, privateKeyWrapper) => {81 82 const collectionId = await createCollectionExpectSuccess();83 const alice = privateKeyWrapper('//Alice');84 const bob = privateKeyWrapper('//Bob');8586 await destroyCollectionExpectSuccess(collectionId);8788 const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));89 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;9091 92 await createCollectionExpectSuccess();93 });94 });9596 it('Regular user can\'t remove collection admin', async () => {97 await usingApi(async (api, privateKeyWrapper) => {98 const collectionId = await createCollectionExpectSuccess();99 const alice = privateKeyWrapper('//Alice');100 const bob = privateKeyWrapper('//Bob');101 const charlie = privateKeyWrapper('//Charlie');102103 const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));104 await submitTransactionAsync(alice, addAdminTx);105106 const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));107 await expect(submitTransactionExpectFailAsync(charlie, changeOwnerTx)).to.be.rejected;108109 110 await createCollectionExpectSuccess();111 });112 });113114 it('Admin can\'t remove collection admin.', async () => {115 await usingApi(async (api, privateKeyWrapper) => {116 const collectionId = await createCollectionExpectSuccess();117 const alice = privateKeyWrapper('//Alice');118 const bob = privateKeyWrapper('//Bob');119 const charlie = privateKeyWrapper('//Charlie');120121 const addBobAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));122 await submitTransactionAsync(alice, addBobAdminTx);123 const addCharlieAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));124 await submitTransactionAsync(alice, addCharlieAdminTx);125126 const adminListAfterAddAdmin = await getAdminList(api, collectionId);127 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));128 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(charlie.address));129130 const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));131 await expect(submitTransactionExpectFailAsync(charlie, removeAdminTx)).to.be.rejected;132133 const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);134 expect(adminListAfterRemoveAdmin).to.be.deep.contains(normalizeAccountId(bob.address));135 expect(adminListAfterRemoveAdmin).to.be.deep.contains(normalizeAccountId(charlie.address));136 });137 });138});