From a79890b2ddb54a9b31d1b3630b1f851c51fe59d0 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Mon, 22 Jul 2024 15:47:32 -0400 Subject: [PATCH] fix: endorser manager should use context.conn Signed-off-by: Daniel Bluhm --- .../endorse_transaction/v1_0/manager.py | 20 ++++------------ .../v1_0/tests/test_manager.py | 23 +++++++------------ 2 files changed, 13 insertions(+), 30 deletions(-) diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py index 13e7ad0386..48971bbac2 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py @@ -21,7 +21,6 @@ notify_revocation_reg_endorsed_event, ) from ....storage.error import StorageError, StorageNotFoundError -from ....transport.inbound.receipt import MessageReceipt from ....wallet.base import BaseWallet from ....wallet.util import notify_endorse_did_attrib_event, notify_endorse_did_event from .messages.cancel_transaction import CancelTransaction @@ -310,9 +309,7 @@ async def create_endorse_response( ) # we don't have an endorsed transaction so just return did meta-data ledger_response = { - "result": { - "txn": {"type": "1", "data": {"dest": meta_data["did"]}} - }, + "result": {"txn": {"type": "1", "data": {"dest": meta_data["did"]}}}, "meta_data": meta_data, } endorsed_msg = json.dumps(ledger_response) @@ -430,9 +427,7 @@ async def complete_transaction( # if we are the author, we need to write the endorsed ledger transaction ... # ... EXCEPT for DID transactions, which the endorser will write - if (not endorser) and ( - txn_goal_code != TransactionRecord.WRITE_DID_TRANSACTION - ): + if (not endorser) and (txn_goal_code != TransactionRecord.WRITE_DID_TRANSACTION): ledger = self.profile.inject(BaseLedger) if not ledger: raise TransactionManagerError("No ledger available") @@ -772,20 +767,17 @@ async def set_transaction_my_job(self, record: ConnRecord, transaction_my_job: s return tx_job_to_send async def set_transaction_their_job( - self, tx_job_received: TransactionJobToSend, receipt: MessageReceipt + self, tx_job_received: TransactionJobToSend, connection: ConnRecord ): """Set transaction_their_job. Args: tx_job_received: The transaction job that is received from the other agent - receipt: The Message Receipt Object + connection: connection to set metadata on """ try: async with self._profile.session() as session: - connection = await ConnRecord.retrieve_by_did( - session, receipt.sender_did, receipt.recipient_did - ) value = await connection.metadata_get(session, "transaction_jobs") if value: value["transaction_their_job"] = tx_job_received.job @@ -893,9 +885,7 @@ async def endorsed_txn_post_processing( elif ledger_response["result"]["txn"]["type"] == "114": # revocation entry transaction rev_reg_id = ledger_response["result"]["txn"]["data"]["revocRegDefId"] - revoked = ledger_response["result"]["txn"]["data"]["value"].get( - "revoked", [] - ) + revoked = ledger_response["result"]["txn"]["data"]["value"].get("revoked", []) meta_data["context"]["rev_reg_id"] = rev_reg_id if is_anoncreds: await AnonCredsRevocation(self._profile).finish_revocation_list( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py index 87ea1ceff7..bc9aca3b63 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py @@ -157,9 +157,7 @@ async def test_create_record(self): transaction_record.messages_attach[0]["data"]["json"] == self.test_messages_attach ) - assert ( - transaction_record.state == TransactionRecord.STATE_TRANSACTION_CREATED - ) + assert transaction_record.state == TransactionRecord.STATE_TRANSACTION_CREATED async def test_txn_rec_retrieve_by_connection_and_thread_caching(self): async with self.profile.session() as sesn: @@ -604,8 +602,7 @@ async def test_create_refuse_response(self): assert transaction_record.state == TransactionRecord.STATE_TRANSACTION_REFUSED assert ( - refused_transaction_response.transaction_id - == self.test_author_transaction_id + refused_transaction_response.transaction_id == self.test_author_transaction_id ) assert refused_transaction_response.thread_id == transaction_record._id assert refused_transaction_response.signature_response == { @@ -641,9 +638,7 @@ async def test_receive_refuse_response(self): mock_response.endorser_did = self.test_refuser_did with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: - transaction_record = await self.manager.receive_refuse_response( - mock_response - ) + transaction_record = await self.manager.receive_refuse_response(mock_response) save_record.assert_called_once() assert transaction_record._type == TransactionRecord.SIGNATURE_RESPONSE @@ -689,9 +684,7 @@ async def test_cancel_transaction(self): assert transaction_record.state == TransactionRecord.STATE_TRANSACTION_CANCELLED - assert ( - cancelled_transaction_response.thread_id == self.test_author_transaction_id - ) + assert cancelled_transaction_response.thread_id == self.test_author_transaction_id assert ( cancelled_transaction_response.state == TransactionRecord.STATE_TRANSACTION_CANCELLED @@ -810,7 +803,7 @@ async def test_set_transaction_my_job(self): async def test_set_transaction_their_job(self): mock_job = mock.MagicMock() - mock_receipt = mock.MagicMock() + mock_conn = mock.MagicMock() with mock.patch.object( ConnRecord, "retrieve_by_did", mock.CoroutineMock() @@ -826,11 +819,11 @@ async def test_set_transaction_their_job(self): ) for i in range(2): - await self.manager.set_transaction_their_job(mock_job, mock_receipt) + await self.manager.set_transaction_their_job(mock_job, mock_conn) async def test_set_transaction_their_job_conn_not_found(self): mock_job = mock.MagicMock() - mock_receipt = mock.MagicMock() + mock_conn = mock.MagicMock() with mock.patch.object( ConnRecord, "retrieve_by_did", mock.CoroutineMock() @@ -838,7 +831,7 @@ async def test_set_transaction_their_job_conn_not_found(self): mock_retrieve.side_effect = StorageNotFoundError() with self.assertRaises(TransactionManagerError): - await self.manager.set_transaction_their_job(mock_job, mock_receipt) + await self.manager.set_transaction_their_job(mock_job, mock_conn) @mock.patch.object(AnonCredsIssuer, "finish_schema") @mock.patch.object(AnonCredsIssuer, "finish_cred_def")