Skip to content
Snippets Groups Projects

Fix identities live tests

Merged Hugo Trentesaux requested to merge hugo-live-test into master
1 unresolved thread
1 file
+ 28
15
Compare changes
  • Side-by-side
  • Inline
@@ -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";
@@ -187,6 +187,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 {
@@ -234,18 +239,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());
}
}
}
@@ -288,6 +295,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)
@@ -348,13 +364,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
));
}
}
}
Loading