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

Move cache_dir config option to ForkConfig - feat/solidity-tests #750

Closed
Closed
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
6 changes: 3 additions & 3 deletions crates/edr_napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ export interface ChainConfig {
/** Configuration for forking a blockchain */
export interface ForkConfig {
/** The URL of the JSON-RPC endpoint to fork from */
jsonRpcUrl: string
url: string
/**
* The block number to fork from. If not provided, the latest safe block is
* used.
*/
blockNumber?: bigint
/** The HTTP headers to use when making requests to the JSON-RPC endpoint */
httpHeaders?: Array<HttpHeader>
/** The directory to cache remote JSON-RPC responses */
cacheDir?: string
}
export interface HttpHeader {
name: string
Expand Down Expand Up @@ -216,8 +218,6 @@ export interface ProviderConfig {
bailOnTransactionFailure: boolean
/** The gas limit of each block */
blockGasLimit: bigint
/** The directory to cache remote JSON-RPC responses */
cacheDir?: string
/** The chain ID of the blockchain */
chainId: bigint
/** The configuration for chains */
Expand Down
19 changes: 10 additions & 9 deletions crates/edr_napi/src/provider/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ pub struct ChainConfig {
#[napi(object)]
pub struct ForkConfig {
/// The URL of the JSON-RPC endpoint to fork from
pub json_rpc_url: String,
pub url: String,
/// The block number to fork from. If not provided, the latest safe block is
/// used.
pub block_number: Option<BigInt>,
/// The HTTP headers to use when making requests to the JSON-RPC endpoint
pub http_headers: Option<Vec<HttpHeader>>,
/// The directory to cache remote JSON-RPC responses
pub cache_dir: Option<String>,
}

#[napi(object)]
Expand Down Expand Up @@ -92,8 +94,6 @@ pub struct ProviderConfig {
pub bail_on_transaction_failure: bool,
/// The gas limit of each block
pub block_gas_limit: BigInt,
/// The directory to cache remote JSON-RPC responses
pub cache_dir: Option<String>,
/// The chain ID of the blockchain
pub chain_id: BigInt,
/// The configuration for chains
Expand Down Expand Up @@ -140,7 +140,7 @@ impl TryFrom<ForkConfig> for edr_provider::hardhat_rpc_types::ForkConfig {
});

Ok(Self {
json_rpc_url: value.json_rpc_url,
url: value.url,
block_number,
http_headers,
})
Expand Down Expand Up @@ -255,11 +255,12 @@ impl TryFrom<ProviderConfig> for edr_provider::ProviderConfig {
bail_on_call_failure: value.bail_on_call_failure,
bail_on_transaction_failure: value.bail_on_transaction_failure,
block_gas_limit,
cache_dir: PathBuf::from(
value
.cache_dir
.unwrap_or(String::from(edr_defaults::CACHE_DIR)),
),
cache_dir: value
.fork
.as_ref()
.and_then(|fork_config| fork_config.cache_dir.clone())
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from(edr_defaults::CACHE_DIR)),
chain_id: value.chain_id.try_cast()?,
chains,
coinbase: value.coinbase.try_cast()?,
Expand Down
4 changes: 2 additions & 2 deletions crates/edr_provider/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2609,7 +2609,7 @@ fn create_blockchain_and_state(
.transpose()?;

let rpc_client = Arc::new(EthRpcClient::<L1ChainSpec>::new(
&fork_config.json_rpc_url,
&fork_config.url,
config.cache_dir.clone(),
http_headers.clone(),
)?);
Expand Down Expand Up @@ -2839,7 +2839,7 @@ pub(crate) mod test_utils {
fn with_fork(fork: Option<String>) -> anyhow::Result<Self> {
let fork = fork.map(|json_rpc_url| {
ForkConfig {
json_rpc_url,
url: json_rpc_url,
// Random recent block for better cache consistency
block_number: Some(FORK_BLOCK_NUMBER),
http_headers: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct ResetProviderConfig {
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ForkConfig {
pub json_rpc_url: String,
pub url: String,
pub block_number: Option<u64>,
pub http_headers: Option<HashMap<String, String>>,
}
2 changes: 1 addition & 1 deletion crates/edr_provider/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ where
pub async fn run_full_block(url: String, block_number: u64, chain_id: u64) -> anyhow::Result<()> {
let runtime = tokio::runtime::Handle::current();
let default_config = create_test_config_with_fork(Some(ForkConfig {
json_rpc_url: url.clone(),
url: url.clone(),
block_number: Some(block_number - 1),
http_headers: None,
}));
Expand Down
2 changes: 1 addition & 1 deletion crates/edr_provider/tests/hardhat_request_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn serde_hardhat_mine() {
fn serde_hardhat_reset() {
help_test_method_invocation_serde(MethodInvocation::Reset(Some(ResetProviderConfig {
forking: Some(ForkConfig {
json_rpc_url: String::from("http://whatever.com/whatever"),
url: String::from("http://whatever.com/whatever"),
block_number: Some(123456),
http_headers: None,
}),
Expand Down