From 1ff4be74f98f087585e7fe55f8038ff7a81695d4 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sun, 10 Jul 2022 00:19:57 +0200 Subject: [PATCH] feat: add --fork-block-number setter for anvil bindings (#1468) --- ethers-core/src/utils/anvil.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ethers-core/src/utils/anvil.rs b/ethers-core/src/utils/anvil.rs index b762fbb3..4a8e62a8 100644 --- a/ethers-core/src/utils/anvil.rs +++ b/ethers-core/src/utils/anvil.rs @@ -82,6 +82,7 @@ pub struct Anvil { block_time: Option, mnemonic: Option, fork: Option, + fork_block_number: Option, args: Vec, } @@ -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>(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");