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

* feat(ethers-core): double anvil startup time

* feat(ethers-core): add timeout utils

* chore: fmt

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
Wias Liaw 2022-09-18 23:50:12 +08:00 committed by GitHub
parent 3926749213
commit 1e83b86233
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -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.
///
@ -93,6 +93,7 @@ pub struct Anvil {
fork: Option<String>,
fork_block_number: Option<u64>,
args: Vec<String>,
timeout: Option<u64>,
}
impl Anvil {
@ -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 {
@ -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?")
}