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

Revert change to send_credential_ack return value #1660

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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