Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add warnings tests #57

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import random

import pytest

import vyper


@pytest.fixture
def huge_bytestring():
r = random.Random(b"vyper")

return bytes([r.getrandbits(8) for _ in range(0x6001)])


def test_contract_size_exceeded(huge_bytestring):
code = f"""
@external
def a() -> bool:
q: Bytes[24577] = {huge_bytestring}
return True
"""
with pytest.warns(vyper.warnings.ContractSizeLimit):
vyper.compile_code(code, output_formats=["bytecode_runtime"])
50 changes: 50 additions & 0 deletions tests/functional/syntax/warnings/test_deprecation_warning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import json

import pytest

import vyper
from vyper.cli.vyper_json import compile_json

deprecated = [
"""
struct Foo:
a: uint256
b: uint256

@external
def foo():
f: Foo = Foo({a: 128, b: 256})
""",
"""
event Foo:
a: uint256
b: uint256

@external
def foo():
log Foo({a: 128, b: 256})
""",
]


@pytest.mark.parametrize("code", deprecated)
def test_deprecated_warning(code):
with pytest.warns(vyper.warnings.Deprecation):
vyper.compile_code(code)


def test_deprecated_optimize_boolean_flag():
code = """
@external
def foo():
pass
"""

input_json = {
"language": "Vyper",
"sources": {"contracts/foo.vy": {"content": code}},
"settings": {"outputSelection": {"*": ["*"]}, "optimize": True},
}

with pytest.warns(vyper.warnings.Deprecation):
compile_json(json.dumps(input_json))
18 changes: 18 additions & 0 deletions tests/functional/syntax/warnings/test_enum_usage_warning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest

import vyper


def test_enum_usage_warning():
code = """
enum Foo:
Fe
Fi
Fo

@external
def foo() -> Foo:
return Foo.Fe
"""
with pytest.warns(vyper.warnings.EnumUsage):
vyper.compile_code(code)
22 changes: 0 additions & 22 deletions tests/unit/compiler/test_compile_code.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
import random

import pytest

import vyper


@pytest.fixture
def huge_bytestring():
r = random.Random(b"vyper")

return bytes([r.getrandbits(8) for _ in range(0x6001)])


def test_contract_size_exceeded(huge_bytestring):
code = f"""
@external
def a() -> bool:
q: Bytes[24577] = {huge_bytestring}
return True
"""
with pytest.warns(vyper.warnings.ContractSizeLimit):
vyper.compile_code(code, output_formats=["bytecode_runtime"])


# test that each compilation run gets a fresh analysis and storage allocator
def test_shared_modules_allocation(make_input_bundle):
lib1 = """
Expand Down
Loading