Skip to content

Commit

Permalink
all: mark cancun fork as deployed (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz authored Apr 10, 2024
1 parent cb53427 commit b7499ed
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fixtures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
python: '3.11'
- name: 'fixtures_develop'
evm-type: 'develop'
fill-params: '--until=Cancun'
fill-params: '--until=Prague'
solc: '0.8.21'
python: '3.11'
steps:
Expand Down
11 changes: 6 additions & 5 deletions .vscode/launch.recommended.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,31 @@
"cwd": "${workspaceFolder}"
},
{
"name": "Launch fill --until Shanghai",
"name": "Launch fill --until Cancun",
"type": "python",
"request": "launch",
"module": "pytest",
"args": [
"-c",
"pytest.ini",
"--until",
"Shanghai",
"Cancun",
"--evm-bin",
"${input:evmBinary}",
"-v"
],
"cwd": "${workspaceFolder}"
},
{
"name": "Launch fill --until Cancun",
"name": "Launch fill --until Prague",
"type": "python",
"request": "launch",
"module": "pytest",
"args": [
"-c",
"pytest.ini",
"--until",
"Cancun",
"Prague",
"--evm-bin",
"${input:evmBinary}",
"-v"
Expand Down Expand Up @@ -132,8 +132,9 @@
"Paris",
"Shanghai",
"Cancun",
"Prague",
],
"default": "Shanghai"
"default": "Cancun"
},
{
"type": "promptString",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.recommended.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
// To discover tests for an upcoming fork, use the `--until` argument as following.
// "--until=Cancun",
// "--until=Prague",
// Hopefully vscode-python will support multiple test framework environments sooon, see
// https://github.com/microsoft/vscode-python/issues/12075
// For now, to toggle between running "framework tests" and "filling tests" comment/
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Test fixtures for use by clients are available for each release on the [Github r
- State test field `transaction` now uses the proper zero-padded hex number format for fields `maxPriorityFeePerGas`, `maxFeePerGas`, and `maxFeePerBlobGas`
- Fixtures' hashes (in the `_info` field) are now calculated by removing the "_info" field entirely instead of it being set to an empty dict.

### 💥 Breaking Change

- Cancun is now the latest deployed fork, and the development fork is now Prague ([#489](https://github.com/ethereum/execution-spec-tests/pull/489)).

## 🔜 [v2.1.1](https://github.com/ethereum/execution-spec-tests/releases/tag/v2.1.1) - 2024-03-09

### 🧪 Test Cases
Expand Down
2 changes: 1 addition & 1 deletion docs/consuming_tests/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Artifacts can be downloaded directly from [the release page](https://github.com/
# The following two artifacts are intended for consumption by clients:
# - fixtures.tar.gz: Generated up to the last deployed fork.
# - fixtures_develop.tar.gz: Generated up to and including the latest dev fork.
# As of Oct 2023, dev is Cancun, deployed is Shanghai.
# As of March 2024, dev is Prague, deployed is Cancun.

ARTIFACT="fixtures_develop.tar.gz"

Expand Down
8 changes: 0 additions & 8 deletions src/ethereum_test_forks/forks/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,6 @@ class Cancun(Shanghai):
Cancun fork
"""

@classmethod
def is_deployed(cls):
"""
Flags that Cancun has not been deployed to mainnet; it is under active
development.
"""
return False

@classmethod
def solc_min_version(cls) -> Version:
"""
Expand Down
13 changes: 8 additions & 5 deletions src/ethereum_test_forks/tests/test_forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from ..transition_base_fork import transition_fork

FIRST_DEPLOYED = Frontier
LAST_DEPLOYED = Shanghai
LAST_DEPLOYED = Cancun
LAST_DEVELOPMENT = Prague
DEVELOPMENT_FORKS = [Cancun, Prague]
DEVELOPMENT_FORKS = [Prague]


def test_transition_forks():
Expand Down Expand Up @@ -67,9 +67,12 @@ def test_transition_forks():


def test_forks_from(): # noqa: D103
assert forks_from(Paris) == [Paris, LAST_DEPLOYED]
assert forks_from(Paris, deployed_only=True) == [Paris, LAST_DEPLOYED]
assert forks_from(Paris, deployed_only=False) == [Paris, LAST_DEPLOYED] + DEVELOPMENT_FORKS
assert forks_from(Paris)[0] == Paris
assert forks_from(Paris)[-1] == LAST_DEPLOYED
assert forks_from(Paris, deployed_only=True)[0] == Paris
assert forks_from(Paris, deployed_only=True)[-1] == LAST_DEPLOYED
assert forks_from(Paris, deployed_only=False)[0] == Paris
assert forks_from(Paris, deployed_only=False)[-1] == LAST_DEVELOPMENT


def test_forks():
Expand Down
3 changes: 2 additions & 1 deletion src/ethereum_test_tools/code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from .code import Code
from .generators import CalldataCase, Case, CodeGasMeasure, Conditional, Initcode, Switch
from .yul import Yul, YulCompiler
from .yul import Solc, Yul, YulCompiler

__all__ = (
"Case",
Expand All @@ -12,6 +12,7 @@
"CodeGasMeasure",
"Conditional",
"Initcode",
"Solc",
"Switch",
"Yul",
"YulCompiler",
Expand Down
144 changes: 64 additions & 80 deletions src/ethereum_test_tools/code/yul.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import re
import warnings
from functools import cached_property
from pathlib import Path
from shutil import which
from subprocess import PIPE, run
from typing import Optional, Sized, SupportsBytes, Tuple, Type, Union
from subprocess import CompletedProcess, run
from typing import Optional, Sized, SupportsBytes, Type

from semver import Version

Expand All @@ -17,86 +18,92 @@
from .code import Code

DEFAULT_SOLC_ARGS = ("--assemble", "-")
VERSION_PATTERN = re.compile(r"Version: (.*)")


def get_evm_version_from_fork(fork: Fork | None):
"""
Get the solc evm version corresponding to `fork`.
class Solc:
"""Solc compiler."""

Args
----
fork (Fork): The fork to retrieve the corresponding evm version for.
binary: Path

Returns
-------
str: The name of evm version as required by solc's --evm-version.
"""
if not fork:
return None
return fork.solc_name()
def __init__(
self,
binary: Optional[Path | str] = None,
):
if binary is None:
which_path = which("solc")
if which_path is not None:
binary = Path(which_path)
if binary is None or not Path(binary).exists():
raise Exception(
"""`solc` binary executable not found, please refer to
https://docs.soliditylang.org/en/latest/installing-solidity.html
for help downloading and installing `solc`"""
)
self.binary = Path(binary)

def run(self, *args: str, input: str | None = None) -> CompletedProcess:
"""Run solc with the given arguments"""
return run(
[self.binary, *args],
capture_output=True,
text=True,
input=input,
)

@cached_property
def version(self) -> Version:
"""Return solc's version"""
for line in self.run("--version").stdout.splitlines():
if match := VERSION_PATTERN.search(line):
# Sanitize
solc_version_string = match.group(1).replace("g++", "gpp")
return Version.parse(solc_version_string)
warnings.warn("Unable to determine solc version.")
return Version(0)


class Yul(SupportsBytes, Sized):
class Yul(Solc, SupportsBytes, Sized):
"""
Yul compiler.
Compiles Yul source code into bytecode.
"""

source: str
compiled: Optional[bytes] = None
evm_version: str | None

def __init__(
self,
source: str,
fork: Optional[Fork] = None,
binary: Optional[Path | str] = None,
):
super().__init__(binary)
self.source = source
self.evm_version = get_evm_version_from_fork(fork)
if binary is None:
which_path = which("solc")
if which_path is not None:
binary = Path(which_path)
if binary is None or not Path(binary).exists():
raise Exception(
"""`solc` binary executable not found, please refer to
https://docs.soliditylang.org/en/latest/installing-solidity.html
for help downloading and installing `solc`"""
)
self.binary = Path(binary)
self.evm_version = fork.solc_name() if fork else None

def __bytes__(self) -> bytes:
"""
Assembles using `solc --assemble`.
"""
if not self.compiled:
solc_args: Tuple[Union[Path, str], ...] = ()
if self.evm_version:
solc_args = (
self.binary,
"--evm-version",
self.evm_version,
*DEFAULT_SOLC_ARGS,
)
else:
solc_args = (self.binary, *DEFAULT_SOLC_ARGS)
result = run(
solc_args,
input=str.encode(self.source),
stdout=PIPE,
stderr=PIPE,
)
@cached_property
def compiled(self) -> bytes:
"""Returns the compiled Yul source code."""
solc_args = ("--evm-version", self.evm_version) if self.evm_version else ()

result = self.run(*solc_args, *DEFAULT_SOLC_ARGS, input=self.source)

if result.returncode:
stderr_lines = result.stderr.splitlines()
stderr_message = "\n".join(line.strip() for line in stderr_lines)
raise Exception(f"failed to compile yul source:\n{stderr_message[7:]}")

if result.returncode != 0:
stderr_lines = result.stderr.decode().split("\n")
stderr_message = "\n".join(line.strip() for line in stderr_lines)
raise Exception(f"failed to compile yul source:\n{stderr_message[7:]}")
lines = result.stdout.splitlines()

lines = result.stdout.decode().split("\n")
hex_str = lines[lines.index("Binary representation:") + 1]

hex_str = lines[lines.index("Binary representation:") + 1]
return bytes.fromhex(hex_str)

self.compiled = bytes.fromhex(hex_str)
def __bytes__(self) -> bytes:
"""
Assembles using `solc --assemble`.
"""
return self.compiled

def __len__(self) -> int:
Expand All @@ -117,28 +124,5 @@ def __radd__(self, other: str | bytes | SupportsBytes) -> Code:
"""
return Code(to_bytes(other) + bytes(self))

def version(self) -> Version:
"""
Return solc's version string
"""
result = run(
[self.binary, "--version"],
stdout=PIPE,
stderr=PIPE,
)
solc_output = result.stdout.decode().split("\n")
version_pattern = r"Version: (.*)"
solc_version_string = ""
for line in solc_output:
if match := re.search(version_pattern, line):
solc_version_string = match.group(1)
break
if not solc_version_string:
warnings.warn("Unable to determine solc version.")
return Version(0)
# Sanitize
solc_version_string = solc_version_string.replace("g++", "gpp")
return Version.parse(solc_version_string)


YulCompiler = Type[Yul]
2 changes: 1 addition & 1 deletion src/ethereum_test_tools/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@pytest.fixture(scope="session")
def solc_version() -> Version:
"""Return the version of solc being used for tests."""
solc_version = Yul("").version().finalize_version()
solc_version = Yul("").version.finalize_version()
if solc_version < Frontier.solc_min_version():
raise Exception("Unsupported solc version: {}".format(solc_version))
return solc_version
19 changes: 14 additions & 5 deletions src/ethereum_test_tools/tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
import pytest
from semver import Version

from ethereum_test_forks import Fork, Homestead, Shanghai, get_deployed_forks
from ethereum_test_forks import (
Cancun,
Fork,
Homestead,
Shanghai,
get_closest_fork_with_solc_support,
get_deployed_forks,
)
from evm_transition_tool import FixtureFormats, GethTransitionTool

from ..code import CalldataCase, Case, Code, Conditional, Initcode, Switch, Yul
from ..code import CalldataCase, Case, Code, Conditional, Initcode, Solc, Switch, Yul
from ..common import Account, Environment, Hash, TestAddress, Transaction
from ..spec import StateTest
from ..vm.opcode import Opcodes as Op
Expand Down Expand Up @@ -66,7 +73,9 @@ def yul_code(request: pytest.FixtureRequest, fork: Fork, padding_before: str, pa
else:
compiled_yul_code = Code("")
for yul_code in yul_code_snippets:
compiled_yul_code += Yul(yul_code, fork=fork)
compiled_yul_code += Yul(
yul_code, fork=get_closest_fork_with_solc_support(fork, Solc().version)
)
if padding_after is not None:
compiled_yul_code += Code(padding_after)
return compiled_yul_code
Expand All @@ -83,7 +92,7 @@ def expected_bytes(request: pytest.FixtureRequest, solc_version: Version, fork:
solc_padding = "00"
return bytes.fromhex(expected_bytes.substitute(solc_padding=solc_padding))
if isinstance(expected_bytes, bytes):
if fork == Shanghai:
if fork >= Shanghai:
expected_bytes = b"\x5f" + expected_bytes[2:]
if solc_version < SOLC_PADDING_VERSION or fork <= Homestead:
return expected_bytes
Expand Down Expand Up @@ -650,7 +659,7 @@ def test_switch(tx_data: bytes, switch_bytecode: bytes, expected_storage: Mappin
)
state_test.generate(
t8n=GethTransitionTool(),
fork=Shanghai,
fork=Cancun,
fixture_format=FixtureFormats.BLOCKCHAIN_TEST,
eips=None,
)
Loading

0 comments on commit b7499ed

Please sign in to comment.