From d20449de57f8eb4ee1ce343210005ef0e9c0c319 Mon Sep 17 00:00:00 2001 From: Buckram Date: Thu, 13 Jun 2024 11:16:01 +0300 Subject: [PATCH 1/4] Add state to DaemonBuilder --- cw-orch-daemon/src/sync/builder.rs | 7 +++++++ cw-orch-daemon/tests/daemon_state.rs | 26 ++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/cw-orch-daemon/src/sync/builder.rs b/cw-orch-daemon/src/sync/builder.rs index e10c2a1bd..c2fcd0605 100644 --- a/cw-orch-daemon/src/sync/builder.rs +++ b/cw-orch-daemon/src/sync/builder.rs @@ -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. /// diff --git a/cw-orch-daemon/tests/daemon_state.rs b/cw-orch-daemon/tests/daemon_state.rs index e0102a410..a59b34447 100644 --- a/cw-orch-daemon/tests/daemon_state.rs +++ b/cw-orch-daemon/tests/daemon_state.rs @@ -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"; @@ -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] From e7186b78e789e4b2a51472f444cdce9e4d2d783e Mon Sep 17 00:00:00 2001 From: Buckram Date: Thu, 13 Jun 2024 11:18:08 +0300 Subject: [PATCH 2/4] add to async builder as well --- cw-orch-daemon/src/builder.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cw-orch-daemon/src/builder.rs b/cw-orch-daemon/src/builder.rs index 75c871bd9..f90ba8f16 100644 --- a/cw-orch-daemon/src/builder.rs +++ b/cw-orch-daemon/src/builder.rs @@ -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. /// From 37c95007bcf630ae6c1041958d9e6c48ef2252dc Mon Sep 17 00:00:00 2001 From: Kayanski Date: Thu, 13 Jun 2024 08:38:42 +0000 Subject: [PATCH 3/4] Changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7339993ad..c84f717ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 DaemonBuidler to be able to share state between daemons + ### Breaking - Daemon : Changed return types on daemon queriers to match CosmWasm std types From 0a8fefd5ed714b1d10a205ad0cc6c8edc7150bd7 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Thu, 13 Jun 2024 08:40:03 +0000 Subject: [PATCH 4/4] Nit --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c84f717ef..9684e4e92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ - 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 DaemonBuidler to be able to share state between daemons +- Added `state` to DaemonBuilder to be able to share state between daemons ### Breaking