difftreelog
Merge pull request #367 from UniqueNetwork/feature/CORE-402
in: master
Feature/core 402
3 files changed
pallets/common/src/lib.rsdiffbeforeafterboth1097 user: &T::CrossAccountId,1097 user: &T::CrossAccountId,1098 admin: bool,1098 admin: bool,1099 ) -> DispatchResult {1099 ) -> DispatchResult {1100 collection.check_is_owner_or_admin(sender)?;1100 collection.check_is_owner(sender)?;110111011102 let was_admin = <IsAdmin<T>>::get((collection.id, user));1102 let was_admin = <IsAdmin<T>>::get((collection.id, user));1103 if was_admin == admin {1103 if was_admin == admin {tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth17import {ApiPromise} from '@polkadot/api';17import {ApiPromise} from '@polkadot/api';18import chai from 'chai';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';20import privateKey from './substrate/privateKey';20import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';21import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';21import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';22import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';222341 });42 });42 });43 });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});44});684569describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {46describe('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 });6870 it("Not owner can't add collection admin.", async () => {69 it("Admin can't add collection admin.", async () => {71 await usingApi(async (api, privateKeyWrapper) => {70 await usingApi(async (api) => {72 const collectionId = await createCollectionExpectSuccess();71 const collectionId = await createCollectionExpectSuccess();73 const alice = privateKeyWrapper('//Alice');72 const alice = privateKey('//Alice');74 const nonOwner = privateKeyWrapper('//Bob_stash');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);757876 const changeAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(alice.address));79 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));77 await expect(submitTransactionExpectFailAsync(nonOwner, changeAdminTx)).to.be.rejected;86 await expect(submitTransactionAsync(bob, changeAdminTxCharlie)).to.be.rejected;7887 79 const adminListAfterAddAdmin = await getAdminList(api, collectionId);88 const adminListAfterAddNewAdmin = await getAdminList(api, collectionId);80 expect(adminListAfterAddAdmin).not.to.be.deep.contains(normalizeAccountId(alice.address));89 expect(adminListAfterAddNewAdmin).to.be.deep.contains(normalizeAccountId(bob.address));8182 // Verifying that nothing bad happened (network is live, new collections can be created, etc.)83 await createCollectionExpectSuccess();90 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains(normalizeAccountId(charlie.address));84 });91 });85 });92 });93tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth161617import 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';212246 });47 });47 });48 });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 });754976 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 });12296123 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');129103130 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 });114115 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');121122 const adminListAfterAddAdmin = await getAdminList(api, collectionId);123 expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));124125 const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));126 await expect(submitTransactionAsync(charlie, removeAdminTx)).to.be.rejected;127128 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