Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix script_container attribute access #1275

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions boa3/internal/analyser/moduleanalyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions boa3/internal/compiler/codegenerator/codegeneratorvisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions boa3_test/test_sc/interop_test/runtime/ScriptContainerHash.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions boa3_test/tests/compiler_tests/test_interop/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Loading