Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX committed Sep 30, 2024
1 parent 2312401 commit eaa2ea8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/pre_derived_keys_cache/pre_derived_keys_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl PreDerivedKeysCache {
Self {
probably_free_factor_instances: RwLock::new(

Check warning on line 88 in src/pre_derived_keys_cache/pre_derived_keys_cache.rs

View check run for this annotation

Codecov / codecov/patch

src/pre_derived_keys_cache/pre_derived_keys_cache.rs#L88

Added line #L88 was not covered by tests
probably_free_factor_instances
.0
.into_iter()
.into_group_map_by(|x| UnquantifiedUnindexDerivationRequest::from(x.clone()))
.into_iter()
Expand Down
41 changes: 41 additions & 0 deletions src/recovery_securify_cache/helpers/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl Accounts {
self.accounts.len()
}

/// Should never be true, since we do not allow empty.
pub fn is_empty(&self) -> bool {
self.accounts.is_empty()
}
Expand All @@ -52,3 +53,43 @@ impl Accounts {
self.network_id
}
}

#[cfg(test)]
mod tests {
use super::*;

type Sut = Accounts;

#[test]
fn empty_throws() {
assert!(matches!(
Sut::new(NetworkID::Mainnet, IndexSet::new()),
Err(CommonError::EmptyCollection)
));
}

#[test]
fn wrong_network_single() {
assert!(matches!(
Sut::new(NetworkID::Stokenet, IndexSet::just(Account::sample())),
Err(CommonError::WrongNetwork)
));
}

#[test]
fn wrong_network_two() {
assert!(matches!(
Sut::new(
NetworkID::Stokenet,
IndexSet::from_iter([Account::sample_other(), Account::sample(),])
),
Err(CommonError::WrongNetwork)
));
}

#[test]
fn ok_new() {
let sut = Sut::new(NetworkID::Mainnet, IndexSet::just(Account::sample())).unwrap();
assert!(!sut.is_empty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,11 @@ use crate::prelude::*;
/// Gateway might not keep track of past FactorInstances, some of the FactorInstances
/// in KeySpace::Securified might in fact have been used in the past for some entity.
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)]
pub struct ProbablyFreeFactorInstances {
factor_instances: Vec<HierarchicalDeterministicFactorInstance>,
}

impl IntoIterator for ProbablyFreeFactorInstances {
type Item = HierarchicalDeterministicFactorInstance;
type IntoIter = <IndexSet<HierarchicalDeterministicFactorInstance> as IntoIterator>::IntoIter;

fn into_iter(self) -> Self::IntoIter {
self.factor_instances().into_iter()
}
}
pub struct ProbablyFreeFactorInstances(pub FactorInstances);

impl ProbablyFreeFactorInstances {
pub fn factor_instances(&self) -> IndexSet<HierarchicalDeterministicFactorInstance> {
self.factor_instances.iter().cloned().collect()
}
pub fn new(instances: IndexSet<HierarchicalDeterministicFactorInstance>) -> Self {
Self {
factor_instances: instances.into_iter().collect(),
}
Self(instances.into())
}
}

Expand Down

0 comments on commit eaa2ea8

Please sign in to comment.