Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feat(ethers-core): double anvil startup time #1702

Merged
merged 3 commits into from
Sep 18, 2022
Merged
Changes from 2 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
12 changes: 10 additions & 2 deletions ethers-core/src/utils/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
};

/// How long we will wait for anvil to indicate that it is ready.
const ANVIL_STARTUP_TIMEOUT_MILLIS: u64 = 5_000;
const ANVIL_STARTUP_TIMEOUT_MILLIS: u64 = 10_000;

/// An anvil CLI instance. Will close the instance when dropped.
///
Expand Down Expand Up @@ -93,6 +93,7 @@ pub struct Anvil {
fork: Option<String>,
fork_block_number: Option<u64>,
args: Vec<String>,
timeout: Option<u64>,
}

impl Anvil {
Expand Down Expand Up @@ -206,6 +207,13 @@ impl Anvil {
self
}

/// Sets the timeout which will be used when the `anvil` instance is launched.
#[must_use]
pub fn timeout<T: Into<u64>>(mut self, timeout: T) -> Self {
self.timeout = Some(timeout.into());
self
}

/// Consumes the builder and spawns `anvil` with stdout redirected
/// to /dev/null.
pub fn spawn(self) -> AnvilInstance {
Expand Down Expand Up @@ -251,7 +259,7 @@ impl Anvil {
let mut addresses = Vec::new();
let mut is_private_key = false;
loop {
if start + Duration::from_millis(ANVIL_STARTUP_TIMEOUT_MILLIS) <= Instant::now() {
if start + Duration::from_millis(self.timeout.unwrap_or(ANVIL_STARTUP_TIMEOUT_MILLIS)) <= Instant::now() {
panic!("Timed out waiting for anvil to start. Is anvil installed?")
}

Expand Down