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

fix(anvil): reset cache path during anvil_reset without fork url #9729

Merged
merged 17 commits into from
Feb 25, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix test on windows, fmt
nbaztec committed Jan 22, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 55dbfa08f98ba890fcbd6de9db1fbc2a80d6ab4e
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
@@ -527,7 +527,7 @@ impl Backend {
.await?
.ok_or(BlockchainError::BlockNotFound)?;
// update all settings related to the forked block
{
{
if let Some(fork_url) = forking.json_rpc_url {
// Set the fork block number
let mut node_config = self.node_config.write().await;
13 changes: 11 additions & 2 deletions crates/anvil/tests/it/fork.rs
Original file line number Diff line number Diff line change
@@ -1486,14 +1486,23 @@ async fn test_reset_updates_cache_path_when_rpc_url_not_provided() {
let db = api.backend.get_db().read().await;
let cache_debug = format!("{:?}", db.maybe_inner().unwrap().cache());
let re = regex::Regex::new(r#"JsonBlockCacheDB \{ cache_path: Some\("([^"]+)"\)"#).unwrap();
let m = re
let cache_path = re
.captures_iter(&cache_debug)
.next()
.expect("must have JsonBlockCacheDB match")
.get(1)
.expect("must have matching path")
.as_str();
m.strip_suffix("/storage.json").unwrap().split("/").last().unwrap().parse::<u64>().unwrap()

std::path::PathBuf::from(cache_path)
.parent()
.expect("must have filename")
.file_name()
.expect("must have block number as dir name")
.to_str()
.expect("must be valid string")
.parse::<u64>()
.expect("must be valid number")
}

assert_eq!(BLOCK_NUMBER, get_block_from_cache_path(&mut api).await);