Skip to content

Commit

Permalink
Clonable Stronghold Instance (#257)
Browse files Browse the repository at this point in the history
* feat(interface): make stronghold clonable

* feat: updated tests

* feat(doc): add changes doc
  • Loading branch information
felsweg-iota authored Sep 13, 2021
1 parent 9b8d0da commit 681a024
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/clone-stronghold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"iota-stronghold": minor
---

- make stronghold interface clonable
1 change: 1 addition & 0 deletions client/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use p2p::{
Multiaddr, PeerId,
};

#[derive(Clone)]
/// The main type for the Stronghold System. Used as the entry point for the actor model. Contains various pieces of
/// metadata to interpret the data in the vault and store.
pub struct Stronghold {
Expand Down
10 changes: 9 additions & 1 deletion client/src/tests/interface_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ async fn test_stronghold() {
.await
.unwrap();

// clone it, and check for consistency
let stronghold2 = stronghold.clone();

// Write at the first record of the vault using Some(0). Also creates the new vault.
assert!(stronghold
assert!(stronghold2
.write_to_vault(
loc0.clone(),
b"test".to_vec(),
Expand All @@ -42,6 +45,11 @@ async fn test_stronghold() {
.is_ok());

// read head.
let (p, _) = stronghold2.read_secret(client_path.clone(), loc0.clone()).await;

assert_eq!(std::str::from_utf8(&p.unwrap()), Ok("test"));

// read head from first reference
let (p, _) = stronghold.read_secret(client_path.clone(), loc0.clone()).await;

assert_eq!(std::str::from_utf8(&p.unwrap()), Ok("test"));
Expand Down

0 comments on commit 681a024

Please sign in to comment.