Skip to content

Commit

Permalink
fix: endorser manager should use context.conn
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Jul 22, 2024
1 parent cd59ccc commit a79890b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 30 deletions.
20 changes: 5 additions & 15 deletions aries_cloudagent/protocols/endorse_transaction/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 == {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -826,19 +819,19 @@ 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()
) as mock_retrieve:
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")
Expand Down

0 comments on commit a79890b

Please sign in to comment.