1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import chai from 'chai';19import chaiAsPromised from 'chai-as-promised';20import {itSub, usingPlaygrounds} from './util/playgrounds';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425describe('Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {26 let donor: IKeyringPair;2728 before(async () => {29 await usingPlaygrounds(async (_, privateKeyWrapper) => {30 donor = privateKeyWrapper('//Alice');31 });32 });3334 itSub('Add collection admin.', async ({helper}) => {35 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);36 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});3738 const collection = await helper.collection.getData(collectionId);39 expect(collection!.normalizedOwner!).to.be.equal(helper.address.normalizeSubstrate(alice.address));4041 await helper.nft.addAdmin(alice, collectionId, {Substrate: bob.address});4243 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);44 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});45 });46});4748describe('Negative Integration Test addCollectionAdmin(collection_id, new_admin_id):', () => {49 let donor: IKeyringPair;5051 before(async () => {52 await usingPlaygrounds(async (_, privateKeyWrapper) => {53 donor = privateKeyWrapper('//Alice');54 });55 });5657 itSub("Not owner can't add collection admin.", async ({helper}) => {58 const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);59 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});6061 const collection = await helper.collection.getData(collectionId);62 expect(collection?.normalizedOwner).to.be.equal(helper.address.normalizeSubstrate(alice.address));6364 const changeAdminTxBob = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: bob.address});65 const changeAdminTxCharlie = async () => helper.collection.addAdmin(bob, collectionId, {Substrate: charlie.address});66 await expect(changeAdminTxCharlie()).to.be.rejectedWith(/common\.NoPermission/);67 await expect(changeAdminTxBob()).to.be.rejectedWith(/common\.NoPermission/);6869 const adminListAfterAddAdmin = await helper.collection.getAdmins(collectionId);70 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: charlie.address});71 expect(adminListAfterAddAdmin).to.be.not.deep.contains({Substrate: bob.address});72 });7374 itSub("Admin can't add collection admin.", async ({helper}) => {75 const [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);76 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});7778 await collection.addAdmin(alice, {Substrate: bob.address});7980 const adminListAfterAddAdmin = await collection.getAdmins();81 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: bob.address});8283 const changeAdminTxCharlie = async () => collection.addAdmin(bob, {Substrate: charlie.address});84 await expect(changeAdminTxCharlie()).to.be.rejectedWith(/common\.NoPermission/);8586 const adminListAfterAddNewAdmin = await collection.getAdmins();87 expect(adminListAfterAddNewAdmin).to.be.deep.contains({Substrate: bob.address});88 expect(adminListAfterAddNewAdmin).to.be.not.deep.contains({Substrate: charlie.address});89 });9091 itSub("Can't add collection admin of not existing collection.", async ({helper}) => {92 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);93 const collectionId = (1 << 32) - 1;9495 const addAdminTx = async () => helper.collection.addAdmin(alice, collectionId, {Substrate: bob.address});96 await expect(addAdminTx()).to.be.rejectedWith(/common\.CollectionNotFound/);9798 99 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});100 });101102 itSub("Can't add an admin to a destroyed collection.", async ({helper}) => {103 const [alice, bob] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);104 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});105106 await collection.burn(alice);107 const addAdminTx = async () => collection.addAdmin(alice, {Substrate: bob.address});108 await expect(addAdminTx()).to.be.rejectedWith(/common\.CollectionNotFound/);109110 111 await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});112 });113114 itSub('Add an admin to a collection that has reached the maximum number of admins limit', async ({helper}) => {115 const [alice, ...accounts] = await helper.arrange.createAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);116 const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});117118 const chainAdminLimit = (helper.api!.consts.common.collectionAdminsLimit as any).toNumber();119 expect(chainAdminLimit).to.be.equal(5);120121 for (let i = 0; i < chainAdminLimit; i++) {122 await collection.addAdmin(alice, {Substrate: accounts[i].address});123 const adminListAfterAddAdmin = await collection.getAdmins();124 expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: accounts[i].address});125 }126127 const addExtraAdminTx = async () => collection.addAdmin(alice, {Substrate: accounts[chainAdminLimit].address});128 await expect(addExtraAdminTx()).to.be.rejectedWith(/common\.CollectionAdminCountExceeded/);129 });130});