Skip to content
Snippets Groups Projects
Commit 5731e0fb authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

wip add position of duplicate

parent cd65d4bd
No related branches found
No related tags found
No related merge requests found
Pipeline #19181 failed
...@@ -21,7 +21,7 @@ use countmap::CountMap; ...@@ -21,7 +21,7 @@ use countmap::CountMap;
use hex_literal::hex; use hex_literal::hex;
use sp_core::crypto::AccountId32; use sp_core::crypto::AccountId32;
use sp_core::{blake2_128, ByteArray, H256}; use sp_core::{blake2_128, ByteArray, H256};
use std::collections::HashMap; use std::collections::{HashMap, HashSet};
use subxt::config::SubstrateConfig as GdevConfig; use subxt::config::SubstrateConfig as GdevConfig;
const DEFAULT_ENDPOINT: &str = "ws://localhost:9944"; const DEFAULT_ENDPOINT: &str = "ws://localhost:9944";
...@@ -182,6 +182,11 @@ mod verifier { ...@@ -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) /// check accounts sufficients and consumers (specific to duniter-account pallet)
async fn verify_accounts(&mut self, accounts: &HashMap<AccountId32, AccountInfo>) { async fn verify_accounts(&mut self, accounts: &HashMap<AccountId32, AccountInfo>) {
for (account_id, account_info) in accounts { for (account_id, account_info) in accounts {
...@@ -229,18 +234,20 @@ mod verifier { ...@@ -229,18 +234,20 @@ mod verifier {
) { ) {
// counts occurence of owner key // counts occurence of owner key
let mut countmap = CountMap::<AccountId32, u8>::new(); 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 { for (idty_index, idty_value) in identities {
countmap.insert_or_increment(idty_value.owner_key.clone()); countmap.insert_or_increment(idty_value.owner_key.clone());
if let Some(count) = countmap.get_count(&idty_value.owner_key) { if let Some(count) = countmap.get_count(&idty_value.owner_key) {
if count > 1 { if count > 1 {
self.assert( self.error(format!(
false, "address {} is the owner_key of {count} identities",
format!(
"owner_key {} is present {count} times",
idty_value.owner_key idty_value.owner_key
), ));
); if count == 2 {
duplicates.insert(idty_value.owner_key.clone());
}
} }
} }
...@@ -283,6 +290,15 @@ mod verifier { ...@@ -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) /// check the identity hashmap (length, identity existence, hash matches owner key)
...@@ -343,13 +359,10 @@ mod verifier { ...@@ -343,13 +359,10 @@ mod verifier {
self.assert(idty_index == index_of, 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)); format!("identity number {idty_index} with owner key {0} is mapped to identity index {index_of}", idty_value.owner_key));
} else { } else {
self.assert( self.error(format!(
false,
format!(
"identity with owner key {} is not present in hashmap", "identity with owner key {} is not present in hashmap",
idty_value.owner_key idty_value.owner_key
), ));
);
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment