Пример #1
0
def test_array_value_types(build_node, type_str):
    node = build_node(f"{type_str}[1]")
    primitive = get_primitive_types()[type_str]

    type_definition = get_type_from_annotation(node, DataLocation.STORAGE)

    assert isinstance(type_definition, primitive._type)
Пример #2
0
def test_base_types_as_arrays(type_str):
    primitive = get_primitive_types()[type_str]

    type_definition = get_type_from_abi({"type": f"{type_str}[3]"})

    assert isinstance(type_definition, ArrayDefinition)
    assert type_definition.length == 3
    assert isinstance(type_definition.value_type, primitive._type)
Пример #3
0
def test_mapping(build_node, type_str, type_str2):
    node = build_node(f"HashMap[{type_str}, {type_str2}]")
    primitives = get_primitive_types()

    type_definition = get_type_from_annotation(node, DataLocation.STORAGE)

    assert isinstance(type_definition, MappingDefinition)
    assert isinstance(type_definition.key_type, primitives[type_str]._type)
    assert isinstance(type_definition.value_type, primitives[type_str2]._type)
Пример #4
0
def test_base_types_as_arrays(build_node, type_str):
    node = build_node(f"{type_str}[3]")
    primitive = get_primitive_types()[type_str]

    type_definition = get_type_from_annotation(node, DataLocation.STORAGE)

    assert isinstance(type_definition, ArrayDefinition)
    assert type_definition.length == 3
    assert isinstance(type_definition.value_type, primitive._type)
Пример #5
0
    def types_from_Constant(self, node):
        # literal value (integer, string, etc)
        types_list = []
        for primitive in types.get_primitive_types().values():
            try:
                obj = primitive.from_literal(node)
                types_list.append(obj)
            except VyperException:
                continue
        if types_list:
            return types_list

        if isinstance(node, vy_ast.Num):
            raise OverflowException(
                "Numeric literal is outside of allowable range for number types", node,
            )
        raise InvalidLiteral(f"Could not determine type for literal value '{node.value}'", node)
Пример #6
0
def test_base_types(type_str):
    primitive = get_primitive_types()[type_str]

    type_definition = get_type_from_abi({"type": type_str})

    assert isinstance(type_definition, primitive._type)