difftreelog
Merge pull request #367 from UniqueNetwork/feature/CORE-402
in: master
Feature/core 402
3 files changed
pallets/common/src/lib.rsdiffbeforeafterboth--- 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 = <IsAdmin<T>>::get((collection.id, user));
if was_admin == admin {
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {ApiPromise} from '@polkadot/api';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';21import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {27 it('Add collection admin.', async () => {28 await usingApi(async (api, privateKeyWrapper) => {29 const collectionId = await createCollectionExpectSuccess();30 const alice = privateKeyWrapper('//Alice');31 const bob = privateKeyWrapper('//Bob');3233 const collection = await queryCollectionExpectSuccess(api, collectionId);34 expect(collection.owner.toString()).to.be.equal(alice.address);3536 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));37 await submitTransactionAsync(alice, changeAdminTx);3839 const adminListAfterAddAdmin = await getAdminList(api, collectionId);40 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));41 });42 });4344 it('Add admin using added collection admin.', async () => {45 await usingApi(async (api, privateKeyWrapper) => {46 const collectionId = await createCollectionExpectSuccess();47 const alice = privateKeyWrapper('//Alice');48 const bob = privateKeyWrapper('//Bob');49 const charlie = privateKeyWrapper('//CHARLIE');5051 const collection = await queryCollectionExpectSuccess(api, collectionId);52 expect(collection.owner.toString()).to.be.equal(alice.address);5354 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));55 await submitTransactionAsync(alice, changeAdminTx);5657 const adminListAfterAddAdmin = await getAdminList(api, collectionId);58 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));5960 const changeAdminTxCharlie = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));61 await submitTransactionAsync(bob, changeAdminTxCharlie);62 const adminListAfterAddNewAdmin = await getAdminList(api, collectionId);63 expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(bob.address));64 expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(charlie.address));65 });66 });67});6869describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {70 it("Not owner can't add collection admin.", async () => {71 await usingApi(async (api, privateKeyWrapper) => {72 const collectionId = await createCollectionExpectSuccess();73 const alice = privateKeyWrapper('//Alice');74 const nonOwner = privateKeyWrapper('//Bob_stash');7576 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(alice.address));77 await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected;7879 const adminListAfterAddAdmin = await getAdminList(api, collectionId);80 expect(adminListAfterAddAdmin).not.to.be.deep.contains(normalizeAccountId(alice.address));8182 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)83 await createCollectionExpectSuccess();84 });85 });86 it("Can't add collection admin of not existing collection.", async () => {87 await usingApi(async (api, privateKeyWrapper) => {88 // tslint:disable-next-line: no-bitwise89 const collectionId = (1 << 32) - 1;90 const alice = privateKeyWrapper('//Alice');91 const bob = privateKeyWrapper('//Bob');9293 const changeOwnerTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));94 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;9596 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)97 await createCollectionExpectSuccess();98 });99 });100101 it("Can't add an admin to a destroyed collection.", async () => {102 await usingApi(async (api, privateKeyWrapper) => {103 const collectionId = await createCollectionExpectSuccess();104 const alice = privateKeyWrapper('//Alice');105 const bob = privateKeyWrapper('//Bob');106 await destroyCollectionExpectSuccess(collectionId);107 const changeOwnerTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));108 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;109110 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)111 await createCollectionExpectSuccess();112 });113 });114115 it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {116 await usingApi(async (api: ApiPromise, privateKeyWrapper) => {117 const alice = privateKeyWrapper('//Alice');118 const accounts = [119 privateKeyWrapper('//AdminTest/1').address,120 privateKeyWrapper('//AdminTest/2').address,121 privateKeyWrapper('//AdminTest/3').address,122 privateKeyWrapper('//AdminTest/4').address,123 privateKeyWrapper('//AdminTest/5').address,124 privateKeyWrapper('//AdminTest/6').address,125 privateKeyWrapper('//AdminTest/7').address,126 ];127 const collectionId = await createCollectionExpectSuccess();128129 const chainAdminLimit = (api.consts.common.collectionAdminsLimit as any).toNumber();130 expect(chainAdminLimit).to.be.equal(5);131132 for (let i = 0; i < chainAdminLimit; i++) {133 await addCollectionAdminExpectSuccess(alice, collectionId, accounts[i]);134 const adminListAfterAddAdmin = await getAdminList(api, collectionId);135 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(accounts[i]));136 }137138 const tx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(accounts[chainAdminLimit]));139 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;140 });141 });142});tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- 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));
+ });
+ });
});