difftreelog
CORE-402 Now admin can't add admin
in: master
2 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.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 });93