Skip to content

Commit

Permalink
Merge branch 'master' into feat/mem-dealloc
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper authored Oct 16, 2024
2 parents 5d82615 + 039d369 commit c9fbfac
Show file tree
Hide file tree
Showing 26 changed files with 588 additions and 450 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: Bug Report
about: Any general feedback or bug reports about the Vyper Compiler. No new features proposals.
labels: ["needs triage"]
---

### Version Information
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/vip.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
name: Vyper Improvement Proposal (VIP)
about: This is the suggested template for new VIPs.
labels: ["needs triage"]
---
## Simple Summary
"If you can't explain it simply, you don't understand it well enough." Provide a simplified and layman-accessible explanation of the VIP.
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:
# need to fetch unshallow so that setuptools_scm can infer the version
fetch-depth: 0

# debug
- name: Git shorthash
run: git rev-parse --short HEAD

- name: Python
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -60,6 +64,10 @@ jobs:
# need to fetch unshallow so that setuptools_scm can infer the version
fetch-depth: 0

# debug
- name: Git shorthash
run: git rev-parse --short HEAD

- name: Python
uses: actions/setup-python@v5
with:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/release-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
# fetch unshallow so commit hash matches github release.
# see https://github.com/vyperlang/vyper/blob/8f9a8cac49aafb3fbc9dde78f0f6125c390c32f0/.github/workflows/build.yml#L27-L32
fetch-depth: 0

# debug
- name: Git shorthash
run: git rev-parse --short HEAD

- name: Python
uses: actions/setup-python@v5
Expand Down
8 changes: 1 addition & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from tests.utils import working_directory
from vyper import compiler
from vyper.codegen.ir_node import IRnode
from vyper.compiler.input_bundle import FilesystemInputBundle, InputBundle
from vyper.compiler.input_bundle import FilesystemInputBundle
from vyper.compiler.settings import OptimizationLevel, Settings, set_global_settings
from vyper.exceptions import EvmVersionException
from vyper.ir import compile_ir, optimizer
Expand Down Expand Up @@ -166,12 +166,6 @@ def fn(sources_dict):
return fn


# for tests which just need an input bundle, doesn't matter what it is
@pytest.fixture
def dummy_input_bundle():
return InputBundle([])


@pytest.fixture(scope="module")
def gas_limit():
# set absurdly high gas limit so that london basefee never adjusts
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/codegen/features/test_clampers.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def foo(b: int128[6][1][2]) -> int128[6][1][2]:

c = get_contract(code)
with tx_failed():
_make_tx(env, c.address, "foo(int128[6][1][2]])", values)
_make_tx(env, c.address, "foo(int128[6][1][2])", values)


@pytest.mark.parametrize("value", [0, 1, -1, 2**127 - 1, -(2**127)])
Expand All @@ -453,7 +453,7 @@ def test_int128_dynarray_clamper_failing(env, tx_failed, get_contract, bad_value
# ensure the invalid value is detected at all locations in the array
code = """
@external
def foo(b: int128[5]) -> int128[5]:
def foo(b: DynArray[int128, 5]) -> DynArray[int128, 5]:
return b
"""

Expand Down
28 changes: 28 additions & 0 deletions tests/functional/codegen/modules/test_interface_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,31 @@ def foo() -> bool:
c = get_contract(main, input_bundle=input_bundle)

assert c.foo() is True


def test_import_interface_flags(make_input_bundle, get_contract):
ifaces = """
flag Foo:
BOO
MOO
POO
interface IFoo:
def foo() -> Foo: nonpayable
"""

contract = """
import ifaces
implements: ifaces
@external
def foo() -> ifaces.Foo:
return ifaces.Foo.POO
"""

input_bundle = make_input_bundle({"ifaces.vyi": ifaces})

c = get_contract(contract, input_bundle=input_bundle)

assert c.foo() == 4
2 changes: 1 addition & 1 deletion tests/functional/codegen/types/numbers/test_decimals.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def foo():
compile_code(code)


def test_replace_decimal_nested_intermediate_underflow(dummy_input_bundle):
def test_replace_decimal_nested_intermediate_underflow():
code = """
@external
def foo():
Expand Down
13 changes: 11 additions & 2 deletions tests/functional/syntax/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,22 @@ def test_interfaces_success(good_code):


def test_imports_and_implements_within_interface(make_input_bundle):
interface_code = """
ibar_code = """
@external
def foobar():
...
"""
ifoo_code = """
import bar
input_bundle = make_input_bundle({"foo.vyi": interface_code})
implements: bar
@external
def foobar():
...
"""

input_bundle = make_input_bundle({"foo.vyi": ifoo_code, "bar.vyi": ibar_code})

code = """
import foo as Foo
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/ast/nodes/test_hex.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def foo():


@pytest.mark.parametrize("code", code_invalid_checksum)
def test_invalid_checksum(code, dummy_input_bundle):
def test_invalid_checksum(code):
with pytest.raises(InvalidLiteral):
vyper_module = vy_ast.parse_to_ast(code)
semantics.analyze_module(vyper_module, dummy_input_bundle)
semantics.analyze_module(vyper_module)
24 changes: 24 additions & 0 deletions tests/unit/cli/vyper_json/test_compile_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,27 @@ def test_relative_import_paths(input_json):
input_json["sources"]["contracts/potato/baz/potato.vy"] = {"content": "from . import baz"}
input_json["sources"]["contracts/potato/footato.vy"] = {"content": "from baz import baz"}
compile_from_input_dict(input_json)


def test_compile_json_with_abi_top(make_input_bundle):
stream = """
{
"abi": [
{
"name": "validate",
"inputs": [
{ "name": "creator", "type": "address" },
{ "name": "token", "type": "address" },
{ "name": "amount_per_second", "type": "uint256" },
{ "name": "reason", "type": "bytes" }
],
"outputs": [{ "name": "max_stream_life", "type": "uint256" }]
}
]
}
"""
code = """
from . import stream
"""
input_bundle = make_input_bundle({"stream.json": stream, "code.vy": code})
vyper.compiler.compile_code(code, input_bundle=input_bundle)
20 changes: 10 additions & 10 deletions tests/unit/semantics/analysis/test_array_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@pytest.mark.parametrize("value", ["address", "Bytes[10]", "decimal", "bool"])
def test_type_mismatch(namespace, value, dummy_input_bundle):
def test_type_mismatch(namespace, value):
code = f"""
a: uint256[3]
Expand All @@ -22,11 +22,11 @@ def foo(b: {value}):
"""
vyper_module = parse_to_ast(code)
with pytest.raises(TypeMismatch):
analyze_module(vyper_module, dummy_input_bundle)
analyze_module(vyper_module)


@pytest.mark.parametrize("value", ["1.0", "0.0", "'foo'", "0x00", "b'\x01'", "False"])
def test_invalid_literal(namespace, value, dummy_input_bundle):
def test_invalid_literal(namespace, value):
code = f"""
a: uint256[3]
Expand All @@ -37,11 +37,11 @@ def foo():
"""
vyper_module = parse_to_ast(code)
with pytest.raises(TypeMismatch):
analyze_module(vyper_module, dummy_input_bundle)
analyze_module(vyper_module)


@pytest.mark.parametrize("value", [-1, 3, -(2**127), 2**127 - 1, 2**256 - 1])
def test_out_of_bounds(namespace, value, dummy_input_bundle):
def test_out_of_bounds(namespace, value):
code = f"""
a: uint256[3]
Expand All @@ -52,11 +52,11 @@ def foo():
"""
vyper_module = parse_to_ast(code)
with pytest.raises(ArrayIndexException):
analyze_module(vyper_module, dummy_input_bundle)
analyze_module(vyper_module)


@pytest.mark.parametrize("value", ["b", "self.b"])
def test_undeclared_definition(namespace, value, dummy_input_bundle):
def test_undeclared_definition(namespace, value):
code = f"""
a: uint256[3]
Expand All @@ -67,11 +67,11 @@ def foo():
"""
vyper_module = parse_to_ast(code)
with pytest.raises(UndeclaredDefinition):
analyze_module(vyper_module, dummy_input_bundle)
analyze_module(vyper_module)


@pytest.mark.parametrize("value", ["a", "foo", "int128"])
def test_invalid_reference(namespace, value, dummy_input_bundle):
def test_invalid_reference(namespace, value):
code = f"""
a: uint256[3]
Expand All @@ -82,4 +82,4 @@ def foo():
"""
vyper_module = parse_to_ast(code)
with pytest.raises(InvalidReference):
analyze_module(vyper_module, dummy_input_bundle)
analyze_module(vyper_module)
24 changes: 12 additions & 12 deletions tests/unit/semantics/analysis/test_cyclic_function_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
from vyper.semantics.analysis import analyze_module


def test_self_function_call(dummy_input_bundle):
def test_self_function_call():
code = """
@internal
def foo():
self.foo()
"""
vyper_module = parse_to_ast(code)
with pytest.raises(CallViolation) as e:
analyze_module(vyper_module, dummy_input_bundle)
analyze_module(vyper_module)

assert e.value.message == "Contract contains cyclic function call: foo -> foo"


def test_self_function_call2(dummy_input_bundle):
def test_self_function_call2():
code = """
@external
def foo():
Expand All @@ -30,12 +30,12 @@ def bar():
"""
vyper_module = parse_to_ast(code)
with pytest.raises(CallViolation) as e:
analyze_module(vyper_module, dummy_input_bundle)
analyze_module(vyper_module)

assert e.value.message == "Contract contains cyclic function call: foo -> bar -> bar"


def test_cyclic_function_call(dummy_input_bundle):
def test_cyclic_function_call():
code = """
@internal
def foo():
Expand All @@ -47,12 +47,12 @@ def bar():
"""
vyper_module = parse_to_ast(code)
with pytest.raises(CallViolation) as e:
analyze_module(vyper_module, dummy_input_bundle)
analyze_module(vyper_module)

assert e.value.message == "Contract contains cyclic function call: foo -> bar -> foo"


def test_multi_cyclic_function_call(dummy_input_bundle):
def test_multi_cyclic_function_call():
code = """
@internal
def foo():
Expand All @@ -72,14 +72,14 @@ def potato():
"""
vyper_module = parse_to_ast(code)
with pytest.raises(CallViolation) as e:
analyze_module(vyper_module, dummy_input_bundle)
analyze_module(vyper_module)

expected_message = "Contract contains cyclic function call: foo -> bar -> baz -> potato -> foo"

assert e.value.message == expected_message


def test_multi_cyclic_function_call2(dummy_input_bundle):
def test_multi_cyclic_function_call2():
code = """
@internal
def foo():
Expand All @@ -99,14 +99,14 @@ def potato():
"""
vyper_module = parse_to_ast(code)
with pytest.raises(CallViolation) as e:
analyze_module(vyper_module, dummy_input_bundle)
analyze_module(vyper_module)

expected_message = "Contract contains cyclic function call: foo -> bar -> baz -> potato -> bar"

assert e.value.message == expected_message


def test_global_ann_assign_callable_no_crash(dummy_input_bundle):
def test_global_ann_assign_callable_no_crash():
code = """
balanceOf: public(HashMap[address, uint256])
Expand All @@ -116,5 +116,5 @@ def foo(to : address):
"""
vyper_module = parse_to_ast(code)
with pytest.raises(StructureException) as excinfo:
analyze_module(vyper_module, dummy_input_bundle)
analyze_module(vyper_module)
assert excinfo.value.message == "HashMap[address, uint256] is not callable"
Loading

0 comments on commit c9fbfac

Please sign in to comment.