diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/credential_issue_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/credential_issue_handler.py index 938d2a2a1f..9048311cfe 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/credential_issue_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/credential_issue_handler.py @@ -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 ) diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py index 8e07df1ce7..f7c8d490c4 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py @@ -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() @@ -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() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/manager.py b/aries_cloudagent/protocols/issue_credential/v1_0/manager.py index bc11f4995e..7934d1725d 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/manager.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/manager.py @@ -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() @@ -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 @@ -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") @@ -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 diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/routes.py b/aries_cloudagent/protocols/issue_credential/v1_0/routes.py index abe70b2d96..fd8c7b3f59 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/routes.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/routes.py @@ -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 ( 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 68ad3d7c3b..6e3df6387e 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 @@ -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" diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py index 0fe2cf8d78..280f19ce05 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py @@ -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) @@ -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) @@ -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): @@ -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()) ), )