From 7bd01f46369b1a92d5bd4d061f4bfe6fd27fb4cd Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Mon, 06 Jun 2022 12:55:35 +0000 Subject: [PATCH] CORE-402 Now admin can't add admin --- --- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -1097,7 +1097,7 @@ user: &T::CrossAccountId, admin: bool, ) -> DispatchResult { - collection.check_is_owner_or_admin(sender)?; + collection.check_is_owner(sender)?; let was_admin = >::get((collection.id, user)); if was_admin == admin { --- a/tests/src/addCollectionAdmin.test.ts +++ b/tests/src/addCollectionAdmin.test.ts @@ -17,6 +17,7 @@ import {ApiPromise} from '@polkadot/api'; 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 {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers'; @@ -40,49 +41,56 @@ expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address)); }); }); +}); - it('Add admin using added collection admin.', async () => { - await usingApi(async (api, privateKeyWrapper) => { +describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => { + it("Not owner can't add 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 collection = await queryCollectionExpectSuccess(api, collectionId); expect(collection.owner.toString()).to.be.equal(alice.address); - const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address)); - await submitTransactionAsync(alice, changeAdminTx); - const adminListAfterAddAdmin = await getAdminList(api, collectionId); - expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address)); + expect(adminListAfterAddAdmin).to.be.not.deep.contains(normalizeAccountId(bob.address)); const changeAdminTxCharlie = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address)); - await submitTransactionAsync(bob, changeAdminTxCharlie); + await expect(submitTransactionAsync(bob, changeAdminTxCharlie)).to.be.rejected; + const adminListAfterAddNewAdmin = await getAdminList(api, collectionId); - expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(bob.address)); - expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(charlie.address)); + expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(bob.address)); + expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(charlie.address)); }); }); -}); -describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => { - it("Not owner can't add collection admin.", async () => { - await usingApi(async (api, privateKeyWrapper) => { + it("Admin can't add collection admin.", async () => { + await usingApi(async (api) => { const collectionId = await createCollectionExpectSuccess(); - const alice = privateKeyWrapper('//Alice'); - const nonOwner = privateKeyWrapper('//Bob_stash'); + const alice = privateKey('//Alice'); + const bob = privateKey('//Bob'); + const charlie = privateKey('//CHARLIE'); - const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(alice.address)); - await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected; + const collection = await queryCollectionExpectSuccess(api, collectionId); + expect(collection.owner.toString()).to.be.equal(alice.address); + const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address)); + await submitTransactionAsync(alice, changeAdminTx); + const adminListAfterAddAdmin = await getAdminList(api, collectionId); - expect(adminListAfterAddAdmin).not.to.be.deep.contains(normalizeAccountId(alice.address)); + expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address)); - // Verifying that nothing bad happened (network is live, new collections can be created, etc.) - await createCollectionExpectSuccess(); + const changeAdminTxCharlie = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address)); + await expect(submitTransactionAsync(bob, changeAdminTxCharlie)).to.be.rejected; + + const adminListAfterAddNewAdmin = await getAdminList(api, collectionId); + expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(bob.address)); + expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(charlie.address)); }); }); + it("Can't add collection admin of not existing collection.", async () => { await usingApi(async (api, privateKeyWrapper) => { // tslint:disable-next-line: no-bitwise -- gitstuff