Skip to content

Commit

Permalink
add some subscript/attribute tests for module uses
Browse files Browse the repository at this point in the history
(note these also pass on master)
  • Loading branch information
charles-cooper committed Feb 12, 2024
1 parent 68faed2 commit 591b97b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/functional/syntax/modules/test_initializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,48 @@ def foo(new_value: uint256):
assert e.value._hint == expected_hint


def test_missing_uses_subscript(make_input_bundle):
# test missing uses through nested subscript/attribute access
lib1 = """
struct Foo:
array: uint256[5]
foos: Foo[5]
"""
lib2 = """
import lib1
counter: uint256
@internal
def foo():
pass
"""
main = """
import lib1
import lib2
initializes: lib1
# did not `use` or `initialize` lib2!
@external
def foo(new_value: uint256):
# cannot access lib1 state through lib2
lib2.lib1.foos[0].array[1] = new_value
"""
input_bundle = make_input_bundle({"lib1.vy": lib1, "lib2.vy": lib2})

with pytest.raises(ImmutableViolation) as e:
compile_code(main, input_bundle=input_bundle)

assert e.value._message == "Cannot access `lib2` state!"

expected_hint = "add `uses: lib2` or `initializes: lib2` as a "
expected_hint += "top-level statement to your contract"
assert e.value._hint == expected_hint


def test_missing_uses_nested_attribute_function_call(make_input_bundle):
# test missing uses through nested attribute access
lib1 = """
Expand Down

0 comments on commit 591b97b

Please sign in to comment.