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

Commit

Permalink
feat(ethers-core): double anvil startup time (#1702)
Browse files Browse the repository at this point in the history
* feat(ethers-core): double anvil startup time

* feat(ethers-core): add timeout utils

* chore: fmt

Co-authored-by: Georgios Konstantopoulos <[email protected]>
  • Loading branch information
wiasliaw and gakonst authored Sep 18, 2022
1 parent 3926749 commit 1e83b86
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 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,9 @@ 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

0 comments on commit 1e83b86

Please sign in to comment.