From a22c0b6c83a670c6d035b9259f3bfc1f6cf2c06a Mon Sep 17 00:00:00 2001 From: Harsh Multani Date: Sat, 8 May 2021 00:55:28 +0530 Subject: [PATCH] Resolved Merged Conflicts Signed-off-by: Harsh Multani --- .../endorse_transaction/v1_0/routes.py | 40 +------------------ .../v1_0/tests/test_routes.py | 11 +---- 2 files changed, 4 insertions(+), 47 deletions(-) diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py index 39da9932ea..c78d5ae450 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py @@ -1,3 +1,4 @@ + """Endorse Transaction handling admin routes.""" from aiohttp import web @@ -118,13 +119,10 @@ class EndorserInfoSchema(OpenAPISchema): async def transactions_list(request: web.BaseRequest): """ Request handler for searching transaction records. - Args: request: aiohttp request object - Returns: The transaction list response - """ context: AdminRequestContext = request["context"] @@ -150,13 +148,10 @@ async def transactions_list(request: web.BaseRequest): async def transactions_retrieve(request: web.BaseRequest): """ Request handler for fetching a single transaction record. - Args: request: aiohttp request object - Returns: The transaction record response - """ context: AdminRequestContext = request["context"] @@ -186,13 +181,10 @@ async def transactions_retrieve(request: web.BaseRequest): async def transaction_create_request(request: web.BaseRequest): """ Request handler for creating a new transaction record and request. - Args: request: aiohttp request object - Returns: The transaction record - """ context: AdminRequestContext = request["context"] @@ -268,13 +260,10 @@ async def transaction_create_request(request: web.BaseRequest): async def endorse_transaction_response(request: web.BaseRequest): """ Request handler for creating an endorsed transaction response. - Args: request: aiohttp request object - Returns: The updated transaction record details - """ context: AdminRequestContext = request["context"] @@ -372,13 +361,10 @@ async def endorse_transaction_response(request: web.BaseRequest): async def refuse_transaction_response(request: web.BaseRequest): """ Request handler for creating a refused transaction response. - Args: request: aiohttp request object - Returns: The updated transaction record details - """ context: AdminRequestContext = request["context"] @@ -453,13 +439,10 @@ async def refuse_transaction_response(request: web.BaseRequest): async def cancel_transaction(request: web.BaseRequest): """ Request handler for cancelling a Transaction request. - Args: request: aiohttp request object - Returns: The updated transaction record details - """ context: AdminRequestContext = request["context"] @@ -520,13 +503,10 @@ async def cancel_transaction(request: web.BaseRequest): async def transaction_resend(request: web.BaseRequest): """ Request handler for resending a transaction request. - Args: request: aiohttp request object - Returns: The updated transaction record details - """ context: AdminRequestContext = request["context"] @@ -588,13 +568,10 @@ async def transaction_resend(request: web.BaseRequest): async def set_endorser_role(request: web.BaseRequest): """ Request handler for assigning transaction jobs. - Args: request: aiohttp request object - Returns: The assigned transaction jobs - """ context: AdminRequestContext = request["context"] @@ -630,13 +607,10 @@ async def set_endorser_role(request: web.BaseRequest): async def set_endorser_info(request: web.BaseRequest): """ Request handler for assigning endorser information. - Args: request: aiohttp request object - Returns: The assigned endorser information - """ context: AdminRequestContext = request["context"] @@ -695,13 +669,10 @@ async def set_endorser_info(request: web.BaseRequest): async def transaction_write(request: web.BaseRequest): """ Request handler for writing an endorsed transaction to the ledger. - Args: request: aiohttp request object - Returns: The returned ledger response - """ context: AdminRequestContext = request["context"] @@ -725,14 +696,12 @@ async def transaction_write(request: web.BaseRequest): """ ledger_transaction = transaction.messages_attach[0]["data"]["json"] - ledger = context.inject(BaseLedger, required=False) if not ledger: reason = "No ledger available" if not context.settings.get_value("wallet.type"): reason += ": missing wallet-type?" raise web.HTTPForbidden(reason=reason) - async with ledger: try: ledger_response_json = await shield( @@ -740,9 +709,7 @@ async def transaction_write(request: web.BaseRequest): ) except (IndyIssuerError, LedgerError) as err: raise web.HTTPBadRequest(reason=err.roll_up) from err - ledger_response = json.loads(ledger_response_json) - # write the wallet non-secrets record # TODO refactor this code (duplicated from ledger.indy.py) if ledger_response["result"]["txn"]["type"] == "101": @@ -762,7 +729,6 @@ async def transaction_write(request: web.BaseRequest): async with ledger: storage = ledger.get_indy_storage() await storage.add_record(record) - elif ledger_response["result"]["txn"]["type"] == "102": # cred def transaction async with ledger: @@ -771,7 +737,6 @@ async def transaction_write(request: web.BaseRequest): schema_response = await shield(ledger.get_schema(schema_seq_no)) except (IndyIssuerError, LedgerError) as err: raise web.HTTPBadRequest(reason=err.roll_up) from err - schema_id = schema_response["id"] schema_id_parts = schema_id.split(":") public_did = ledger_response["result"]["txn"]["metadata"]["from"] @@ -792,7 +757,6 @@ async def transaction_write(request: web.BaseRequest): async with ledger: storage = ledger.get_indy_storage() await storage.add_record(record) - else: # TODO unknown ledger transaction type, just ignore for now ... pass @@ -846,4 +810,4 @@ def post_process_routes(app: web.Application): "name": "endorse-transaction", "description": "Endorse a Transaction", } - ) + ) \ No newline at end of file diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py index d1f754c7ad..764bd144d8 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py @@ -1,3 +1,4 @@ + import json from asynctest import mock as async_mock, TestCase as AsyncTestCase @@ -1486,7 +1487,6 @@ async def test_transaction_write_schema_txn(self): ], ) await test_module.transaction_write(self.request) - mock_response.assert_called_once_with({"...": "..."}) """ @@ -1613,10 +1613,8 @@ async def test_transaction_write_no_ledger_x(self): {"data": {"json": json.dumps({"message": "attached"})}} ], ) - with self.assertRaises(test_module.web.HTTPForbidden): await test_module.transaction_write(self.request) - async def test_transaction_write_ledger_txn_submit_x(self): self.request.match_info = {"tran_id": "dummy"} self.ledger.txn_submit = async_mock.CoroutineMock( @@ -1646,10 +1644,8 @@ async def test_transaction_write_ledger_txn_submit_x(self): {"data": {"json": json.dumps({"message": "attached"})}} ], ) - with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.transaction_write(self.request) - async def test_transaction_write_cred_def_txn(self): self.request.match_info = {"tran_id": "dummy"} self.ledger.txn_submit = async_mock.CoroutineMock( @@ -1702,9 +1698,7 @@ async def test_transaction_write_cred_def_txn(self): ], ) await test_module.transaction_write(self.request) - mock_response.assert_called_once_with({"...": "..."}) - async def test_transaction_write_ledger_cred_def_txn_ledger_get_schema_x(self): self.request.match_info = {"tran_id": "dummy"} self.ledger.txn_submit = async_mock.CoroutineMock( @@ -1748,7 +1742,6 @@ async def test_transaction_write_ledger_cred_def_txn_ledger_get_schema_x(self): {"data": {"json": json.dumps({"message": "attached"})}} ], ) - with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.transaction_write(self.request) """ @@ -1801,4 +1794,4 @@ async def test_post_process_routes(self): mock_app = async_mock.MagicMock(_state={"swagger_dict": {"paths": {}}}) test_module.post_process_routes(mock_app) - assert "tags" in mock_app._state["swagger_dict"] + assert "tags" in mock_app._state["swagger_dict"] \ No newline at end of file