From 0f16e4497b3bd0175d9ce9d6c7fa21ae5206f554 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Thu, 09 Jun 2022 12:40:48 +0000 Subject: [PATCH] Merge branch 'develop' into feature/rmrk-proxy-rebased --- --- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -1132,7 +1132,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 --- 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)); + }); + }); }); -- gitstuff