Skip to content

Commit

Permalink
Expose underlying cache_db with env.db() function
Browse files Browse the repository at this point in the history
  • Loading branch information
jbargu committed May 24, 2024
1 parent 23e9c29 commit 5c131d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions core/src/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CacheDB<EmptyDB>, 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<ArbiterDB, ArbiterCoreError> {
Expand Down
9 changes: 8 additions & 1 deletion core/tests/environment_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5c131d9

Please sign in to comment.