1234567891011121314151617import type {IKeyringPair} from '@polkadot/types/types';18import {itSub, usingPlaygrounds, expect} from './util/index.js';19import {NON_EXISTENT_COLLECTION_ID} from '@unique/playgrounds/types.js';2021describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {22 let donor: IKeyringPair;2324 before(async () => {25 await usingPlaygrounds(async (_, privateKey) => {26 donor = await privateKey({url: import.meta.url});27 });28 });2930 itSub('Add collection admin.', async ({helper}) => {31 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);32 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});3334 const collection = await helper.collection.getData(collectionId);35 expect(collection!.normalizedOwner!).to.be.equal(helper.address.normalizeSubstrate(alice.address));3637 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});3839 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);40 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});41 });42});4344describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {45 let donor: IKeyringPair;4647 before(async () => {48 await usingPlaygrounds(async (_, privateKey) => {49 donor = await privateKey({url: import.meta.url});50 });51 });5253 itSub("Not owner can't add collection admin.", async ({helper}) => {54 const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);55 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});5657 const collection = await helper.collection.getData(collectionId);58 expect(collection?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));5960 await expect(helper.collection.addAdmin(bob, collectionId, {Substrate: charlie.address})).to.be.rejectedWith(/common\.NoPermission/);61 await expect(helper.collection.addAdmin(bob, collectionId, {Substrate: bob.address})).to.be.rejectedWith(/common\.NoPermission/);6263 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);64 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: charlie.address});65 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: bob.address});66 });6768 itSub("Admin can't add collection admin.", async ({helper}) => {69 const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);70 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});7172 await collection.addAdmin(alice, {Substrate: bob.address});7374 const adminListAfterAddAdmin = await collection.getAdmins();75 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});7677 await expect(collection.addAdmin(bob, {Substrate: charlie.address})).to.be.rejectedWith(/common\.NoPermission/);7879 const adminListAfterAddNewAdmin = await collection.getAdmins();80 expect(adminListAfterAddNewAdmin).to.be.deep.contains({Substrate: bob.address});81 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains({Substrate: charlie.address});82 });8384 itSub("Can't add collection admin of not existing collection.", async ({helper}) => {85 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);86 const collectionId = NON_EXISTENT_COLLECTION_ID;8788 await expect(helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejectedWith(/common\.CollectionNotFound/);8990 91 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});92 });9394 itSub("Can't add an admin to a destroyed collection.", async ({helper}) => {95 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);96 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});9798 await collection.burn(alice);99 await expect(collection.addAdmin(alice, {Substrate: bob.address})).to.be.rejectedWith(/common\.CollectionNotFound/);100101 102 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});103 });104105 itSub('Add an admin to a collection that has reached the maximum number of admins limit', async ({helper}) => {106 const [alice, ...accounts] = await helper.arrange.createAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);107 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});108109 const chainAdminLimit = (helper.getApi().consts.common.collectionAdminsLimit as any).toNumber();110 expect(chainAdminLimit).to.be.equal(5);111112 for(let i = 0; i < chainAdminLimit; i++) {113 await collection.addAdmin(alice, {Substrate: accounts[i].address});114 const adminListAfterAddAdmin = await collection.getAdmins();115 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: accounts[i].address});116 }117118 await expect(collection.addAdmin(alice, {Substrate: accounts[chainAdminLimit].address})).to.be.rejectedWith(/common\.CollectionAdminCountExceeded/);119 });120});