Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/vyperlang/vyper into refa…
Browse files Browse the repository at this point in the history
…ctor/folding_alt
  • Loading branch information
tserg committed Sep 29, 2023
2 parents 504f787 + c913b2d commit af43e56
Show file tree
Hide file tree
Showing 31 changed files with 123 additions and 106 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
run: pip install tox

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

- name: Upload Coverage
uses: codecov/codecov-action@v1
Expand Down Expand Up @@ -148,12 +148,12 @@ jobs:

# 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 --reruns 10 --reruns-delay 1 -r aR tests/`
# `TOXENV=fuzzing tox -r -- --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 --reruns 10 --reruns-delay 1 -r aR tests/
run: TOXENV=fuzzing tox -r -- --splits 60 --group ${{ matrix.group }} --splitting-algorithm least_duration -r aR tests/

- name: Upload Coverage
uses: codecov/codecov-action@v1
Expand Down
13 changes: 11 additions & 2 deletions docs/control-structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,25 @@ Ranges are created using the ``range`` function. The following examples are vali
``STOP`` is a literal integer greater than zero. ``i`` begins as zero and increments by one until it is equal to ``STOP``.

.. code-block:: python
for i in range(stop, bound=N):
...
Here, ``stop`` can be a variable with integer type, greater than zero. ``N`` must be a compile-time constant. ``i`` begins as zero and increments by one until it is equal to ``stop``. If ``stop`` is larger than ``N``, execution will revert at runtime. In certain cases, you may not have a guarantee that ``stop`` is less than ``N``, but still want to avoid the possibility of runtime reversion. To accomplish this, use the ``bound=`` keyword in combination with ``min(stop, N)`` as the argument to ``range``, like ``range(min(stop, N), bound=N)``. This is helpful for use cases like chunking up operations on larger arrays across multiple transactions.

Another use of range can be with ``START`` and ``STOP`` bounds.

.. code-block:: python
for i in range(START, STOP):
...
``START`` and ``STOP`` are literal integers, with ``STOP`` being a greater value than ``START``. ``i`` begins as ``START`` and increments by one until it is equal to ``STOP``.
Here, ``START`` and ``STOP`` are literal integers, with ``STOP`` being a greater value than ``START``. ``i`` begins as ``START`` and increments by one until it is equal to ``STOP``.

.. code-block:: python
for i in range(a, a + N):
...
``a`` is a variable with an integer type and ``N`` is a literal integer greater than zero. ``i`` begins as ``a`` and increments by one until it is equal to ``a + N``.
``a`` is a variable with an integer type and ``N`` is a literal integer greater than zero. ``i`` begins as ``a`` and increments by one until it is equal to ``a + N``. If ``a + N`` would overflow, execution will revert.
2 changes: 0 additions & 2 deletions examples/tokens/ERC1155ownable.vy
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ def mint(receiver: address, id: uint256, amount:uint256):
@param receiver the account that will receive the minted token
@param id the ID of the token
@param amount of tokens for this ID
@param data the data associated with this mint. Usually stays empty
"""
assert not self.paused, "The contract has been paused"
assert self.owner == msg.sender, "Only the contract owner can mint"
Expand All @@ -232,7 +231,6 @@ def mintBatch(receiver: address, ids: DynArray[uint256, BATCH_SIZE], amounts: Dy
@param receiver the account that will receive the minted token
@param ids array of ids for the tokens
@param amounts amounts of tokens for each ID in the ids array
@param data the data associated with this mint. Usually stays empty
"""
assert not self.paused, "The contract has been paused"
assert self.owner == msg.sender, "Only the contract owner can mint"
Expand Down
4 changes: 2 additions & 2 deletions tests/ast/nodes/test_evaluate_binop_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=None)
@settings(max_examples=50)
@given(left=st_decimals, right=st_decimals)
@example(left=Decimal("0.9999999999"), right=Decimal("0.0000000001"))
@example(left=Decimal("0.0000000001"), right=Decimal("0.9999999999"))
Expand Down Expand Up @@ -52,7 +52,7 @@ def test_binop_pow():


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=None)
@settings(max_examples=50)
@given(
values=st.lists(st_decimals, min_size=2, max_size=10),
ops=st.lists(st.sampled_from("+-*/%"), min_size=11, max_size=11),
Expand Down
8 changes: 4 additions & 4 deletions tests/ast/nodes/test_evaluate_binop_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(left=st_int32, right=st_int32)
@example(left=1, right=1)
@example(left=1, right=-1)
Expand Down Expand Up @@ -42,7 +42,7 @@ def foo(a: int128, b: int128) -> int128:


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(left=st_uint64, right=st_uint64)
@pytest.mark.parametrize("op", "+-*/%")
def test_binop_uint256(get_contract, assert_tx_failed, op, left, right):
Expand All @@ -69,7 +69,7 @@ def foo(a: uint256, b: uint256) -> uint256:

@pytest.mark.xfail(reason="need to implement safe exponentiation logic")
@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(left=st.integers(min_value=2, max_value=245), right=st.integers(min_value=0, max_value=16))
@example(left=0, right=0)
@example(left=0, right=1)
Expand All @@ -89,7 +89,7 @@ def foo(a: uint256, b: uint256) -> uint256:


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(
values=st.lists(st.integers(min_value=-256, max_value=256), min_size=2, max_size=10),
ops=st.lists(st.sampled_from("+-*/%"), min_size=11, max_size=11),
Expand Down
4 changes: 2 additions & 2 deletions tests/ast/nodes/test_evaluate_boolop.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(values=st.lists(st.booleans(), min_size=2, max_size=10))
@pytest.mark.parametrize("comparator", ["and", "or"])
def test_boolop_simple(get_contract, values, comparator):
Expand All @@ -32,7 +32,7 @@ def foo({input_value}) -> bool:


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(
values=st.lists(st.booleans(), min_size=2, max_size=10),
comparators=st.lists(st.sampled_from(["and", "or"]), min_size=11, max_size=11),
Expand Down
8 changes: 4 additions & 4 deletions tests/ast/nodes/test_evaluate_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# TODO expand to all signed types
@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(left=st.integers(), right=st.integers())
@pytest.mark.parametrize("op", ["==", "!=", "<", "<=", ">=", ">"])
def test_compare_eq_signed(get_contract, op, left, right):
Expand All @@ -28,7 +28,7 @@ def foo(a: int128, b: int128) -> bool:

# TODO expand to all unsigned types
@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(left=st.integers(min_value=0), right=st.integers(min_value=0))
@pytest.mark.parametrize("op", ["==", "!=", "<", "<=", ">=", ">"])
def test_compare_eq_unsigned(get_contract, op, left, right):
Expand All @@ -47,7 +47,7 @@ def foo(a: uint128, b: uint128) -> bool:


@pytest.mark.fuzzing
@settings(max_examples=20, deadline=1000)
@settings(max_examples=20)
@given(left=st.integers(), right=st.lists(st.integers(), min_size=1, max_size=16))
def test_compare_in(left, right, get_contract):
source = f"""
Expand Down Expand Up @@ -76,7 +76,7 @@ def bar(a: int128) -> bool:


@pytest.mark.fuzzing
@settings(max_examples=20, deadline=1000)
@settings(max_examples=20)
@given(left=st.integers(), right=st.lists(st.integers(), min_size=1, max_size=16))
def test_compare_not_in(left, right, get_contract):
source = f"""
Expand Down
2 changes: 1 addition & 1 deletion tests/ast/nodes/test_evaluate_subscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(
idx=st.integers(min_value=0, max_value=9),
array=st.lists(st.integers(), min_size=10, max_size=10),
Expand Down
4 changes: 2 additions & 2 deletions tests/base_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def _get_contract(w3, source_code, optimize, *args, override_opt_level=None, **k
settings.optimize = override_opt_level or optimize
out = compiler.compile_code(
source_code,
# test that metadata gets generated
["abi", "bytecode", "metadata"],
# test that metadata and natspecs get generated
["abi", "bytecode", "metadata", "userdoc", "devdoc"],
settings=settings,
interface_codes=kwargs.pop("interface_codes", None),
show_gas_estimates=True, # Enable gas estimates for testing
Expand Down
4 changes: 2 additions & 2 deletions tests/builtins/folding/test_abs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(a=st.integers(min_value=-(2**255) + 1, max_value=2**255 - 1))
@example(a=0)
def test_abs(get_contract, a):
Expand All @@ -27,7 +27,7 @@ def foo(a: int256) -> int256:


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(a=st.integers(min_value=2**255, max_value=2**256 - 1))
def test_abs_upper_bound_folding(get_contract, a):
source = f"""
Expand Down
2 changes: 1 addition & 1 deletion tests/builtins/folding/test_addmod_mulmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(a=st_uint256, b=st_uint256, c=st_uint256)
@pytest.mark.parametrize("fn_name", ["uint256_addmod", "uint256_mulmod"])
def test_modmath(get_contract, a, b, c, fn_name):
Expand Down
8 changes: 4 additions & 4 deletions tests/builtins/folding/test_bitwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@pytest.mark.parametrize("op", ["&", "|", "^"])
@given(a=st_uint256, b=st_uint256)
def test_bitwise_ops(get_contract, a, b, op):
Expand All @@ -34,7 +34,7 @@ def foo(a: uint256, b: uint256) -> uint256:


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@pytest.mark.parametrize("op", ["<<", ">>"])
@given(a=st_uint256, b=st.integers(min_value=0, max_value=256))
def test_bitwise_shift_unsigned(get_contract, a, b, op):
Expand Down Expand Up @@ -64,7 +64,7 @@ def foo(a: uint256, b: uint256) -> uint256:


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@pytest.mark.parametrize("op", ["<<", ">>"])
@given(a=st_sint256, b=st.integers(min_value=0, max_value=256))
def test_bitwise_shift_signed(get_contract, a, b, op):
Expand Down Expand Up @@ -92,7 +92,7 @@ def foo(a: int256, b: uint256) -> int256:


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(value=st_uint256)
def test_bitwise_not(get_contract, value):
source = """
Expand Down
2 changes: 1 addition & 1 deletion tests/builtins/folding/test_floor_ceil.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(value=st_decimals)
@example(value=Decimal("0.9999999999"))
@example(value=Decimal("0.0000000001"))
Expand Down
4 changes: 2 additions & 2 deletions tests/builtins/folding/test_fold_as_wei_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


@pytest.mark.fuzzing
@settings(max_examples=10, deadline=1000)
@settings(max_examples=10)
@given(value=st_decimals)
@pytest.mark.parametrize("denom", denoms)
def test_decimal(get_contract, value, denom):
Expand All @@ -38,7 +38,7 @@ def foo(a: decimal) -> uint256:


@pytest.mark.fuzzing
@settings(max_examples=10, deadline=1000)
@settings(max_examples=10)
@given(value=st.integers(min_value=0, max_value=2**128))
@pytest.mark.parametrize("denom", denoms)
def test_integer(get_contract, value, denom):
Expand Down
6 changes: 3 additions & 3 deletions tests/builtins/folding/test_keccak_sha.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@pytest.mark.fuzzing
@given(value=st.text(alphabet=alphabet, min_size=0, max_size=100))
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@pytest.mark.parametrize("fn_name", ["keccak256", "sha256"])
def test_string(get_contract, value, fn_name):
source = f"""
Expand All @@ -29,7 +29,7 @@ def foo(a: String[100]) -> bytes32:

@pytest.mark.fuzzing
@given(value=st.binary(min_size=0, max_size=100))
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@pytest.mark.parametrize("fn_name", ["keccak256", "sha256"])
def test_bytes(get_contract, value, fn_name):
source = f"""
Expand All @@ -48,7 +48,7 @@ def foo(a: Bytes[100]) -> bytes32:

@pytest.mark.fuzzing
@given(value=st.binary(min_size=1, max_size=100))
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@pytest.mark.parametrize("fn_name", ["keccak256", "sha256"])
def test_hex(get_contract, value, fn_name):
source = f"""
Expand Down
6 changes: 3 additions & 3 deletions tests/builtins/folding/test_min_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(left=st_decimals, right=st_decimals)
@pytest.mark.parametrize("fn_name", ["min", "max"])
def test_decimal(get_contract, left, right, fn_name):
Expand All @@ -37,7 +37,7 @@ def foo(a: decimal, b: decimal) -> decimal:


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(left=st_int128, right=st_int128)
@pytest.mark.parametrize("fn_name", ["min", "max"])
def test_int128(get_contract, left, right, fn_name):
Expand All @@ -56,7 +56,7 @@ def foo(a: int128, b: int128) -> int128:


@pytest.mark.fuzzing
@settings(max_examples=50, deadline=1000)
@settings(max_examples=50)
@given(left=st_uint256, right=st_uint256)
@pytest.mark.parametrize("fn_name", ["min", "max"])
def test_min_uint256(get_contract, left, right, fn_name):
Expand Down
2 changes: 1 addition & 1 deletion tests/builtins/folding/test_powmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.mark.fuzzing
@settings(max_examples=100, deadline=1000)
@settings(max_examples=100)
@given(a=st_uint256, b=st_uint256)
def test_powmod_uint256(get_contract, a, b):
source = """
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from functools import wraps

import hypothesis
import pytest
from eth_tester import EthereumTester, PyEVMBackend
from eth_utils import setup_DEBUG2_logging
Expand All @@ -23,6 +24,11 @@
############


# disable hypothesis deadline globally
hypothesis.settings.register_profile("ci", deadline=None)
hypothesis.settings.load_profile("ci")


def set_evm_verbose_logging():
logger = logging.getLogger("eth.vm.computation.Computation")
setup_DEBUG2_logging()
Expand Down
4 changes: 2 additions & 2 deletions tests/fuzzing/test_exponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def foo(a: int16) -> int16:
@example(a=2**127 - 1)
# 256 bits
@example(a=2**256 - 1)
@settings(max_examples=200, deadline=1000)
@settings(max_examples=200)
def test_max_exp(get_contract, assert_tx_failed, a):
code = f"""
@external
Expand Down Expand Up @@ -127,7 +127,7 @@ def foo(b: uint256) -> uint256:
@example(a=2**63 - 1)
# 128 bits
@example(a=2**127 - 1)
@settings(max_examples=200, deadline=1000)
@settings(max_examples=200)
def test_max_exp_int128(get_contract, assert_tx_failed, a):
code = f"""
@external
Expand Down
Loading

0 comments on commit af43e56

Please sign in to comment.