From 2419de33d6e17f7becaf868f46e3eb042be1bffe Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Fri, 23 Aug 2024 14:09:16 +0200 Subject: [PATCH 1/3] fix #1273 --- boa3/internal/analyser/moduleanalyser.py | 3 +++ boa3/internal/compiler/codegenerator/codegeneratorvisitor.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/boa3/internal/analyser/moduleanalyser.py b/boa3/internal/analyser/moduleanalyser.py index 1c28c3e26..a00ca888d 100644 --- a/boa3/internal/analyser/moduleanalyser.py +++ b/boa3/internal/analyser/moduleanalyser.py @@ -18,6 +18,7 @@ from boa3.internal.model.builtin.compile_time.neometadatatype import MetadataTypeSingleton from boa3.internal.model.builtin.decorator import ContractDecorator from boa3.internal.model.builtin.decorator.builtindecorator import IBuiltinDecorator +from boa3.internal.model.builtin.interop.runtime import ScriptContainerProperty from boa3.internal.model.builtin.method.builtinmethod import IBuiltinMethod from boa3.internal.model.callable import Callable from boa3.internal.model.decorator import IDecorator @@ -1432,6 +1433,8 @@ def visit_Attribute(self, attribute: ast.Attribute) -> ISymbol | str: if isinstance(value, Variable): value = value.type + elif isinstance(value, ScriptContainerProperty): + value = value.type attribute_symbol = None if hasattr(value, 'symbols') and attribute.attr in value.symbols: diff --git a/boa3/internal/compiler/codegenerator/codegeneratorvisitor.py b/boa3/internal/compiler/codegenerator/codegeneratorvisitor.py index 1f3b4287d..f6eec5457 100644 --- a/boa3/internal/compiler/codegenerator/codegeneratorvisitor.py +++ b/boa3/internal/compiler/codegenerator/codegeneratorvisitor.py @@ -126,6 +126,9 @@ def visit_to_generate(self, node) -> GeneratorData: result = self.visit(node) if not result.already_generated and result.symbol_id is not None: + if isinstance(node, ast.Attribute): + self.visit_to_generate(node.value) + if self.is_exception_name(result.symbol_id): self.generator.convert_new_exception() else: From 65132076e3890604fe851e929480d3b642ba39f2 Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Fri, 23 Aug 2024 14:45:17 +0200 Subject: [PATCH 2/3] tighten --- boa3/internal/compiler/codegenerator/codegeneratorvisitor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boa3/internal/compiler/codegenerator/codegeneratorvisitor.py b/boa3/internal/compiler/codegenerator/codegeneratorvisitor.py index f6eec5457..d8b544f2d 100644 --- a/boa3/internal/compiler/codegenerator/codegeneratorvisitor.py +++ b/boa3/internal/compiler/codegenerator/codegeneratorvisitor.py @@ -126,7 +126,7 @@ def visit_to_generate(self, node) -> GeneratorData: result = self.visit(node) if not result.already_generated and result.symbol_id is not None: - if isinstance(node, ast.Attribute): + if isinstance(node, ast.Attribute) and isinstance(node.value, ast.Attribute): self.visit_to_generate(node.value) if self.is_exception_name(result.symbol_id): From 37bfa8b5f2fe595b73039c53f460ddc7b0af5049 Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Fri, 23 Aug 2024 15:09:09 +0200 Subject: [PATCH 3/3] add testcase --- .../interop_test/runtime/ScriptContainerHash.py | 8 ++++++++ .../interop_test/runtime/ScriptContainerHash2.py | 7 +++++++ .../compiler_tests/test_interop/test_runtime.py | 13 +++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 boa3_test/test_sc/interop_test/runtime/ScriptContainerHash.py create mode 100644 boa3_test/test_sc/interop_test/runtime/ScriptContainerHash2.py diff --git a/boa3_test/test_sc/interop_test/runtime/ScriptContainerHash.py b/boa3_test/test_sc/interop_test/runtime/ScriptContainerHash.py new file mode 100644 index 000000000..a52b30dee --- /dev/null +++ b/boa3_test/test_sc/interop_test/runtime/ScriptContainerHash.py @@ -0,0 +1,8 @@ +from boa3.builtin.compile_time import public +from boa3.builtin.type import UInt256 +from boa3.builtin.interop.runtime import script_container + + +@public +def main() -> UInt256: + return script_container.hash diff --git a/boa3_test/test_sc/interop_test/runtime/ScriptContainerHash2.py b/boa3_test/test_sc/interop_test/runtime/ScriptContainerHash2.py new file mode 100644 index 000000000..541ba38b0 --- /dev/null +++ b/boa3_test/test_sc/interop_test/runtime/ScriptContainerHash2.py @@ -0,0 +1,7 @@ +from boa3.builtin.compile_time import public +from boa3.builtin.type import UInt256 +from boa3.builtin.interop import runtime + +@public +def main() -> UInt256: + return runtime.script_container.hash diff --git a/boa3_test/tests/compiler_tests/test_interop/test_runtime.py b/boa3_test/tests/compiler_tests/test_interop/test_runtime.py index 21c91c105..b78026ee8 100644 --- a/boa3_test/tests/compiler_tests/test_interop/test_runtime.py +++ b/boa3_test/tests/compiler_tests/test_interop/test_runtime.py @@ -890,3 +890,16 @@ async def test_load_script(self): return_type=int ) self.assertEqual(expected_result, result) + + async def test_script_container_hash(self): + # test https://github.com/CityOfZion/neo3-boa/issues/1273 + # both import styles must work + await self.set_up_contract('ScriptContainerHash.py') + + result, _ = await self.call('main', [], return_type=types.UInt256) + self.assertIsInstance(result, types.UInt256) + + await self.set_up_contract('ScriptContainerHash2.py') + result, _ = await self.call('main', [], return_type=types.UInt256) + self.assertIsInstance(result, types.UInt256) +