Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "sent" key to both Schema and Cred Defs when using Endorsers #1663

18 changes: 16 additions & 2 deletions aries_cloudagent/messaging/credential_definitions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
23 changes: 20 additions & 3 deletions aries_cloudagent/messaging/schemas/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down
20 changes: 19 additions & 1 deletion aries_cloudagent/messaging/schemas/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down