Skip to content

Commit

Permalink
update triple storage test
Browse files Browse the repository at this point in the history
  • Loading branch information
volovyks committed Nov 19, 2024
1 parent a570030 commit 656ace2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions chain-signatures/node/src/protocol/triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ impl TripleManager {
self.triple_storage.len_mine().await.unwrap_or(0)
}

/// Returns the number of used triples
pub async fn len_used(&self) -> usize {
self.triple_storage.len_used().await.unwrap_or(0)
}

/// Returns if there's any unspent triple in the manager.
pub async fn is_empty(&self) -> bool {
self.len_generated().await == 0
Expand Down
5 changes: 5 additions & 0 deletions integration-tests/chain-signatures/tests/cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ async fn test_triple_persistence() -> anyhow::Result<()> {
assert_eq!(triple_manager.len_mine().await, 0);
assert!(triple_manager.is_empty().await);
assert_eq!(triple_manager.len_potential().await, 0);
assert_eq!(triple_manager.len_used().await, 0);

triple_manager.insert(triple_1).await;
triple_manager.insert(triple_2).await;
Expand All @@ -252,6 +253,7 @@ async fn test_triple_persistence() -> anyhow::Result<()> {
assert_eq!(triple_manager.len_generated().await, 2);
assert_eq!(triple_manager.len_mine().await, 0);
assert_eq!(triple_manager.len_potential().await, 2);
assert_eq!(triple_manager.len_used().await, 0);

// Take triple and check that it is removed from the storage
triple_manager
Expand All @@ -265,6 +267,7 @@ async fn test_triple_persistence() -> anyhow::Result<()> {
assert_eq!(triple_manager.len_generated().await, 0);
assert_eq!(triple_manager.len_mine().await, 0);
assert_eq!(triple_manager.len_potential().await, 0);
assert_eq!(triple_manager.len_used().await, 2);

let mine_id_1: u64 = 3;
let mine_triple_1 = dummy_triple(mine_id_1);
Expand All @@ -281,6 +284,7 @@ async fn test_triple_persistence() -> anyhow::Result<()> {
assert_eq!(triple_manager.len_generated().await, 2);
assert_eq!(triple_manager.len_mine().await, 2);
assert_eq!(triple_manager.len_potential().await, 2);
assert_eq!(triple_manager.len_used().await, 2);

// Take mine triple and check that it is removed from the storage
triple_manager.take_two_mine().await.unwrap();
Expand All @@ -292,6 +296,7 @@ async fn test_triple_persistence() -> anyhow::Result<()> {
assert_eq!(triple_manager.len_mine().await, 0);
assert!(triple_manager.is_empty().await);
assert_eq!(triple_manager.len_potential().await, 0);
assert_eq!(triple_manager.len_used().await, 4);

Ok(())
}
Expand Down

0 comments on commit 656ace2

Please sign in to comment.