feat: add --fork-block-number setter for anvil bindings (#1468)

This commit is contained in:
Matthias Seitz 2022-07-10 00:19:57 +02:00 committed by GitHub
parent 8db1899820
commit 1ff4be74f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -82,6 +82,7 @@ pub struct Anvil {
block_time: Option<u64>, block_time: Option<u64>,
mnemonic: Option<String>, mnemonic: Option<String>,
fork: Option<String>, fork: Option<String>,
fork_block_number: Option<u64>,
args: Vec<String>, args: Vec<String>,
} }
@ -113,6 +114,15 @@ impl Anvil {
self self
} }
/// Sets the `fork-block-number` which will be used in addition to [`Self::fork`].
///
/// **Note:** if set, then this requires `fork` to be set as well
#[must_use]
pub fn fork_block_number<T: Into<u64>>(mut self, fork_block_number: T) -> Self {
self.fork_block_number = Some(fork_block_number.into());
self
}
/// Sets the `fork` argument to fork from another currently running Ethereum client /// 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, /// 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 /// e.g. `http://localhost:8545`. You can optionally specify the block to fork from
@ -163,6 +173,10 @@ impl Anvil {
cmd.arg("-f").arg(fork); cmd.arg("-f").arg(fork);
} }
if let Some(fork_block_number) = self.fork_block_number {
cmd.arg("--fork-block-number").arg(fork_block_number.to_string());
}
cmd.args(self.args); cmd.args(self.args);
let mut child = cmd.spawn().expect("couldnt start anvil"); let mut child = cmd.spawn().expect("couldnt start anvil");