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.tsdiffbeforeafterboth--- 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
tests/src/removeCollectionAdmin.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 chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {26 it('Remove collection admin.', async () => {27 await usingApi(async (api, privateKeyWrapper) => {28 const collectionId = await createCollectionExpectSuccess();29 const alice = privateKeyWrapper('//Alice');30 const bob = privateKeyWrapper('//Bob');31 const collection = await queryCollectionExpectSuccess(api, collectionId);32 expect(collection.owner.toString()).to.be.deep.eq(alice.address);33 // first - add collection admin Bob34 const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));35 await submitTransactionAsync(alice, addAdminTx);3637 const adminListAfterAddAdmin = await getAdminList(api, collectionId);38 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));3940 // then remove bob from admins of collection41 const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));42 await submitTransactionAsync(alice, removeAdminTx);4344 const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);45 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));46 });47 });4849 it('Remove collection admin by admin.', async () => {50 await usingApi(async (api, privateKeyWrapper) => {51 const collectionId = await createCollectionExpectSuccess();52 const alice = privateKeyWrapper('//Alice');53 const bob = privateKeyWrapper('//Bob');54 const charlie = privateKeyWrapper('//Charlie');55 const collection = await queryCollectionExpectSuccess(api, collectionId);56 expect(collection.owner.toString()).to.be.eq(alice.address);57 // first - add collection admin Bob58 const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));59 await submitTransactionAsync(alice, addAdminTx);6061 const addAdminTx2 = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));62 await submitTransactionAsync(alice, addAdminTx2);6364 const adminListAfterAddAdmin = await getAdminList(api, collectionId);65 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));6667 // then remove bob from admins of collection68 const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));69 await submitTransactionAsync(charlie, removeAdminTx);7071 const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);72 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));73 });74 });7576 it('Remove admin from collection that has no admins', async () => {77 await usingApi(async (api, privateKeyWrapper) => {78 const alice = privateKeyWrapper('//Alice');79 const collectionId = await createCollectionExpectSuccess();8081 const adminListBeforeAddAdmin = await getAdminList(api, collectionId);82 expect(adminListBeforeAddAdmin).to.have.lengthOf(0);8384 const tx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(alice.address));85 await submitTransactionAsync(alice, tx);86 });87 });88});8990describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {91 it('Can\'t remove collection admin from not existing collection', async () => {92 await usingApi(async (api, privateKeyWrapper) => {93 // tslint:disable-next-line: no-bitwise94 const collectionId = (1 << 32) - 1;95 const alice = privateKeyWrapper('//Alice');96 const bob = privateKeyWrapper('//Bob');9798 const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));99 await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;100101 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)102 await createCollectionExpectSuccess();103 });104 });105106 it('Can\'t remove collection admin from deleted collection', async () => {107 await usingApi(async (api, privateKeyWrapper) => {108 // tslint:disable-next-line: no-bitwise109 const collectionId = await createCollectionExpectSuccess();110 const alice = privateKeyWrapper('//Alice');111 const bob = privateKeyWrapper('//Bob');112113 await destroyCollectionExpectSuccess(collectionId);114115 const changeOwnerTx = api.tx.unique.removeCollectionAdmin(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('Regular user Can\'t remove collection admin', async () => {124 await usingApi(async (api, privateKeyWrapper) => {125 const collectionId = await createCollectionExpectSuccess();126 const alice = privateKeyWrapper('//Alice');127 const bob = privateKeyWrapper('//Bob');128 const charlie = privateKeyWrapper('//Charlie');129130 const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));131 await submitTransactionAsync(alice, addAdminTx);132133 const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));134 await expect(submitTransactionExpectFailAsync(charlie, changeOwnerTx)).to.be.rejected;135136 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)137 await createCollectionExpectSuccess();138 });139 });140});