git.delta.rocks / unique-network / refs/commits / 1be4d6be040e

difftreelog

Merge pull request #367 from UniqueNetwork/feature/CORE-402

bugrazoid2022-06-09parents: #66f33e3 #974a15e.patch.diff
in: master
Feature/core 402

3 files changed

modifiedpallets/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 {
modifiedtests/src/addCollectionAdmin.test.tsdiffbeforeafterboth
after · tests/src/addCollectionAdmin.test.ts
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});
modifiedtests/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));
+    });
+  });
 });