--- a/tests/src/removeCollectionAdmin.test.ts +++ b/tests/src/removeCollectionAdmin.test.ts @@ -16,6 +16,7 @@ import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; +import privateKey from './substrate/privateKey'; import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api'; import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers'; @@ -46,33 +47,6 @@ }); }); - it('Remove collection admin by admin.', async () => { - await usingApi(async (api, privateKeyWrapper) => { - const collectionId = await createCollectionExpectSuccess(); - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const charlie = privateKeyWrapper('//Charlie'); - const collection = await queryCollectionExpectSuccess(api, collectionId); - expect(collection.owner.toString()).to.be.eq(alice.address); - // first - add collection admin Bob - const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address)); - await submitTransactionAsync(alice, addAdminTx); - - const addAdminTx2 = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address)); - await submitTransactionAsync(alice, addAdminTx2); - - const adminListAfterAddAdmin = await getAdminList(api, collectionId); - expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address)); - - // then remove bob from admins of collection - const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address)); - await submitTransactionAsync(charlie, removeAdminTx); - - const adminListAfterRemoveAdmin = await getAdminList(api, collectionId); - expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address)); - }); - }); - it('Remove admin from collection that has no admins', async () => { await usingApi(async (api, privateKeyWrapper) => { const alice = privateKeyWrapper('//Alice'); @@ -120,12 +94,12 @@ }); }); - it('Regular user Can\'t remove collection admin', async () => { - await usingApi(async (api, privateKeyWrapper) => { + it('Regular user can\'t remove collection admin', async () => { + await usingApi(async (api) => { const collectionId = await createCollectionExpectSuccess(); - const alice = privateKeyWrapper('//Alice'); - const bob = privateKeyWrapper('//Bob'); - const charlie = privateKeyWrapper('//Charlie'); + const alice = privateKey('//Alice'); + const bob = privateKey('//Bob'); + const charlie = privateKey('//Charlie'); const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address)); await submitTransactionAsync(alice, addAdminTx); @@ -137,4 +111,23 @@ await createCollectionExpectSuccess(); }); }); + + it('Admin can\'t remove collection admin.', async () => { + await usingApi(async (api) => { + const collectionId = await createCollectionExpectSuccess(); + const alice = privateKey('//Alice'); + const bob = privateKey('//Bob'); + const charlie = privateKey('//Charlie'); + + const adminListAfterAddAdmin = await getAdminList(api, collectionId); + expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address)); + + const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address)); + await expect(submitTransactionAsync(charlie, removeAdminTx)).to.be.rejected; + + const adminListAfterRemoveAdmin = await getAdminList(api, collectionId); + expect(adminListAfterRemoveAdmin).to.be.deep.contains(normalizeAccountId(bob.address)); + expect(adminListAfterRemoveAdmin).to.be.deep.contains(normalizeAccountId(charlie.address)); + }); + }); });