From 591b97b50c8f3ac0b4b828202e04a2a0ec7fe351 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Mon, 12 Feb 2024 18:03:15 -0500 Subject: [PATCH] add some subscript/attribute tests for module uses (note these also pass on master) --- .../syntax/modules/test_initializers.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/functional/syntax/modules/test_initializers.py b/tests/functional/syntax/modules/test_initializers.py index a12f5f57ea..0412e83c7d 100644 --- a/tests/functional/syntax/modules/test_initializers.py +++ b/tests/functional/syntax/modules/test_initializers.py @@ -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 = """