Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose underlying cache_db with env.db() function #977

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Loading