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});1// 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 privateKey from './substrate/privateKey';21import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';22import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';2324chai.use(chaiAsPromised);25const expect = chai.expect;2627describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {28 it('Add collection admin.', async () => {29 await usingApi(async (api, privateKeyWrapper) => {30 const collectionId = await createCollectionExpectSuccess();31 const alice = privateKeyWrapper('//Alice');32 const bob = privateKeyWrapper('//Bob');3334 const collection = await queryCollectionExpectSuccess(api, collectionId);35 expect(collection.owner.toString()).to.be.equal(alice.address);3637 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));38 await submitTransactionAsync(alice, changeAdminTx);3940 const adminListAfterAddAdmin = await getAdminList(api, collectionId);41 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));42 });43 });44});4546describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {47 it("Not owner can't add collection admin.", async () => {48 await usingApi(async (api) => {49 const collectionId = await createCollectionExpectSuccess();50 const alice = privateKey('//Alice');51 const bob = privateKey('//Bob');52 const charlie = privateKey('//CHARLIE');5354 const collection = await queryCollectionExpectSuccess(api, collectionId);55 expect(collection.owner.toString()).to.be.equal(alice.address);5657 const adminListAfterAddAdmin = await getAdminList(api, collectionId);58 expect(adminListAfterAddAdmin).to.be.not.deep.contains(normalizeAccountId(bob.address));5960 const changeAdminTxCharlie = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));61 await expect(submitTransactionAsync(bob, changeAdminTxCharlie)).to.be.rejected;62 63 const adminListAfterAddNewAdmin = await getAdminList(api, collectionId);64 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(bob.address));65 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(charlie.address));66 });67 });6869 it("Admin can't add collection admin.", async () => {70 await usingApi(async (api) => {71 const collectionId = await createCollectionExpectSuccess();72 const alice = privateKey('//Alice');73 const bob = privateKey('//Bob');74 const charlie = privateKey('//CHARLIE');7576 const collection = await queryCollectionExpectSuccess(api, collectionId);77 expect(collection.owner.toString()).to.be.equal(alice.address);7879 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));80 await submitTransactionAsync(alice, changeAdminTx);8182 const adminListAfterAddAdmin = await getAdminList(api, collectionId);83 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));8485 const changeAdminTxCharlie = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));86 await expect(submitTransactionAsync(bob, changeAdminTxCharlie)).to.be.rejected;87 88 const adminListAfterAddNewAdmin = await getAdminList(api, collectionId);89 expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(bob.address));90 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(charlie.address));91 });92 });9394 it("Can't add collection admin of not existing collection.", async () => {95 await usingApi(async (api, privateKeyWrapper) => {96 // tslint:disable-next-line: no-bitwise97 const collectionId = (1 << 32) - 1;98 const alice = privateKeyWrapper('//Alice');99 const bob = privateKeyWrapper('//Bob');100101 const changeOwnerTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));102 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;103104 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)105 await createCollectionExpectSuccess();106 });107 });108109 it("Can't add an admin to a destroyed collection.", async () => {110 await usingApi(async (api, privateKeyWrapper) => {111 const collectionId = await createCollectionExpectSuccess();112 const alice = privateKeyWrapper('//Alice');113 const bob = privateKeyWrapper('//Bob');114 await destroyCollectionExpectSuccess(collectionId);115 const changeOwnerTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));116 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;117118 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)119 await createCollectionExpectSuccess();120 });121 });122123 it('Add an admin to a collection that has reached the maximum number of admins limit', async () => {124 await usingApi(async (api: ApiPromise, privateKeyWrapper) => {125 const alice = privateKeyWrapper('//Alice');126 const accounts = [127 privateKeyWrapper('//AdminTest/1').address,128 privateKeyWrapper('//AdminTest/2').address,129 privateKeyWrapper('//AdminTest/3').address,130 privateKeyWrapper('//AdminTest/4').address,131 privateKeyWrapper('//AdminTest/5').address,132 privateKeyWrapper('//AdminTest/6').address,133 privateKeyWrapper('//AdminTest/7').address,134 ];135 const collectionId = await createCollectionExpectSuccess();136137 const chainAdminLimit = (api.consts.common.collectionAdminsLimit as any).toNumber();138 expect(chainAdminLimit).to.be.equal(5);139140 for (let i = 0; i < chainAdminLimit; i++) {141 await addCollectionAdminExpectSuccess(alice, collectionId, accounts[i]);142 const adminListAfterAddAdmin = await getAdminList(api, collectionId);143 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(accounts[i]));144 }145146 const tx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(accounts[chainAdminLimit]));147 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;148 });149 });150});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));
+ });
+ });
});