|
2 | 2 |
|
3 | 3 | use alloy_consensus::EMPTY_ROOT_HASH; |
4 | 4 | use alloy_eips::BlockNumberOrTag; |
5 | | -use alloy_primitives::Address; |
| 5 | +use alloy_node_bindings::utils::run_with_tempdir; |
| 6 | +use alloy_primitives::{Address, U256}; |
6 | 7 | use alloy_provider::Provider; |
7 | 8 | use anvil::{spawn, EthereumHardfork, NodeConfig}; |
| 9 | +use std::time::Duration; |
8 | 10 |
|
9 | 11 | #[tokio::test(flavor = "multi_thread")] |
10 | 12 | async fn test_can_change_mining_mode() { |
@@ -118,3 +120,33 @@ async fn test_cancun_fields() { |
118 | 120 | assert!(block.header.blob_gas_used.is_some()); |
119 | 121 | assert!(block.header.excess_blob_gas.is_some()); |
120 | 122 | } |
| 123 | + |
| 124 | +#[tokio::test(flavor = "multi_thread")] |
| 125 | +#[cfg(not(windows))] |
| 126 | +async fn test_cache_path() { |
| 127 | + run_with_tempdir("custom-anvil-cache", |tmp_dir| async move { |
| 128 | + let cache_path = tmp_dir.join("cache"); |
| 129 | + let (api, _handle) = spawn( |
| 130 | + NodeConfig::test() |
| 131 | + .with_cache_path(Some(cache_path.clone())) |
| 132 | + .with_max_persisted_states(Some(5_usize)) |
| 133 | + .with_blocktime(Some(Duration::from_millis(1))), |
| 134 | + ) |
| 135 | + .await; |
| 136 | + |
| 137 | + api.anvil_mine(Some(U256::from(1000)), None).await.unwrap(); |
| 138 | + |
| 139 | + // sleep to ensure the cache is written |
| 140 | + tokio::time::sleep(Duration::from_secs(2)).await; |
| 141 | + |
| 142 | + assert!(cache_path.exists()); |
| 143 | + assert!(cache_path.read_dir().unwrap().count() > 0); |
| 144 | + |
| 145 | + // Clean the directory, this is to prevent an error when temp_dir is dropped. |
| 146 | + let _ = std::fs::remove_dir_all(cache_path); |
| 147 | + |
| 148 | + //sleep to ensure OS file handles are released |
| 149 | + tokio::time::sleep(Duration::from_secs(1)).await; |
| 150 | + }) |
| 151 | + .await; |
| 152 | +} |
0 commit comments