Skip to content

Commit

Permalink
Merge pull request #463 from andrewwhitehead/fix/without-indy
Browse files Browse the repository at this point in the history
Contain references to indy package, IndyError class
  • Loading branch information
swcurran authored Apr 17, 2020
2 parents 7169190 + e184a23 commit c1f453e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 39 deletions.
17 changes: 9 additions & 8 deletions aries_cloudagent/holder/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 8 additions & 12 deletions aries_cloudagent/protocols/issue_credential/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
14 changes: 6 additions & 8 deletions aries_cloudagent/protocols/present_proof/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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][
Expand Down Expand Up @@ -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}"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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}],
},
},
},
Expand Down Expand Up @@ -608,19 +608,19 @@ 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}],
},
},
},
)
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": {
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit c1f453e

Please sign in to comment.