feat: add --fork-block-number setter for anvil bindings
@@ -82,6 +82,7 @@ pub struct Anvil {
block_time: Option<u64>,
mnemonic: Option<String>,
fork: Option<String>,
+ fork_block_number: Option<u64>,
args: Vec<String>,
}
@@ -113,6 +114,15 @@ impl Anvil {
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
/// 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
@@ -163,6 +173,10 @@ impl Anvil {
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);
let mut child = cmd.spawn().expect("couldnt start anvil");
