Skip to content

Commit

Permalink
Merge branch 'master' into fix/security-policy
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Apr 30, 2024
2 parents 24adb16 + 04cadaa commit 2b94958
Show file tree
Hide file tree
Showing 32 changed files with 1,053 additions and 208 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ jobs:
tests/
- name: Upload Coverage
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
tests/
- name: Upload Coverage
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
Expand Down
4 changes: 1 addition & 3 deletions tests/functional/builtins/codegen/test_abi_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from eth.codecs import abi

from tests.utils import decimal_to_int
from vyper.exceptions import ArgumentException, StackTooDeep, StructureException
from vyper.exceptions import ArgumentException, StructureException

TEST_ADDR = "0x" + b"".join(chr(i).encode("utf-8") for i in range(20)).hex()

Expand Down Expand Up @@ -201,7 +201,6 @@ def abi_decode(x: Bytes[{len}]) -> DynArray[DynArray[uint256, 3], 3]:

@pytest.mark.parametrize("args", nested_3d_array_args)
@pytest.mark.parametrize("unwrap_tuple", (True, False))
@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_abi_decode_nested_dynarray2(get_contract, args, unwrap_tuple):
if unwrap_tuple is True:
encoded = abi.encode("(uint256[][][])", (args,))
Expand Down Expand Up @@ -279,7 +278,6 @@ def foo(bs: Bytes[160]) -> (uint256, DynArray[uint256, 3]):
assert c.foo(encoded) == [2**256 - 1, bs]


@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_abi_decode_private_nested_dynarray(get_contract):
code = """
bytez: DynArray[DynArray[DynArray[uint256, 3], 3], 3]
Expand Down
3 changes: 0 additions & 3 deletions tests/functional/builtins/codegen/test_abi_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from eth.codecs import abi

from tests.utils import decimal_to_int
from vyper.exceptions import StackTooDeep


# @pytest.mark.parametrize("string", ["a", "abc", "abcde", "potato"])
Expand Down Expand Up @@ -227,7 +226,6 @@ def abi_encode(


@pytest.mark.parametrize("args", nested_3d_array_args)
@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_abi_encode_nested_dynarray_2(get_contract, args):
code = """
@external
Expand Down Expand Up @@ -332,7 +330,6 @@ def foo(bs: DynArray[uint256, 3]) -> (uint256, Bytes[160]):
assert c.foo(bs) == [2**256 - 1, abi.encode("(uint256[])", (bs,))]


@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_abi_encode_private_nested_dynarray(get_contract):
code = """
bytez: Bytes[1696]
Expand Down
55 changes: 49 additions & 6 deletions tests/functional/codegen/features/iteration/test_for_range.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest

from vyper.exceptions import StaticAssertionException
from vyper.utils import SizeLimits


def test_basic_repeater(get_contract_with_gas_estimation):
basic_repeater = """
Expand Down Expand Up @@ -271,17 +274,38 @@ def test():


@pytest.mark.parametrize("typ", ["uint8", "int128", "uint256"])
def test_for_range_oob_check(get_contract, tx_failed, typ):
def test_for_range_oob_compile_time_check(get_contract, tx_failed, typ, experimental_codegen):
code = f"""
@external
def test():
x: {typ} = max_value({typ})
for i: {typ} in range(x, x + 2, bound=2):
pass
"""
if not experimental_codegen:
return
with pytest.raises(StaticAssertionException):
get_contract(code)


@pytest.mark.parametrize(
"typ, max_value",
[
("uint8", SizeLimits.MAX_UINT8),
("int128", SizeLimits.MAX_INT128),
("uint256", SizeLimits.MAX_UINT256),
],
)
def test_for_range_oob_runtime_check(get_contract, tx_failed, typ, max_value):
code = f"""
@external
def test(x: {typ}):
for i: {typ} in range(x, x + 2, bound=2):
pass
"""
c = get_contract(code)
with tx_failed():
c.test()
c.test(max_value)


@pytest.mark.parametrize("typ", ["int128", "uint256"])
Expand Down Expand Up @@ -416,7 +440,25 @@ def foo(a: {typ}) -> {typ}:
assert c.foo(0) == 31337


def test_for_range_signed_int_overflow(get_contract, tx_failed):
def test_for_range_signed_int_overflow_runtime_check(get_contract, tx_failed, experimental_codegen):
code = """
@external
def foo(_min:int256, _max: int256) -> DynArray[int256, 10]:
res: DynArray[int256, 10] = empty(DynArray[int256, 10])
x:int256 = _max
y:int256 = _min+2
for i:int256 in range(x,y , bound=10):
res.append(i)
return res
"""
c = get_contract(code)
with tx_failed():
c.foo(SizeLimits.MIN_INT256, SizeLimits.MAX_INT256)


def test_for_range_signed_int_overflow_compile_time_check(
get_contract, tx_failed, experimental_codegen
):
code = """
@external
def foo() -> DynArray[int256, 10]:
Expand All @@ -427,6 +469,7 @@ def foo() -> DynArray[int256, 10]:
res.append(i)
return res
"""
c = get_contract(code)
with tx_failed():
c.foo()
if not experimental_codegen:
return
with pytest.raises(StaticAssertionException):
get_contract(code)
4 changes: 0 additions & 4 deletions tests/functional/codegen/features/test_constructor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pytest
from web3.exceptions import ValidationError

from vyper.exceptions import StackTooDeep


def test_init_argument_test(get_contract_with_gas_estimation):
init_argument_test = """
Expand Down Expand Up @@ -165,7 +163,6 @@ def get_foo() -> uint256:
assert c.get_foo() == 39


@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_nested_dynamic_array_constructor_arg_2(w3, get_contract_with_gas_estimation):
code = """
foo: int128
Expand Down Expand Up @@ -211,7 +208,6 @@ def get_foo() -> DynArray[DynArray[uint256, 3], 3]:
assert c.get_foo() == [[37, 41, 73], [37041, 41073, 73037], [146, 123, 148]]


@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_initialise_nested_dynamic_array_2(w3, get_contract_with_gas_estimation):
code = """
foo: DynArray[DynArray[DynArray[int128, 3], 3], 3]
Expand Down
2 changes: 0 additions & 2 deletions tests/functional/codegen/features/test_immutable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest

from vyper.compiler.settings import OptimizationLevel
from vyper.exceptions import StackTooDeep


@pytest.mark.parametrize(
Expand Down Expand Up @@ -199,7 +198,6 @@ def get_idx_two() -> uint256:
assert c.get_idx_two() == expected_values[2][2]


@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_nested_dynarray_immutable(get_contract):
code = """
my_list: immutable(DynArray[DynArray[DynArray[int128, 3], 3], 3])
Expand Down
26 changes: 22 additions & 4 deletions tests/functional/codegen/types/numbers/test_signed_ints.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from vyper.exceptions import (
InvalidOperation,
OverflowException,
StaticAssertionException,
TypeMismatch,
ZeroDivisionException,
)
Expand Down Expand Up @@ -73,18 +74,35 @@ def foo(x: int256) -> int256:

# TODO: make this test pass
@pytest.mark.parametrize("base", (0, 1))
def test_exponent_negative_power(get_contract, tx_failed, base):
def test_exponent_negative_power_runtime_check(get_contract, tx_failed, base, experimental_codegen):
# #2985
code = f"""
@external
def bar() -> int16:
x: int16 = -2
def bar(negative:int16) -> int16:
x: int16 = negative
return {base} ** x
"""
c = get_contract(code)
# known bug: 2985
with tx_failed():
c.bar()
c.bar(-2)


@pytest.mark.parametrize("base", (0, 1))
def test_exponent_negative_power_compile_time_check(
get_contract, tx_failed, base, experimental_codegen
):
# #2985
code = f"""
@external
def bar() -> int16:
x: int16 = -2
return {base} ** x
"""
if not experimental_codegen:
return
with pytest.raises(StaticAssertionException):
get_contract(code)


def test_exponent_min_int16(get_contract):
Expand Down
7 changes: 1 addition & 6 deletions tests/functional/codegen/types/test_dynamic_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def loo(x: DynArray[DynArray[int128, 2], 2]) -> int128:
print("Passed list tests")


@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_string_list(get_contract):
code = """
@external
Expand Down Expand Up @@ -1491,7 +1490,6 @@ def foo(x: int128) -> int128:
assert c.foo(7) == 392


@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_struct_of_lists(get_contract):
code = """
struct Foo:
Expand Down Expand Up @@ -1580,7 +1578,6 @@ def bar(x: int128) -> DynArray[int128, 3]:
assert c.bar(7) == [7, 14]


@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_nested_struct_of_lists(get_contract, assert_compile_failed, optimize):
code = """
struct nestedFoo:
Expand Down Expand Up @@ -1710,9 +1707,7 @@ def __init__():
("DynArray[DynArray[DynArray[uint256, 5], 5], 5]", [[[], []], []]),
],
)
def test_empty_nested_dynarray(get_contract, typ, val, venom_xfail):
if val == [[[], []], []]:
venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_empty_nested_dynarray(get_contract, typ, val):
code = f"""
@external
def foo() -> {typ}:
Expand Down
Loading

0 comments on commit 2b94958

Please sign in to comment.