1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util/playgrounds';1920describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {21 let donor: IKeyringPair;2223 before(async () => {24 await usingPlaygrounds(async (_, privateKeyWrapper) => {25 donor = privateKeyWrapper('//Alice');26 });27 });2829 itSub('Add collection admin.', async ({helper}) => {30 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);31 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});3233 const collection = await helper.collection.getData(collectionId);34 expect(collection!.normalizedOwner!).to.be.equal(helper.address.normalizeSubstrate(alice.address));3536 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});3738 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);39 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});40 });41});4243describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {44 let donor: IKeyringPair;4546 before(async () => {47 await usingPlaygrounds(async (_, privateKeyWrapper) => {48 donor = privateKeyWrapper('//Alice');49 });50 });5152 itSub("Not owner can't add collection admin.", async ({helper}) => {53 const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);54 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});5556 const collection = await helper.collection.getData(collectionId);57 expect(collection?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));5859 const changeAdminTxBob = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: bob.address});60 const changeAdminTxCharlie = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: charlie.address});61 await expect(changeAdminTxCharlie()).to.be.rejectedWith(/common\.NoPermission/);62 await expect(changeAdminTxBob()).to.be.rejectedWith(/common\.NoPermission/);6364 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);65 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: charlie.address});66 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: bob.address});67 });6869 itSub("Admin can't add collection admin.", async ({helper}) => {70 const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);71 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});7273 await collection.addAdmin(alice, {Substrate: bob.address});7475 const adminListAfterAddAdmin = await collection.getAdmins();76 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});7778 const changeAdminTxCharlie = async () => collection.addAdmin(bob, {Substrate: charlie.address});79 await expect(changeAdminTxCharlie()).to.be.rejectedWith(/common\.NoPermission/);8081 const adminListAfterAddNewAdmin = await collection.getAdmins();82 expect(adminListAfterAddNewAdmin).to.be.deep.contains({Substrate: bob.address});83 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains({Substrate: charlie.address});84 });8586 itSub("Can't add collection admin of not existing collection.", async ({helper}) => {87 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);88 const collectionId = (1 << 32) - 1;8990 const addAdminTx = async () => helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});91 await expect(addAdminTx()).to.be.rejectedWith(/common\.CollectionNotFound/);9293 94 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});95 });9697 itSub("Can't add an admin to a destroyed collection.", async ({helper}) => {98 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);99 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});100101 await collection.burn(alice);102 const addAdminTx = async () => collection.addAdmin(alice, {Substrate: bob.address});103 await expect(addAdminTx()).to.be.rejectedWith(/common\.CollectionNotFound/);104105 106 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});107 });108109 itSub('Add an admin to a collection that has reached the maximum number of admins limit', async ({helper}) => {110 const [alice, ...accounts] = await helper.arrange.createAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);111 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});112113 const chainAdminLimit = (helper.getApi().consts.common.collectionAdminsLimit as any).toNumber();114 expect(chainAdminLimit).to.be.equal(5);115116 for (let i = 0; i < chainAdminLimit; i++) {117 await collection.addAdmin(alice, {Substrate: accounts[i].address});118 const adminListAfterAddAdmin = await collection.getAdmins();119 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: accounts[i].address});120 }121122 const addExtraAdminTx = async () => collection.addAdmin(alice, {Substrate: accounts[chainAdminLimit].address});123 await expect(addExtraAdminTx()).to.be.rejectedWith(/common\.CollectionAdminCountExceeded/);124 });125});