From e184a23c18c12ee0539d002b556425bfcdf27d25 Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Thu, 16 Apr 2020 18:14:57 -0700 Subject: [PATCH] contain references to indy package, IndyError class Signed-off-by: Andrew Whitehead --- aries_cloudagent/holder/indy.py | 17 ++++++++-------- .../issue_credential/v1_0/manager.py | 20 ++++++++----------- .../v1_0/tests/test_manager.py | 4 ++-- .../protocols/present_proof/v1_0/manager.py | 14 ++++++------- .../present_proof/v1_0/tests/test_manager.py | 18 ++++++++--------- 5 files changed, 34 insertions(+), 39 deletions(-) diff --git a/aries_cloudagent/holder/indy.py b/aries_cloudagent/holder/indy.py index d19a9c14ed..85331f1269 100644 --- a/aries_cloudagent/holder/indy.py +++ b/aries_cloudagent/holder/indy.py @@ -366,13 +366,14 @@ async def create_revocation_state( """ - tails_file_reader = await create_tails_reader(tails_file_path) - rev_state_json = await indy.anoncreds.create_revocation_state( - tails_file_reader, - rev_reg_def_json=json.dumps(rev_reg_def), - cred_rev_id=cred_rev_id, - rev_reg_delta_json=json.dumps(rev_reg_delta), - timestamp=timestamp, - ) + with IndyErrorHandler("Error when constructing revocation state", HolderError): + tails_file_reader = await create_tails_reader(tails_file_path) + rev_state_json = await indy.anoncreds.create_revocation_state( + tails_file_reader, + rev_reg_def_json=json.dumps(rev_reg_def), + cred_rev_id=cred_rev_id, + rev_reg_delta_json=json.dumps(rev_reg_delta), + timestamp=timestamp, + ) return rev_state_json diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/manager.py b/aries_cloudagent/protocols/issue_credential/v1_0/manager.py index ab76081c0c..81ae6f9a93 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/manager.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/manager.py @@ -4,8 +4,6 @@ import logging from typing import Mapping, Text, Sequence, Tuple -from indy.error import IndyError - from .messages.credential_ack import CredentialAck from .messages.credential_issue import CredentialIssue from .messages.credential_offer import CredentialOffer @@ -16,7 +14,7 @@ from ....cache.base import BaseCache from ....config.injection_context import InjectionContext from ....core.error import BaseError -from ....holder.base import BaseHolder +from ....holder.base import BaseHolder, HolderError from ....issuer.base import BaseIssuer from ....issuer.indy import IssuerRevocationRegistryFullError from ....ledger.base import BaseLedger @@ -156,9 +154,7 @@ async def create_proposal( cred_def_id=cred_def_id, issuer_did=issuer_did, ) - credential_proposal_message.assign_trace_decorator( - self.context.settings, trace, - ) + credential_proposal_message.assign_trace_decorator(self.context.settings, trace) if auto_remove is None: auto_remove = not self.context.settings.get("preserve_exchange_records") @@ -231,7 +227,7 @@ async def create_offer( credential_exchange_record.credential_proposal_dict ) credential_proposal_message.assign_trace_decorator( - self.context.settings, credential_exchange_record.trace, + self.context.settings, credential_exchange_record.trace ) cred_def_id = await self._match_sent_cred_def_id( { @@ -274,7 +270,7 @@ async def _create(cred_def_id): "thid": credential_exchange_record.thread_id } credential_offer_message.assign_trace_decorator( - self.context.settings, credential_exchange_record.trace, + self.context.settings, credential_exchange_record.trace ) credential_exchange_record.thread_id = credential_offer_message._thread_id @@ -422,7 +418,7 @@ async def _create(): "thid": credential_exchange_record.thread_id } credential_request_message.assign_trace_decorator( - self.context.settings, credential_exchange_record.trace, + self.context.settings, credential_exchange_record.trace ) credential_exchange_record.state = V10CredentialExchange.STATE_REQUEST_SENT @@ -560,7 +556,7 @@ async def issue_credential( ) credential_message._thread = {"thid": credential_exchange_record.thread_id} credential_message.assign_trace_decorator( - self.context.settings, credential_exchange_record.trace, + self.context.settings, credential_exchange_record.trace ) return (credential_exchange_record, credential_message) @@ -655,7 +651,7 @@ async def store_credential( credential_id=credential_id, rev_reg_def=revoc_reg_def, ) - except IndyError as e: + except HolderError as e: self._logger.error(f"Error storing credential. {e.error_code}: {e.message}") raise e @@ -676,7 +672,7 @@ async def store_credential( credential_exchange_record.parent_thread_id, ) credential_ack_message.assign_trace_decorator( - self.context.settings, credential_exchange_record.trace, + self.context.settings, credential_exchange_record.trace ) if credential_exchange_record.auto_remove: diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py index acc1f0911f..90a3fd241d 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py @@ -1084,11 +1084,11 @@ async def test_store_credential_holder_store_indy_error(self): cred_id = "cred-id" holder = async_mock.MagicMock() holder.store_credential = async_mock.CoroutineMock( - side_effect=test_module.IndyError(706, {"message": "Nope"}) + side_effect=test_module.HolderError(706, {"message": "Nope"}) ) self.context.injector.bind_instance(BaseHolder, holder) - with self.assertRaises(test_module.IndyError): + with self.assertRaises(test_module.HolderError): await self.manager.store_credential( credential_exchange_record=stored_exchange, credential_id=cred_id ) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/manager.py b/aries_cloudagent/protocols/present_proof/v1_0/manager.py index 229a147474..52f06b50e2 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/manager.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/manager.py @@ -4,12 +4,10 @@ import logging import time -from indy.error import IndyError - from ....revocation.models.revocation_registry import RevocationRegistry from ....config.injection_context import InjectionContext from ....core.error import BaseError -from ....holder.base import BaseHolder +from ....holder.base import BaseHolder, HolderError from ....ledger.base import BaseLedger from ....messaging.decorators.attach_decorator import AttachDecorator from ....messaging.responder import BaseResponder @@ -158,7 +156,7 @@ async def create_bound_request( "thid": presentation_exchange_record.thread_id } presentation_request_message.assign_trace_decorator( - self.context.settings, presentation_exchange_record.trace, + self.context.settings, presentation_exchange_record.trace ) presentation_exchange_record.thread_id = presentation_request_message._thread_id @@ -283,7 +281,7 @@ async def create_presentation( req_preds = presentation_request.get("requested_predicates", {}) for referent in preds_creds: requested_referents[referent] = { - "cred_id": preds_creds[referent]["cred_id"], + "cred_id": preds_creds[referent]["cred_id"] } if referent in req_preds and "non_revoked" in req_preds[referent]: requested_referents[referent]["non_revoked"] = req_preds[referent][ @@ -389,7 +387,7 @@ async def create_presentation( tails_local_path, ) ) - except IndyError as e: + except HolderError as e: self._logger.error( f"Failed to create revocation state: {e.error_code}, {e.message}" ) @@ -427,7 +425,7 @@ async def create_presentation( presentation_message._thread = {"thid": presentation_exchange_record.thread_id} presentation_message.assign_trace_decorator( - self.context.settings, presentation_exchange_record.trace, + self.context.settings, presentation_exchange_record.trace ) # save presentation exchange state @@ -604,7 +602,7 @@ async def send_presentation_ack( "thid": presentation_exchange_record.thread_id } presentation_ack_message.assign_trace_decorator( - self.context.settings, presentation_exchange_record.trace, + self.context.settings, presentation_exchange_record.trace ) await responder.send_reply(presentation_ack_message) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py index a1e013f9e9..71e18ccef7 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py @@ -83,7 +83,7 @@ async def setUp(self): "value": { "IssuanceType": "ISSUANCE_BY_DEFAULT", "maxCredNum": 1000, - "publicKeys": {"accumKey": {"z": "1 ...",}}, + "publicKeys": {"accumKey": {"z": "1 ..."}}, "tailsHash": "3MLjUFQz9x9n5u9rFu8Ba9C5bo4HNFjkPNc54jZPSNaZ", "tailsLocation": "http://sample.ca/path", }, @@ -438,7 +438,7 @@ async def test_create_presentation_bad_revoc_state(self): ) self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") self.holder.create_revocation_state = async_mock.CoroutineMock( - side_effect=test_module.IndyError(706, {"message": "Nope"}) + side_effect=test_module.HolderError(706, {"message": "Nope"}) ) self.context.injector.clear_binding(BaseHolder) self.context.injector.bind_instance(BaseHolder, self.holder) @@ -465,7 +465,7 @@ async def test_create_presentation_bad_revoc_state(self): indy_proof_req, holder=self.holder ) - with self.assertRaises(test_module.IndyError): + with self.assertRaises(test_module.HolderError): await self.manager.create_presentation(exchange_in, req_creds) async def test_no_matching_creds_for_proof_req(self): @@ -514,11 +514,11 @@ async def test_receive_presentation(self): "requested_attributes": { "0_favourite_uuid": { "name": "favourite", - "restrictions": [{"cred_def_id": CD_ID,}], + "restrictions": [{"cred_def_id": CD_ID}], }, "1_icon_uuid": { "name": "icon", - "restrictions": [{"cred_def_id": CD_ID,}], + "restrictions": [{"cred_def_id": CD_ID}], }, }, }, @@ -608,11 +608,11 @@ async def test_receive_presentation_bait_and_switch(self): "requested_attributes": { "0_favourite_uuid": { "name": "favourite", - "restrictions": [{"cred_def_id": CD_ID,}], + "restrictions": [{"cred_def_id": CD_ID}], }, "1_icon_uuid": { "name": "icon", - "restrictions": [{"cred_def_id": CD_ID,}], + "restrictions": [{"cred_def_id": CD_ID}], }, }, }, @@ -620,7 +620,7 @@ async def test_receive_presentation_bait_and_switch(self): self.context.message = async_mock.MagicMock() self.context.message.indy_proof = async_mock.MagicMock( return_value={ - "proof": {"proofs": [],}, + "proof": {"proofs": []}, "requested_proof": { "revealed_attrs": { "0_favourite_uuid": { @@ -676,7 +676,7 @@ async def test_receive_presentation_connection_less(self): retrieve_ex.return_value = exchange_dummy exchange_out = await self.manager.receive_presentation() retrieve_ex.assert_called_once_with( - self.context, {"thread_id": self.context.message._thread_id}, None, + self.context, {"thread_id": self.context.message._thread_id}, None ) save_ex.assert_called_once()