-
Notifications
You must be signed in to change notification settings - Fork 767
/
main.rs
53 lines (44 loc) · 1.56 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#![cfg(not(target_arch = "wasm32"))]
use ethers_core::utils::{Anvil, AnvilInstance};
use ethers_providers::{Http, Provider};
use std::time::Duration;
#[cfg(feature = "ipc")]
use ethers_providers::Ipc;
#[cfg(feature = "ipc")]
use tempfile::NamedTempFile;
#[cfg(feature = "ws")]
use ethers_providers::Ws;
mod provider;
mod txpool;
#[cfg(all(feature = "ws", not(feature = "legacy-ws"), not(feature = "celo")))]
mod ws_errors;
/// Spawns Anvil and instantiates an Http provider.
pub fn spawn_anvil() -> (Provider<Http>, AnvilInstance) {
let anvil = Anvil::new().block_time(1u64).spawn();
let provider = Provider::<Http>::try_from(anvil.endpoint())
.unwrap()
.interval(Duration::from_millis(50u64));
(provider, anvil)
}
/// Spawns Anvil and instantiates a Ws provider.
#[cfg(feature = "ws")]
pub async fn spawn_anvil_ws() -> (Provider<Ws>, AnvilInstance) {
let anvil = Anvil::new().block_time(1u64).spawn();
let provider = Provider::<Ws>::connect(anvil.ws_endpoint())
.await
.unwrap()
.interval(Duration::from_millis(50u64));
(provider, anvil)
}
/// Spawns Anvil and instantiates a Ipc provider.
#[cfg(feature = "ipc")]
pub async fn spawn_anvil_ipc() -> (Provider<Ipc>, AnvilInstance, NamedTempFile) {
let ipc = NamedTempFile::new().unwrap();
let anvil =
Anvil::new().block_time(1u64).arg("--ipc").arg(ipc.path().display().to_string()).spawn();
let provider = Provider::<Ipc>::connect_ipc(ipc.path())
.await
.unwrap()
.interval(Duration::from_millis(50u64));
(provider, anvil, ipc)
}