Skip to content

Commit

Permalink
Merge pull request #57 from tserg/tests/warnings
Browse files Browse the repository at this point in the history
add warnings tests
  • Loading branch information
charles-cooper authored Jan 21, 2025
2 parents 0f17464 + 2dda7f1 commit 49e8522
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 22 deletions.
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

0 comments on commit 49e8522

Please sign in to comment.