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
--- 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
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
1616
17import chai from 'chai';17import chai from 'chai';
18import chaiAsPromised from 'chai-as-promised';18import chaiAsPromised from 'chai-as-promised';
19import privateKey from './substrate/privateKey';
19import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';20import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
20import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';21import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';
2122
46 });47 });
47 });48 });
48
49 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 Bob
58 const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
59 await submitTransactionAsync(alice, addAdminTx);
60
61 const addAdminTx2 = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));
62 await submitTransactionAsync(alice, addAdminTx2);
63
64 const adminListAfterAddAdmin = await getAdminList(api, collectionId);
65 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
66
67 // then remove bob from admins of collection
68 const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
69 await submitTransactionAsync(charlie, removeAdminTx);
70
71 const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);
72 expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));
73 });
74 });
7549
76 it('Remove admin from collection that has no admins', async () => {50 it('Remove admin from collection that has no admins', async () => {
77 await usingApi(async (api, privateKeyWrapper) => {51 await usingApi(async (api, privateKeyWrapper) => {
120 });94 });
121 });95 });
12296
123 it('Regular user Can\'t remove collection admin', async () => {97 it('Regular user can\'t remove collection admin', async () => {
124 await usingApi(async (api, privateKeyWrapper) => {98 await usingApi(async (api) => {
125 const collectionId = await createCollectionExpectSuccess();99 const collectionId = await createCollectionExpectSuccess();
126 const alice = privateKeyWrapper('//Alice');100 const alice = privateKey('//Alice');
127 const bob = privateKeyWrapper('//Bob');101 const bob = privateKey('//Bob');
128 const charlie = privateKeyWrapper('//Charlie');102 const charlie = privateKey('//Charlie');
129103
130 const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));104 const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
131 await submitTransactionAsync(alice, addAdminTx);105 await submitTransactionAsync(alice, addAdminTx);
138 });112 });
139 });113 });
114
115 it('Admin can\'t remove collection admin.', async () => {
116 await usingApi(async (api) => {
117 const collectionId = await createCollectionExpectSuccess();
118 const alice = privateKey('//Alice');
119 const bob = privateKey('//Bob');
120 const charlie = privateKey('//Charlie');
121
122 const adminListAfterAddAdmin = await getAdminList(api, collectionId);
123 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
124
125 const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
126 await expect(submitTransactionAsync(charlie, removeAdminTx)).to.be.rejected;
127
128 const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);
129 expect(adminListAfterRemoveAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
130 expect(adminListAfterRemoveAdmin).to.be.deep.contains(normalizeAccountId(charlie.address));
131 });
132 });
140});133});
141134