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 error when removing a wallet on askar-profile #1518

Merged
merged 8 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
9 changes: 9 additions & 0 deletions aries_cloudagent/multitenant/askar_profile_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,12 @@ async def get_wallet_profile(
).extend(extra_settings)

return AskarProfile(multitenant_wallet.opened, profile_context)

async def remove_wallet_profile(self, profile: Profile):
"""Remove the wallet profile instance.

Args:
profile: The wallet profile instance

"""
await profile.remove()
12 changes: 10 additions & 2 deletions aries_cloudagent/multitenant/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ async def remove_wallet(self, wallet_id: str, wallet_key: str = None):
{"wallet.key": wallet_key},
)

del self._instances[wallet_id]
await profile.remove()
await self.remove_wallet_profile(profile)

# Remove all routing records associated with wallet
async with self._profile.session() as session:
Expand All @@ -282,6 +281,15 @@ async def remove_wallet(self, wallet_id: str, wallet_key: str = None):

await wallet.delete_record(session)

@abstractmethod
async def remove_wallet_profile(self, profile: Profile):
"""Remove the wallet profile instance.

Args:
profile: The wallet profile instance

"""

async def add_key(
self, wallet_id: str, recipient_key: str, *, skip_if_exists: bool = False
):
Expand Down
11 changes: 11 additions & 0 deletions aries_cloudagent/multitenant/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,14 @@ async def get_wallet_profile(
self._instances[wallet_id] = profile

return self._instances[wallet_id]

async def remove_wallet_profile(self, profile: Profile):
"""Remove the wallet profile instance.

Args:
profile: The wallet profile instance

"""
wallet_id = profile.settings.get("wallet.id")
del self._instances[wallet_id]
await profile.remove()
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,10 @@ def side_effect(context, provision):
wallet_config.call_args[0][0].settings.get("wallet.name")
== multitenant_sub_wallet_name
)

async def test_remove_wallet_profile(self):
test_profile = InMemoryProfile.test_profile()

with async_mock.patch.object(InMemoryProfile, "remove") as profile_remove:
await self.manager.remove_wallet_profile(test_profile)
profile_remove.assert_called_once_with()
8 changes: 3 additions & 5 deletions aries_cloudagent/multitenant/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ async def test_remove_wallet_removes_profile_wallet_storage_records(self):
) as retrieve_by_id, async_mock.patch.object(
BaseMultitenantManager, "get_wallet_profile"
) as get_wallet_profile, async_mock.patch.object(
InMemoryProfile, "remove"
) as remove_profile, async_mock.patch.object(
BaseMultitenantManager, "remove_wallet_profile"
) as remove_wallet_profile, async_mock.patch.object(
WalletRecord, "delete_record"
) as wallet_delete_record, async_mock.patch.object(
InMemoryStorage, "delete_all_records"
Expand All @@ -320,17 +320,15 @@ async def test_remove_wallet_removes_profile_wallet_storage_records(self):
)
wallet_profile = InMemoryProfile.test_profile()

self.manager._instances["test"] = wallet_profile
retrieve_by_id.return_value = wallet_record
get_wallet_profile.return_value = wallet_profile

await self.manager.remove_wallet("test")

assert "test" not in self.manager._instances
get_wallet_profile.assert_called_once_with(
self.profile.context, wallet_record, {"wallet.key": "test_key"}
)
remove_profile.assert_called_once_with()
remove_wallet_profile.assert_called_once_with(wallet_profile)
assert wallet_delete_record.call_count == 1
delete_all_records.assert_called_once_with(
RouteRecord.RECORD_TYPE, {"wallet_id": "test"}
Expand Down
11 changes: 11 additions & 0 deletions aries_cloudagent/multitenant/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,14 @@ def side_effect(context, provision):
assert profile.settings.get("mediation.invite") == "http://invite.com"
assert profile.settings.get("mediation.default_id") == "24a96ef5"
assert profile.settings.get("mediation.clear") == True

async def test_remove_wallet_profile(self):
test_profile = InMemoryProfile.test_profile(
settings={"wallet.id": "test"},
)
self.manager._instances["test"] = test_profile

with async_mock.patch.object(InMemoryProfile, "remove") as profile_remove:
await self.manager.remove_wallet_profile(test_profile)
assert "test" not in self.manager._instances
profile_remove.assert_called_once_with()