forked from vyperlang/vyper
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/extcall_range
- Loading branch information
Showing
54 changed files
with
1,205 additions
and
223 deletions.
There are no files selected for viewing
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
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
66 changes: 66 additions & 0 deletions
66
tests/functional/codegen/calling_convention/test_inlineable_functions.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,66 @@ | ||
""" | ||
Test functionality of internal functions which may be inlined | ||
""" | ||
# note for refactor: this may be able to be merged with | ||
# calling_convention/test_internal_call.py | ||
|
||
|
||
def test_call_in_call(get_contract): | ||
code = """ | ||
@internal | ||
def _foo(a: uint256,) -> uint256: | ||
return 1 + a | ||
@internal | ||
def _foo2() -> uint256: | ||
return 4 | ||
@external | ||
def foo() -> uint256: | ||
return self._foo(self._foo2()) | ||
""" | ||
|
||
c = get_contract(code) | ||
assert c.foo() == 5 | ||
|
||
|
||
def test_call_in_call_with_raise(get_contract, tx_failed): | ||
code = """ | ||
@internal | ||
def sum(a: uint256) -> uint256: | ||
if a > 1: | ||
return a + 1 | ||
raise | ||
@internal | ||
def middle(a: uint256) -> uint256: | ||
return self.sum(a) | ||
@external | ||
def test(a: uint256) -> uint256: | ||
return self.middle(a) | ||
""" | ||
|
||
c = get_contract(code) | ||
|
||
assert c.test(2) == 3 | ||
|
||
with tx_failed(): | ||
c.test(0) | ||
|
||
|
||
def test_inliner_with_unused_param(get_contract): | ||
code = """ | ||
data: public(uint256) | ||
@internal | ||
def _foo(start: uint256, length: uint256): | ||
self.data = start | ||
@external | ||
def foo(x: uint256, y: uint256): | ||
self._foo(x, y) | ||
""" | ||
|
||
c = get_contract(code) | ||
c.foo(1, 2) |
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
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
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
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)) |
Oops, something went wrong.