Skip to content

Commit

Permalink
Merge pull request #1660 from andrewwhitehead/fix/send-cred-ack
Browse files Browse the repository at this point in the history
Revert change to send_credential_ack return value
  • Loading branch information
swcurran authored Mar 10, 2022
2 parents b5ac76e + 44e4828 commit 681e9aa
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
)
)

credential_ack_message = await credential_manager.send_credential_ack(
(_, credential_ack_message) = await credential_manager.send_credential_ack(
cred_ex_record
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ async def test_called_auto_store(self):
receive_credential=async_mock.CoroutineMock(),
store_credential=async_mock.CoroutineMock(),
send_credential_ack=async_mock.CoroutineMock(
return_value="credential_ack_message"
return_value=(
async_mock.CoroutineMock(),
async_mock.CoroutineMock(),
)
),
)
request_context.message = CredentialIssue()
Expand Down Expand Up @@ -78,7 +81,12 @@ async def test_called_auto_store_x(self):
store_credential=async_mock.CoroutineMock(
side_effect=test_module.IndyHolderError()
),
send_credential_ack=async_mock.CoroutineMock(),
send_credential_ack=async_mock.CoroutineMock(
return_value=(
async_mock.CoroutineMock(),
async_mock.CoroutineMock(),
)
),
)

request_context.message = CredentialIssue()
Expand Down
11 changes: 6 additions & 5 deletions aries_cloudagent/protocols/issue_credential/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,14 +877,15 @@ async def store_credential(
async def send_credential_ack(
self,
cred_ex_record: V10CredentialExchange,
):
) -> Tuple[V10CredentialExchange, CredentialAck]:
"""
Create, send, and return ack message for input credential exchange record.
Delete credential exchange record if set to auto-remove.
Returns:
credential ack message for tracing
a tuple of the updated credential exchange record
and the credential ack message for tracing
"""
credential_ack_message = CredentialAck()
Expand All @@ -906,7 +907,7 @@ async def send_credential_ack(
"Skipping credential exchange ack, record not found: '%s'",
cred_ex_record.credential_exchange_id,
)
return None
return (cred_ex_record, None)

if (
cred_ex_record.state
Expand All @@ -917,7 +918,7 @@ async def send_credential_ack(
cred_ex_record.state,
cred_ex_record.credential_exchange_id,
)
return None
return (cred_ex_record, None)

cred_ex_record.state = V10CredentialExchange.STATE_ACKED
await cred_ex_record.save(txn, reason="ack credential")
Expand All @@ -944,7 +945,7 @@ async def send_credential_ack(
cred_ex_record.thread_id,
)

return credential_ack_message
return (cred_ex_record, credential_ack_message)

async def receive_credential_ack(
self, message: CredentialAck, connection_id: str
Expand Down
7 changes: 4 additions & 3 deletions aries_cloudagent/protocols/issue_credential/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,9 +1183,10 @@ async def credential_exchange_store(request: web.BaseRequest):
)

try: # protocol owes an ack
credential_ack_message = await credential_manager.send_credential_ack(
cred_ex_record
)
(
cred_ex_record,
credential_ack_message,
) = await credential_manager.send_credential_ack(cred_ex_record)
result = cred_ex_record.serialize() # pick up state done

except (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1615,15 +1615,17 @@ async def test_send_credential_ack(self):
test_module.LOGGER, "warning", async_mock.MagicMock()
) as mock_log_warning:
mock_delete_ex.side_effect = test_module.StorageError()
ack = await self.manager.send_credential_ack(stored_exchange)
(exch, ack) = await self.manager.send_credential_ack(stored_exchange)
assert ack._thread
mock_log_exception.assert_called_once() # cover exception log-and-continue
mock_log_warning.assert_called_once() # no BaseResponder
assert exch.state == V10CredentialExchange.STATE_ACKED

mock_responder = MockResponder() # cover with responder
self.context.injector.bind_instance(BaseResponder, mock_responder)
ack = await self.manager.send_credential_ack(stored_exchange)
(exch, ack) = await self.manager.send_credential_ack(stored_exchange)
assert ack._thread
assert exch.state == V10CredentialExchange.STATE_ACKED

async def test_receive_credential_ack(self):
connection_id = "connection-id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,8 @@ async def test_credential_exchange_store(self):
mock_cred_ex_record
)
mock_credential_manager.return_value.send_credential_ack.return_value = (
async_mock.MagicMock()
mock_cred_ex_record,
async_mock.MagicMock(),
)

await test_module.credential_exchange_store(self.request)
Expand Down Expand Up @@ -1223,7 +1224,8 @@ async def test_credential_exchange_store_bad_cred_id_json(self):
mock_cred_ex_record
)
mock_credential_manager.return_value.send_credential_ack.return_value = (
async_mock.MagicMock()
mock_cred_ex_record,
async_mock.MagicMock(),
)

await test_module.credential_exchange_store(self.request)
Expand Down Expand Up @@ -1276,7 +1278,8 @@ async def test_credential_exchange_store_no_conn_record(self):
mock_cred_ex
)
mock_credential_manager.return_value.send_credential_ack.return_value = (
async_mock.MagicMock()
mock_cred_ex,
async_mock.MagicMock(),
)

with self.assertRaises(test_module.web.HTTPBadRequest):
Expand Down Expand Up @@ -1336,7 +1339,7 @@ async def test_credential_exchange_store_x(self):
return_value=mock_cred_ex_record
),
send_credential_ack=async_mock.CoroutineMock(
return_value=async_mock.MagicMock()
return_value=(mock_cred_ex_record, async_mock.MagicMock())
),
)

Expand Down

0 comments on commit 681e9aa

Please sign in to comment.