git.delta.rocks / unique-network / refs/commits / 06f5d9ab3e7d

difftreelog

source

tests/src/collator-selection/identity.seqtest.ts4.8 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    if (!process.env.RUN_COLLATOR_TESTS) this.skip();3738    await usingPlaygrounds(async (helper, privateKey) => {39      requirePalletsOrSkip(this, helper, [Pallets.Identity]);40      superuser = await privateKey('//Alice');41    });42  });4344  itSub('Normal calls do not work', async ({helper}) => {45    // console.error = () => {};46    await expect(helper.executeExtrinsic(superuser, 'api.tx.identity.setIdentity', [{info: {display: {Raw: 'Meowser'}}}]))47      .to.be.rejectedWith(/Transaction call is not expected/);48  });4950  itSub('Sets identities', async ({helper}) => {51    const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;5253    const crowdSize = 10;54    const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);55    const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);56    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);5758    expect((await getIdentityAccounts(helper)).length).to.be.equal(oldIdentitiesCount + crowdSize);59  });6061  itSub('Setting identities does not delete existing but does overwrite', async ({helper}) => {62    const crowd = await helper.arrange.createCrowd(10, 0n, superuser);63    const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);6465    // insert a single identity66    let singleIdentity = identities.pop()!;67    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [[singleIdentity]]);6869    const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;7071    // change an identity and push it with a few new others72    singleIdentity = [singleIdentity[0], {info: {display: {Raw: 'something special'}}}];73    identities.push(singleIdentity);74    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);7576    // oldIdentitiesCount + 9 because one identity is overwritten, not inserted on top77    expect((await getIdentityAccounts(helper)).length).to.be.equal(oldIdentitiesCount + 9);78    expect((await helper.callRpc('api.query.identity.identityOf', [singleIdentity[0]])).toHuman().info.display)79      .to.be.deep.equal({Raw: 'something special'});80  });8182  itSub('Removes identities', async ({helper}) => {83    const crowd = await helper.arrange.createCrowd(10, 0n, superuser);84    const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);85    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);86    const oldIdentities = await getIdentityAccounts(helper);8788    // delete a couple, check that they are no longer there89    const scapegoats = [crowd.pop()!.address, crowd.pop()!.address];90    await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [scapegoats]);91    const newIdentities = await getIdentityAccounts(helper);92    expect(newIdentities.concat(scapegoats)).to.be.have.members(oldIdentities);93  });9495  after(async function() {96    if (!process.env.RUN_COLLATOR_TESTS) return;9798    await usingPlaygrounds(async helper => {99      if (helper.fetchMissingPalletNames([Pallets.Identity]).length != 0) return;100101      const identitiesToRemove: string[] = await getIdentityAccounts(helper);102      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [identitiesToRemove]);103    });104  });105});