diff --git a/boa3/internal/analyser/moduleanalyser.py b/boa3/internal/analyser/moduleanalyser.py index 3e584042..b7993960 100644 --- a/boa3/internal/analyser/moduleanalyser.py +++ b/boa3/internal/analyser/moduleanalyser.py @@ -17,6 +17,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.interop.runtime import NotifyMethod from boa3.internal.model.builtin.method.builtinmethod import IBuiltinMethod from boa3.internal.model.callable import Callable @@ -1445,6 +1446,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 86b47fd8..04e94c84 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) and isinstance(node.value, ast.Attribute): + self.visit_to_generate(node.value) + if self.is_exception_name(result.symbol_id): self.generator.convert_new_exception() else: 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 00000000..a52b30de --- /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 00000000..541ba38b --- /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 085452e5..c6a77c99 100644 --- a/boa3_test/tests/compiler_tests/test_interop/test_runtime.py +++ b/boa3_test/tests/compiler_tests/test_interop/test_runtime.py @@ -894,3 +894,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) +