forked from vyperlang/vyper
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from tserg/tests/warnings
add warnings tests
- Loading branch information
Showing
4 changed files
with
91 additions
and
22 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
tests/functional/syntax/warnings/test_contract_size_limit_warning.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
50
tests/functional/syntax/warnings/test_deprecation_warning.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
tests/functional/syntax/warnings/test_enum_usage_warning.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters