Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
- Writing to a file happens when all Daemon's that use same file dropped instead of hot writes
- `force_write` added to the `DaemonState` to allow force write of the state
- Added `event_attr_values` to get all the attribute values corresponding to a key

- Added `state` to DaemonBuilder to be able to share state between daemons

### Breaking

- Daemon : Changed return types on daemon queriers to match CosmWasm std types
Expand Down
7 changes: 7 additions & 0 deletions cw-orch-daemon/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ impl DaemonAsyncBuilder {
self
}

/// Reuse already existent [`DaemonState`]
/// Useful for multi-chain scenarios
pub fn state(&mut self, state: DaemonState) -> &mut Self {
self.state = Some(state);
self
}

/// Specifies path to the daemon state file
/// Defaults to env variable.
///
Expand Down
7 changes: 7 additions & 0 deletions cw-orch-daemon/src/sync/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ impl DaemonBuilder {
self
}

/// Reuse already existent [`DaemonState`]
/// Useful for multi-chain scenarios
pub fn state(&mut self, state: DaemonState) -> &mut Self {
self.state = Some(state);
self
}

/// Specifies path to the daemon state file
/// Defaults to env variable.
///
Expand Down
26 changes: 24 additions & 2 deletions cw-orch-daemon/tests/daemon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use std::sync::Arc;

use cw_orch_core::environment::ChainState;
use cw_orch_daemon::{
env::STATE_FILE_ENV_NAME, json_lock::JsonLockedState, networks::OSMOSIS_1, DaemonBuilder,
DaemonError, DaemonStateFile,
env::STATE_FILE_ENV_NAME,
json_lock::JsonLockedState,
networks::{JUNO_1, OSMOSIS_1},
DaemonBuilder, DaemonError, DaemonStateFile,
};

pub const DUMMY_MNEMONIC:&str = "chapter wrist alcohol shine angry noise mercy simple rebel recycle vehicle wrap morning giraffe lazy outdoor noise blood ginger sort reunion boss crowd dutch";
Expand Down Expand Up @@ -202,6 +204,26 @@ fn does_not_error_when_using_different_files() {
std::env::remove_var(STATE_FILE_ENV_NAME);
}

#[test]
#[serial_test::serial]
fn reuse_same_state_multichain() {
std::env::set_var(STATE_FILE_ENV_NAME, TEST_STATE_FILE);
let daemon = DaemonBuilder::default()
.chain(OSMOSIS_1)
.mnemonic(DUMMY_MNEMONIC)
.build()
.unwrap();

let daemon_res = DaemonBuilder::default()
.chain(JUNO_1)
.state(daemon.state())
.mnemonic(DUMMY_MNEMONIC)
.build();

assert!(daemon_res.is_ok());
std::env::remove_var(STATE_FILE_ENV_NAME);
}

#[test]
#[serial_test::serial]
#[should_panic]
Expand Down