diff --git a/core/src/environment/mod.rs b/core/src/environment/mod.rs index 4586c52b..151c3d94 100644 --- a/core/src/environment/mod.rs +++ b/core/src/environment/mod.rs @@ -634,6 +634,15 @@ impl Environment { self } + /// Obtains the current underlying [`CacheDB`] instance + /// after a read lock was acquired to inspect the current execution state + pub fn db(&self) -> Result, ArbiterCoreError> { + match self.db.state.read() { + Ok(cache_db) => Ok(cache_db.clone()), + Err(err) => Err(ArbiterCoreError::RwLockError(err.to_string())), + } + } + /// Stops the execution of the environment and returns the [`ArbiterDB`] in /// its final state. pub fn stop(mut self) -> Result { diff --git a/core/tests/environment_integration.rs b/core/tests/environment_integration.rs index 30611405..1fcfbfde 100644 --- a/core/tests/environment_integration.rs +++ b/core/tests/environment_integration.rs @@ -142,13 +142,20 @@ async fn middleware_from_forked_eo() { } #[tokio::test] -async fn env_returns_db() { +async fn env_returns_db_after_stop() { let (environment, client) = startup(); deploy_arbx(client).await; let db = environment.stop().unwrap(); assert!(!db.state.read().unwrap().accounts.is_empty()) } +#[tokio::test] +async fn env_returns_db_mid_execution() { + let (environment, client) = startup(); + deploy_arbx(client).await; + assert!(!environment.db().unwrap().accounts.is_empty()) +} + #[tokio::test] async fn block_logs() { let (environment, client) = startup();