difftreelog
Merge remote-tracking branch 'origin/feat/set-sub-identities' into develop
in: master
6 files changed
Makefilediffbeforeafterboth--- 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
pallets/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;
pallets/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(())
+ }
}
}
pallets/identity/src/weights.rsdiffbeforeafterboth1// 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/>.1617// Original license:18// This file is part of Substrate.1920// Copyright (C) 2022 Parity Technologies (UK) Ltd.21// SPDX-License-Identifier: Apache-2.02223// Licensed under the Apache License, Version 2.0 (the "License");24// you may not use this file except in compliance with the License.25// You may obtain a copy of the License at26//27// http://www.apache.org/licenses/LICENSE-2.028//29// Unless required by applicable law or agreed to in writing, software30// distributed under the License is distributed on an "AS IS" BASIS,31// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.32// See the License for the specific language governing permissions and33// limitations under the License.3435//! Autogenerated weights for pallet_identity36//!37//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev38//! DATE: 2022-11-07, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`39//! HOSTNAME: `bm2`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz`40//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 10244142// Executed Command:43// ./target/production/substrate44// benchmark45// pallet46// --chain=dev47// --steps=5048// --repeat=2049// --pallet=pallet_identity50// --extrinsic=*51// --execution=wasm52// --wasm-execution=compiled53// --heap-pages=409654// --output=./frame/identity/src/weights.rs55// --header=./HEADER-APACHE256// --template=./.maintain/frame-weight-template.hbs5758#![cfg_attr(rustfmt, rustfmt_skip)]59#![allow(unused_parens)]60#![allow(unused_imports)]6162use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};63use sp_std::marker::PhantomData;6465/// Weight functions needed for pallet_identity.66pub trait WeightInfo {67 fn add_registrar(r: u32, ) -> Weight;68 fn set_identity(r: u32, x: u32, ) -> Weight;69 fn set_subs_new(s: u32, ) -> Weight;70 fn set_subs_old(p: u32, ) -> Weight;71 fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight;72 fn request_judgement(r: u32, x: u32, ) -> Weight;73 fn cancel_request(r: u32, x: u32, ) -> Weight;74 fn set_fee(r: u32, ) -> Weight;75 fn set_account_id(r: u32, ) -> Weight;76 fn set_fields(r: u32, ) -> Weight;77 fn provide_judgement(r: u32, x: u32, ) -> Weight;78 fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight;79 fn force_insert_identities(x: u32, n: u32, ) -> Weight;80 fn force_remove_identities(x: u32, n: u32, ) -> Weight;81 fn force_set_subs(s: u32, n: u32, ) -> Weight;82 fn add_sub(s: u32, ) -> Weight;83 fn rename_sub(s: u32, ) -> Weight;84 fn remove_sub(s: u32, ) -> Weight;85 fn quit_sub(s: u32, ) -> Weight;86}8788/// Weights for pallet_identity using the Substrate node and recommended hardware.89pub struct SubstrateWeight<T>(PhantomData<T>);90impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {91 // Storage: Identity Registrars (r:1 w:1)92 /// The range of component `r` is `[1, 19]`.93 fn add_registrar(r: u32, ) -> Weight {94 // Minimum execution time: 20_269 nanoseconds.95 Weight::from_ref_time(21_910_543 as u64)96 // Standard Error: 4_60497 .saturating_add(Weight::from_ref_time(223_104 as u64).saturating_mul(r as u64))98 .saturating_add(T::DbWeight::get().reads(1 as u64))99 .saturating_add(T::DbWeight::get().writes(1 as u64))100 }101 // Storage: Identity IdentityOf (r:1 w:1)102 /// The range of component `r` is `[1, 20]`.103 /// The range of component `x` is `[0, 100]`.104 fn set_identity(r: u32, x: u32, ) -> Weight {105 // Minimum execution time: 41_872 nanoseconds.106 Weight::from_ref_time(40_230_216 as u64)107 // Standard Error: 2_342108 .saturating_add(Weight::from_ref_time(145_168 as u64).saturating_mul(r as u64))109 // Standard Error: 457110 .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(x as u64))111 .saturating_add(T::DbWeight::get().reads(1 as u64))112 .saturating_add(T::DbWeight::get().writes(1 as u64))113 }114 // Storage: Identity IdentityOf (r:1 w:0)115 // Storage: Identity SubsOf (r:1 w:1)116 // Storage: Identity SuperOf (r:2 w:2)117 /// The range of component `s` is `[0, 100]`.118 fn set_subs_new(s: u32, ) -> Weight {119 // Minimum execution time: 12_024 nanoseconds.120 Weight::from_ref_time(32_550_819 as u64)121 // Standard Error: 5_057122 .saturating_add(Weight::from_ref_time(2_521_245 as u64).saturating_mul(s as u64))123 .saturating_add(T::DbWeight::get().reads(2 as u64))124 .saturating_add(T::DbWeight::get().reads((1 as u64).saturating_mul(s as u64)))125 .saturating_add(T::DbWeight::get().writes(1 as u64))126 .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(s as u64)))127 }128 // Storage: Identity IdentityOf (r:1 w:0)129 // Storage: Identity SubsOf (r:1 w:1)130 // Storage: Identity SuperOf (r:0 w:2)131 /// The range of component `p` is `[0, 100]`.132 fn set_subs_old(p: u32, ) -> Weight {133 // Minimum execution time: 12_232 nanoseconds.134 Weight::from_ref_time(34_009_761 as u64)135 // Standard Error: 5_047136 .saturating_add(Weight::from_ref_time(1_113_100 as u64).saturating_mul(p as u64))137 .saturating_add(T::DbWeight::get().reads(2 as u64))138 .saturating_add(T::DbWeight::get().writes(1 as u64))139 .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(p as u64)))140 }141 // Storage: Identity SubsOf (r:1 w:1)142 // Storage: Identity IdentityOf (r:1 w:1)143 // Storage: Identity SuperOf (r:0 w:100)144 /// The range of component `r` is `[1, 20]`.145 /// The range of component `s` is `[0, 100]`.146 /// The range of component `x` is `[0, 100]`.147 fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight {148 // Minimum execution time: 57_144 nanoseconds.149 Weight::from_ref_time(41_559_247 as u64)150 // Standard Error: 9_996151 .saturating_add(Weight::from_ref_time(146_770 as u64).saturating_mul(r as u64))152 // Standard Error: 1_952153 .saturating_add(Weight::from_ref_time(1_086_673 as u64).saturating_mul(s as u64))154 // Standard Error: 1_952155 .saturating_add(Weight::from_ref_time(162_481 as u64).saturating_mul(x as u64))156 .saturating_add(T::DbWeight::get().reads(2 as u64))157 .saturating_add(T::DbWeight::get().writes(2 as u64))158 .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(s as u64)))159 }160 // Storage: Identity Registrars (r:1 w:0)161 // Storage: Identity IdentityOf (r:1 w:1)162 /// The range of component `r` is `[1, 20]`.163 /// The range of component `x` is `[0, 100]`.164 fn request_judgement(r: u32, x: u32, ) -> Weight {165 // Minimum execution time: 44_726 nanoseconds.166 Weight::from_ref_time(41_637_308 as u64)167 // Standard Error: 1_907168 .saturating_add(Weight::from_ref_time(219_078 as u64).saturating_mul(r as u64))169 // Standard Error: 372170 .saturating_add(Weight::from_ref_time(309_888 as u64).saturating_mul(x as u64))171 .saturating_add(T::DbWeight::get().reads(2 as u64))172 .saturating_add(T::DbWeight::get().writes(1 as u64))173 }174 // Storage: Identity IdentityOf (r:1 w:1)175 /// The range of component `r` is `[1, 20]`.176 /// The range of component `x` is `[0, 100]`.177 fn cancel_request(r: u32, x: u32, ) -> Weight {178 // Minimum execution time: 39_719 nanoseconds.179 Weight::from_ref_time(38_008_751 as u64)180 // Standard Error: 2_394181 .saturating_add(Weight::from_ref_time(181_870 as u64).saturating_mul(r as u64))182 // Standard Error: 467183 .saturating_add(Weight::from_ref_time(314_990 as u64).saturating_mul(x as u64))184 .saturating_add(T::DbWeight::get().reads(1 as u64))185 .saturating_add(T::DbWeight::get().writes(1 as u64))186 }187 // Storage: Identity Registrars (r:1 w:1)188 /// The range of component `r` is `[1, 19]`.189 fn set_fee(r: u32, ) -> Weight {190 // Minimum execution time: 10_634 nanoseconds.191 Weight::from_ref_time(11_383_704 as u64)192 // Standard Error: 2_250193 .saturating_add(Weight::from_ref_time(193_094 as u64).saturating_mul(r as u64))194 .saturating_add(T::DbWeight::get().reads(1 as u64))195 .saturating_add(T::DbWeight::get().writes(1 as u64))196 }197 // Storage: Identity Registrars (r:1 w:1)198 /// The range of component `r` is `[1, 19]`.199 fn set_account_id(r: u32, ) -> Weight {200 // Minimum execution time: 10_840 nanoseconds.201 Weight::from_ref_time(11_638_740 as u64)202 // Standard Error: 1_985203 .saturating_add(Weight::from_ref_time(193_016 as u64).saturating_mul(r as u64))204 .saturating_add(T::DbWeight::get().reads(1 as u64))205 .saturating_add(T::DbWeight::get().writes(1 as u64))206 }207 // Storage: Identity Registrars (r:1 w:1)208 /// The range of component `r` is `[1, 19]`.209 fn set_fields(r: u32, ) -> Weight {210 // Minimum execution time: 10_748 nanoseconds.211 Weight::from_ref_time(11_346_901 as u64)212 // Standard Error: 2_132213 .saturating_add(Weight::from_ref_time(196_630 as u64).saturating_mul(r as u64))214 .saturating_add(T::DbWeight::get().reads(1 as u64))215 .saturating_add(T::DbWeight::get().writes(1 as u64))216 }217 // Storage: Identity Registrars (r:1 w:0)218 // Storage: Identity IdentityOf (r:1 w:1)219 /// The range of component `r` is `[1, 19]`.220 /// The range of component `x` is `[0, 100]`.221 fn provide_judgement(r: u32, x: u32, ) -> Weight {222 // Minimum execution time: 33_682 nanoseconds.223 Weight::from_ref_time(31_336_603 as u64)224 // Standard Error: 3_056225 .saturating_add(Weight::from_ref_time(200_403 as u64).saturating_mul(r as u64))226 // Standard Error: 565227 .saturating_add(Weight::from_ref_time(525_142 as u64).saturating_mul(x as u64))228 .saturating_add(T::DbWeight::get().reads(2 as u64))229 .saturating_add(T::DbWeight::get().writes(1 as u64))230 }231 // Storage: Identity SubsOf (r:1 w:1)232 // Storage: Identity IdentityOf (r:1 w:1)233 // Storage: System Account (r:1 w:1)234 // Storage: Identity SuperOf (r:0 w:100)235 /// The range of component `r` is `[1, 20]`.236 /// The range of component `s` is `[0, 100]`.237 /// The range of component `x` is `[0, 100]`.238 fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight {239 // Minimum execution time: 68_794 nanoseconds.240 Weight::from_ref_time(52_114_486 as u64)241 // Standard Error: 4_808242 .saturating_add(Weight::from_ref_time(153_462 as u64).saturating_mul(r as u64))243 // Standard Error: 939244 .saturating_add(Weight::from_ref_time(1_084_612 as u64).saturating_mul(s as u64))245 // Standard Error: 939246 .saturating_add(Weight::from_ref_time(170_112 as u64).saturating_mul(x as u64))247 .saturating_add(T::DbWeight::get().reads(3 as u64))248 .saturating_add(T::DbWeight::get().writes(3 as u64))249 .saturating_add(T::DbWeight::get().writes((1 as u64).saturating_mul(s as u64)))250 }251 // Storage: Identity IdentityOf (r:1 w:1)252 /// The range of component `x` is `[0, 100]`.253 /// The range of component `n` is `[0, 600]`.254 fn force_insert_identities(x: u32, n: u32) -> Weight {255 // Minimum execution time: 41_872 nanoseconds.256 Weight::from_ref_time(40_230_216 as u64)257 // Standard Error: 2_342258 .saturating_add(Weight::from_ref_time(145_168 as u64))259 // Standard Error: 457260 .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(x as u64))261 .saturating_add(T::DbWeight::get().reads(1 as u64))262 .saturating_add(T::DbWeight::get().writes(1 as u64).saturating_mul(n as u64))263 }264 // Storage: Identity IdentityOf (r:1 w:1)265 /// The range of component `x` is `[0, 100]`.266 /// The range of component `n` is `[0, 600]`.267 fn force_remove_identities(x: u32, n: u32) -> Weight {268 // Minimum execution time: 41_872 nanoseconds.269 Weight::from_ref_time(40_230_216 as u64)270 // Standard Error: 2_342271 .saturating_add(Weight::from_ref_time(145_168 as u64))272 // Standard Error: 457273 .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(x as u64))274 .saturating_add(T::DbWeight::get().reads(1 as u64))275 .saturating_add(T::DbWeight::get().writes(1 as u64).saturating_mul(n as u64))276 }277 // Storage: Identity IdentityOf (r:1 w:1)278 // todo:collator279 /// The range of component `s` is `[0, 100]`.280 /// The range of component `n` is `[0, 600]`.281 fn force_set_subs(s: u32, n: u32) -> Weight {282 // Minimum execution time: 41_872 nanoseconds.283 Weight::from_ref_time(40_230_216 as u64)284 // Standard Error: 2_342285 .saturating_add(Weight::from_ref_time(145_168 as u64))286 // Standard Error: 457287 .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(s as u64))288 .saturating_add(T::DbWeight::get().reads(1 as u64))289 .saturating_add(T::DbWeight::get().writes(1 as u64).saturating_mul(n as u64))290 }291 // Storage: Identity IdentityOf (r:1 w:0)292 // Storage: Identity SuperOf (r:1 w:1)293 // Storage: Identity SubsOf (r:1 w:1)294 /// The range of component `s` is `[0, 99]`.295 fn add_sub(s: u32, ) -> Weight {296 // Minimum execution time: 37_914 nanoseconds.297 Weight::from_ref_time(43_488_083 as u64)298 // Standard Error: 1_631299 .saturating_add(Weight::from_ref_time(118_845 as u64).saturating_mul(s as u64))300 .saturating_add(T::DbWeight::get().reads(3 as u64))301 .saturating_add(T::DbWeight::get().writes(2 as u64))302 }303 // Storage: Identity IdentityOf (r:1 w:0)304 // Storage: Identity SuperOf (r:1 w:1)305 /// The range of component `s` is `[1, 100]`.306 fn rename_sub(s: u32, ) -> Weight {307 // Minimum execution time: 16_124 nanoseconds.308 Weight::from_ref_time(18_580_462 as u64)309 // Standard Error: 688310 .saturating_add(Weight::from_ref_time(67_220 as u64).saturating_mul(s as u64))311 .saturating_add(T::DbWeight::get().reads(2 as u64))312 .saturating_add(T::DbWeight::get().writes(1 as u64))313 }314 // Storage: Identity IdentityOf (r:1 w:0)315 // Storage: Identity SuperOf (r:1 w:1)316 // Storage: Identity SubsOf (r:1 w:1)317 /// The range of component `s` is `[1, 100]`.318 fn remove_sub(s: u32, ) -> Weight {319 // Minimum execution time: 41_517 nanoseconds.320 Weight::from_ref_time(45_123_530 as u64)321 // Standard Error: 1_530322 .saturating_add(Weight::from_ref_time(105_429 as u64).saturating_mul(s as u64))323 .saturating_add(T::DbWeight::get().reads(3 as u64))324 .saturating_add(T::DbWeight::get().writes(2 as u64))325 }326 // Storage: Identity SuperOf (r:1 w:1)327 // Storage: Identity SubsOf (r:1 w:1)328 /// The range of component `s` is `[0, 99]`.329 fn quit_sub(s: u32, ) -> Weight {330 // Minimum execution time: 30_171 nanoseconds.331 Weight::from_ref_time(33_355_514 as u64)332 // Standard Error: 1_286333 .saturating_add(Weight::from_ref_time(114_716 as u64).saturating_mul(s as u64))334 .saturating_add(T::DbWeight::get().reads(2 as u64))335 .saturating_add(T::DbWeight::get().writes(2 as u64))336 }337}338339// For backwards compatibility and tests340impl WeightInfo for () {341 // Storage: Identity Registrars (r:1 w:1)342 /// The range of component `r` is `[1, 19]`.343 fn add_registrar(r: u32, ) -> Weight {344 // Minimum execution time: 20_269 nanoseconds.345 Weight::from_ref_time(21_910_543 as u64)346 // Standard Error: 4_604347 .saturating_add(Weight::from_ref_time(223_104 as u64).saturating_mul(r as u64))348 .saturating_add(RocksDbWeight::get().reads(1 as u64))349 .saturating_add(RocksDbWeight::get().writes(1 as u64))350 }351 // Storage: Identity IdentityOf (r:1 w:1)352 /// The range of component `r` is `[1, 20]`.353 /// The range of component `x` is `[0, 100]`.354 fn set_identity(r: u32, x: u32, ) -> Weight {355 // Minimum execution time: 41_872 nanoseconds.356 Weight::from_ref_time(40_230_216 as u64)357 // Standard Error: 2_342358 .saturating_add(Weight::from_ref_time(145_168 as u64).saturating_mul(r as u64))359 // Standard Error: 457360 .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(x as u64))361 .saturating_add(RocksDbWeight::get().reads(1 as u64))362 .saturating_add(RocksDbWeight::get().writes(1 as u64))363 }364 // Storage: Identity IdentityOf (r:1 w:0)365 // Storage: Identity SubsOf (r:1 w:1)366 // Storage: Identity SuperOf (r:2 w:2)367 /// The range of component `s` is `[0, 100]`.368 fn set_subs_new(s: u32, ) -> Weight {369 // Minimum execution time: 12_024 nanoseconds.370 Weight::from_ref_time(32_550_819 as u64)371 // Standard Error: 5_057372 .saturating_add(Weight::from_ref_time(2_521_245 as u64).saturating_mul(s as u64))373 .saturating_add(RocksDbWeight::get().reads(2 as u64))374 .saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(s as u64)))375 .saturating_add(RocksDbWeight::get().writes(1 as u64))376 .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(s as u64)))377 }378 // Storage: Identity IdentityOf (r:1 w:0)379 // Storage: Identity SubsOf (r:1 w:1)380 // Storage: Identity SuperOf (r:0 w:2)381 /// The range of component `p` is `[0, 100]`.382 fn set_subs_old(p: u32, ) -> Weight {383 // Minimum execution time: 12_232 nanoseconds.384 Weight::from_ref_time(34_009_761 as u64)385 // Standard Error: 5_047386 .saturating_add(Weight::from_ref_time(1_113_100 as u64).saturating_mul(p as u64))387 .saturating_add(RocksDbWeight::get().reads(2 as u64))388 .saturating_add(RocksDbWeight::get().writes(1 as u64))389 .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(p as u64)))390 }391 // Storage: Identity SubsOf (r:1 w:1)392 // Storage: Identity IdentityOf (r:1 w:1)393 // Storage: Identity SuperOf (r:0 w:100)394 /// The range of component `r` is `[1, 20]`.395 /// The range of component `s` is `[0, 100]`.396 /// The range of component `x` is `[0, 100]`.397 fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight {398 // Minimum execution time: 57_144 nanoseconds.399 Weight::from_ref_time(41_559_247 as u64)400 // Standard Error: 9_996401 .saturating_add(Weight::from_ref_time(146_770 as u64).saturating_mul(r as u64))402 // Standard Error: 1_952403 .saturating_add(Weight::from_ref_time(1_086_673 as u64).saturating_mul(s as u64))404 // Standard Error: 1_952405 .saturating_add(Weight::from_ref_time(162_481 as u64).saturating_mul(x as u64))406 .saturating_add(RocksDbWeight::get().reads(2 as u64))407 .saturating_add(RocksDbWeight::get().writes(2 as u64))408 .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(s as u64)))409 }410 // Storage: Identity Registrars (r:1 w:0)411 // Storage: Identity IdentityOf (r:1 w:1)412 /// The range of component `r` is `[1, 20]`.413 /// The range of component `x` is `[0, 100]`.414 fn request_judgement(r: u32, x: u32, ) -> Weight {415 // Minimum execution time: 44_726 nanoseconds.416 Weight::from_ref_time(41_637_308 as u64)417 // Standard Error: 1_907418 .saturating_add(Weight::from_ref_time(219_078 as u64).saturating_mul(r as u64))419 // Standard Error: 372420 .saturating_add(Weight::from_ref_time(309_888 as u64).saturating_mul(x as u64))421 .saturating_add(RocksDbWeight::get().reads(2 as u64))422 .saturating_add(RocksDbWeight::get().writes(1 as u64))423 }424 // Storage: Identity IdentityOf (r:1 w:1)425 /// The range of component `r` is `[1, 20]`.426 /// The range of component `x` is `[0, 100]`.427 fn cancel_request(r: u32, x: u32, ) -> Weight {428 // Minimum execution time: 39_719 nanoseconds.429 Weight::from_ref_time(38_008_751 as u64)430 // Standard Error: 2_394431 .saturating_add(Weight::from_ref_time(181_870 as u64).saturating_mul(r as u64))432 // Standard Error: 467433 .saturating_add(Weight::from_ref_time(314_990 as u64).saturating_mul(x as u64))434 .saturating_add(RocksDbWeight::get().reads(1 as u64))435 .saturating_add(RocksDbWeight::get().writes(1 as u64))436 }437 // Storage: Identity Registrars (r:1 w:1)438 /// The range of component `r` is `[1, 19]`.439 fn set_fee(r: u32, ) -> Weight {440 // Minimum execution time: 10_634 nanoseconds.441 Weight::from_ref_time(11_383_704 as u64)442 // Standard Error: 2_250443 .saturating_add(Weight::from_ref_time(193_094 as u64).saturating_mul(r as u64))444 .saturating_add(RocksDbWeight::get().reads(1 as u64))445 .saturating_add(RocksDbWeight::get().writes(1 as u64))446 }447 // Storage: Identity Registrars (r:1 w:1)448 /// The range of component `r` is `[1, 19]`.449 fn set_account_id(r: u32, ) -> Weight {450 // Minimum execution time: 10_840 nanoseconds.451 Weight::from_ref_time(11_638_740 as u64)452 // Standard Error: 1_985453 .saturating_add(Weight::from_ref_time(193_016 as u64).saturating_mul(r as u64))454 .saturating_add(RocksDbWeight::get().reads(1 as u64))455 .saturating_add(RocksDbWeight::get().writes(1 as u64))456 }457 // Storage: Identity Registrars (r:1 w:1)458 /// The range of component `r` is `[1, 19]`.459 fn set_fields(r: u32, ) -> Weight {460 // Minimum execution time: 10_748 nanoseconds.461 Weight::from_ref_time(11_346_901 as u64)462 // Standard Error: 2_132463 .saturating_add(Weight::from_ref_time(196_630 as u64).saturating_mul(r as u64))464 .saturating_add(RocksDbWeight::get().reads(1 as u64))465 .saturating_add(RocksDbWeight::get().writes(1 as u64))466 }467 // Storage: Identity Registrars (r:1 w:0)468 // Storage: Identity IdentityOf (r:1 w:1)469 /// The range of component `r` is `[1, 19]`.470 /// The range of component `x` is `[0, 100]`.471 fn provide_judgement(r: u32, x: u32, ) -> Weight {472 // Minimum execution time: 33_682 nanoseconds.473 Weight::from_ref_time(31_336_603 as u64)474 // Standard Error: 3_056475 .saturating_add(Weight::from_ref_time(200_403 as u64).saturating_mul(r as u64))476 // Standard Error: 565477 .saturating_add(Weight::from_ref_time(525_142 as u64).saturating_mul(x as u64))478 .saturating_add(RocksDbWeight::get().reads(2 as u64))479 .saturating_add(RocksDbWeight::get().writes(1 as u64))480 }481 // Storage: Identity SubsOf (r:1 w:1)482 // Storage: Identity IdentityOf (r:1 w:1)483 // Storage: System Account (r:1 w:1)484 // Storage: Identity SuperOf (r:0 w:100)485 /// The range of component `r` is `[1, 20]`.486 /// The range of component `s` is `[0, 100]`.487 /// The range of component `x` is `[0, 100]`.488 fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight {489 // Minimum execution time: 68_794 nanoseconds.490 Weight::from_ref_time(52_114_486 as u64)491 // Standard Error: 4_808492 .saturating_add(Weight::from_ref_time(153_462 as u64).saturating_mul(r as u64))493 // Standard Error: 939494 .saturating_add(Weight::from_ref_time(1_084_612 as u64).saturating_mul(s as u64))495 // Standard Error: 939496 .saturating_add(Weight::from_ref_time(170_112 as u64).saturating_mul(x as u64))497 .saturating_add(RocksDbWeight::get().reads(3 as u64))498 .saturating_add(RocksDbWeight::get().writes(3 as u64))499 .saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(s as u64)))500 }501 // Storage: Identity IdentityOf (r:1 w:1)502 /// The range of component `x` is `[0, 100]`.503 /// The range of component `n` is `[0, 600]`.504 fn force_insert_identities(x: u32, n: u32) -> Weight {505 // Minimum execution time: 41_872 nanoseconds.506 Weight::from_ref_time(40_230_216 as u64)507 // Standard Error: 2_342508 .saturating_add(Weight::from_ref_time(145_168 as u64))509 // Standard Error: 457510 .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(x as u64))511 .saturating_add(RocksDbWeight::get().reads(1 as u64))512 .saturating_add(RocksDbWeight::get().writes(1 as u64).saturating_mul(n as u64))513 }514 // Storage: Identity IdentityOf (r:1 w:1)515 /// The range of component `x` is `[0, 100]`.516 /// The range of component `n` is `[0, 600]`.517 fn force_remove_identities(x: u32, n: u32) -> Weight {518 // Minimum execution time: 41_872 nanoseconds.519 Weight::from_ref_time(40_230_216 as u64)520 // Standard Error: 2_342521 .saturating_add(Weight::from_ref_time(145_168 as u64))522 // Standard Error: 457523 .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(x as u64))524 .saturating_add(RocksDbWeight::get().reads(1 as u64))525 .saturating_add(RocksDbWeight::get().writes(1 as u64).saturating_mul(n as u64))526 }527 // Storage: Identity IdentityOf (r:1 w:1)528 // todo:collator529 /// The range of component `xs is `[0, 100]`.530 /// The range of component `n` is `[0, 600]`.531 fn force_set_subs(s: u32, n: u32) -> Weight {532 // Minimum execution time: 41_872 nanoseconds.533 Weight::from_ref_time(40_230_216 as u64)534 // Standard Error: 2_342535 .saturating_add(Weight::from_ref_time(145_168 as u64))536 // Standard Error: 457537 .saturating_add(Weight::from_ref_time(291_732 as u64).saturating_mul(s as u64))538 .saturating_add(RocksDbWeight::get().reads(1 as u64))539 .saturating_add(RocksDbWeight::get().writes(1 as u64).saturating_mul(n as u64))540 }541 // Storage: Identity IdentityOf (r:1 w:0)542 // Storage: Identity SuperOf (r:1 w:1)543 // Storage: Identity SubsOf (r:1 w:1)544 /// The range of component `s` is `[0, 99]`.545 fn add_sub(s: u32, ) -> Weight {546 // Minimum execution time: 37_914 nanoseconds.547 Weight::from_ref_time(43_488_083 as u64)548 // Standard Error: 1_631549 .saturating_add(Weight::from_ref_time(118_845 as u64).saturating_mul(s as u64))550 .saturating_add(RocksDbWeight::get().reads(3 as u64))551 .saturating_add(RocksDbWeight::get().writes(2 as u64))552 }553 // Storage: Identity IdentityOf (r:1 w:0)554 // Storage: Identity SuperOf (r:1 w:1)555 /// The range of component `s` is `[1, 100]`.556 fn rename_sub(s: u32, ) -> Weight {557 // Minimum execution time: 16_124 nanoseconds.558 Weight::from_ref_time(18_580_462 as u64)559 // Standard Error: 688560 .saturating_add(Weight::from_ref_time(67_220 as u64).saturating_mul(s as u64))561 .saturating_add(RocksDbWeight::get().reads(2 as u64))562 .saturating_add(RocksDbWeight::get().writes(1 as u64))563 }564 // Storage: Identity IdentityOf (r:1 w:0)565 // Storage: Identity SuperOf (r:1 w:1)566 // Storage: Identity SubsOf (r:1 w:1)567 /// The range of component `s` is `[1, 100]`.568 fn remove_sub(s: u32, ) -> Weight {569 // Minimum execution time: 41_517 nanoseconds.570 Weight::from_ref_time(45_123_530 as u64)571 // Standard Error: 1_530572 .saturating_add(Weight::from_ref_time(105_429 as u64).saturating_mul(s as u64))573 .saturating_add(RocksDbWeight::get().reads(3 as u64))574 .saturating_add(RocksDbWeight::get().writes(2 as u64))575 }576 // Storage: Identity SuperOf (r:1 w:1)577 // Storage: Identity SubsOf (r:1 w:1)578 /// The range of component `s` is `[0, 99]`.579 fn quit_sub(s: u32, ) -> Weight {580 // Minimum execution time: 30_171 nanoseconds.581 Weight::from_ref_time(33_355_514 as u64)582 // Standard Error: 1_286583 .saturating_add(Weight::from_ref_time(114_716 as u64).saturating_mul(s as u64))584 .saturating_add(RocksDbWeight::get().reads(2 as u64))585 .saturating_add(RocksDbWeight::get().writes(2 as u64))586 }587}tests/src/collator-selection/identity.seqtest.tsdiffbeforeafterboth--- a/tests/src/collator-selection/identity.seqtest.ts
+++ b/tests/src/collator-selection/identity.seqtest.ts
@@ -29,6 +29,14 @@
return (await getIdentities(helper)).flatMap(([key, _value]) => key);
}
+async function getSubIdentityAccounts(helper: UniqueHelper, address: string) {
+ return ((await helper.getApi().query.identity.subsOf(address)).toHuman() as any)[1];
+}
+
+async function getSubIdentityName(helper: UniqueHelper, address: string) {
+ return ((await helper.getApi().query.identity.superOf(address)).toHuman() as any);
+}
+
describe('Integration Test: Identities Manipulation', () => {
let superuser: IKeyringPair;
@@ -47,49 +55,220 @@
.to.be.rejectedWith(/Transaction call is not expected/);
});
- itSub('Sets identities', async ({helper}) => {
- const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;
+ describe('Identities', () => {
+ itSub('Sets identities', async ({helper}) => {
+ const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;
- const crowdSize = 10;
- const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);
- const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);
- await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);
+ const crowdSize = 10;
+ const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);
+ const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);
- expect((await getIdentityAccounts(helper)).length).to.be.equal(oldIdentitiesCount + crowdSize);
- });
+ expect((await getIdentityAccounts(helper)).length).to.be.equal(oldIdentitiesCount + crowdSize);
+ });
- itSub('Setting identities does not delete existing but does overwrite', async ({helper}) => {
- const crowd = await helper.arrange.createCrowd(10, 0n, superuser);
- const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);
+ itSub('Setting identities does not delete existing but does overwrite', async ({helper}) => {
+ const crowd = await helper.arrange.createCrowd(10, 0n, superuser);
+ const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);
+
+ // insert a single identity
+ let singleIdentity = identities.pop()!;
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [[singleIdentity]]);
- // insert a single identity
- let singleIdentity = identities.pop()!;
- await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [[singleIdentity]]);
+ const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;
- const oldIdentitiesCount = (await getIdentityAccounts(helper)).length;
+ // change an identity and push it with a few new others
+ singleIdentity = [singleIdentity[0], {info: {display: {Raw: 'something special'}}}];
+ identities.push(singleIdentity);
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);
- // change an identity and push it with a few new others
- singleIdentity = [singleIdentity[0], {info: {display: {Raw: 'something special'}}}];
- identities.push(singleIdentity);
- await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);
+ // oldIdentitiesCount + 9 because one identity is overwritten, not inserted on top
+ expect((await getIdentityAccounts(helper)).length).to.be.equal(oldIdentitiesCount + 9);
+ expect((await helper.callRpc('api.query.identity.identityOf', [singleIdentity[0]])).toHuman().info.display)
+ .to.be.deep.equal({Raw: 'something special'});
+ });
- // oldIdentitiesCount + 9 because one identity is overwritten, not inserted on top
- expect((await getIdentityAccounts(helper)).length).to.be.equal(oldIdentitiesCount + 9);
- expect((await helper.callRpc('api.query.identity.identityOf', [singleIdentity[0]])).toHuman().info.display)
- .to.be.deep.equal({Raw: 'something special'});
+ itSub('Removes identities', async ({helper}) => {
+ const crowd = await helper.arrange.createCrowd(10, 0n, superuser);
+ const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);
+ const oldIdentities = await getIdentityAccounts(helper);
+
+ // delete a couple, check that they are no longer there
+ const scapegoats = [crowd.pop()!.address, crowd.pop()!.address];
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [scapegoats]);
+ const newIdentities = await getIdentityAccounts(helper);
+ expect(newIdentities.concat(scapegoats)).to.be.have.members(oldIdentities);
+ });
});
- itSub('Removes identities', async ({helper}) => {
- const crowd = await helper.arrange.createCrowd(10, 0n, superuser);
- const identities = crowd.map((acc, i) => [acc.address, {info: {display: {Raw: `accounter #${i}`}}}]);
- await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);
- const oldIdentities = await getIdentityAccounts(helper);
+ describe('Sub-identities', () => {
+ itSub('Sets subs', async ({helper}) => {
+ const crowdSize = 18;
+ const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);
+ const supers = [crowd.pop()!, crowd.pop()!, crowd.pop()!];
- // delete a couple, check that they are no longer there
- const scapegoats = [crowd.pop()!.address, crowd.pop()!.address];
- await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [scapegoats]);
- const newIdentities = await getIdentityAccounts(helper);
- expect(newIdentities.concat(scapegoats)).to.be.have.members(oldIdentities);
+ const subsPerSup = crowd.length / supers.length;
+ let subCount = 0;
+ const subs = [
+ crowd.slice(subCount, subCount += subsPerSup + 1),
+ crowd.slice(subCount, subCount += subsPerSup),
+ crowd.slice(subCount, subCount += subsPerSup - 1),
+ ];
+
+ const subsInfo = supers.map((acc, i) => [
+ acc.address, [
+ 1000000n + BigInt(i + 1),
+ subs[i].map((sub, j) => [
+ sub.address, {Raw: `accounter #${j}`},
+ ]),
+ ],
+ ]);
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo]);
+
+ for (let i = 0; i < supers.length; i++) {
+ // check deposit
+ expect(((await helper.getApi().query.identity.subsOf(supers[i].address)).toJSON() as any)[0]).to.be.equal(1000001 + i);
+
+ const subsAccounts = await getSubIdentityAccounts(helper, supers[i].address);
+ // check sub-identities as account ids
+ expect(subsAccounts).to.include.members(subs[i].map(x => x.address));
+
+ for (let j = 0; j < subsAccounts.length; j++) {
+ // check sub-identities' names
+ expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `accounter #${j}`});
+ }
+ }
+ });
+
+ itSub('Setting sub-identities does not delete other existing but does overwrite own', async ({helper}) => {
+ const crowdSize = 18;
+ const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);
+ const supers = [crowd.pop()!, crowd.pop()!, crowd.pop()!];
+
+ const subsPerSup = crowd.length / supers.length;
+ let subCount = 0;
+ const subs = [
+ crowd.slice(subCount, subCount += subsPerSup + 1),
+ crowd.slice(subCount, subCount += subsPerSup),
+ crowd.slice(subCount, subCount += subsPerSup - 1),
+ ];
+
+ const subsInfo1 = supers.map((acc, i) => [
+ acc.address, [
+ 1000000n + BigInt(i + 1),
+ subs[i].map((sub, j) => [
+ sub.address, {Raw: `accounter #${j}`},
+ ]),
+ ],
+ ]);
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo1]);
+
+ // change some sub-identities...
+ subs[2].pop(); subs[2].pop(); subs[2].push(...await helper.arrange.createAccounts([0n], superuser));
+
+ // ...and set them
+ const subsInfo2 = [[
+ supers[2].address, [
+ 999999n,
+ subs[2].map((sub, j) => [
+ sub.address, {Raw: `discounter #${j}`},
+ ]),
+ ],
+ ]];
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo2]);
+
+ // make sure everything else is the same
+ for (let i = 0; i < supers.length - 1; i++) {
+ // check deposit
+ expect(((await helper.getApi().query.identity.subsOf(supers[i].address)).toJSON() as any)[0]).to.be.equal(1000001 + i);
+
+ const subsAccounts = await getSubIdentityAccounts(helper, supers[i].address);
+ // check sub-identities as account ids
+ expect(subsAccounts).to.include.members(subs[i].map(x => x.address));
+
+ for (let j = 0; j < subsAccounts; j++) {
+ // check sub-identities' names
+ expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `accounter #${j}`});
+ }
+ }
+
+ // check deposit
+ expect(((await helper.getApi().query.identity.subsOf(supers[2].address)).toJSON() as any)[0]).to.be.equal(999999);
+
+ const subsAccounts = await getSubIdentityAccounts(helper, supers[2].address);
+ // check sub-identities as account ids
+ expect(subsAccounts).to.include.members(subs[2].map(x => x.address));
+
+ for (let j = 0; j < subsAccounts.length; j++) {
+ // check sub-identities' names
+ expect((await getSubIdentityName(helper, subsAccounts[j]))[1]).to.be.deep.equal({Raw: `discounter #${j}`});
+ }
+ });
+
+ itSub('Removes sub-identities', async ({helper}) => {
+ const crowdSize = 3;
+ const crowd = await helper.arrange.createCrowd(crowdSize, 0n, superuser);
+ const sup = crowd.pop()!;
+
+ const subsInfo1 = [[
+ sup.address, [
+ 1000000n,
+ crowd.map((sub, j) => [
+ sub.address, {Raw: `accounter #${j}`},
+ ]),
+ ],
+ ]];
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo1]);
+
+ // empty sub-identities should delete the records
+ const subsInfo2 = [[
+ sup.address, [
+ 1000000n,
+ [],
+ ],
+ ]];
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo2]);
+
+ // check deposit
+ expect((await helper.getApi().query.identity.subsOf(sup.address)).toHuman()).to.be.deep.equal(['0', []]);
+
+ for (let j = 0; j < crowd.length; j++) {
+ // check sub-identities' names
+ expect((await getSubIdentityName(helper, crowd[j].address))).to.be.null;
+ }
+ });
+
+ itSub('Removing identities deletes associated sub-identities', async ({helper}) => {
+ const crowd = await helper.arrange.createCrowd(3, 0n, superuser);
+ const sup = crowd.pop()!;
+
+ // insert identity
+ const identities = [[sup.address, {info: {display: {Raw: 'mental'}}}]];
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceInsertIdentities', [identities]);
+
+ // and its sub-identities
+ const subsInfo = [[
+ sup.address, [
+ 1000000n,
+ crowd.map((sub, j) => [
+ sub.address, {Raw: `accounter #${j}`},
+ ]),
+ ],
+ ]];
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceSetSubs', [subsInfo]);
+
+ // delete top identity
+ await helper.getSudo().executeExtrinsic(superuser, 'api.tx.identity.forceRemoveIdentities', [[sup.address]]);
+
+ // check that sub-identities are deleted
+ expect((await helper.getApi().query.identity.subsOf(sup.address)).toHuman()).to.be.deep.equal(['0', []]);
+
+ for (let j = 0; j < crowd.length; j++) {
+ // check sub-identities' names
+ expect((await getSubIdentityName(helper, crowd[j].address))).to.be.null;
+ }
+ });
});
after(async function() {
tests/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');