diff --git a/aries_cloudagent/messaging/credential_definitions/routes.py b/aries_cloudagent/messaging/credential_definitions/routes.py index 26694483e4..1603c76cd1 100644 --- a/aries_cloudagent/messaging/credential_definitions/routes.py +++ b/aries_cloudagent/messaging/credential_definitions/routes.py @@ -269,8 +269,17 @@ async def credential_definitions_send_credential_definition(request: web.BaseReq meta_data["processing"]["auto_create_rev_reg"] = True await notify_cred_def_event(context.profile, cred_def_id, meta_data) - return web.json_response({"credential_definition_id": cred_def_id}) + return web.json_response( + { + "sent": {"credential_definition_id": cred_def_id}, + "credential_definition_id": cred_def_id, + } + ) + # If the transaction is for the endorser, but the schema has already been created, + # then we send back the schema since the transaction will fail to be created. + elif "signed_txn" not in cred_def: + return web.json_response({"sent": {"credential_definition_id": cred_def_id}}) else: meta_data["processing"]["auto_create_rev_reg"] = context.settings.get_value( "endorser.auto_create_rev_reg" @@ -300,7 +309,12 @@ async def credential_definitions_send_credential_definition(request: web.BaseReq await outbound_handler(transaction_request, connection_id=connection_id) - return web.json_response({"txn": transaction.serialize()}) + return web.json_response( + { + "sent": {"credential_definition_id": cred_def_id}, + "txn": transaction.serialize(), + } + ) @docs( diff --git a/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py b/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py index a1e72ddf6e..953f185d73 100644 --- a/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py +++ b/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py @@ -81,7 +81,10 @@ async def test_send_credential_definition(self): ) assert result == mock_response.return_value mock_response.assert_called_once_with( - {"credential_definition_id": CRED_DEF_ID} + { + "sent": {"credential_definition_id": CRED_DEF_ID}, + "credential_definition_id": CRED_DEF_ID, + } ) async def test_send_credential_definition_create_transaction_for_endorser(self): @@ -126,7 +129,12 @@ async def test_send_credential_definition_create_transaction_for_endorser(self): ) ) assert result == mock_response.return_value - mock_response.assert_called_once_with({"txn": {"...": "..."}}) + mock_response.assert_called_once_with( + { + "sent": {"credential_definition_id": CRED_DEF_ID}, + "txn": {"...": "..."}, + } + ) async def test_send_credential_definition_create_transaction_for_endorser_storage_x( self, diff --git a/aries_cloudagent/messaging/schemas/routes.py b/aries_cloudagent/messaging/schemas/routes.py index 5c7c6eb7fb..9a44dddbcf 100644 --- a/aries_cloudagent/messaging/schemas/routes.py +++ b/aries_cloudagent/messaging/schemas/routes.py @@ -259,8 +259,20 @@ async def schemas_send_schema(request: web.BaseRequest): if not create_transaction_for_endorser: # Notify event await notify_schema_event(context.profile, schema_id, meta_data) - return web.json_response({"schema_id": schema_id, "schema": schema_def}) - + return web.json_response( + { + "sent": {"schema_id": schema_id, "schema": schema_def}, + "schema_id": schema_id, + "schema": schema_def, + } + ) + + # If the transaction is for the endorser, but the schema has already been created, + # then we send back the schema since the transaction will fail to be created. + elif "signed_txn" not in schema_def: + return web.json_response( + {"sent": {"schema_id": schema_id, "schema": schema_def}} + ) else: transaction_mgr = TransactionManager(context.profile) try: @@ -286,7 +298,12 @@ async def schemas_send_schema(request: web.BaseRequest): await outbound_handler(transaction_request, connection_id=connection_id) - return web.json_response({"txn": transaction.serialize()}) + return web.json_response( + { + "sent": {"schema_id": schema_id, "schema": schema_def}, + "txn": transaction.serialize(), + } + ) @docs( diff --git a/aries_cloudagent/messaging/schemas/tests/test_routes.py b/aries_cloudagent/messaging/schemas/tests/test_routes.py index ff445535ff..74b9f79e82 100644 --- a/aries_cloudagent/messaging/schemas/tests/test_routes.py +++ b/aries_cloudagent/messaging/schemas/tests/test_routes.py @@ -70,6 +70,13 @@ async def test_send_schema(self): assert result == mock_response.return_value mock_response.assert_called_once_with( { + "sent": { + "schema_id": SCHEMA_ID, + "schema": { + "schema": "def", + "signed_txn": "...", + }, + }, "schema_id": SCHEMA_ID, "schema": { "schema": "def", @@ -116,7 +123,18 @@ async def test_send_schema_create_transaction_for_endorser(self): ) result = await test_module.schemas_send_schema(self.request) assert result == mock_response.return_value - mock_response.assert_called_once_with({"txn": {"...": "..."}}) + mock_response.assert_called_once_with( + { + "sent": { + "schema_id": SCHEMA_ID, + "schema": { + "schema": "def", + "signed_txn": "...", + }, + }, + "txn": {"...": "..."}, + } + ) async def test_send_schema_create_transaction_for_endorser_storage_x(self): self.request.json = async_mock.CoroutineMock(