Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: global evm-version config #112

Merged
merged 5 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
```
20 changes: 17 additions & 3 deletions ape_foundry/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -255,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)
Expand Down Expand Up @@ -447,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]):
Expand Down Expand Up @@ -764,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)
Expand Down Expand Up @@ -863,9 +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))

return cmd

def reset_fork(self, block_number: Optional[int] = None):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading