feat: support additional ganache arguments (#347)
* feat: support additional ganache arguments * feat: add fork argument option
This commit is contained in:
parent
ed83223b93
commit
985509ac1c
|
@ -81,6 +81,8 @@ pub struct Ganache {
|
||||||
port: Option<u16>,
|
port: Option<u16>,
|
||||||
block_time: Option<u64>,
|
block_time: Option<u64>,
|
||||||
mnemonic: Option<String>,
|
mnemonic: Option<String>,
|
||||||
|
fork: Option<String>,
|
||||||
|
args: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ganache {
|
impl Ganache {
|
||||||
|
@ -108,6 +110,33 @@ impl Ganache {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the `fork` argument to fork from another currently running Ethereum client
|
||||||
|
/// at a given block. Input should be the HTTP location and port of the other client,
|
||||||
|
/// e.g. `http://localhost:8545`. You can optionally specify the block to fork from
|
||||||
|
/// using an @ sign: `http://localhost:8545@1599200`
|
||||||
|
pub fn fork<T: Into<String>>(mut self, fork: T) -> Self {
|
||||||
|
self.fork = Some(fork.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds an argument to pass to the `ganache-cli`.
|
||||||
|
pub fn arg<T: Into<String>>(mut self, arg: T) -> Self {
|
||||||
|
self.args.push(arg.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds multiple arguments to pass to the `ganache-cli`.
|
||||||
|
pub fn args<I, S>(mut self, args: I) -> Self
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = S>,
|
||||||
|
S: Into<String>,
|
||||||
|
{
|
||||||
|
for arg in args {
|
||||||
|
self = self.arg(arg);
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Consumes the builder and spawns `ganache-cli` with stdout redirected
|
/// Consumes the builder and spawns `ganache-cli` with stdout redirected
|
||||||
/// to /dev/null. This takes ~2 seconds to execute as it blocks while
|
/// to /dev/null. This takes ~2 seconds to execute as it blocks while
|
||||||
/// waiting for `ganache-cli` to launch.
|
/// waiting for `ganache-cli` to launch.
|
||||||
|
@ -129,6 +158,12 @@ impl Ganache {
|
||||||
cmd.arg("-b").arg(block_time.to_string());
|
cmd.arg("-b").arg(block_time.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(fork) = self.fork {
|
||||||
|
cmd.arg("-f").arg(fork);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.args(self.args);
|
||||||
|
|
||||||
let mut child = cmd.spawn().expect("couldnt start ganache-cli");
|
let mut child = cmd.spawn().expect("couldnt start ganache-cli");
|
||||||
|
|
||||||
let stdout = child
|
let stdout = child
|
||||||
|
|
Loading…
Reference in New Issue