From 5731e0fbaa4fb6c2d9aed5abb67b1ccb7dca5cb4 Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Wed, 5 Apr 2023 20:52:10 +0200 Subject: [PATCH] wip add position of duplicate --- live-tests/tests/sanity_gdev.rs | 43 +++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/live-tests/tests/sanity_gdev.rs b/live-tests/tests/sanity_gdev.rs index 93b3b7dcf..eaf12132d 100644 --- a/live-tests/tests/sanity_gdev.rs +++ b/live-tests/tests/sanity_gdev.rs @@ -21,7 +21,7 @@ use countmap::CountMap; use hex_literal::hex; use sp_core::crypto::AccountId32; use sp_core::{blake2_128, ByteArray, H256}; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use subxt::config::SubstrateConfig as GdevConfig; const DEFAULT_ENDPOINT: &str = "ws://localhost:9944"; @@ -182,6 +182,11 @@ mod verifier { } } + /// like assert but just push error + fn error(&mut self, error: String) { + self.errors.push(error); + } + /// check accounts sufficients and consumers (specific to duniter-account pallet) async fn verify_accounts(&mut self, accounts: &HashMap<AccountId32, AccountInfo>) { for (account_id, account_info) in accounts { @@ -229,18 +234,20 @@ mod verifier { ) { // counts occurence of owner key let mut countmap = CountMap::<AccountId32, u8>::new(); + // list owner key with multiple occurences + let mut duplicates = HashSet::new(); for (idty_index, idty_value) in identities { countmap.insert_or_increment(idty_value.owner_key.clone()); if let Some(count) = countmap.get_count(&idty_value.owner_key) { if count > 1 { - self.assert( - false, - format!( - "owner_key {} is present {count} times", - idty_value.owner_key - ), - ); + self.error(format!( + "address {} is the owner_key of {count} identities", + idty_value.owner_key + )); + if count == 2 { + duplicates.insert(idty_value.owner_key.clone()); + } } } @@ -283,6 +290,15 @@ mod verifier { } } } + + for (idty_index, idty_value) in identities { + if duplicates.contains(&idty_value.owner_key) { + self.error(format!( + "duplicate key {} at position {idty_index}", + idty_value.owner_key + )); + } + } } /// check the identity hashmap (length, identity existence, hash matches owner key) @@ -343,13 +359,10 @@ mod verifier { self.assert(idty_index == index_of, format!("identity number {idty_index} with owner key {0} is mapped to identity index {index_of}", idty_value.owner_key)); } else { - self.assert( - false, - format!( - "identity with owner key {} is not present in hashmap", - idty_value.owner_key - ), - ); + self.error(format!( + "identity with owner key {} is not present in hashmap", + idty_value.owner_key + )); } } } -- GitLab