diff --git a/tests/functional/syntax/modules/test_initializers.py b/tests/functional/syntax/modules/test_initializers.py index e1464d28ef..9825e4618f 100644 --- a/tests/functional/syntax/modules/test_initializers.py +++ b/tests/functional/syntax/modules/test_initializers.py @@ -1228,3 +1228,67 @@ def use_lib1(): compile_code(main, input_bundle=input_bundle, output_formats=["annotated_ast_dict"]) is not None ) + + +def test_hint_for_missing_initializer_in_list(make_input_bundle): + lib1 = """ +counter: uint256 + """ + lib3 = """ +counter: uint256 + """ + lib2 = """ +import lib1 +import lib3 + +uses: lib1 +uses: lib3 + +counter: uint256 + +@internal +def foo(): + lib1.counter += 1 + lib3.counter += 1 + """ + main = """ +import lib1 +import lib2 +import lib3 + +initializes: lib2[lib1:=lib1] +initializes: lib1 +initializes: lib3 + """ + input_bundle = make_input_bundle({"lib1.vy": lib1, "lib2.vy": lib2, "lib3.vy": lib3}) + with pytest.raises(InitializerException) as e: + compile_code(main, input_bundle=input_bundle) + assert e.value._message == "`lib2` uses `lib3`, but it is not initialized with `lib3`" + assert e.value._hint == "add `lib3 := lib3` to its initializer list" + + +def test_hint_for_missing_initializer_when_no_import(make_input_bundle): + lib1 = """ +counter: uint256 + """ + lib2 = """ +import lib1 + +uses: lib1 + +counter: uint256 + +@internal +def foo(): + lib1.counter += 1 + """ + main = """ +import lib2 + +initializes: lib2 + """ + input_bundle = make_input_bundle({"lib1.vy": lib1, "lib2.vy": lib2}) + with pytest.raises(InitializerException) as e: + compile_code(main, input_bundle=input_bundle) + assert e.value._message == "`lib2` uses `lib1`, but it is not initialized with `lib1`" + assert e.value._hint == "try importing lib1 first"