git.delta.rocks / unique-network / refs/commits / 61f7eda79233

difftreelog

Merge remote-tracking branch 'origin/feat/set-sub-identities' into develop

Yaroslav Bolyukin2023-01-18parents: #9296d13 #0a35447.patch.diff
in: master

6 files changed

modifiedMakefilediffbeforeafterboth
--- a/Makefile
+++ b/Makefile
@@ -146,5 +146,5 @@
 	make _bench PALLET=app-promotion PALLET_DIR=app-promotion
 	
 .PHONY: bench
-# Disabled: bench-scheduler, bench-collator-selection, bench-rmrk-core, bench-rmrk-equip
-bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets bench-identity
+# Disabled: bench-scheduler, bench-collator-selection, bench-identity, bench-rmrk-core, bench-rmrk-equip
+bench: bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets
modifiedpallets/identity/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/identity/src/benchmarking.rs
+++ b/pallets/identity/src/benchmarking.rs
@@ -417,7 +417,7 @@
 		let n in 0..600;
 		use frame_benchmarking::account;
 		let identities = (0..n).map(|i| (
-			account("caller", i, 0),
+			account("caller", i, SEED),
 			Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {
 				judgements: Default::default(),
 				deposit: Default::default(),
@@ -433,7 +433,7 @@
 		use frame_benchmarking::account;
 		let origin = T::ForceOrigin::successful_origin();
 		let identities = (0..n).map(|i| (
-			account("caller", i, 0),
+			account("caller", i, SEED),
 			Registration::<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields> {
 				judgements: Default::default(),
 				deposit: Default::default(),
@@ -446,6 +446,20 @@
 		let identities = identities.into_iter().map(|(acc, _)| acc).collect::<Vec<_>>();
 	}: _<T::RuntimeOrigin>(origin, identities)
 
+	force_set_subs {
+		let s in 0 .. T::MaxSubAccounts::get();
+		let n in 0..600;
+		use frame_benchmarking::account;
+		let identities = (0..n).map(|i| (
+			account("caller", i, SEED),
+			(
+				BalanceOf::<T>::max_value(),
+				create_sub_accounts::<T>(&caller, s)?.try_into().unwrap(),
+			),
+		)).collect::<Vec<_>>();
+		let origin = T::ForceOrigin::successful_origin();
+	}: _<T::RuntimeOrigin>(origin, identities)
+
 	add_sub {
 		let s in 0 .. T::MaxSubAccounts::get() - 1;
 
modifiedpallets/identity/src/lib.rsdiffbeforeafterboth
--- a/pallets/identity/src/lib.rs
+++ b/pallets/identity/src/lib.rs
@@ -314,6 +314,8 @@
 			main: T::AccountId,
 			deposit: BalanceOf<T>,
 		},
+		/// A number of identities were forcibly updated with new sub-identities.
+		SubIdentitiesInserted { amount: u32 },
 	}
 
 	#[pallet::call]
@@ -1137,13 +1139,64 @@
 		) -> DispatchResult {
 			T::ForceOrigin::ensure_origin(origin)?;
 			for identity in identities.clone() {
-				IdentityOf::<T>::set(identity, None);
+				let (_, sub_ids) = <SubsOf<T>>::take(&identity);
+				<IdentityOf<T>>::remove(&identity);
+				for sub in sub_ids.iter() {
+					<SuperOf<T>>::remove(sub);
+				}
 			}
 			Self::deposit_event(Event::IdentitiesRemoved {
 				amount: identities.len() as u32,
 			});
 			Ok(())
 		}
+
+		/// Set sub-identities to be associated with the provided accounts as force origin.
+		///
+		/// This is not meant to operate in tandem with the identity pallet as is,
+		/// and be instead used to keep identities made and verified externally,
+		/// forbidden from interacting with an ordinary user, since it ignores any safety mechanism.
+		#[pallet::call_index(17)]
+		#[pallet::weight(T::WeightInfo::force_set_subs(
+			T::MaxSubAccounts::get(), // S
+			subs.len() as u32, // N
+		))]
+		pub fn force_set_subs(
+			origin: OriginFor<T>,
+			subs: Vec<(
+				T::AccountId,
+				(
+					BalanceOf<T>,
+					BoundedVec<(T::AccountId, Data), T::MaxSubAccounts>,
+				),
+			)>,
+		) -> DispatchResult {
+			T::ForceOrigin::ensure_origin(origin)?;
+			for identity in subs.clone() {
+				let account = identity.0;
+				let (_, old_subs) = <SubsOf<T>>::get(&account);
+				for old_sub in old_subs {
+					<SuperOf<T>>::remove(old_sub);
+				}
+
+				let mut ids = BoundedVec::<T::AccountId, T::MaxSubAccounts>::default();
+				for (id, name) in identity.1 .1 {
+					<SuperOf<T>>::insert(&id, (account.clone(), name));
+					ids.try_push(id)
+						.expect("subs length is less than T::MaxSubAccounts; qed");
+				}
+
+				if ids.is_empty() {
+					<SubsOf<T>>::remove(&account);
+				} else {
+					<SubsOf<T>>::insert(account, (identity.1 .0, ids));
+				}
+			}
+			Self::deposit_event(Event::SubIdentitiesInserted {
+				amount: subs.len() as u32,
+			});
+			Ok(())
+		}
 	}
 }
 
modifiedpallets/identity/src/weights.rsdiffbeforeafterboth
--- a/pallets/identity/src/weights.rs
+++ b/pallets/identity/src/weights.rs
@@ -78,6 +78,7 @@
 	fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight;
 	fn force_insert_identities(x: u32, n: u32, ) -> Weight;
 	fn force_remove_identities(x: u32, n: u32, ) -> Weight;
+	fn force_set_subs(s: u32, n: u32, ) -> Weight;
 	fn add_sub(s: u32, ) -> Weight;
 	fn rename_sub(s: u32, ) -> Weight;
 	fn remove_sub(s: u32, ) -> Weight;
@@ -273,6 +274,20 @@
 			.saturating_add(T::DbWeight::get().reads(1 as u64))
 			.saturating_add(T::DbWeight::get().writes(1 as u64).saturating_mul(n as u64))
 	}
+	// Storage: Identity IdentityOf (r:1 w:1)
+	// todo:collator
+	/// The range of component `s` is `[0, 100]`.
+	/// The range of component `n` is `[0, 600]`.
+	fn force_set_subs(s: u32, n: u32) -> Weight {
+		// Minimum execution time: 41_872 nanoseconds.
+		Weight::from_ref_time(40_230_216 as u64)
+			// Standard Error: 2_342
+			.saturating_add(Weight::from_ref_time(145_168 as u64))
+			// Standard Error: 457
+			.saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(s as u64))
+			.saturating_add(T::DbWeight::get().reads(1 as u64))
+			.saturating_add(T::DbWeight::get().writes(1 as u64).saturating_mul(n as u64))
+	}
 	// Storage: Identity IdentityOf (r:1 w:0)
 	// Storage: Identity SuperOf (r:1 w:1)
 	// Storage: Identity SubsOf (r:1 w:1)
@@ -509,6 +524,20 @@
 			.saturating_add(RocksDbWeight::get().reads(1 as u64))
 			.saturating_add(RocksDbWeight::get().writes(1 as u64).saturating_mul(n as u64))
 	}
+	// Storage: Identity IdentityOf (r:1 w:1)
+	// todo:collator
+	/// The range of component `xs is `[0, 100]`.
+	/// The range of component `n` is `[0, 600]`.
+	fn force_set_subs(s: u32, n: u32) -> Weight {
+		// Minimum execution time: 41_872 nanoseconds.
+		Weight::from_ref_time(40_230_216 as u64)
+			// Standard Error: 2_342
+			.saturating_add(Weight::from_ref_time(145_168 as u64))
+			// Standard Error: 457
+			.saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(s as u64))
+			.saturating_add(RocksDbWeight::get().reads(1 as u64))
+			.saturating_add(RocksDbWeight::get().writes(1 as u64).saturating_mul(n as u64))
+	}
 	// Storage: Identity IdentityOf (r:1 w:0)
 	// Storage: Identity SuperOf (r:1 w:1)
 	// Storage: Identity SubsOf (r:1 w:1)
modifiedtests/src/collator-selection/identity.seqtest.tsdiffbeforeafterboth
before · tests/src/collator-selection/identity.seqtest.ts
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});
after · tests/src/collator-selection/identity.seqtest.ts
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}3132async function getSubIdentityAccounts(helper: UniqueHelper, address: string) {33  return ((await helper.getApi().query.identity.subsOf(address)).toHuman() as any)[1];34}3536async function getSubIdentityName(helper: UniqueHelper, address: string) {37  return ((await helper.getApi().query.identity.superOf(address)).toHuman() as any);38}3940describe('Integration Test: Identities Manipulation', () => {41  let superuser: IKeyringPair;4243  before(async function() {44    if (!process.env.RUN_COLLATOR_TESTS) this.skip();4546    await usingPlaygrounds(async (helper, privateKey) => {47      requirePalletsOrSkip(this, helper, [Pallets.Identity]);48      superuser = await privateKey('//Alice');49    });50  });5152  itSub('Normal calls do not work', async ({helper}) => {53    // console.error = () => {};54    await expect(helper.executeExtrinsic(superuser, 'api.tx.identity.setIdentity', [{info: {display: {Raw: 'Meowser'}}}]))55      .to.be.rejectedWith(/Transaction call is not expected/);56  });5758  describe('Identities', () => {59    itSub('Sets identities', async ({helper}) => {60      const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;6162      const crowdSize = 10;63      const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);64      const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);65      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);6667      expect((await getIdentityAccounts(helper)).length).to.be.equal(oldIdentitiesCount + crowdSize);68    });6970    itSub('Setting identities does not delete existing but does overwrite', async ({helper}) => {71      const crowd = await helper.arrange.createCrowd(10, 0n, superuser);72      const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);7374      // insert a single identity75      let singleIdentity = identities.pop()!;76      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [[singleIdentity]]);7778      const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;7980      // change an identity and push it with a few new others81      singleIdentity = [singleIdentity[0], {info: {display: {Raw: 'something special'}}}];82      identities.push(singleIdentity);83      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);8485      // oldIdentitiesCount + 9 because one identity is overwritten, not inserted on top86      expect((await getIdentityAccounts(helper)).length).to.be.equal(oldIdentitiesCount + 9);87      expect((await helper.callRpc('api.query.identity.identityOf', [singleIdentity[0]])).toHuman().info.display)88        .to.be.deep.equal({Raw: 'something special'});89    });9091    itSub('Removes identities', async ({helper}) => {92      const crowd = await helper.arrange.createCrowd(10, 0n, superuser);93      const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);94      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);95      const oldIdentities = await getIdentityAccounts(helper);9697      // delete a couple, check that they are no longer there98      const scapegoats = [crowd.pop()!.address, crowd.pop()!.address];99      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [scapegoats]);100      const newIdentities = await getIdentityAccounts(helper);101      expect(newIdentities.concat(scapegoats)).to.be.have.members(oldIdentities);102    });103  });104105  describe('Sub-identities', () => {106    itSub('Sets subs', async ({helper}) => {107      const crowdSize = 18;108      const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);109      const supers = [crowd.pop()!, crowd.pop()!, crowd.pop()!];110111      const subsPerSup = crowd.length / supers.length;112      let subCount = 0;113      const subs = [114        crowd.slice(subCount, subCount += subsPerSup + 1),115        crowd.slice(subCount, subCount += subsPerSup),116        crowd.slice(subCount, subCount += subsPerSup - 1),117      ];118119      const subsInfo = supers.map((acc, i) => [120        acc.address, [121          1000000n + BigInt(i + 1),122          subs[i].map((sub, j) => [123            sub.address, {Raw: `accounter #${j}`},124          ]),125        ],126      ]);127      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo]);128129      for (let i = 0; i < supers.length; i++) {130        // check deposit131        expect(((await helper.getApi().query.identity.subsOf(supers[i].address)).toJSON() as any)[0]).to.be.equal(1000001 + i);132133        const subsAccounts = await getSubIdentityAccounts(helper, supers[i].address);134        // check sub-identities as account ids135        expect(subsAccounts).to.include.members(subs[i].map(x => x.address));136137        for (let j = 0; j < subsAccounts.length; j++) {138          // check sub-identities' names139          expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `accounter #${j}`});140        }141      }142    });143144    itSub('Setting sub-identities does not delete other existing but does overwrite own', async ({helper}) => {145      const crowdSize = 18;146      const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);147      const supers = [crowd.pop()!, crowd.pop()!, crowd.pop()!];148149      const subsPerSup = crowd.length / supers.length;150      let subCount = 0;151      const subs = [152        crowd.slice(subCount, subCount += subsPerSup + 1),153        crowd.slice(subCount, subCount += subsPerSup),154        crowd.slice(subCount, subCount += subsPerSup - 1),155      ];156157      const subsInfo1 = supers.map((acc, i) => [158        acc.address, [159          1000000n + BigInt(i + 1),160          subs[i].map((sub, j) => [161            sub.address, {Raw: `accounter #${j}`},162          ]),163        ],164      ]);165      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo1]);166167      // change some sub-identities...168      subs[2].pop(); subs[2].pop(); subs[2].push(...await helper.arrange.createAccounts([0n], superuser));169170      // ...and set them171      const subsInfo2 = [[172        supers[2].address, [173          999999n,174          subs[2].map((sub, j) => [175            sub.address, {Raw: `discounter #${j}`},176          ]),177        ],178      ]];179      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo2]);180181      // make sure everything else is the same182      for (let i = 0; i < supers.length - 1; i++) {183        // check deposit184        expect(((await helper.getApi().query.identity.subsOf(supers[i].address)).toJSON() as any)[0]).to.be.equal(1000001 + i);185186        const subsAccounts = await getSubIdentityAccounts(helper, supers[i].address);187        // check sub-identities as account ids188        expect(subsAccounts).to.include.members(subs[i].map(x => x.address));189190        for (let j = 0; j < subsAccounts; j++) {191          // check sub-identities' names192          expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `accounter #${j}`});193        }194      }195196      // check deposit197      expect(((await helper.getApi().query.identity.subsOf(supers[2].address)).toJSON() as any)[0]).to.be.equal(999999);198199      const subsAccounts = await getSubIdentityAccounts(helper, supers[2].address);200      // check sub-identities as account ids201      expect(subsAccounts).to.include.members(subs[2].map(x => x.address));202203      for (let j = 0; j < subsAccounts.length; j++) {204        // check sub-identities' names205        expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `discounter #${j}`});206      }207    });208209    itSub('Removes sub-identities', async ({helper}) => {210      const crowdSize = 3;211      const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);212      const sup = crowd.pop()!;213214      const subsInfo1 = [[215        sup.address, [216          1000000n,217          crowd.map((sub, j) => [218            sub.address, {Raw: `accounter #${j}`},219          ]),220        ],221      ]];222      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo1]);223224      // empty sub-identities should delete the records225      const subsInfo2 = [[226        sup.address, [227          1000000n,228          [],229        ],230      ]];231      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo2]);232233      // check deposit234      expect((await helper.getApi().query.identity.subsOf(sup.address)).toHuman()).to.be.deep.equal(['0', []]);235236      for (let j = 0; j < crowd.length; j++) {237        // check sub-identities' names238        expect((await getSubIdentityName(helper, crowd[j].address))).to.be.null;239      }240    });241242    itSub('Removing identities deletes associated sub-identities', async ({helper}) => {243      const crowd = await helper.arrange.createCrowd(3, 0n, superuser);244      const sup = crowd.pop()!;245246      // insert identity247      const identities = [[sup.address, {info: {display: {Raw: 'mental'}}}]];248      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);249250      // and its sub-identities251      const subsInfo = [[252        sup.address, [253          1000000n,254          crowd.map((sub, j) => [255            sub.address, {Raw: `accounter #${j}`},256          ]),257        ],258      ]];259      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo]);260261      // delete top identity262      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [[sup.address]]);263264      // check that sub-identities are deleted265      expect((await helper.getApi().query.identity.subsOf(sup.address)).toHuman()).to.be.deep.equal(['0', []]);266267      for (let j = 0; j < crowd.length; j++) {268        // check sub-identities' names269        expect((await getSubIdentityName(helper, crowd[j].address))).to.be.null;270      }271    });272  });273274  after(async function() {275    if (!process.env.RUN_COLLATOR_TESTS) return;276277    await usingPlaygrounds(async helper => {278      if (helper.fetchMissingPalletNames([Pallets.Identity]).length != 0) return;279280      const identitiesToRemove: string[] = await getIdentityAccounts(helper);281      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [identitiesToRemove]);282    });283  });284});
modifiedtests/src/util/identitySetter.tsdiffbeforeafterboth
--- a/tests/src/util/identitySetter.ts
+++ b/tests/src/util/identitySetter.ts
@@ -1,5 +1,8 @@
 // Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
 // SPDX-License-Identifier: Apache-2.0
+//
+// Usage: `yarn setIdentities [relay WS URL] [parachain WS URL] [sudo key]`
+// Example: `yarn setIdentities wss://polkadot-rpc.dwellir.com ws://localhost:9944 escape pattern miracle train sudden cart adapt embark wedding alien lamp mesh`
 
 import {encodeAddress} from '@polkadot/keyring';
 import {usingPlaygrounds, Pallets} from './index';
@@ -9,36 +12,81 @@
 const paraUrl = process.argv[3] ?? 'ws://localhost:9944';
 const key = process.argv.length > 4 ? process.argv.slice(4).join(' ') : '//Alice';
 
+function extractAccountId(key: any): string {
+  return (key as any).toHuman()[0];
+}
+
 function extractIdentity(key: any, value: any): [string, any] {
-  return [(key as any).toHuman()[0], (value as any).unwrap()];
+  return [extractAccountId(key), (value as any).unwrap()];
 }
 
-async function getIdentities(helper: ChainHelperBase) {
+async function getIdentities(helper: ChainHelperBase, noneCasePredicate?: (key: any, value: any) => void) {
   const identities: [string, any][] = [];
-  for(const [key, value] of await helper.getApi().query.identity.identityOf.entries())
+  for(const [key, v] of await helper.getApi().query.identity.identityOf.entries()) {
+    const value = v as any;
+    if (value.isNone) {
+      if (noneCasePredicate) noneCasePredicate(key, value);
+      continue;
+    }
     identities.push(extractIdentity(key, value));
+  }
   return identities;
 }
 
-// This is a utility for pulling
+function constructSubInfo(identityAccount: string, subQuery: any, supers: any[], ss58?: number): [string, any] {
+  const deposit = subQuery.toJSON()[0];
+  const subIdentities = subQuery.toHuman()[1];
+  subIdentities.map((sub: string) => supers.find((sup: any) => sup[0] === sub));
+  // supers.find((x: any) => x[0] === subIdentities[0])![1].toHuman();
+  return [
+    encodeAddress(identityAccount, ss58), [
+      deposit,
+      subIdentities.map((sub: string) => [
+        encodeAddress(sub, ss58),
+        supers.find((sup: any) => sup[0] === sub)![1].toJSON()[1],
+      ]),
+    ],
+  ];
+}
+
+async function getSubs(helper: ChainHelperBase) {
+  return (await helper.getApi().query.identity.subsOf.entries()).map(([key, value]) => [extractAccountId(key), value as any]);
+}
+
+async function getSupers(helper: ChainHelperBase) {
+  return (await helper.getApi().query.identity.superOf.entries()).map(([key, value]) => [extractAccountId(key), value as any]);
+}
+
+// The utility for pulling identity and sub-identity data
 const forceInsertIdentities = async (): Promise<void> => {
   const identitiesOnRelay: any[] = [];
+  const subsOnRelay: any[] = [];
   const identitiesToRemove: string[] = [];
   await usingPlaygrounds(async helper => {
     try {
       // iterate over every identity
-      for(const [key, v] of await helper.getApi().query.identity.identityOf.entries()) {
-        const value = v as any;
-        if (value.isNone) {
-          // in the nigh-impossible case that storage map would actually give None for a value, might as well delete it
-          identitiesToRemove.push((key as any).toHuman()[0]);
-          continue;
-        }
-
+      for(const [key, value] of await getIdentities(helper, (key, _value) => identitiesToRemove.push((key as any).toHuman()[0]))) {
         // if any of the judgements resulted in a good confirmed outcome, keep this identity
-        if (value.unwrap().toHuman().judgements.filter((x: any) => x[1] == 'Reasonable' || x[1] == 'KnownGood').length == 0) continue;
-        identitiesOnRelay.push(extractIdentity(key, value));
+        if (value.toHuman().judgements.filter((x: any) => x[1] == 'Reasonable' || x[1] == 'KnownGood').length == 0) continue;
+        identitiesOnRelay.push([key, value]);
+      }
+
+      const sublessIdentities = [...identitiesOnRelay];
+      const supersOfSubs = await getSupers(helper);
+
+      // iterate over every sub-identity
+      for(const [key, value] of await getSubs(helper)) {
+        // only get subs of the identities interesting to us
+        const identityIndex = sublessIdentities.findIndex((x: any) => x[0] == key);
+        if (identityIndex == -1) continue;
+        sublessIdentities.splice(identityIndex, 1);
+        subsOnRelay.push(constructSubInfo(key, value, supersOfSubs));
       }
+
+      // mark the rest of sub-identities for deletion with empty arrays
+      /*for(const [account, _identity] of sublessIdentities) {
+        subsOnRelay.push([account, ['0', []]]);
+      }*/
     } catch (error) {
       console.error(error);
       throw Error('Error during fetching identities');
@@ -60,7 +108,7 @@
         const identity = paraIdentities.find(i => i[0] === encodedKey);
         if (identity) {
           // only update if the identity info does not exist or is changed
-          if (value.toString() === identity[1].toString()) {
+          if (JSON.stringify(value) === JSON.stringify(identity[1])) {
             continue;
           }
         }
@@ -71,11 +119,36 @@
         // identitiesToRemove.push((key as any).toHuman()[0]);
       }
 
-      // await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [identitiesToRemove]);
-      await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identitiesToAdd]);
-      console.log(`Tried to upload ${identitiesToAdd.length} identities `
-        + `and found ${identitiesToRemove.length} identities for potential removal. `
-        + `Now there are ${(await helper.getApi().query.identity.identityOf.keys()).length}.`);
+      const paraSubs = await getSubs(helper);
+      const supersOfSubs = await getSupers(helper);
+      const subsToUpdate: any[] = [];
+
+      if (identitiesToRemove.length != 0)
+        await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [identitiesToRemove]);
+      if (identitiesToAdd.length != 0)
+        await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identitiesToAdd]);
+
+      console.log(`Tried to upload ${identitiesToAdd.length} identities`
+        + ` and found ${identitiesToRemove.length} identities for potential removal.`
+        + ` Now there are ${(await helper.getApi().query.identity.identityOf.keys()).length}.`);
+
+      for (const [key, value] of subsOnRelay) {
+        const encodedKey = encodeAddress(key, ss58Format);
+        const sub = paraSubs.find(i => i[0] === encodedKey);
+        if (sub) {
+          // only update if the sub-identity info does not exist or is changed
+          if (JSON.stringify(value) === JSON.stringify(constructSubInfo(sub[0], sub[1], supersOfSubs)[1])) {
+            continue;
+          }
+        }
+        subsToUpdate.push([key, value]);
+      }
+
+      if (subsToUpdate.length != 0)
+        await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsToUpdate]);
+
+      console.log(`Also tried to update ${subsToUpdate.length} identities with their sub-identities.`
+        + ` Now there are ${(await helper.getApi().query.identity.subsOf.keys()).length} identities with subs.`);
     } catch (error) {
       console.error(error);
       throw Error('Error during setting identities');