Beispiel #1
0
def test_modify_iterator(namespace):
    code = """

a: uint256[3]

@internal
def bar():
    for i in self.a:
        self.a[0] = 1
    """
    vyper_module = parse_to_ast(code)
    with pytest.raises(ImmutableViolation):
        validate_semantics(vyper_module, {})
Beispiel #2
0
def test_modify_iterator_function_outside_loop(namespace):
    code = """

a: uint256[3]

@internal
def foo():
    self.a[0] = 1

@internal
def bar():
    self.foo()
    for i in self.a:
        pass
    """
    vyper_module = parse_to_ast(code)
    validate_semantics(vyper_module, {})
Beispiel #3
0
def test_modify_iterator_function_call(namespace):
    code = """

a: uint256[3]

@private
def foo():
    self.a[0] = 1

@private
def bar():
    for i in self.a:
        self.foo()
    """
    vyper_module = parse_to_ast(code)
    with pytest.raises(ImmutableViolation):
        validate_semantics(vyper_module, {})
Beispiel #4
0
def test_pass_memory_var_to_other_function(namespace):
    code = """

@internal
def foo(a: uint256[3]) -> uint256[3]:
    b: uint256[3] = a
    b[1] = 42
    return b


@internal
def bar():
    a: uint256[3] = [1,2,3]
    for i in a:
        self.foo(a)
    """
    vyper_module = parse_to_ast(code)
    validate_semantics(vyper_module, {})