Skip to content

Commit

Permalink
set auth header for fork
Browse files Browse the repository at this point in the history
  • Loading branch information
anukul committed Dec 12, 2024
1 parent 360bcc7 commit 92785ee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/cheatcodes/src/evm/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ fn create_fork_request(
evm_opts.fork_block_number = block;
evm_opts.fork_retries = rpc_endpoint.config.retries;
evm_opts.fork_retry_backoff = rpc_endpoint.config.retry_backoff;
if let Some(Ok(auth)) = rpc_endpoint.auth {
evm_opts.fork_headers = Some(vec![format!("Authorization: {auth}")]);
}
let fork = CreateFork {
enable_caching: !ccx.state.config.no_storage_caching &&
ccx.state.config.rpc_storage_caching.enable_for_endpoint(&url),
Expand Down
6 changes: 6 additions & 0 deletions crates/common/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ impl ProviderBuilder {
self
}

/// Sets http headers. If `None`, defaults to the already-set value.
pub fn maybe_headers(mut self, headers: Option<Vec<String>>) -> Self {
self.headers = headers.unwrap_or(self.headers);
self
}

/// Constructs the `RetryProvider` taking all configs into account.
pub fn build(self) -> Result<RetryProvider> {
let Self {
Expand Down
1 change: 1 addition & 0 deletions crates/evm/core/src/fork/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ async fn create_fork(mut fork: CreateFork) -> eyre::Result<(ForkId, CreatedFork,
ProviderBuilder::new(fork.url.as_str())
.maybe_max_retry(fork.evm_opts.fork_retries)
.maybe_initial_backoff(fork.evm_opts.fork_retry_backoff)
.maybe_headers(fork.evm_opts.fork_headers.clone())
.compute_units_per_second(fork.evm_opts.get_compute_units_per_second())
.build()?,
);
Expand Down
4 changes: 4 additions & 0 deletions crates/evm/core/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub struct EvmOpts {
/// Initial retry backoff.
pub fork_retry_backoff: Option<u64>,

/// Headers to use with `fork_url`
pub fork_headers: Option<Vec<String>>,

/// The available compute units per second.
///
/// See also <https://docs.alchemy.com/reference/compute-units#what-are-cups-compute-units-per-second>
Expand Down Expand Up @@ -80,6 +83,7 @@ impl Default for EvmOpts {
fork_block_number: None,
fork_retries: None,
fork_retry_backoff: None,
fork_headers: None,
compute_units_per_second: None,
no_rpc_rate_limit: false,
no_storage_caching: false,
Expand Down

0 comments on commit 92785ee

Please sign in to comment.