Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Dec 18, 2023
1 parent 73193d5 commit 9f667ca
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 115 deletions.
14 changes: 7 additions & 7 deletions tests/functional/codegen/features/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def foo_():
log MyLog(b'yo')
"""

assert_tx_failed(lambda: get_contract_with_gas_estimation(loggy_code), InvalidType)
assert_tx_failed(lambda: get_contract_with_gas_estimation(loggy_code), TypeMismatch)


def test_fails_when_topic_is_the_wrong_size(assert_tx_failed, get_contract_with_gas_estimation):
Expand All @@ -579,7 +579,7 @@ def foo():
log MyLog(b'bars')
"""

assert_tx_failed(lambda: get_contract_with_gas_estimation(loggy_code), InvalidType)
assert_tx_failed(lambda: get_contract_with_gas_estimation(loggy_code), TypeMismatch)


def test_fails_when_input_topic_is_the_wrong_size(
Expand Down Expand Up @@ -607,7 +607,7 @@ def foo():
log MyLog(b'bars')
"""

assert_tx_failed(lambda: get_contract_with_gas_estimation(loggy_code), InvalidType)
assert_tx_failed(lambda: get_contract_with_gas_estimation(loggy_code), TypeMismatch)


def test_fails_when_input_data_is_the_wrong_size(
Expand Down Expand Up @@ -1236,15 +1236,15 @@ def foo():
def foo():
raw_log([1, 2], b"moo")
""",
InvalidType,
TypeMismatch,
),
(
"""
@external
def foo():
raw_log([1, 2], b"moo")
""",
InvalidType,
TypeMismatch,
),
(
"""
Expand All @@ -1261,7 +1261,7 @@ def foo():
def foo():
raw_log([b"cow"], b"dog")
""",
(StructureException, InvalidType),
(StructureException, TypeMismatch),
),
(
"""
Expand All @@ -1270,7 +1270,7 @@ def foo():
# bytes20 instead of bytes32
raw_log([], 0x1234567890123456789012345678901234567890)
""",
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,6 +1,6 @@
import pytest

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

fail_list = [
( # bad AST nodes given as arguments
Expand All @@ -9,15 +9,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
@@ -1,6 +1,6 @@
import pytest

from vyper.exceptions import ArgumentException, InvalidType, StructureException
from vyper.exceptions import ArgumentException, StructureException

fail_list = [
(
Expand All @@ -26,7 +26,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
6 changes: 3 additions & 3 deletions tests/functional/syntax/test_bool.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 InvalidOperation, InvalidType, SyntaxException, TypeMismatch
from vyper.exceptions import InvalidOperation, SyntaxException, TypeMismatch

fail_list = [
(
Expand All @@ -12,7 +12,7 @@ def foo():
x: bool = True
x = 5
""",
InvalidType,
TypeMismatch,
),
(
"""
Expand All @@ -29,7 +29,7 @@ def foo():
x: bool = True
x = 129
""",
InvalidType,
TypeMismatch,
),
(
"""
Expand Down
11 changes: 2 additions & 9 deletions tests/functional/syntax/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from vyper import compiler
from vyper.exceptions import (
InvalidOperation,
InvalidType,
StructureException,
SyntaxException,
TypeMismatch,
Expand Down Expand Up @@ -56,24 +55,18 @@ def foo(x: Bytes[100]) -> int128:
def foo(x: int128) -> Bytes[75]:
return x
""",
(
"""
"""
@external
def foo() -> Bytes[10]:
x: Bytes[10] = '0x1234567890123456789012345678901234567890'
x = 0x1234567890123456789012345678901234567890
return x
""",
InvalidType,
),
(
"""
"""
@external
def foo() -> Bytes[10]:
return "badmintonzz"
""",
InvalidType,
),
(
"""
@external
Expand Down
20 changes: 5 additions & 15 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 @@ -19,14 +19,11 @@ def foo():


fail_list = [
(
"""
"""
@external
def foo() -> int128[2]:
return [3,chain.id]
""",
InvalidType,
),
"""
@external
def foo() -> decimal:
Expand Down Expand Up @@ -54,25 +51,18 @@ def add_record():
def add_record():
self.a[chain.id] = chain.id + 20
""",
(
"""
"""
@external
def foo(inp: Bytes[10]) -> Bytes[3]:
return slice(inp, chain.id, -3)
""",
InvalidType,
),
]


@pytest.mark.parametrize("bad_code", fail_list)
def test_chain_fail(bad_code):
if isinstance(bad_code, tuple):
with pytest.raises(bad_code[1]):
compiler.compile_code(bad_code[0])
else:
with pytest.raises(TypeMismatch):
compiler.compile_code(bad_code)
with pytest.raises(TypeMismatch):
compiler.compile_code(bad_code)


valid_list = [
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
10 changes: 5 additions & 5 deletions tests/functional/syntax/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from vyper.exceptions import (
ArgumentException,
ImmutableViolation,
InvalidType,
NamespaceCollision,
StateAccessViolation,
StructureException,
SyntaxException,
TypeMismatch,
VariableDeclarationException,
)

Expand All @@ -33,16 +33,16 @@
"""
VAL: constant(uint256) = "test"
""",
InvalidType,
TypeMismatch,
),
# invalid range
(
"""
VAL: constant(uint256) = -1
""",
InvalidType,
TypeMismatch,
),
# reserverd keyword
# reserved keyword
(
"""
wei: constant(uint256) = 1
Expand All @@ -62,7 +62,7 @@
"""
VAL: constant(Bytes[4]) = b"testtest"
""",
InvalidType,
TypeMismatch,
),
# global with same name
(
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_extract32.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def foo(inp: Bytes[32]) -> int128:
def foo(inp: Bytes[32]) -> int128:
return extract32(inp, -1, output_type=int128)
""",
InvalidType, # `start` cannot be negative
TypeMismatch, # `start` cannot be negative
),
(
"""
Expand Down
Loading

0 comments on commit 9f667ca

Please sign in to comment.