diff --git a/live-tests/tests/sanity_gdev.rs b/live-tests/tests/sanity_gdev.rs index 93b3b7dcf0888e47d6326346fe73fbaae17a5dd0..eaf12132d1a871b8cff2873f395ea15e4f80e5b0 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 + )); } } }