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

#86drpndk1 - Change how to add a method to the permissions #1240

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

jplippi
Copy link
Contributor

@jplippi jplippi commented Apr 23, 2024

Summary or solution description
This issue changes the add_permission function from NeoMetadata to accept methods in the form of lists and tuples, including handling of wildcard when present in such iterables.

@jplippi jplippi requested a review from meevee98 April 23, 2024 02:17
@melanke
Copy link
Contributor

melanke commented Apr 23, 2024

boa3/builtin/compile_time/__init__.py Outdated Show resolved Hide resolved
boa3/builtin/compile_time/__init__.py Outdated Show resolved Hide resolved
boa3/builtin/compile_time/__init__.py Outdated Show resolved Hide resolved
boa3/builtin/compile_time/__init__.py Outdated Show resolved Hide resolved
boa3/builtin/compile_time/__init__.py Outdated Show resolved Hide resolved
boa3/builtin/compile_time/__init__.py Outdated Show resolved Hide resolved
boa3/builtin/compile_time/__init__.py Outdated Show resolved Hide resolved
boa3/builtin/compile_time/__init__.py Outdated Show resolved Hide resolved
boa3/builtin/compile_time/__init__.py Outdated Show resolved Hide resolved
boa3/builtin/compile_time/__init__.py Outdated Show resolved Hide resolved
@coveralls
Copy link
Collaborator

coveralls commented Apr 23, 2024

Coverage Status

coverage: 91.907%. remained the same
when pulling 26b00be on CU-86drpndk1
into 10b77de on development.

Comment on lines 347 to 348
elif ((isinstance(methods, tuple) and (any(not isinstance(method, str) for method in methods) or len(methods) == 0)) or
(isinstance(methods, list) and (any(not isinstance(method, str) for method in methods) or len(methods) == 0))):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the validation is the same for both tuple and list right?
you could just wright:

Suggested change
elif ((isinstance(methods, tuple) and (any(not isinstance(method, str) for method in methods) or len(methods) == 0)) or
(isinstance(methods, list) and (any(not isinstance(method, str) for method in methods) or len(methods) == 0))):
elif ((isinstance(methods, (tuple, list)) and (any(not isinstance(method, str) for method in methods) or len(methods) == 0))):

@@ -306,7 +306,8 @@ def add_group(self, pub_key: str, signature: str):
if new_group not in self._permissions:
self._groups.append(new_group)

def add_permission(self, *, contract: str = IMPORT_WILDCARD, methods: list[str, str] = IMPORT_WILDCARD):
def add_permission(self, *, contract: str = IMPORT_WILDCARD,
methods: list[str] | str | tuple = IMPORT_WILDCARD):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just an observation for tuple type annotation: you can annotate a tuple of any size like this: tuple[str, ...]

@jplippi jplippi force-pushed the CU-86drpndk1 branch 3 times, most recently from 18b961e to 1c4fe29 Compare April 23, 2024 21:06
@@ -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')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case where the list or tuple contains multiple elements, not just a single element or wildcard. This will ensure that the function can handle multiple methods correctly.

self.assertIn({"contract": "*", "methods": "*"}, manifest['permissions'])

async def test_metadata_info_permissions_wildcard_list(self):
path = self.get_contract_path('MetadataInfoPermissionsWildcardList.py')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be beneficial to add a negative test case where the input is not a list or tuple to ensure the function behaves as expected in such scenarios.

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

async def test_metadata_info_permissions_wildcard_tuple(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case where the list or tuple contains a mix of specific methods and a wildcard. This will help to verify that the function can correctly handle such cases.

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling exceptions that may occur during the execution of compile_and_save method.

@@ -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')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a docstring to the test_metadata_info_permissions_wildcard_list_single_element method to explain what it tests.

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

async def test_metadata_info_permissions_wildcard_list(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a docstring to the test_metadata_info_permissions_wildcard_list method to explain what it tests.

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

async def test_metadata_info_permissions_wildcard_tuple(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a docstring to the test_metadata_info_permissions_wildcard_tuple method to explain what it tests.

@meevee98 meevee98 merged commit a9273f6 into development Apr 24, 2024
4 checks passed
@meevee98 meevee98 deleted the CU-86drpndk1 branch April 24, 2024 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants