Skip to content

Commit

Permalink
Resolved Merged Conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Multani <[email protected]>
  • Loading branch information
HarshMultani-AyanWorks committed May 7, 2021
1 parent 6fbfbbd commit a22c0b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 47 deletions.
40 changes: 2 additions & 38 deletions aries_cloudagent/protocols/endorse_transaction/v1_0/routes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

"""Endorse Transaction handling admin routes."""

from aiohttp import web
Expand Down Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand All @@ -725,24 +696,20 @@ 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(
ledger.txn_submit(ledger_transaction, sign=False, taa_accept=False)
)
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":
Expand All @@ -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:
Expand All @@ -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"]
Expand All @@ -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
Expand Down Expand Up @@ -846,4 +810,4 @@ def post_process_routes(app: web.Application):
"name": "endorse-transaction",
"description": "Endorse a Transaction",
}
)
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import json

from asynctest import mock as async_mock, TestCase as AsyncTestCase
Expand Down Expand Up @@ -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({"...": "..."})
"""

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
"""
Expand Down Expand Up @@ -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"]

0 comments on commit a22c0b6

Please sign in to comment.