From b1639a86562f0ca94ad15d9c228e8d14c8f2782c Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 26 Jul 2024 11:56:32 -0500 Subject: [PATCH 1/5] feat: evm-version local network --- README.md | 21 ++++++++++++++++++++- ape_foundry/provider.py | 12 ++++++++++++ tests/test_provider.py | 9 +++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 65db812..4662d9b 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ foundry: priority_fee: 0 ``` -# Auto-mining +## Auto-mining Anvil nodes by default auto-mine. However, you can disable auto-mining on startup by configuring the foundry plugin like so: @@ -169,3 +169,22 @@ To mine on an interval instead, set the `block_time` config: foundry: block_time: 10 # mine a new block every 10 seconds ``` + +## EVM Version (hardfork) + +To change the EVM version for local foundry networks, use the `evm_version` config: + +```yaml +foundry: + evm_version: shanghai +``` + +To change the EVM version for forked networks, set it the specific forked-network config(s): + +```yaml +foundry: + fork: + ethereum: + mainnet: + evm_version: shanghai +``` diff --git a/ape_foundry/provider.py b/ape_foundry/provider.py index a26f80c..9b5d719 100644 --- a/ape_foundry/provider.py +++ b/ape_foundry/provider.py @@ -70,6 +70,9 @@ class FoundryNetworkConfig(PluginConfig): Defaults to ``True``. If ``host`` is remote, will not be able to start. """ + evm_version: Optional[str] = None + """The EVM hardfork to use, e.g. `shanghai`.""" + # Retry strategy configs, try increasing these if you're getting FoundrySubprocessError request_timeout: int = 30 fork_request_timeout: int = 300 @@ -419,6 +422,15 @@ def disconnect(self): super().disconnect() def build_command(self) -> list[str]: + cmd = self._build_command() + + if evm_version := self.settings.evm_version: + cmd.extend(("--hardfork", evm_version)) + + return cmd + + def _build_command(self) -> list[str]: + # All shared between forks and local. cmd = [ self.anvil_bin, "--port", diff --git a/tests/test_provider.py b/tests/test_provider.py index 63c4322..e3c3765 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -467,3 +467,12 @@ def test_initial_balance(accounts): # just showing we were able to increase it. acct = accounts[9] assert convert("10_000 ETH", int) < acct.balance <= convert("100_000 ETH", int) + + +@pytest.mark.parametrize("host", ("https://example.com", "example.com")) +def test_evm_version(project, local_network, host): + with project.temp_config(foundry={"evm_version": "shanghai"}): + provider = local_network.get_provider("foundry") + cmd = provider.build_command() + assert "--hardfork" in cmd + assert "shanghai" in cmd From d76db7a0757fabf11372a3f668a0857320f4cb5e Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 26 Jul 2024 12:32:48 -0500 Subject: [PATCH 2/5] fix: also set evm-version global in fork --- ape_foundry/provider.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ape_foundry/provider.py b/ape_foundry/provider.py index 9b5d719..93c571f 100644 --- a/ape_foundry/provider.py +++ b/ape_foundry/provider.py @@ -877,6 +877,8 @@ def build_command(self) -> list[str]: if self._fork_config.evm_version is not None: cmd.extend(("--hardfork", self._fork_config.evm_version)) + elif self.settings.evm_version is not None: + cmd.extend(("--hardfork", self.settings.evm_version)) return cmd From 0027b101e082d8ccbcf4972c5f93bc1e874747c7 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 26 Jul 2024 12:33:39 -0500 Subject: [PATCH 3/5] docs: todo --- ape_foundry/provider.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ape_foundry/provider.py b/ape_foundry/provider.py index 93c571f..f35ee5f 100644 --- a/ape_foundry/provider.py +++ b/ape_foundry/provider.py @@ -57,6 +57,8 @@ class FoundryForkConfig(PluginConfig): upstream_provider: Optional[str] = None block_number: Optional[int] = None + + # TODO: Delete in 0.9 release evm_version: Optional[str] = None From d5d178bc925a919c24d36277c69f765097c7d734 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 26 Jul 2024 12:35:08 -0500 Subject: [PATCH 4/5] docs: del todo --- ape_foundry/provider.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ape_foundry/provider.py b/ape_foundry/provider.py index f35ee5f..93c571f 100644 --- a/ape_foundry/provider.py +++ b/ape_foundry/provider.py @@ -57,8 +57,6 @@ class FoundryForkConfig(PluginConfig): upstream_provider: Optional[str] = None block_number: Optional[int] = None - - # TODO: Delete in 0.9 release evm_version: Optional[str] = None From de81c06f7d358c0176345eb14fe60084d5a039f7 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 26 Jul 2024 12:38:41 -0500 Subject: [PATCH 5/5] refactor: smarter way --- ape_foundry/provider.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ape_foundry/provider.py b/ape_foundry/provider.py index 93c571f..f62df62 100644 --- a/ape_foundry/provider.py +++ b/ape_foundry/provider.py @@ -258,6 +258,10 @@ def auto_mine(self) -> bool: def auto_mine(self, value) -> None: self.make_request("anvil_setAutomine", [value]) + @property + def evm_version(self) -> Optional[str]: + return self.settings.evm_version + @property def settings(self) -> FoundryNetworkConfig: return cast(FoundryNetworkConfig, super().settings) @@ -422,15 +426,6 @@ def disconnect(self): super().disconnect() def build_command(self) -> list[str]: - cmd = self._build_command() - - if evm_version := self.settings.evm_version: - cmd.extend(("--hardfork", evm_version)) - - return cmd - - def _build_command(self) -> list[str]: - # All shared between forks and local. cmd = [ self.anvil_bin, "--port", @@ -459,6 +454,9 @@ def _build_command(self) -> list[str]: if self.settings.disable_block_gas_limit: cmd.append("--disable-block-gas-limit") + if evm_version := self.evm_version: + cmd.extend(("--hardfork", evm_version)) + return cmd def set_balance(self, account: AddressType, amount: Union[int, float, str, bytes]): @@ -776,6 +774,13 @@ def _get_upstream(data: dict) -> Optional[str]: def fork_block_number(self) -> Optional[int]: return self._fork_config.block_number + @property + def evm_version(self) -> Optional[str]: + if evm_version := self._fork_config.evm_version: + return evm_version + + return self.settings.evm_version + def get_block(self, block_id: BlockID) -> BlockAPI: if isinstance(block_id, str) and block_id.isnumeric(): block_id = int(block_id) @@ -875,11 +880,6 @@ def build_command(self) -> list[str]: if self._fork_config.evm_version is None: self._fork_config.evm_version = self.detect_evm_version() - if self._fork_config.evm_version is not None: - cmd.extend(("--hardfork", self._fork_config.evm_version)) - elif self.settings.evm_version is not None: - cmd.extend(("--hardfork", self.settings.evm_version)) - return cmd def reset_fork(self, block_number: Optional[int] = None):