Skip to content

Commit

Permalink
fix syntax tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Feb 6, 2024
1 parent ef4686d commit 7a608bd
Show file tree
Hide file tree
Showing 27 changed files with 111 additions and 135 deletions.
22 changes: 0 additions & 22 deletions tests/functional/syntax/exceptions/test_invalid_type_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,12 @@ def test_unknown_type_exception(bad_code, get_contract, assert_compile_failed):


invalid_list = [
"""
@external
def foo():
raw_log(b"cow", b"dog")
""",
"""
@external
def foo():
xs: uint256[1] = []
""",
# Must be a literal string.
"""
@external
def mint(_to: address, _value: uint256):
assert msg.sender == self,msg.sender
""",
# literal longer than event member
"""
event Foo:
message: String[1]
@external
def foo():
log Foo("abcd")
""",
# Raise reason must be string
"""
@external
Expand All @@ -58,10 +40,6 @@ def mint(_to: address, _value: uint256):
# Key of mapping must be a base type
"""
b: HashMap[(int128, decimal), int128]
""",
# Address literal must be checksummed
"""
a: constant(address) = 0x3cd751e6b0078be393132286c442345e5dc49699
""",
"""
x: String <= 33
Expand Down
22 changes: 22 additions & 0 deletions tests/functional/syntax/exceptions/test_type_mismatch_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ def foo():
b: Bytes[1] = b"\x05"
x: uint256 = as_wei_value(b, "babbage")
""",
"""
@external
def foo():
raw_log(b"cow", b"dog")
""",
"""
@external
def foo():
xs: uint256[1] = []
""",
# literal longer than event member
"""
event Foo:
message: String[1]
@external
def foo():
log Foo("abcd")
""",
# Address literal must be checksummed
"""
a: constant(address) = 0x3cd751e6b0078be393132286c442345e5dc49699
""",
]


Expand Down
6 changes: 3 additions & 3 deletions tests/functional/syntax/test_abi_encode.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from vyper import compiler
from vyper.exceptions import InvalidType, TypeMismatch
from vyper.exceptions import TypeMismatch

fail_list = [
(
Expand Down Expand Up @@ -36,15 +36,15 @@ def foo(x: uint256) -> Bytes[36]:
def foo(x: uint256) -> Bytes[36]:
return _abi_encode(x, method_id=b"abcde")
""",
InvalidType, # len(method_id) must be less than 4
TypeMismatch, # len(method_id) must be less than 4
),
(
"""
@external
def foo(x: uint256) -> Bytes[36]:
return _abi_encode(x, method_id=0x1234567890)
""",
InvalidType, # len(method_id) must be less than 4
TypeMismatch, # len(method_id) must be less than 4
),
]

Expand Down
4 changes: 2 additions & 2 deletions tests/functional/syntax/test_abs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from vyper import compile_code
from vyper.exceptions import InvalidType
from vyper.exceptions import TypeMismatch

fail_list = [
(
Expand All @@ -12,7 +12,7 @@ def foo():
-57896044618658097711785492504343953926634992332820282019728792003956564819968
)
""",
InvalidType,
TypeMismatch,
)
]

Expand Down
6 changes: 3 additions & 3 deletions tests/functional/syntax/test_addmulmod.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from vyper import compile_code
from vyper.exceptions import InvalidType
from vyper.exceptions import TypeMismatch

fail_list = [
( # bad AST nodes given as arguments
Expand All @@ -10,15 +10,15 @@
def foo() -> uint256:
return uint256_addmod(1.1, 1.2, 3.0)
""",
InvalidType,
TypeMismatch,
),
( # bad AST nodes given as arguments
"""
@external
def foo() -> uint256:
return uint256_mulmod(1.1, 1.2, 3.0)
""",
InvalidType,
TypeMismatch,
),
]

Expand Down
14 changes: 7 additions & 7 deletions tests/functional/syntax/test_ann_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from vyper import compiler
from vyper.exceptions import (
InvalidAttribute,
InvalidType,
TypeMismatch,
UndeclaredDefinition,
UnknownAttribute,
VariableDeclarationException,
Expand Down Expand Up @@ -41,7 +41,7 @@ def test():
def test():
a: int128 = 33.33
""",
InvalidType,
TypeMismatch,
),
(
"""
Expand All @@ -50,7 +50,7 @@ def data() -> int128:
s: int128[5] = [1, 2, 3, 4, 5, 6]
return 235357
""",
InvalidType,
TypeMismatch,
),
(
"""
Expand All @@ -62,7 +62,7 @@ def foo() -> int128:
s: S = S({a: 1.2, b: 1})
return s.a
""",
InvalidType,
TypeMismatch,
),
(
"""
Expand Down Expand Up @@ -105,7 +105,7 @@ def foo() -> bool:
a: uint256 = -1
return True
""",
InvalidType,
TypeMismatch,
),
(
"""
Expand All @@ -114,7 +114,7 @@ def foo() -> bool:
a: uint256[2] = [13, -42]
return True
""",
InvalidType,
TypeMismatch,
),
(
"""
Expand All @@ -123,7 +123,7 @@ def foo() -> bool:
a: int128 = 170141183460469231731687303715884105728
return True
""",
InvalidType,
TypeMismatch,
),
]

Expand Down
4 changes: 2 additions & 2 deletions tests/functional/syntax/test_as_wei_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from vyper.exceptions import (
ArgumentException,
InvalidLiteral,
InvalidType,
OverflowException,
StructureException,
TypeMismatch,
UndeclaredDefinition,
)

Expand Down Expand Up @@ -44,7 +44,7 @@ def foo() -> int128:
def foo():
x: int128 = as_wei_value(0xf5, "szabo")
""",
InvalidType,
TypeMismatch,
),
(
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/syntax/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pytest import raises

from vyper import compiler
from vyper.exceptions import InvalidType, TypeMismatch
from vyper.exceptions import TypeMismatch

fail_list = [
(
Expand All @@ -11,15 +11,15 @@
def foo() -> int128[2]:
return [3,block.timestamp]
""",
InvalidType,
TypeMismatch,
),
(
"""
@external
def foo() -> int128[2]:
return [block.timestamp - block.timestamp, block.timestamp]
""",
InvalidType,
TypeMismatch,
),
"""
@external
Expand All @@ -34,7 +34,7 @@ def foo() -> decimal:
def foo():
x: Bytes[10] = slice(b"cow", -1, block.timestamp)
""",
InvalidType,
TypeMismatch,
),
"""
@external
Expand Down
17 changes: 4 additions & 13 deletions tests/functional/syntax/test_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
from pytest import raises

from vyper import compiler
from vyper.exceptions import InvalidOperation, InvalidType, SyntaxException, TypeMismatch
from vyper.exceptions import InvalidOperation, SyntaxException, TypeMismatch

fail_list = [
(
"""
"""
@external
def foo():
x: bool = True
x = 5
""",
InvalidType,
),
(
"""
@external
Expand All @@ -22,15 +19,12 @@ def foo():
""",
SyntaxException,
),
(
"""
"""
@external
def foo():
x: bool = True
x = 129
""",
InvalidType,
),
(
"""
@external
Expand Down Expand Up @@ -63,15 +57,12 @@ def foo(a: address) -> bool:
""",
InvalidOperation,
),
(
"""
"""
@external
def test(a: address) -> bool:
assert(a)
return True
""",
TypeMismatch,
),
]


Expand Down
12 changes: 3 additions & 9 deletions tests/functional/syntax/test_bytes.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import pytest

from vyper import compiler
from vyper.exceptions import (
InvalidOperation,
InvalidType,
StructureException,
SyntaxException,
TypeMismatch,
)
from vyper.exceptions import InvalidOperation, StructureException, SyntaxException, TypeMismatch

fail_list = [
(
Expand Down Expand Up @@ -64,15 +58,15 @@ def foo() -> Bytes[10]:
x = 0x1234567890123456789012345678901234567890
return x
""",
InvalidType,
TypeMismatch,
),
(
"""
@external
def foo() -> Bytes[10]:
return "badmintonzz"
""",
InvalidType,
TypeMismatch,
),
(
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/syntax/test_chainid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from vyper import compiler
from vyper.compiler.settings import Settings
from vyper.evm.opcodes import EVM_VERSIONS
from vyper.exceptions import InvalidType, TypeMismatch
from vyper.exceptions import TypeMismatch


@pytest.mark.parametrize("evm_version", list(EVM_VERSIONS))
Expand All @@ -25,7 +25,7 @@ def foo():
def foo() -> int128[2]:
return [3,chain.id]
""",
InvalidType,
TypeMismatch,
),
"""
@external
Expand Down Expand Up @@ -60,7 +60,7 @@ def add_record():
def foo(inp: Bytes[10]) -> Bytes[3]:
return slice(inp, chain.id, -3)
""",
InvalidType,
TypeMismatch,
),
]

Expand Down
4 changes: 2 additions & 2 deletions tests/functional/syntax/test_concat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from vyper import compiler
from vyper.exceptions import ArgumentException, InvalidType, TypeMismatch
from vyper.exceptions import ArgumentException, TypeMismatch

fail_list = [
(
Expand All @@ -18,7 +18,7 @@ def cat(i1: Bytes[10], i2: Bytes[30]) -> Bytes[40]:
def cat(i1: Bytes[10], i2: Bytes[30]) -> Bytes[40]:
return concat(i1, 5)
""",
InvalidType,
TypeMismatch,
),
(
"""
Expand Down
Loading

0 comments on commit 7a608bd

Please sign in to comment.