Skip to content

Commit

Permalink
Merge branch 'refactor/folding_alt2' into refactor/no_folding
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Dec 27, 2023
2 parents 7134cc2 + 3736bf5 commit dd2522d
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 54 deletions.
4 changes: 2 additions & 2 deletions tests/functional/syntax/exceptions/test_argument_exception.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import ArgumentException

fail_list = [
Expand Down Expand Up @@ -95,4 +95,4 @@ def foo():
@pytest.mark.parametrize("bad_code", fail_list)
def test_function_declaration_exception(bad_code):
with pytest.raises(ArgumentException):
compiler.compile_code(bad_code)
compile_code(bad_code)
13 changes: 9 additions & 4 deletions tests/functional/syntax/test_abs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import InvalidType

fail_list = [
Expand All @@ -18,18 +18,23 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_abs_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)
def test_abs_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
"""
FOO: constant(int256) = -3
BAR: constant(int256) = abs(FOO)
@external
def foo():
a: int256 = BAR
"""
]


@pytest.mark.parametrize("code", valid_list)
def test_abs_pass(code):
assert compiler.compile_code(code) is not None
assert compile_code(code) is not None
4 changes: 2 additions & 2 deletions tests/functional/syntax/test_addmulmod.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import InvalidType

fail_list = [
Expand Down Expand Up @@ -46,4 +46,4 @@ def test_add_mod_fail(assert_compile_failed, get_contract, code, exc):

@pytest.mark.parametrize("code", valid_list)
def test_addmulmod_pass(code):
assert compiler.compile_code(code) is not None
assert compile_code(code) is not None
10 changes: 8 additions & 2 deletions tests/functional/syntax/test_as_wei_value.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

from vyper import compile_code
from vyper.exceptions import (
ArgumentException,
InvalidLiteral,
Expand Down Expand Up @@ -84,8 +85,9 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_as_wei_fail(get_contract_with_gas_estimation, bad_code, exc, assert_compile_failed):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)
def test_as_wei_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
Expand Down Expand Up @@ -114,6 +116,10 @@ def foo() -> uint256:
"""
y: constant(String[5]) = "szabo"
x: constant(uint256) = as_wei_value(5, y)
@external
def foo():
a: uint256 = x
""",
]

Expand Down
3 changes: 2 additions & 1 deletion tests/functional/syntax/test_ceil.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest

from vyper.compiler import compile_code
from vyper import compile_code

valid_list = [
"""
BAR: constant(decimal) = 2.5
FOO: constant(int256) = ceil(BAR)
@external
def foo():
a: int256 = FOO
Expand Down
9 changes: 5 additions & 4 deletions tests/functional/syntax/test_dynamic_array.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import StructureException

fail_list = [
Expand Down Expand Up @@ -36,8 +36,9 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_block_fail(assert_compile_failed, get_contract, bad_code, exc):
assert_compile_failed(lambda: get_contract(bad_code), exc)
def test_block_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
Expand All @@ -56,4 +57,4 @@ def test_block_fail(assert_compile_failed, get_contract, bad_code, exc):

@pytest.mark.parametrize("good_code", valid_list)
def test_dynarray_pass(good_code):
assert compiler.compile_code(good_code) is not None
assert compile_code(good_code) is not None
15 changes: 10 additions & 5 deletions tests/functional/syntax/test_epsilon.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import pytest

from vyper import compile_code
from vyper.exceptions import InvalidType

fail_list = [
"""
(
"""
FOO: constant(address) = epsilon(address)
"""
""",
InvalidType,
)
]


@pytest.mark.parametrize("bad_code", fail_list)
def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), InvalidType)
@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_block_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)
3 changes: 2 additions & 1 deletion tests/functional/syntax/test_floor.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pytest

from vyper.compiler import compile_code
from vyper import compile_code

valid_list = [
"""
BAR: constant(decimal) = 2.5
FOO: constant(int256) = floor(BAR)
@external
def foo():
a: int256 = FOO
Expand Down
14 changes: 7 additions & 7 deletions tests/functional/syntax/test_len.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
from pytest import raises

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import TypeMismatch

fail_list = [
Expand All @@ -21,11 +20,11 @@ def foo(inp: int128) -> uint256:
@pytest.mark.parametrize("bad_code", fail_list)
def test_block_fail(bad_code):
if isinstance(bad_code, tuple):
with raises(bad_code[1]):
compiler.compile_code(bad_code[0])
with pytest.raises(bad_code[1]):
compile_code(bad_code[0])
else:
with raises(TypeMismatch):
compiler.compile_code(bad_code)
with pytest.raises(TypeMismatch):
compile_code(bad_code)


valid_list = [
Expand All @@ -42,6 +41,7 @@ def foo(inp: String[10]) -> uint256:
"""
BAR: constant(String[5]) = "vyper"
FOO: constant(uint256) = len(BAR)
@external
def foo() -> uint256:
a: uint256 = FOO
Expand All @@ -52,4 +52,4 @@ def foo() -> uint256:

@pytest.mark.parametrize("good_code", valid_list)
def test_list_success(good_code):
assert compiler.compile_code(good_code) is not None
assert compile_code(good_code) is not None
9 changes: 5 additions & 4 deletions tests/functional/syntax/test_method_id.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import InvalidLiteral, InvalidType

fail_list = [
Expand Down Expand Up @@ -28,8 +28,9 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_method_id_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)
def test_method_id_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
Expand All @@ -46,4 +47,4 @@ def foo(a: Bytes[4] = BAR):

@pytest.mark.parametrize("code", valid_list)
def test_method_id_pass(code):
assert compiler.compile_code(code) is not None
assert compile_code(code) is not None
17 changes: 13 additions & 4 deletions tests/functional/syntax/test_minmax.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import InvalidType, OverflowException, TypeMismatch

fail_list = [
Expand Down Expand Up @@ -32,24 +32,33 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)
def test_block_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
"""
FOO: constant(uint256) = 123
BAR: constant(uint256) = 456
BAZ: constant(uint256) = min(FOO, BAR)
@external
def foo():
a: uint256 = BAZ
""",
"""
FOO: constant(uint256) = 123
BAR: constant(uint256) = 456
BAZ: constant(uint256) = max(FOO, BAR)
@external
def foo():
a: uint256 = BAZ
""",
]


@pytest.mark.parametrize("good_code", valid_list)
def test_block_success(good_code):
assert compiler.compile_code(good_code) is not None
assert compile_code(good_code) is not None
27 changes: 21 additions & 6 deletions tests/functional/syntax/test_minmax_value.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
import pytest

from vyper import compile_code
from vyper.exceptions import InvalidType

fail_list = [
"""
(
"""
@external
def foo():
a: address = min_value(address)
""",
"""
InvalidType,
),
(
"""
@external
def foo():
a: address = max_value(address)
""",
"""
InvalidType,
),
(
"""
FOO: constant(address) = min_value(address)
@external
def foo():
a: address = FOO
""",
InvalidType,
),
]


@pytest.mark.parametrize("bad_code", fail_list)
def test_block_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), InvalidType)
@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_block_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)
13 changes: 9 additions & 4 deletions tests/functional/syntax/test_powmod.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import InvalidType

fail_list = [
Expand All @@ -16,19 +16,24 @@ def foo():


@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_powmod_fail(assert_compile_failed, get_contract_with_gas_estimation, bad_code, exc):
assert_compile_failed(lambda: get_contract_with_gas_estimation(bad_code), exc)
def test_powmod_fail(bad_code, exc):
with pytest.raises(exc):
compile_code(bad_code)


valid_list = [
"""
FOO: constant(uint256) = 3
BAR: constant(uint256) = 5
BAZ: constant(uint256) = pow_mod256(FOO, BAR)
@external
def foo():
a: uint256 = BAZ
"""
]


@pytest.mark.parametrize("code", valid_list)
def test_powmod_pass(code):
assert compiler.compile_code(code) is not None
assert compile_code(code) is not None
6 changes: 3 additions & 3 deletions tests/functional/syntax/test_raw_call.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper import compiler
from vyper import compile_code
from vyper.exceptions import ArgumentException, InvalidType, SyntaxException, TypeMismatch

fail_list = [
Expand Down Expand Up @@ -39,7 +39,7 @@ def foo():
@pytest.mark.parametrize("bad_code,exc", fail_list)
def test_raw_call_fail(bad_code, exc):
with pytest.raises(exc):
compiler.compile_code(bad_code)
compile_code(bad_code)


valid_list = [
Expand Down Expand Up @@ -109,4 +109,4 @@ def foo():

@pytest.mark.parametrize("good_code", valid_list)
def test_raw_call_success(good_code):
assert compiler.compile_code(good_code) is not None
assert compile_code(good_code) is not None
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_ternary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from vyper.compiler import compile_code
from vyper import compile_code
from vyper.exceptions import InvalidType, TypeMismatch

good_list = [
Expand Down
Loading

0 comments on commit dd2522d

Please sign in to comment.