Skip to content

Commit

Permalink
Cover missing statements (#648)
Browse files Browse the repository at this point in the history
* Cover missing statements

* Change deprecation text in felt.py

* Update starknet_py/cairo/type_parser.py

Co-authored-by: war-in <61014013+war-in@users.noreply.github.com>

Co-authored-by: war-in <61014013+war-in@users.noreply.github.com>
  • Loading branch information
Solpatium and war-in committed Jan 10, 2023
1 parent aaf2daa commit fc90643
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
9 changes: 9 additions & 0 deletions starknet_py/cairo/felt.py
@@ -1,3 +1,4 @@
import warnings
from typing import List

from starkware.cairo.lang.compiler.ast.cairo_types import (
Expand All @@ -12,12 +13,20 @@


def is_felt_pointer(cairo_type: CairoType) -> bool:
warnings.warn(
"Function is_felt_pointer is deprecated. Use starknet_py.cairo.type_parser module instead.",
category=DeprecationWarning,
)
return isinstance(cairo_type, TypePointer) and isinstance(
cairo_type.pointee, TypeFelt
)


def is_uint256(definition: StructDefinition) -> bool:
warnings.warn(
"Function is_uint256 is deprecated. Use starknet_py.cairo.type_parser module instead.",
category=DeprecationWarning,
)
(struct_name, *_) = definition.full_name.path

return (
Expand Down
20 changes: 20 additions & 0 deletions starknet_py/cairo/serialization/_context_test.py
@@ -0,0 +1,20 @@
import pytest

from starknet_py.cairo.serialization._context import SerializationContext
from starknet_py.cairo.serialization.errors import (
InvalidTypeException,
InvalidValueException,
)


@pytest.mark.parametrize(
"initial_exception, wrapped_class",
[
(ValueError("Test"), InvalidValueException),
(TypeError("Test"), InvalidTypeException),
],
)
def test_if_exceptions_are_wrapped(initial_exception, wrapped_class):
with pytest.raises(wrapped_class, match="Error: Test"):
with SerializationContext.create():
raise initial_exception
6 changes: 4 additions & 2 deletions starknet_py/cairo/type_parser.py
Expand Up @@ -45,7 +45,7 @@ def __init__(self, defined_types: Dict[str, StructType]):
for name, struct in defined_types.items():
if name != struct.name:
raise ValueError(
f"Keys must match name of type, '{name}' != '{struct.name}'"
f"Keys must match name of type, '{name}' != '{struct.name}'."
)

def parse_inline_type(self, type_string: str) -> CairoType:
Expand Down Expand Up @@ -105,7 +105,9 @@ def _transform_cairo_lang_type(
# info about other structs, so they will be just TypeIdentifier (structure that was not parsed).

# This is an error of our logic, so we throw a RuntimeError.
raise RuntimeError(f"Received unknown type '{cairo_type}' from parser")
raise RuntimeError(
f"Received unknown type '{cairo_type}' from parser."
) # pragma: no cover

def _get_struct(self, name: str):
if name not in self.defined_types:
Expand Down
7 changes: 7 additions & 0 deletions starknet_py/cairo/type_parser_test.py
Expand Up @@ -110,3 +110,10 @@ def test_missing_type():

assert err_info.value.type_name == "Uint256"
assert str(err_info.value) == "Type 'Uint256' is not defined"


def test_names_not_matching():
with pytest.raises(
ValueError, match="Keys must match name of type, 'OtherName' != 'Uint256'."
):
TypeParser({"OtherName": uint256_type})

0 comments on commit fc90643

Please sign in to comment.