Skip to content

Commit

Permalink
CU-86drpndk1 - Change how to add a method to the permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
jplippi committed Apr 23, 2024
1 parent 10b77de commit 18b961e
Show file tree
Hide file tree
Showing 9 changed files with 511 additions and 385 deletions.
775 changes: 393 additions & 382 deletions boa3/builtin/compile_time/__init__.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion boa3_test/test_sc/metadata_test/MetadataInfoPermissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def permissions_manifest() -> NeoMetadata:
meta = NeoMetadata()

# the contract needs permission to call this method from any contract
meta.add_permission(methods=['onNEP17Payment'])
meta.add_permission(methods='onNEP17Payment')

# the contract needs permission to call this method from a specific contract
meta.add_permission(contract='0x3846a4aa420d9831044396dd3a56011514cd10e3', methods=['get_object'])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from boa3.builtin.compile_time import NeoMetadata, public


@public
def main() -> int:
return 5


def permissions_manifest() -> NeoMetadata:
meta = NeoMetadata()

meta.add_permission(contract='*', methods=[])

return meta
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ def permissions_manifest() -> NeoMetadata:
meta.add_permission(methods=b'onNEP17Payment')
meta.add_permission(methods=123)
meta.add_permission(methods=True)
meta.add_permission(methods='onNEP17Payment')
meta.add_permission(methods=(1, 2, 3))
meta.add_permission(methods=(b'onNEP17Payment', 123, True))

meta.add_permission(contract=b'12345678901234567890')
meta.add_permission(contract=123)
meta.add_permission(contract=True)
meta.add_permission(contract=['0x3846a4aa420d9831044396dd3a56011514cd10e3'])

meta.add_permission(contract=123, methods='onNEP17Payment')
meta.add_permission(contract=123, methods=b'onNEP17Payment')

return meta
14 changes: 14 additions & 0 deletions boa3_test/test_sc/metadata_test/MetadataInfoPermissionsTuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from boa3.builtin.compile_time import NeoMetadata, public


@public
def main() -> int:
return 5


def permissions_manifest() -> NeoMetadata:
meta = NeoMetadata()

meta.add_permission(contract='*', methods=('total_supply', 'onNEP17Payment'))

return meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from boa3.builtin.compile_time import NeoMetadata, public


@public
def main() -> int:
return 5


def permissions_manifest() -> NeoMetadata:
meta = NeoMetadata()

meta.add_permission(contract='*', methods=['*', 'onNEP17Payment'])

return meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from boa3.builtin.compile_time import NeoMetadata, public


@public
def main() -> int:
return 5


def permissions_manifest() -> NeoMetadata:
meta = NeoMetadata()

meta.add_permission(contract='*', methods=['*'])

return meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from boa3.builtin.compile_time import NeoMetadata, public


@public
def main() -> int:
return 5


def permissions_manifest() -> NeoMetadata:
meta = NeoMetadata()

meta.add_permission(contract='*', methods=('*', 'onNEP17Payment'))

return meta
44 changes: 44 additions & 0 deletions boa3_test/tests/compiler_tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,23 @@ def test_metadata_info_permissions_default(self):
self.assertIsInstance(manifest['permissions'], list)
self.assertEqual(len(manifest['permissions']), 0)

def test_metadata_info_permissions_empty_list(self):
path = self.get_contract_path('MetadataInfoPermissionsEmptyList.py')
output, manifest = self.compile_and_save(path)

self.assertIn('permissions', manifest)
self.assertIsInstance(manifest['permissions'], list)
self.assertEqual(len(manifest['permissions']), 0)

def test_metadata_info_permissions_tuple(self):
path = self.get_contract_path('MetadataInfoPermissionsTuple.py')
output, manifest = self.compile_and_save(path)

self.assertIn('permissions', manifest)
self.assertIsInstance(manifest['permissions'], list)
self.assertEqual(len(manifest['permissions']), 1)
self.assertIn({"contract": "*", "methods": ['total_supply', 'onNEP17Payment']}, manifest['permissions'])

async def test_metadata_info_permissions_wildcard(self):
path = self.get_contract_path('MetadataInfoPermissionsWildcard.py')
output, manifest = self.compile_and_save(path)
Expand All @@ -452,6 +469,33 @@ async def test_metadata_info_permissions_wildcard(self):
result, _ = await self.call('main', [], return_type=int)
self.assertEqual(result, 100_000_000) # NEO total supply

async def test_metadata_info_permissions_wildcard_list_single_element(self):
path = self.get_contract_path('MetadataInfoPermissionsWildcardListSingleElement.py')
output, manifest = self.compile_and_save(path)

self.assertIn('permissions', manifest)
self.assertIsInstance(manifest['permissions'], list)
self.assertEqual(len(manifest['permissions']), 1)
self.assertIn({"contract": "*", "methods": "*"}, manifest['permissions'])

async def test_metadata_info_permissions_wildcard_list(self):
path = self.get_contract_path('MetadataInfoPermissionsWildcardList.py')
output, manifest = self.compile_and_save(path)

self.assertIn('permissions', manifest)
self.assertIsInstance(manifest['permissions'], list)
self.assertEqual(len(manifest['permissions']), 1)
self.assertIn({"contract": "*", "methods": "*"}, manifest['permissions'])

async def test_metadata_info_permissions_wildcard_tuple(self):
path = self.get_contract_path('MetadataInfoPermissionsWildcardTuple.py')
output, manifest = self.compile_and_save(path)

self.assertIn('permissions', manifest)
self.assertIsInstance(manifest['permissions'], list)
self.assertEqual(len(manifest['permissions']), 1)
self.assertIn({"contract": "*", "methods": "*"}, manifest['permissions'])

def test_metadata_info_permissions_native_contract(self):
path = self.get_contract_path('MetadataInfoPermissionsNativeContract.py')
output, manifest = self.compile_and_save(path)
Expand Down

0 comments on commit 18b961e

Please sign in to comment.