1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {usingPlaygrounds, expect, itSub, Pallets, requirePalletsOrSkip} from './util';19import {UniqueHelper} from './util/playgrounds/unique';2021async function getIdentities(helper: UniqueHelper) {22 const identities: [string, any][] = [];23 for(const [key, value] of await helper.getApi().query.identity.identityOf.entries())24 identities.push([(key as any).toHuman(), (value as any).unwrap()]);25 return identities;26}2728async function getIdentityAccounts(helper: UniqueHelper) {29 return (await getIdentities(helper)).flatMap(([key, _value]) => key);30}3132describe('Integration Test: Identities Manipulation', () => {33 let superuser: IKeyringPair;3435 before(async function() {36 await usingPlaygrounds(async (helper, privateKey) => {37 requirePalletsOrSkip(this, helper, [Pallets.Identity]);38 superuser = await privateKey('//Alice');39 });40 });4142 itSub('Normal calls do not work', async ({helper}) => {43 44 await expect(helper.executeExtrinsic(superuser, 'api.tx.identity.setIdentity', [{info: {display: {Raw: 'Meowser'}}}]))45 .to.be.rejectedWith(/Transaction call is not expected/);46 });4748 itSub('Sets identities', async ({helper}) => {49 const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;5051 const crowdSize = 10;52 const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);53 const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);54 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);5556 expect((await getIdentityAccounts(helper)).length).to.be.equal(oldIdentitiesCount + crowdSize);57 });5859 itSub('Setting identities does not delete existing but does overwrite', async ({helper}) => {60 const crowd = await helper.arrange.createCrowd(10, 0n, superuser);61 const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);6263 64 let singleIdentity = identities.pop()!;65 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [[singleIdentity]]);6667 const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;6869 70 singleIdentity = [singleIdentity[0], {info: {display: {Raw: 'something special'}}}];71 identities.push(singleIdentity);72 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);7374 75 expect((await getIdentityAccounts(helper)).length).to.be.equal(oldIdentitiesCount + 9);76 expect((await helper.callRpc('api.query.identity.identityOf', [singleIdentity[0]])).toHuman().info.display)77 .to.be.deep.equal({Raw: 'something special'});78 });7980 itSub('Removes identities', async ({helper}) => {81 const crowd = await helper.arrange.createCrowd(10, 0n, superuser);82 const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);83 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);84 const oldIdentities = await getIdentityAccounts(helper);8586 87 const scapegoats = [crowd.pop()!.address, crowd.pop()!.address];88 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [scapegoats]);89 const newIdentities = await getIdentityAccounts(helper);90 expect(newIdentities.concat(scapegoats)).to.be.have.members(oldIdentities);91 });9293 after(async function() {94 await usingPlaygrounds(async helper => {95 if (helper.fetchMissingPalletNames([Pallets.Identity]).length != 0) return;9697 const identitiesToRemove: string[] = await getIdentityAccounts(helper);98 await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [identitiesToRemove]);99 });100 });101});