diff --git a/aries_cloudagent/revocation/indy.py b/aries_cloudagent/revocation/indy.py index c2d46b503f..abbfc9ea96 100644 --- a/aries_cloudagent/revocation/indy.py +++ b/aries_cloudagent/revocation/indy.py @@ -237,9 +237,7 @@ async def get_or_create_active_registry( triggered and the caller should retry after a delay. """ try: - active_rev_reg_rec = await self.get_active_issuer_rev_reg_record( - cred_def_id - ) + active_rev_reg_rec = await self.get_active_issuer_rev_reg_record(cred_def_id) rev_reg = active_rev_reg_rec.get_registry() await rev_reg.get_or_fetch_local_tails_path() return active_rev_reg_rec, rev_reg @@ -254,11 +252,14 @@ async def get_or_create_active_registry( # all registries are full, create a new one if not full_registries: # Use any registry to get max cred num - any_registry = ( - await IssuerRevRegRecord.query_by_cred_def_id( - session, cred_def_id, limit=1 + any_registry = await IssuerRevRegRecord.query_by_cred_def_id( + session, cred_def_id, limit=1 + ) + if not any_registry: + raise RevocationError( + f"No revocation registry record found in issuer wallet for cred def id {cred_def_id}" # noqa: E501 ) - )[0] + any_registry = any_registry[0] await self.init_issuer_registry( cred_def_id, max_cred_num=any_registry.max_cred_num, diff --git a/aries_cloudagent/revocation/tests/test_indy.py b/aries_cloudagent/revocation/tests/test_indy.py index 43eb0c4b81..482bb9ba49 100644 --- a/aries_cloudagent/revocation/tests/test_indy.py +++ b/aries_cloudagent/revocation/tests/test_indy.py @@ -11,6 +11,7 @@ from ...multitenant.manager import MultitenantManager from ...storage.error import StorageNotFoundError from ..error import ( + RevocationError, RevocationNotSupportedError, RevocationRegistryBadSizeError, ) @@ -161,9 +162,7 @@ async def test_decommission_issuer_registries(self): recs = await self.revoc.list_issuer_registries() assert len(recs) == 2 - init_list = list( - filter(lambda r: r.state == IssuerRevRegRecord.STATE_INIT, recs) - ) + init_list = list(filter(lambda r: r.state == IssuerRevRegRecord.STATE_INIT, recs)) assert len(init_list) == 2 # store the ids to verify they are decommissioned @@ -204,14 +203,10 @@ async def test_decommission_issuer_registries(self): filter(lambda r: r.state == IssuerRevRegRecord.STATE_DECOMMISSIONED, recs) ) assert len(decomm_list) == 2 - decomm_rev_reg_ids = [ - rec.revoc_reg_id for rec in decomm_list if rec.revoc_reg_id - ] + decomm_rev_reg_ids = [rec.revoc_reg_id for rec in decomm_list if rec.revoc_reg_id] # new ones replacing the decommissioned are in init state - init_list = list( - filter(lambda r: r.state == IssuerRevRegRecord.STATE_INIT, recs) - ) + init_list = list(filter(lambda r: r.state == IssuerRevRegRecord.STATE_INIT, recs)) assert len(init_list) == 2 # check that the original rev reg ids are decommissioned @@ -295,6 +290,19 @@ async def test_get_or_create_active_registry_has_no_active_and_only_full_registi assert not result assert self.revoc.init_issuer_registry.call_args.kwargs["max_cred_num"] == 3 + @mock.patch( + "aries_cloudagent.revocation.indy.IndyRevocation.get_active_issuer_rev_reg_record", + mock.CoroutineMock(side_effect=StorageNotFoundError("No such record")), + ) + @mock.patch( + "aries_cloudagent.revocation.indy.IndyRevocation.init_issuer_registry", + mock.CoroutineMock(return_value=None), + ) + @mock.patch.object(IssuerRevRegRecord, "query_by_cred_def_id", side_effect=[[], []]) + async def test_get_or_create_active_registry_has_no_active_or_any_registry(self, *_): + with self.assertRaises(RevocationError): + await self.revoc.get_or_create_active_registry("cred_def_id") + @mock.patch( "aries_cloudagent.revocation.indy.IndyRevocation.get_active_issuer_rev_reg_record", mock.CoroutineMock(side_effect=StorageNotFoundError("No such record")),