Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vyperlang/vyper into revm
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Mar 19, 2024
2 parents 88d0296 + 58ecff5 commit ebd239b
Show file tree
Hide file tree
Showing 66 changed files with 2,040 additions and 770 deletions.
152 changes: 87 additions & 65 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: Install Dependencies
run: pip install .[lint]

- name: Debug dependencies
run: pip freeze

- name: Run Black
run: black --check -C --force-exclude=vyper/version.py ./vyper ./tests ./setup.py

Expand All @@ -35,6 +38,9 @@ jobs:
- name: Run isort
run: isort --check-only --diff ./vyper ./tests ./setup.py

- name: Run mypy
run: make mypy

docs:
runs-on: ubuntu-latest

Expand All @@ -47,47 +53,68 @@ jobs:
python-version: "3.11"
cache: "pip"

- name: Install Tox
run: pip install tox

- name: Run Tox
run: TOXENV=docs tox -r

mypy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"

- name: Install Dependencies
run: pip install .[lint]
- name: Install deps
# TODO these should really be in setup.py
run: pip install shibuya sphinx sphinx-copybutton

- name: Run mypy
run: make mypy
- name: Run docs
run: sphinx-build -E -b html docs dist/docs -n -q --color

# "Regular"/core tests.
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [["3.11", "311"]]
# run in modes: --optimize [gas, none, codesize]
opt-mode: ["gas", "none", "codesize"]
evm-version: [shanghai]
debug: [true, false]
# run across other python versions.# we don't really need to run all
# modes across all python versions - one is enough
memorymock: [false]

# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations
include:
# test default settings with 3.11 across all supported evm versions
- python-version: ["3.11", "311"]
debug: false
opt-mode: gas
evm-version: london
- python-version: ["3.11", "311"]
debug: false
opt-mode: gas
evm-version: paris

# redundant rule, for clarity
- python-version: ["3.11", "311"]
debug: false
opt-mode: gas
evm-version: shanghai

# enable when py-evm makes it work:
#- python-version: ["3.11", "311"]
# debug: false
# opt-mode: gas
# evm-version: cancun

# run with `--memorymock`, but only need to do it one configuration
# TODO: consider removing the memorymock tests
- python-version: ["3.11", "311"]
opt-mode: gas
debug: false
evm-version: shanghai
memorymock: true

# run across other python versions. we don't really need to run all
# modes across all python versions - one is enough
- python-version: ["3.10", "310"]
opt-mode: gas
debug: false
evm-version: shanghai
- python-version: ["3.12", "312"]
opt-mode: gas
debug: false
evm-version: shanghai

name: py${{ matrix.python-version[1] }}-opt-${{ matrix.opt-mode }}${{ matrix.debug && '-debug' || '' }}
name: py${{ matrix.python-version[1] }}-opt-${{ matrix.opt-mode }}${{ matrix.debug && '-debug' || '' }}${{ matrix.memorymock && '-memorymock' || '' }}-${{ matrix.evm-version }}

steps:
- uses: actions/checkout@v4
Expand All @@ -101,11 +128,23 @@ jobs:
python-version: ${{ matrix.python-version[0] }}
cache: "pip"

- name: Install Tox
run: pip install tox
- name: Install dependencies
run: pip install .[test]

- name: Run Tox
run: TOXENV=py${{ matrix.python-version[1] }} tox -r -- --optimize ${{ matrix.opt-mode }} ${{ matrix.debug && '--enable-compiler-debug-mode' || '' }} -r aR tests/
- name: Debug dependencies
run: pip freeze

- name: Run tests
run: |
pytest \
--dist worksteal \
-m "not fuzzing" \
--optimize ${{ matrix.opt-mode }} \
--evm-version ${{ matrix.evm-version }} \
${{ matrix.debug && '--enable-compiler-debug-mode' || '' }} \
${{ matrix.memorymock && '--memorymock' || '' }} \
--showlocals -r aR \
tests/
- name: Upload Coverage
uses: codecov/codecov-action@v4
Expand Down Expand Up @@ -133,7 +172,10 @@ jobs:

strategy:
matrix:
group: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
# note that every time this is updated, `--splits` needs to be
# updated below as well.
# python -c "print(list(range(1, 121)))"
group: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120]

steps:
- uses: actions/checkout@v4
Expand All @@ -144,17 +186,24 @@ jobs:
python-version: "3.11"
cache: "pip"

- name: Install Tox
run: pip install tox
- name: Install dependencies
run: pip install .[test]

# fetch test durations
# NOTE: if the tests get poorly distributed, run this and commit the resulting `.test_durations` file to the `vyper-test-durations` repo.
# `TOXENV=fuzzing tox -r -- --store-durations -r aR tests/`
# `pytest -m "fuzzing" --store-durations -r aR tests/`
- name: Fetch test-durations
run: curl --location "https://raw.githubusercontent.com/vyperlang/vyper-test-durations/5982755ee8459f771f2e8622427c36494646e1dd/test_durations" -o .test_durations

- name: Run Tox
run: TOXENV=fuzzing tox -r -- --splits 60 --group ${{ matrix.group }} --splitting-algorithm least_duration -r aR tests/
run: curl --location "https://raw.githubusercontent.com/vyperlang/vyper-test-durations/master/test_durations" -o .test_durations

- name: Run tests
run: |
pytest \
-m "fuzzing" \
--splits 120 \
--group ${{ matrix.group }} \
--splitting-algorithm least_duration \
--dist worksteal \
-r aR tests/
- name: Upload Coverage
uses: codecov/codecov-action@v4
Expand All @@ -173,30 +222,3 @@ jobs:
- name: Check slow tests all succeeded
if: ${{ needs.fuzzing.result != 'success' }}
run: exit 1

memory:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
# need to fetch unshallow so that setuptools_scm can infer the version
fetch-depth: 0

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"

- name: Install Tox
run: pip install tox

- name: Run Tox
run: TOXENV=memory tox -r

- name: Upload Coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
- id: mypy
additional_dependencies:
- "types-setuptools"
args: # settings from tox.ini
args: # settings from Makefile
- --install-types
- --non-interactive
- --follow-imports=silent
Expand Down
21 changes: 7 additions & 14 deletions docs/compiling-a-contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,10 @@ When using the JSON interface, you can include the ``"evmVersion"`` key within t
Target Options
--------------

The following is a list of supported EVM versions, and changes in the compiler introduced with each version. Backward compatibility is not guaranteed between each version.
The following is a list of supported EVM versions, and changes in the compiler introduced with each version. Backward compatibility is not guaranteed between each version. In general, the compiler team maintains an informal policy that the compiler will support 3 years of hard fork rulesets, but this policy may be revisited as appropriate.


.. py:attribute:: istanbul
- The ``CHAINID`` opcode is accessible via ``chain.id``
- The ``SELFBALANCE`` opcode is used for calls to ``self.balance``
- Gas estimates changed for ``SLOAD`` and ``BALANCE``

.. py:attribute:: berlin
- Gas estimates changed for ``EXTCODESIZE``, ``EXTCODECOPY``, ``EXTCODEHASH``, ``SLOAD``, ``SSTORE``, ``CALL``, ``CALLCODE``, ``DELEGATECALL`` and ``STATICCALL``
- Functions marked with ``@nonreentrant`` are protected with different values (3 and 2) than contracts targeting pre-berlin.
- ``BASEFEE`` is accessible via ``block.basefee``
.. py:attribute:: london
.. py:attribute:: paris
Expand Down Expand Up @@ -247,7 +237,7 @@ The following example describes the expected input format of ``vyper-json``. Com
},
// Optional
"settings": {
"evmVersion": "shanghai", // EVM version to compile for. Can be istanbul, berlin, paris, shanghai (default) or cancun (experimental!).
"evmVersion": "shanghai", // EVM version to compile for. Can be london, paris, shanghai (default) or cancun (experimental!).
// optional, optimization mode
// defaults to "gas". can be one of "gas", "codesize", "none",
// false and true (the last two are for backwards compatibility).
Expand Down Expand Up @@ -275,11 +265,14 @@ The following example describes the expected input format of ``vyper-json``. Com
// evm.bytecode.opcodes - Opcodes list
// evm.deployedBytecode.object - Deployed bytecode object
// evm.deployedBytecode.opcodes - Deployed opcodes list
// evm.deployedBytecode.sourceMap - Deployed source mapping (useful for debugging)
// evm.deployedBytecode.sourceMap - Solidity-style source mapping
// evm.deployedBytecode.sourceMapFull - Deployed source mapping (useful for debugging)
// evm.methodIdentifiers - The list of function hashes
//
// Using `evm`, `evm.bytecode`, etc. will select every target part of that output.
// Additionally, `*` can be used as a wildcard to request everything.
// Note that the sourceMapFull.pc_ast_map is the recommended source map to use;
// the other types are included for legacy and compatibility reasons.
//
"outputSelection": {
"*": ["evm.bytecode", "abi"], // Enable the abi and bytecode outputs for every single contract
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exclude = '''
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
Expand Down
2 changes: 1 addition & 1 deletion quicktest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

# run pytest but bail out on first error and suppress coverage.
# useful for dev workflow
pytest -q --no-cov -s --instafail -x --disable-warnings "$@"
pytest --dist worksteal -q --no-cov -s --instafail -x --disable-warnings "$@"
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ extend-ignore = E203
max-line-length = 100
exclude =
venv*
.tox
docs
build
per-file-ignores =
Expand Down
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

extras_require = {
"test": [
"pytest>=6.2.5,<7.0",
"pytest-cov>=2.10,<3.0",
"pytest>=8.0,<9.0",
"pytest-cov>=4.1,<5.0",
"pytest-instafail>=0.4,<1.0",
"pytest-xdist>=2.5,<3.0",
"pytest-xdist>=3.5,<4.0",
"pytest-split>=0.7.0,<1.0",
"eth-tester[py-evm]>=0.9.0b1,<0.10",
"eth_abi>=4.0.0,<5.0.0",
"py-evm>=0.7.0a1,<0.8",
"web3==6.0.0",
"tox>=3.15,<4.0",
"lark==1.1.9",
"hypothesis[lark]>=5.37.1,<6.0",
"eth-stdlib==0.2.6",
"hypothesis[lark]>=6.0,<7.0",
"eth-stdlib==0.2.7",
"setuptools",
"pyrevm @ git+https://github.com/gakonst/pyrevm.git@master",
],
"lint": [
Expand Down Expand Up @@ -116,6 +116,7 @@ def _global_version(version):
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
package_data={"vyper.ast": ["grammar.lark"]},
data_files=[("", [hash_file_rel_path])],
Expand Down
24 changes: 21 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from web3.contract import Contract
from web3.providers.eth_tester import EthereumTesterProvider

import vyper.evm.opcodes as evm
from tests.revm.revm_env import RevmEnv
from tests.utils import working_directory
from vyper import compiler
Expand All @@ -39,7 +40,7 @@


def set_evm_verbose_logging():
logger = logging.getLogger("eth.vm.computation.Computation")
logger = logging.getLogger("eth.vm.computation.BaseComputation")
setup_DEBUG2_logging()
logger.setLevel("DEBUG2")

Expand All @@ -60,6 +61,13 @@ def pytest_addoption(parser):
)
parser.addoption("--enable-compiler-debug-mode", action="store_true")

parser.addoption(
"--evm-version",
choices=list(evm.EVM_VERSIONS.keys()),
default="shanghai",
help="set evm version",
)


@pytest.fixture(scope="module")
def output_formats():
Expand All @@ -82,6 +90,18 @@ def debug(pytestconfig):
_set_debug_mode(debug)


@pytest.fixture(scope="session", autouse=True)
def evm_version(pytestconfig):
# note: we configure the evm version that we emit code for,
# but eth-tester is only configured with the latest mainnet
# version.
evm_version_str = pytestconfig.getoption("evm_version")
evm.DEFAULT_EVM_VERSION = evm_version_str
# this should get overridden by anchor_evm_version,
# but set it anyway
evm.active_evm_version = evm.EVM_VERSIONS[evm_version_str]


@pytest.fixture
def chdir_tmp_path(tmp_path):
# this is useful for when you want imports to have relpaths
Expand Down Expand Up @@ -319,7 +339,6 @@ def _get_contract(
**kwargs,
):
settings = Settings()
settings.evm_version = kwargs.pop("evm_version", None)
settings.optimize = override_opt_level or optimize
out = compiler.compile_code(
source_code,
Expand Down Expand Up @@ -402,7 +421,6 @@ def _deploy_blueprint_for(
w3, source_code, optimize, output_formats, initcode_prefix=ERC5202_PREFIX, **kwargs
):
settings = Settings()
settings.evm_version = kwargs.pop("evm_version", None)
settings.optimize = optimize
out = compiler.compile_code(
source_code,
Expand Down
Loading

0 comments on commit ebd239b

Please sign in to comment.