Skip to content

Commit

Permalink
WIPL add more test points
Browse files Browse the repository at this point in the history
  • Loading branch information
talhadaar committed Nov 24, 2023
1 parent 95ad418 commit 0e342aa
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions tests/bridge_rbac_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def _verify_assign_permission_to_role(self, tx, permission_id, role_id):

# get block events and verify
block_idx = tx['blockNumber']
events = self._contract.events.PermissionAssignedToRole.create_filter(fromBlock=block_idx, toBlock=block_idx).get_all_entries()
events = self._contract.events.PermissionAssigned.create_filter(fromBlock=block_idx, toBlock=block_idx).get_all_entries()
self._verify_permission_assigned_or_unassigned_to_role_event(events, self._eth_kp_src.ss58_address, permission_id, role_id)

# verify fetch_role_permissions returns correct data
Expand All @@ -361,7 +361,7 @@ def _verify_unassign_permission_to_role(self, tx, permission_id, role_id):

# get block events and verify
block_idx = tx['blockNumber']
events = self._contract.events.PermissionUnassignedToRole.create_filter(fromBlock=block_idx, toBlock=block_idx).get_all_entries()
events = self._contract.events.PermissionAssigned.create_filter(fromBlock=block_idx, toBlock=block_idx).get_all_entries()
self._verify_permission_assigned_or_unassigned_to_role_event(events, self._eth_kp_src.ss58_address, permission_id, role_id)

# verify fetch_role_permissions returns correct data
Expand Down Expand Up @@ -412,6 +412,32 @@ def _verify_disable_group(self, tx, group_id):
self.assertEqual(data[0], group_id)
self.assertEqual(data[2], False)

def _verify_assign_role_to_group(self, tx, role_id, group_id):
self.assertEqual(tx['status'], TX_SUCCESS_STATUS)

# get block events and verify
block_idx = tx['blockNumber']
events = self._contract.events.RoleAssignedToGroup.create_filter(fromBlock=block_idx, toBlock=block_idx).get_all_entries()
self._verify_role_assigned_or_unassigned_to_group_event(events, self._eth_kp_src.ss58_address, role_id, group_id)

# verify fetch_group_roles returns correct data
data = self._contract.functions.fetch_group_roles(self._account, group_id).call()
if not any(role_id in roles for roles in data):
self.fail(f'Role {role_id} not assigned to group {group_id}')

def _verify_unassign_role_to_group(self, tx, role_id, group_id):
self.assertEqual(tx['status'], TX_SUCCESS_STATUS)

# get block events and verify
block_idx = tx['blockNumber']
events = self._contract.events.RoleUnassignedToGroup.create_filter(fromBlock=block_idx, toBlock=block_idx).get_all_entries()
self._verify_role_assigned_or_unassigned_to_group_event(events, self._eth_kp_src.ss58_address, role_id, group_id)

# verify fetch_group_roles returns correct data
data = self._contract.functions.fetch_group_roles(self._account, group_id).call()
if any(role_id in roles for roles in data):
self.fail(f'Role {role_id} still assigned to group {group_id}')

def _verify_assign_user_to_group(self, tx, user_id, group_id):
self.assertEqual(tx['status'], TX_SUCCESS_STATUS)

Expand Down Expand Up @@ -505,7 +531,7 @@ def test_rbac_bridge(self):
# assign role to group
self._verify_assign_role_to_group(self._assign_role_to_group(roles[0][0], groups[0][0]), roles[0][0], groups[0][0])
self._assign_role_to_group(roles[1][0], groups[0][0])
self._assign_role_to_group(roles[2][0], groups[0][0])[0]
self._assign_role_to_group(roles[2][0], groups[0][0])

# unassign role to group
self._verify_unassign_role_to_group(self._unassign_role_to_group(roles[0][0], groups[0][0]), roles[0][0], groups[0][0])
Expand Down

0 comments on commit 0e342aa

Please sign in to comment.