From e869f46d2d7cd18a75336d19f9848e2e0ee3d304 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Thu, 22 Feb 2024 09:40:29 -0500 Subject: [PATCH] chore: add another borrowship test clarify the behavior of storage access through nested attribute access --- .../syntax/modules/test_initializers.py | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/functional/syntax/modules/test_initializers.py b/tests/functional/syntax/modules/test_initializers.py index 66a201a33d..162bd46199 100644 --- a/tests/functional/syntax/modules/test_initializers.py +++ b/tests/functional/syntax/modules/test_initializers.py @@ -845,7 +845,7 @@ def foo(): @external def foo(new_value: uint256): - # can access lib1 state through lib2? + # cannot access lib1 state through lib2, lib2 does not `use` lib1. lib2.lib1.counter = new_value """ input_bundle = make_input_bundle({"lib1.vy": lib1, "lib2.vy": lib2}) @@ -860,6 +860,35 @@ def foo(new_value: uint256): assert e.value._hint == expected_hint +def test_uses_skip_import2(make_input_bundle): + lib1 = """ +counter: uint256 + """ + lib2 = """ +import lib1 + +initializes: lib1 + +@internal +def foo(): + pass + """ + main = """ +import lib1 +import lib2 + +initializes: lib2 + +@external +def foo(new_value: uint256): + # *can* access lib1 state through lib2, because lib2 initializes lib1 + lib2.lib1.counter = new_value + """ + input_bundle = make_input_bundle({"lib1.vy": lib1, "lib2.vy": lib2}) + + assert compile_code(main, input_bundle=input_bundle) is not None + + def test_invalid_uses(make_input_bundle, chdir_tmp_path): lib1 = """ counter: uint256