git.delta.rocks / unique-network / refs/commits / b946921f1190

difftreelog

source

tests/src/identity.seqtest.ts4.7 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {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    // console.error = () => {};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    // insert a single identity64    let singleIdentity = identities.pop()!;65    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [[singleIdentity]]);6667    const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;6869    // change an identity and push it with a few new others70    singleIdentity = [singleIdentity[0], {info: {display: {Raw: 'something special'}}}];71    identities.push(singleIdentity);72    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);7374    // oldIdentitiesCount + 9 because one identity is overwritten, not inserted on top75    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    // delete a couple, check that they are no longer there87    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});