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 b9a474d commit 6b58aeb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
4 changes: 2 additions & 2 deletions tests/functional/codegen/types/numbers/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from vyper.compiler import compile_code
from vyper.exceptions import InvalidType
from vyper.exceptions import TypeMismatch
from vyper.utils import MemoryPositions


Expand Down Expand Up @@ -151,7 +151,7 @@ def test_custom_constants_fail(get_contract, assert_compile_failed, storage_type
def foo() -> {return_type}:
return MY_CONSTANT
"""
assert_compile_failed(lambda: get_contract(code), InvalidType)
assert_compile_failed(lambda: get_contract(code), TypeMismatch)


def test_constant_address(get_contract):
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/codegen/types/numbers/test_signed_ints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from vyper.exceptions import InvalidOperation, InvalidType, OverflowException, ZeroDivisionException
from vyper.exceptions import InvalidOperation, InvalidType, OverflowException, TypeMismatch, ZeroDivisionException
from vyper.semantics.types import IntegerT
from vyper.utils import evm_div, evm_mod

Expand Down Expand Up @@ -204,7 +204,7 @@ def num_sub() -> {typ}:
if typ.bits == 256:
assert_compile_failed(lambda: get_contract(code), OverflowException)
else:
assert_compile_failed(lambda: get_contract(code), InvalidType)
assert_compile_failed(lambda: get_contract(code), TypeMismatch)


ARITHMETIC_OPS = {
Expand Down Expand Up @@ -312,7 +312,7 @@ def foo() -> {typ}:
assert_tx_failed(lambda: c.foo(x, y))
assert_tx_failed(lambda: get_contract(code_2).foo(x))
assert_tx_failed(lambda: get_contract(code_3).foo(y))
assert_compile_failed(lambda: get_contract(code_4), (InvalidType, OverflowException))
assert_compile_failed(lambda: get_contract(code_4), (TypeMismatch, OverflowException))


COMPARISON_OPS = {
Expand Down
7 changes: 3 additions & 4 deletions tests/functional/codegen/types/test_dynamic_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
ArgumentException,
ArrayIndexException,
ImmutableViolation,
InvalidType,
OverflowException,
StateAccessViolation,
TypeMismatch,
Expand Down Expand Up @@ -1102,7 +1101,7 @@ def foo() -> DynArray[{subtyp}, 3]:
x.append({lit})
return x
"""
assert_compile_failed(lambda: get_contract(code), InvalidType)
assert_compile_failed(lambda: get_contract(code), TypeMismatch)


invalid_appends_pops = [
Expand Down Expand Up @@ -1718,7 +1717,7 @@ def test_constant_list_fail(get_contract, assert_compile_failed, storage_type, r
def foo() -> DynArray[{return_type}, 3]:
return MY_CONSTANT
"""
assert_compile_failed(lambda: get_contract(code), InvalidType)
assert_compile_failed(lambda: get_contract(code), TypeMismatch)


@pytest.mark.parametrize("storage_type,return_type", itertools.permutations(integer_types, 2))
Expand All @@ -1730,7 +1729,7 @@ def test_constant_list_fail_2(get_contract, assert_compile_failed, storage_type,
def foo() -> {return_type}:
return MY_CONSTANT[0]
"""
assert_compile_failed(lambda: get_contract(code), InvalidType)
assert_compile_failed(lambda: get_contract(code), TypeMismatch)


@pytest.mark.parametrize("storage_type,return_type", itertools.permutations(integer_types, 2))
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/codegen/types/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from vyper.exceptions import ArrayIndexException, InvalidType, OverflowException, TypeMismatch
from vyper.exceptions import ArrayIndexException, OverflowException, TypeMismatch


def test_list_tester_code(get_contract_with_gas_estimation):
Expand Down Expand Up @@ -701,7 +701,7 @@ def test_constant_list_fail(get_contract, assert_compile_failed, storage_type, r
def foo() -> {return_type}[3]:
return MY_CONSTANT
"""
assert_compile_failed(lambda: get_contract(code), InvalidType)
assert_compile_failed(lambda: get_contract(code), TypeMismatch)


@pytest.mark.parametrize("storage_type,return_type", itertools.permutations(integer_types, 2))
Expand All @@ -713,7 +713,7 @@ def test_constant_list_fail_2(get_contract, assert_compile_failed, storage_type,
def foo() -> {return_type}:
return MY_CONSTANT[0]
"""
assert_compile_failed(lambda: get_contract(code), InvalidType)
assert_compile_failed(lambda: get_contract(code), TypeMismatch)


@pytest.mark.parametrize("storage_type,return_type", itertools.permutations(integer_types, 2))
Expand Down Expand Up @@ -817,7 +817,7 @@ def test_constant_nested_list_fail(get_contract, assert_compile_failed, storage_
def foo() -> {return_type}[2][3]:
return MY_CONSTANT
"""
assert_compile_failed(lambda: get_contract(code), InvalidType)
assert_compile_failed(lambda: get_contract(code), TypeMismatch)


@pytest.mark.parametrize("storage_type,return_type", itertools.permutations(integer_types, 2))
Expand All @@ -831,4 +831,4 @@ def test_constant_nested_list_fail_2(
def foo() -> {return_type}:
return MY_CONSTANT[0][0]
"""
assert_compile_failed(lambda: get_contract(code), InvalidType)
assert_compile_failed(lambda: get_contract(code), TypeMismatch)
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

0 comments on commit 6b58aeb

Please sign in to comment.