From 8415ad96581a0a59129c0a060246ad6ac5f07ba0 Mon Sep 17 00:00:00 2001 From: janhviacn Date: Wed, 19 Oct 2022 07:06:15 +0000 Subject: [PATCH 01/22] Update click and black version to latest. --- requirements.txt | 4 ++-- src/diem/identifier/bech32.py | 2 +- src/diem/offchain/command.py | 2 +- src/diem/offchain/types/command_types.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index 84d1244c..e713e87d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,10 +4,10 @@ numpy==1.18 protobuf==3.12.4 pytest==6.2.1 pytest-asyncio==0.14.0 -click==7.1 +click==8.1.3 aiohttp==3.7.4.post0 pylama -black +black==22.10.0 pyre-check pytest-cov mypy-protobuf diff --git a/src/diem/identifier/bech32.py b/src/diem/identifier/bech32.py index 01d82f07..c3de41d6 100644 --- a/src/diem/identifier/bech32.py +++ b/src/diem/identifier/bech32.py @@ -23,7 +23,7 @@ class Bech32Error(Exception): - """ Represents an error when creating a Diem address. """ + """Represents an error when creating a Diem address.""" pass diff --git a/src/diem/offchain/command.py b/src/diem/offchain/command.py index 5ed4d650..6dc7377c 100644 --- a/src/diem/offchain/command.py +++ b/src/diem/offchain/command.py @@ -9,7 +9,7 @@ class Command(ABC): - """Command defines common interface for all commands """ + """Command defines common interface for all commands""" @abstractmethod def id(self) -> str: diff --git a/src/diem/offchain/types/command_types.py b/src/diem/offchain/types/command_types.py index 38442301..de867225 100644 --- a/src/diem/offchain/types/command_types.py +++ b/src/diem/offchain/types/command_types.py @@ -98,7 +98,7 @@ class OffChainErrorType: class OffChainCommandResponseResultType: - """ Type of result in a CommandResponseObject""" + """Type of result in a CommandResponseObject""" ReferenceIDCommandResponse = "ReferenceIDCommandResponse" From 21f39cff62767dd1ffd766fd8c37f49bc786c15f Mon Sep 17 00:00:00 2001 From: janhviacn Date: Thu, 22 Dec 2022 12:06:32 +0000 Subject: [PATCH 02/22] updating click & black version --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index e713e87d..7251a8f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ + requests==2.20.0 cryptography==3.3.2 numpy==1.18 From 72d6e73b8303566701d9980d179d63560fa5d880 Mon Sep 17 00:00:00 2001 From: janhviacn Date: Wed, 4 Jan 2023 08:01:01 +0000 Subject: [PATCH 03/22] Updating to new diem branch link --- .gitmodules | 6 ++++++ diem | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index bffa3e75..f1e5eb28 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,9 @@ [submodule "diem"] path = diem url = https://github.com/diem/diem.git +[submodule "diem_testnet_tag"] + path = diem + url = https://github.com/jsladerman/diem.git +[submodule "diem_testnet_tag1"] + path = diem + url = https://github.com/jsladerman/diem.git diff --git a/diem b/diem index 3916c548..87d6f7e1 160000 --- a/diem +++ b/diem @@ -1 +1 @@ -Subproject commit 3916c548380111f241d9ffbf7eecc09929bd2f4a +Subproject commit 87d6f7e1a736207d030fb6468b3dc2c8fb0b7d20 From 12537c1f498ee7a026d800463786104a94d3a7b8 Mon Sep 17 00:00:00 2001 From: janhviacn Date: Wed, 4 Jan 2023 08:29:16 +0000 Subject: [PATCH 04/22] Updating to submodule name diem_testnet_tag --- .gitmodules | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.gitmodules b/.gitmodules index f1e5eb28..9f45b9a5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,3 @@ -[submodule "diem"] - path = diem - url = https://github.com/diem/diem.git [submodule "diem_testnet_tag"] path = diem - url = https://github.com/jsladerman/diem.git -[submodule "diem_testnet_tag1"] - path = diem - url = https://github.com/jsladerman/diem.git + url = https://github.com/diem/diem.git From 8d01310702a399fc34cb5ecca8efdb3713a8927e Mon Sep 17 00:00:00 2001 From: janhviacn Date: Fri, 6 Jan 2023 07:49:59 +0000 Subject: [PATCH 05/22] Updating diem_testnet_tag url --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 9f45b9a5..05a254c1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "diem_testnet_tag"] path = diem - url = https://github.com/diem/diem.git + url = https://github.com/jsladerman/diem.git From 991f248fab41331d2d92b90d9ae835f551086186 Mon Sep 17 00:00:00 2001 From: janhviacn Date: Fri, 6 Jan 2023 07:55:21 +0000 Subject: [PATCH 06/22] updating build37 submodule command --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7988f1e0..02d53935 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: make init - name: submodule for docker compose run: | - git submodule update --init diem + git submodule update --init --recursive diem make docker - name: Test run: | From af2dd40cbfff73004022f3e6eeb02b0fac169e6b Mon Sep 17 00:00:00 2001 From: janhviacn Date: Fri, 6 Jan 2023 08:25:38 +0000 Subject: [PATCH 07/22] build37 submodule command update --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 02d53935..6c03a3e5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: make init - name: submodule for docker compose run: | - git submodule update --init --recursive diem + git submodule update --remote --merge diem make docker - name: Test run: | From ee27b01cc0fe49ccbe844e604d1eb6888041d9fa Mon Sep 17 00:00:00 2001 From: janhviacn Date: Fri, 6 Jan 2023 08:33:17 +0000 Subject: [PATCH 08/22] updating build37 submodule command --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c03a3e5..b6b4a757 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: make init - name: submodule for docker compose run: | - git submodule update --remote --merge diem + git submodule update --init --remote --merge diem make docker - name: Test run: | From 92d2f256e50452afd0e743adf1441f8e43d7fc7a Mon Sep 17 00:00:00 2001 From: janhviacn Date: Fri, 6 Jan 2023 08:59:38 +0000 Subject: [PATCH 09/22] updating url to diem --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 05a254c1..d09fc423 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "diem_testnet_tag"] path = diem - url = https://github.com/jsladerman/diem.git + url = https://github.com/diem/diem.git From ac478f0e7c004f2fc2b9d88cdef34ec72ccf1472 Mon Sep 17 00:00:00 2001 From: janhviacn Date: Fri, 6 Jan 2023 09:28:03 +0000 Subject: [PATCH 10/22] updating build38 & 39 submodule command --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6b4a757..90c86c16 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,7 +44,7 @@ jobs: make init - name: submodule for docker compose run: | - git submodule update --init diem + git submodule update --init --remote --merge diem make docker - name: Test run: | @@ -65,7 +65,7 @@ jobs: make init - name: submodule for docker compose run: | - git submodule update --init diem + git submodule update --init --remote --merge diem make docker - name: Test run: | From 63a19496adb89b4b440ae028254a9eaf11f3c29f Mon Sep 17 00:00:00 2001 From: janhviacn Date: Fri, 6 Jan 2023 09:30:20 +0000 Subject: [PATCH 11/22] updating gitmodules file --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index d09fc423..9f45b9a5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "diem_testnet_tag"] path = diem - url = https://github.com/diem/diem.git + url = https://github.com/diem/diem.git From b24f80c396c692a26b8b00024fd2d7b7b7338d5f Mon Sep 17 00:00:00 2001 From: janhviacn Date: Fri, 6 Jan 2023 09:53:25 +0000 Subject: [PATCH 12/22] updated diem repo to latest commit --- .github/workflows/build.yml | 6 +++--- diem | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 90c86c16..7988f1e0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: make init - name: submodule for docker compose run: | - git submodule update --init --remote --merge diem + git submodule update --init diem make docker - name: Test run: | @@ -44,7 +44,7 @@ jobs: make init - name: submodule for docker compose run: | - git submodule update --init --remote --merge diem + git submodule update --init diem make docker - name: Test run: | @@ -65,7 +65,7 @@ jobs: make init - name: submodule for docker compose run: | - git submodule update --init --remote --merge diem + git submodule update --init diem make docker - name: Test run: | diff --git a/diem b/diem index 87d6f7e1..1a6910c2 160000 --- a/diem +++ b/diem @@ -1 +1 @@ -Subproject commit 87d6f7e1a736207d030fb6468b3dc2c8fb0b7d20 +Subproject commit 1a6910c2fad633a09a38f2774596fa989ffcfed0 From 05e3f450a6db38cb4b9fb465b77a398672752a12 Mon Sep 17 00:00:00 2001 From: janhviacn Date: Fri, 6 Jan 2023 10:11:28 +0000 Subject: [PATCH 13/22] updated runner version --- .github/workflows/build.yml | 6 +++--- .github/workflows/python-publish.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7988f1e0..7c5fa1ad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ on: jobs: build37: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Set up Python 3.7 @@ -32,7 +32,7 @@ jobs: run: | make dist build38: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Set up Python 3.8 @@ -53,7 +53,7 @@ jobs: run: | make dist build39: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Set up Python 3.9 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index bdaaeb9a..d55a3539 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -11,7 +11,7 @@ on: jobs: deploy: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 From d413aa39d058c64a1fd1d8731105903dab3fd08c Mon Sep 17 00:00:00 2001 From: janhviacn Date: Fri, 6 Jan 2023 10:34:46 +0000 Subject: [PATCH 14/22] reverted runner version --- .github/workflows/build.yml | 6 +++--- .github/workflows/python-publish.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7c5fa1ad..7988f1e0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ on: jobs: build37: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python 3.7 @@ -32,7 +32,7 @@ jobs: run: | make dist build38: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python 3.8 @@ -53,7 +53,7 @@ jobs: run: | make dist build39: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python 3.9 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index d55a3539..bdaaeb9a 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -11,7 +11,7 @@ on: jobs: deploy: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From 44e0b8292728f2c9e8f8ef94ec91565f0b3a131a Mon Sep 17 00:00:00 2001 From: janhviacn Date: Mon, 9 Jan 2023 09:35:02 +0000 Subject: [PATCH 15/22] removed json variable and pyre-ignore comment --- src/diem/jsonrpc/async_client.py | 2 +- src/diem/offchain/types/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/diem/jsonrpc/async_client.py b/src/diem/jsonrpc/async_client.py index e4804717..bdf82c4e 100644 --- a/src/diem/jsonrpc/async_client.py +++ b/src/diem/jsonrpc/async_client.py @@ -577,7 +577,7 @@ async def execute_without_retry( raise InvalidServerResponse(f"No error or result in response: {json}") except parser.ParseError as e: - raise InvalidServerResponse(f"Parse result failed: {e}, response: {json}") + raise InvalidServerResponse(f"Parse result failed: {e}, response: ") async def _send_http_request( self, diff --git a/src/diem/offchain/types/__init__.py b/src/diem/offchain/types/__init__.py index 60d7b3b2..70d3fe7e 100644 --- a/src/diem/offchain/types/__init__.py +++ b/src/diem/offchain/types/__init__.py @@ -124,7 +124,7 @@ def _field_value_from_dict(field: dataclasses.Field, obj: typing.Any, field_path full_name = _join_field_path(field_path, field.name) field_type = field.type args = field.type.__args__ if hasattr(field.type, "__args__") else [] - is_optional = len(args) == 2 and isinstance(None, args[1]) # pyre-ignore + is_optional = len(args) == 2 and isinstance(None, args[1]) if is_optional: field_type = args[0] val = obj.get(field.name) From 24e948a3bb974cc7aa81d75b7593ce6f9bcf0b11 Mon Sep 17 00:00:00 2001 From: janhviacn Date: Mon, 9 Jan 2023 09:46:29 +0000 Subject: [PATCH 16/22] Reformatted __init__.py file --- src/diem/offchain/types/__init__.py | 38 ++++++----------------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/src/diem/offchain/types/__init__.py b/src/diem/offchain/types/__init__.py index 70d3fe7e..851c8f51 100644 --- a/src/diem/offchain/types/__init__.py +++ b/src/diem/offchain/types/__init__.py @@ -124,7 +124,7 @@ def _field_value_from_dict(field: dataclasses.Field, obj: typing.Any, field_path full_name = _join_field_path(field_path, field.name) field_type = field.type args = field.type.__args__ if hasattr(field.type, "__args__") else [] - is_optional = len(args) == 2 and isinstance(None, args[1]) + is_optional = len(args) == 2 and isinstance(None, args[1]) if is_optional: field_type = args[0] val = obj.get(field.name) @@ -166,14 +166,9 @@ def new_payment_object( return PaymentObject( reference_id=reference_id or str(uuid.uuid4()), sender=PaymentActorObject( - address=sender_account_id, - kyc_data=sender_kyc_data, - status=StatusObject(status=Status.needs_kyc_data), - ), - receiver=PaymentActorObject( - address=receiver_account_id, - status=StatusObject(status=Status.none), + address=sender_account_id, kyc_data=sender_kyc_data, status=StatusObject(status=Status.needs_kyc_data) ), + receiver=PaymentActorObject(address=receiver_account_id, status=StatusObject(status=Status.none)), action=PaymentActionObject(amount=amount, currency=currency), description=description, original_payment_reference_id=original_payment_reference_id, @@ -196,10 +191,7 @@ def replace_payment_actor( changes["additional_kyc_data"] = additional_kyc_data if status or abort_code or abort_message: changes["status"] = replace_payment_status( - actor.status, - status=status, - abort_code=abort_code, - abort_message=abort_message, + actor.status, status=status, abort_code=abort_code, abort_message=abort_message ) if metadata: if not isinstance(metadata, list): @@ -224,19 +216,11 @@ def replace_payment_status( return dataclasses.replace(status_obj, **changes) -def new_payment_request( - payment: PaymentObject, - cid: typing.Optional[str] = None, -) -> CommandRequestObject: +def new_payment_request(payment: PaymentObject, cid: typing.Optional[str] = None) -> CommandRequestObject: return CommandRequestObject( cid=cid or str(uuid.uuid4()), command_type=CommandType.PaymentCommand, - command=to_dict( - PaymentCommandObject( - _ObjectType=CommandType.PaymentCommand, - payment=payment, - ) - ), + command=to_dict(PaymentCommandObject(_ObjectType=CommandType.PaymentCommand, payment=payment)), ) @@ -254,17 +238,11 @@ def reply_request( def individual_kyc_data(**kwargs) -> KycDataObject: # pyre-ignore - return KycDataObject( - type=KycDataObjectType.individual, - **kwargs, - ) + return KycDataObject(type=KycDataObjectType.individual, **kwargs) def entity_kyc_data(**kwargs) -> KycDataObject: # pyre-ignore - return KycDataObject( - type=KycDataObjectType.entity, - **kwargs, - ) + return KycDataObject(type=KycDataObjectType.entity, **kwargs) def validate_write_once_fields(path: str, new: typing.Any, prior: typing.Any) -> None: # pyre-ignore From faf5f9febeed85fc56914b2bc4aec6a40d922348 Mon Sep 17 00:00:00 2001 From: janhviacn Date: Thu, 12 Jan 2023 07:53:13 +0000 Subject: [PATCH 17/22] build issue fixing --- requirements.txt | 4 +- src/diem/jsonrpc/async_client.py | 3 +- src/diem/jsonrpc/client.py | 2 +- src/diem/testing/cli.py | 10 +- src/diem/testing/miniwallet/app/app.py | 2 +- src/diem/testing/miniwallet/app/models.py | 2 +- .../suites/basic/test_create_test_account.py | 8 +- .../suites/basic/test_receive_payment.py | 11 +-- .../suites/offchainv2/test_payment_command.py | 45 ++------- .../suites/offchainv2/test_receive_payment.py | 97 +++++-------------- src/diem/utils.py | 9 +- 11 files changed, 49 insertions(+), 144 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7251a8f4..9a3eb2ed 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,10 +5,10 @@ numpy==1.18 protobuf==3.12.4 pytest==6.2.1 pytest-asyncio==0.14.0 -click==8.1.3 +click aiohttp==3.7.4.post0 pylama -black==22.10.0 +black pyre-check pytest-cov mypy-protobuf diff --git a/src/diem/jsonrpc/async_client.py b/src/diem/jsonrpc/async_client.py index bdf82c4e..97186904 100644 --- a/src/diem/jsonrpc/async_client.py +++ b/src/diem/jsonrpc/async_client.py @@ -564,6 +564,7 @@ async def execute_without_retry( "method": method, "params": params or [], } + json = {} try: json = await self._rs.send_request(self, request, ignore_stale_response or False) if "error" in json: @@ -577,7 +578,7 @@ async def execute_without_retry( raise InvalidServerResponse(f"No error or result in response: {json}") except parser.ParseError as e: - raise InvalidServerResponse(f"Parse result failed: {e}, response: ") + raise InvalidServerResponse(f"Parse result failed: {e}, response: {json}") async def _send_http_request( self, diff --git a/src/diem/jsonrpc/client.py b/src/diem/jsonrpc/client.py index 455078c7..b8757342 100644 --- a/src/diem/jsonrpc/client.py +++ b/src/diem/jsonrpc/client.py @@ -585,7 +585,7 @@ def execute_without_retry( except requests.RequestException as e: raise NetworkError(f"Error in connecting to server: {e}\nPlease retry...") except parser.ParseError as e: - raise InvalidServerResponse(f"Parse result failed: {e}, response: {json}") + raise InvalidServerResponse(f"Parse result failed: {e}, response: ") def _send_http_request( self, diff --git a/src/diem/testing/cli.py b/src/diem/testing/cli.py index c5408aa4..8c7f0710 100644 --- a/src/diem/testing/cli.py +++ b/src/diem/testing/cli.py @@ -14,7 +14,7 @@ log_format: str = "%(name)s [%(asctime)s] %(levelname)s: %(message)s" -click.option = functools.partial(click.option, show_default=True) # pyre-ignore +click.option = functools.partial(click.option, show_default=True) def coro(f): # pyre-ignore @@ -187,13 +187,7 @@ async def start_server( help="Before start test, the target wallet application host port should be ready for connection. This is wait timeout (seconds) for the port ready.", type=int, ) -@click.option( - "--include-offchain-v2", - type=bool, - is_flag=True, - default=False, - help="Include offchain v2 test suites", -) +@click.option("--include-offchain-v2", type=bool, is_flag=True, default=False, help="Include offchain v2 test suites") @click.help_option("-h", "--help") def test( target: str, diff --git a/src/diem/testing/miniwallet/app/app.py b/src/diem/testing/miniwallet/app/app.py index a0270726..37c9e427 100644 --- a/src/diem/testing/miniwallet/app/app.py +++ b/src/diem/testing/miniwallet/app/app.py @@ -149,7 +149,7 @@ async def worker() -> None: async def txn_metadata(self, txn: Transaction) -> Tuple[bytes, bytes]: if await self.offchain.is_under_dual_attestation_limit(txn.currency, txn.amount): if txn.refund_diem_txn_version and txn.refund_reason: - return self.diem_account.refund_metadata(txn.refund_diem_txn_version, txn.refund_reason) # pyre-ignore + return self.diem_account.refund_metadata(txn.refund_diem_txn_version, txn.refund_reason) if txn.subaddress_hex: return self.diem_account.general_metadata(txn.subaddress(), str(txn.payee)) if txn.reference_id: diff --git a/src/diem/testing/miniwallet/app/models.py b/src/diem/testing/miniwallet/app/models.py index 7c47b0f8..5e56ce42 100644 --- a/src/diem/testing/miniwallet/app/models.py +++ b/src/diem/testing/miniwallet/app/models.py @@ -26,7 +26,7 @@ def __post_init__(self) -> None: self.diem_id = create_diem_id(self.id, str(self.vasp_domain)) if self.vasp_domain else None def kyc_data_object(self) -> offchain.KycDataObject: - return self.kyc_data if self.kyc_data else offchain.individual_kyc_data() # pyre-ignore + return self.kyc_data if self.kyc_data else offchain.individual_kyc_data() @dataclass diff --git a/src/diem/testing/suites/basic/test_create_test_account.py b/src/diem/testing/suites/basic/test_create_test_account.py index e14dbead..e5991455 100644 --- a/src/diem/testing/suites/basic/test_create_test_account.py +++ b/src/diem/testing/suites/basic/test_create_test_account.py @@ -26,13 +26,7 @@ async def test_create_an_account_with_initial_deposit_balances( assert await account.balance(currency) == amount -@pytest.mark.parametrize( # pyre-ignore - "kyc_data", - [ - offchain.individual_kyc_data(), - offchain.entity_kyc_data(), - ], -) +@pytest.mark.parametrize("kyc_data", [offchain.individual_kyc_data(), offchain.entity_kyc_data()]) async def test_create_an_account_with_minimum_valid_kyc_data( target_client: RestClient, kyc_data: offchain.KycDataObject ) -> None: diff --git a/src/diem/testing/suites/basic/test_receive_payment.py b/src/diem/testing/suites/basic/test_receive_payment.py index 110d3e4b..7da15be8 100644 --- a/src/diem/testing/suites/basic/test_receive_payment.py +++ b/src/diem/testing/suites/basic/test_receive_payment.py @@ -74,10 +74,7 @@ async def test_receive_payment_with_invalid_metadata( @pytest.mark.parametrize("amount", [10_000, 1200_000, 125550_000]) async def test_receive_payment_with_general_metadata_and_valid_from_and_to_subaddresses( - stub_client: RestClient, - target_client: RestClient, - currency: str, - amount: int, + stub_client: RestClient, target_client: RestClient, currency: str, amount: int ) -> None: """ Test Plan: @@ -101,7 +98,7 @@ async def test_receive_payment_with_general_metadata_and_valid_from_and_to_subad await sender_account.log_events() -@pytest.mark.parametrize( # pyre-ignore +@pytest.mark.parametrize( "invalid_to_subaddress", [None, b"", b"bb4a3ba109a3175f", b"subaddress_more_than_8_bytes", b"too_short"] ) async def test_receive_payment_with_general_metadata_and_invalid_to_subaddress( @@ -163,7 +160,7 @@ async def test_receive_payment_with_general_metadata_and_invalid_to_subaddress( await sender_account.log_events() -@pytest.mark.parametrize( # pyre-ignore +@pytest.mark.parametrize( "invalid_from_subaddress", [None, b"", b"bb4a3ba109a3175f", b"subaddress_more_than_8_bytes", b"too_short"] ) async def test_receive_payment_with_general_metadata_and_invalid_from_subaddress( @@ -216,7 +213,7 @@ async def test_receive_payment_with_general_metadata_and_invalid_from_subaddress @pytest.mark.parametrize( "invalid_from_subaddress", [None, b"", b"bb4a3ba109a3175f", b"subaddress_more_than_8_bytes", b"too_short"] ) -@pytest.mark.parametrize( # pyre-ignore +@pytest.mark.parametrize( "invalid_to_subaddress", [None, b"", b"bb4a3ba109a3175f", b"subaddress_more_than_8_bytes", b"too_short"] ) async def test_receive_payment_with_general_metadata_and_invalid_subaddresses( diff --git a/src/diem/testing/suites/offchainv2/test_payment_command.py b/src/diem/testing/suites/offchainv2/test_payment_command.py index 5832b3f0..3fe785b6 100644 --- a/src/diem/testing/suites/offchainv2/test_payment_command.py +++ b/src/diem/testing/suites/offchainv2/test_payment_command.py @@ -264,11 +264,7 @@ async def test_payment_command_contains_invalid_actor_metadata_item_type( async def test_replay_the_same_payment_command( - currency: str, - travel_rule_threshold: int, - stub_wallet_app: App, - stub_client: RestClient, - target_client: RestClient, + currency: str, travel_rule_threshold: int, stub_wallet_app: App, stub_client: RestClient, target_client: RestClient ) -> None: """ Test Plan: @@ -285,9 +281,7 @@ async def test_replay_the_same_payment_command( target_kyc = await target_client.get_kyc_sample() stub_kyc = await stub_client.get_kyc_sample() sender_account = await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.minimum, - disable_background_tasks=True, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.minimum, disable_background_tasks=True ) receiver_account = await target_client.create_account(kyc_data=stub_kyc.minimum) try: @@ -306,11 +300,7 @@ async def test_replay_the_same_payment_command( async def test_payment_command_sender_kyc_data_can_only_be_written_once( - currency: str, - travel_rule_threshold: int, - stub_wallet_app: App, - stub_client: RestClient, - target_client: RestClient, + currency: str, travel_rule_threshold: int, stub_wallet_app: App, stub_client: RestClient, target_client: RestClient ) -> None: """ Test Plan: @@ -330,9 +320,7 @@ async def test_payment_command_sender_kyc_data_can_only_be_written_once( target_kyc = await target_client.get_kyc_sample() stub_kyc = await stub_client.get_kyc_sample() sender_account = await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.minimum, - disable_background_tasks=True, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.minimum, disable_background_tasks=True ) receiver_account = await target_client.create_account(kyc_data=stub_kyc.minimum) try: @@ -393,9 +381,7 @@ async def test_payment_command_sender_address_can_only_be_written_once( target_kyc = await target_client.get_kyc_sample() stub_kyc = await stub_client.get_kyc_sample() sender_account = await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.minimum, - disable_background_tasks=True, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.minimum, disable_background_tasks=True ) receiver_account = await target_client.create_account(kyc_data=stub_kyc.minimum) try: @@ -431,14 +417,7 @@ async def test_payment_command_sender_address_can_only_be_written_once( await sender_account.log_events() -@pytest.mark.parametrize( - "field_name", - [ - "currency", - "amount", - "timestamp", - ], -) +@pytest.mark.parametrize("field_name", ["currency", "amount", "timestamp"]) async def test_payment_command_action_can_only_be_written_once( currency: str, travel_rule_threshold: int, @@ -466,9 +445,7 @@ async def test_payment_command_action_can_only_be_written_once( target_kyc = await target_client.get_kyc_sample() stub_kyc = await stub_client.get_kyc_sample() sender_account = await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.minimum, - disable_background_tasks=True, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.minimum, disable_background_tasks=True ) receiver_account = await target_client.create_account(kyc_data=stub_kyc.minimum) try: @@ -486,6 +463,7 @@ async def test_payment_command_action_can_only_be_written_once( offchain_cmd = updated_cmd.to_offchain_command() # update action field value + field_value = "" if field_name == "currency": field_value = "XDX" if offchain_cmd.payment.action.currency == "XUS" else "XUS" elif field_name == "amount": @@ -535,12 +513,7 @@ async def assert_payment_command_field_error( set_field(request, full_field_name, field_value) status_code, resp = await send_request_json( - diem_client, - stub_config.account, - sender_address, - receiver_address, - json.dumps(request), - hrp, + diem_client, stub_config.account, sender_address, receiver_address, json.dumps(request), hrp ) assert status_code == 400 assert resp.status == "failure" diff --git a/src/diem/testing/suites/offchainv2/test_receive_payment.py b/src/diem/testing/suites/offchainv2/test_receive_payment.py index 7d7165d0..c13643bc 100644 --- a/src/diem/testing/suites/offchainv2/test_receive_payment.py +++ b/src/diem/testing/suites/offchainv2/test_receive_payment.py @@ -13,10 +13,7 @@ async def test_receive_payment_with_travel_rule_metadata_and_valid_reference_id( - stub_client: RestClient, - target_client: RestClient, - currency: str, - travel_rule_threshold: int, + stub_client: RestClient, target_client: RestClient, currency: str, travel_rule_threshold: int ) -> None: """ Test Plan: @@ -42,9 +39,7 @@ async def test_receive_payment_with_travel_rule_metadata_and_valid_reference_id( await sender_account.log_events() -@pytest.mark.parametrize( # pyre-ignore - "invalid_ref_id", [None, "", "ref_id_is_not_uuid", "6cd81d79-f041-4f28-867f-e4d54950833e"] -) +@pytest.mark.parametrize("invalid_ref_id", [None, "", "ref_id_is_not_uuid", "6cd81d79-f041-4f28-867f-e4d54950833e"]) async def test_receive_payment_with_travel_rule_metadata_and_invalid_reference_id( stub_client: RestClient, target_client: RestClient, @@ -115,10 +110,7 @@ async def test_receive_payment_with_travel_rule_metadata_and_invalid_reference_i async def test_receive_payment_meets_travel_rule_threshold_both_kyc_data_evaluations_are_accepted( - currency: str, - travel_rule_threshold: int, - target_client: RestClient, - stub_client: RestClient, + currency: str, travel_rule_threshold: int, target_client: RestClient, stub_client: RestClient ) -> None: """ Test Plan: @@ -134,8 +126,7 @@ async def test_receive_payment_meets_travel_rule_threshold_both_kyc_data_evaluat stub_kyc = await stub_client.get_kyc_sample() await receive_payment_meets_travel_rule_threshold( sender=await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.minimum, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.minimum ), receiver=await target_client.create_account(kyc_data=stub_kyc.minimum), payment_command_states=["S_INIT", "R_SEND", "READY"], @@ -145,11 +136,7 @@ async def test_receive_payment_meets_travel_rule_threshold_both_kyc_data_evaluat async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_rejected_by_the_receiver( - currency: str, - travel_rule_threshold: int, - target_client: RestClient, - stub_client: RestClient, - hrp: str, + currency: str, travel_rule_threshold: int, target_client: RestClient, stub_client: RestClient, hrp: str ) -> None: """ Test Plan: @@ -164,10 +151,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_re target_kyc = await target_client.get_kyc_sample() stub_kyc = await stub_client.get_kyc_sample() await receive_payment_meets_travel_rule_threshold( - sender=await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.reject, - ), + sender=await stub_client.create_account(balances={currency: travel_rule_threshold}, kyc_data=target_kyc.reject), receiver=await target_client.create_account(kyc_data=stub_kyc.minimum), payment_command_states=["S_INIT", "R_ABORT"], currency=currency, @@ -176,10 +160,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_re async def test_receive_payment_meets_travel_rule_threshold_receiver_kyc_data_is_rejected_by_the_sender( - currency: str, - travel_rule_threshold: int, - target_client: RestClient, - stub_client: RestClient, + currency: str, travel_rule_threshold: int, target_client: RestClient, stub_client: RestClient ) -> None: """ Test Plan: @@ -195,8 +176,7 @@ async def test_receive_payment_meets_travel_rule_threshold_receiver_kyc_data_is_ stub_kyc = await stub_client.get_kyc_sample() await receive_payment_meets_travel_rule_threshold( sender=await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.minimum, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.minimum ), receiver=await target_client.create_account(kyc_data=stub_kyc.reject), payment_command_states=["S_INIT", "R_SEND", "S_ABORT"], @@ -206,10 +186,7 @@ async def test_receive_payment_meets_travel_rule_threshold_receiver_kyc_data_is_ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_soft_match_then_accepted_after_reviewing_additional_kyc_data( - currency: str, - travel_rule_threshold: int, - target_client: RestClient, - stub_client: RestClient, + currency: str, travel_rule_threshold: int, target_client: RestClient, stub_client: RestClient ) -> None: """ Test Plan: @@ -225,8 +202,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_so stub_kyc = await stub_client.get_kyc_sample() await receive_payment_meets_travel_rule_threshold( sender=await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.soft_match, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.soft_match ), receiver=await target_client.create_account(kyc_data=stub_kyc.minimum), payment_command_states=["S_INIT", "R_SOFT", "S_SOFT_SEND", "R_SEND", "READY"], @@ -236,10 +212,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_so async def test_receive_payment_meets_travel_rule_threshold_receiver_kyc_data_is_soft_match_then_accepted_after_reviewing_additional_kyc_data( - currency: str, - travel_rule_threshold: int, - target_client: RestClient, - stub_client: RestClient, + currency: str, travel_rule_threshold: int, target_client: RestClient, stub_client: RestClient ) -> None: """ Test Plan: @@ -255,8 +228,7 @@ async def test_receive_payment_meets_travel_rule_threshold_receiver_kyc_data_is_ stub_kyc = await stub_client.get_kyc_sample() await receive_payment_meets_travel_rule_threshold( sender=await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.minimum, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.minimum ), receiver=await target_client.create_account(kyc_data=stub_kyc.soft_match), payment_command_states=["S_INIT", "R_SEND", "S_SOFT", "R_SOFT_SEND", "READY"], @@ -266,10 +238,7 @@ async def test_receive_payment_meets_travel_rule_threshold_receiver_kyc_data_is_ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_soft_match_then_rejected_after_reviewing_additional_kyc_data( - currency: str, - travel_rule_threshold: int, - target_client: RestClient, - stub_client: RestClient, + currency: str, travel_rule_threshold: int, target_client: RestClient, stub_client: RestClient ) -> None: """ Test Plan: @@ -285,8 +254,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_so stub_kyc = await stub_client.get_kyc_sample() await receive_payment_meets_travel_rule_threshold( sender=await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.soft_reject, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.soft_reject ), receiver=await target_client.create_account(kyc_data=stub_kyc.minimum), payment_command_states=["S_INIT", "R_SOFT", "S_SOFT_SEND", "R_ABORT"], @@ -296,10 +264,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_so async def test_receive_payment_meets_travel_rule_threshold_receiver_kyc_data_is_soft_match_then_rejected_after_reviewing_additional_kyc_data( - currency: str, - travel_rule_threshold: int, - target_client: RestClient, - stub_client: RestClient, + currency: str, travel_rule_threshold: int, target_client: RestClient, stub_client: RestClient ) -> None: """ Test Plan: @@ -315,8 +280,7 @@ async def test_receive_payment_meets_travel_rule_threshold_receiver_kyc_data_is_ stub_kyc = await stub_client.get_kyc_sample() await receive_payment_meets_travel_rule_threshold( sender=await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.minimum, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.minimum ), receiver=await target_client.create_account(kyc_data=stub_kyc.soft_reject), payment_command_states=["S_INIT", "R_SEND", "S_SOFT", "R_SOFT_SEND", "S_ABORT"], @@ -326,10 +290,7 @@ async def test_receive_payment_meets_travel_rule_threshold_receiver_kyc_data_is_ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_soft_match_then_receiver_aborts_for_sending_additional_kyc_data( - currency: str, - travel_rule_threshold: int, - target_client: RestClient, - stub_client: RestClient, + currency: str, travel_rule_threshold: int, target_client: RestClient, stub_client: RestClient ) -> None: """ Test Plan: @@ -358,10 +319,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_so async def test_receive_payment_meets_travel_rule_threshold_sender_and_receiver_kyc_data_are_soft_match_then_accepted_after_reviewing_additional_kyc_data( - currency: str, - travel_rule_threshold: int, - target_client: RestClient, - stub_client: RestClient, + currency: str, travel_rule_threshold: int, target_client: RestClient, stub_client: RestClient ) -> None: """ Test Plan: @@ -377,8 +335,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_and_receiver_k stub_kyc = await stub_client.get_kyc_sample() await receive_payment_meets_travel_rule_threshold( sender=await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.soft_match, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.soft_match ), receiver=await target_client.create_account(kyc_data=stub_kyc.soft_match), payment_command_states=["S_INIT", "R_SOFT", "S_SOFT_SEND", "R_SEND", "S_SOFT", "R_SOFT_SEND", "READY"], @@ -388,10 +345,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_and_receiver_k async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_soft_match_and_accepted_receiver_kyc_data_is_rejected( - currency: str, - travel_rule_threshold: int, - target_client: RestClient, - stub_client: RestClient, + currency: str, travel_rule_threshold: int, target_client: RestClient, stub_client: RestClient ) -> None: """ Test Plan: @@ -407,8 +361,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_so stub_kyc = await stub_client.get_kyc_sample() await receive_payment_meets_travel_rule_threshold( sender=await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.soft_match, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.soft_match ), receiver=await target_client.create_account(kyc_data=stub_kyc.reject), payment_command_states=["S_INIT", "R_SOFT", "S_SOFT_SEND", "R_SEND", "S_ABORT"], @@ -418,10 +371,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_so async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_soft_match_and_accepted_receiver_kyc_data_is_soft_match_and_rejected( - currency: str, - travel_rule_threshold: int, - target_client: RestClient, - stub_client: RestClient, + currency: str, travel_rule_threshold: int, target_client: RestClient, stub_client: RestClient ) -> None: """ Test Plan: @@ -437,8 +387,7 @@ async def test_receive_payment_meets_travel_rule_threshold_sender_kyc_data_is_so stub_kyc = await stub_client.get_kyc_sample() await receive_payment_meets_travel_rule_threshold( sender=await stub_client.create_account( - balances={currency: travel_rule_threshold}, - kyc_data=target_kyc.soft_match, + balances={currency: travel_rule_threshold}, kyc_data=target_kyc.soft_match ), receiver=await target_client.create_account(kyc_data=stub_kyc.soft_reject), payment_command_states=["S_INIT", "R_SOFT", "S_SOFT_SEND", "R_SEND", "S_SOFT", "R_SOFT_SEND", "S_ABORT"], diff --git a/src/diem/utils.py b/src/diem/utils.py index 76e354f6..9c97f538 100644 --- a/src/diem/utils.py +++ b/src/diem/utils.py @@ -8,10 +8,7 @@ import hashlib, typing, time, socket, asyncio from . import diem_types, jsonrpc, stdlib -from .constants import ( - SUB_ADDRESS_LEN, - DIEM_HASH_PREFIX, -) +from .constants import SUB_ADDRESS_LEN, DIEM_HASH_PREFIX class InvalidAccountAddressError(Exception): @@ -226,7 +223,7 @@ def shutdown_event_loop(loop: asyncio.events.AbstractEventLoop) -> None: asyncio.runners._cancel_all_tasks(loop) # pyre-ignore loop.run_until_complete(loop.shutdown_asyncgens()) if hasattr(loop, "shutdown_default_executor"): - loop.run_until_complete(getattr(loop, "shutdown_default_executor")()) + loop.run_until_complete(loop.__getattribute__("shutdown_default_executor")) finally: asyncio.set_event_loop(None) loop.close() @@ -238,7 +235,7 @@ async def with_retry(coroutine, max_retries=5, delay_secs=0.1, exception=Excepti tries += 1 try: return await coroutine() - except exception as e: # pyre-ignore + except exception as e: if tries < max_retries: # simplest backoff strategy: tries * delay await asyncio.sleep(delay_secs * tries) From 7b9392a4bbb3fbda6edf737a18cd4b8a34e2ad2a Mon Sep 17 00:00:00 2001 From: janhviacn Date: Fri, 13 Jan 2023 20:37:56 +0000 Subject: [PATCH 18/22] updated files --- requirements.txt | 4 ++-- src/diem/jsonrpc/client.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9a3eb2ed..7251a8f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,10 +5,10 @@ numpy==1.18 protobuf==3.12.4 pytest==6.2.1 pytest-asyncio==0.14.0 -click +click==8.1.3 aiohttp==3.7.4.post0 pylama -black +black==22.10.0 pyre-check pytest-cov mypy-protobuf diff --git a/src/diem/jsonrpc/client.py b/src/diem/jsonrpc/client.py index b8757342..c8900972 100644 --- a/src/diem/jsonrpc/client.py +++ b/src/diem/jsonrpc/client.py @@ -570,6 +570,7 @@ def execute_without_retry( "method": method, "params": params or [], } + json = {} try: json = self._rs.send_request(self, request, ignore_stale_response or False) if "error" in json: @@ -585,7 +586,7 @@ def execute_without_retry( except requests.RequestException as e: raise NetworkError(f"Error in connecting to server: {e}\nPlease retry...") except parser.ParseError as e: - raise InvalidServerResponse(f"Parse result failed: {e}, response: ") + raise InvalidServerResponse(f"Parse result failed: {e}, response: {json}") def _send_http_request( self, From 1e85889cb62a8ddfb586350be96736b24a245a9e Mon Sep 17 00:00:00 2001 From: janhviacn Date: Mon, 16 Jan 2023 12:19:03 +0000 Subject: [PATCH 19/22] updated files --- requirements.txt | 1 - src/diem/jsonrpc/client.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7251a8f4..e713e87d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ - requests==2.20.0 cryptography==3.3.2 numpy==1.18 diff --git a/src/diem/jsonrpc/client.py b/src/diem/jsonrpc/client.py index c8900972..d26be866 100644 --- a/src/diem/jsonrpc/client.py +++ b/src/diem/jsonrpc/client.py @@ -570,6 +570,7 @@ def execute_without_retry( "method": method, "params": params or [], } + json = {} try: json = self._rs.send_request(self, request, ignore_stale_response or False) From f3e027ce9393d80f706b7d5530880fc0e98bd233 Mon Sep 17 00:00:00 2001 From: janhviacn Date: Mon, 16 Jan 2023 13:07:14 +0000 Subject: [PATCH 20/22] updating changes --- src/diem/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diem/utils.py b/src/diem/utils.py index 9c97f538..ba93923f 100644 --- a/src/diem/utils.py +++ b/src/diem/utils.py @@ -223,7 +223,7 @@ def shutdown_event_loop(loop: asyncio.events.AbstractEventLoop) -> None: asyncio.runners._cancel_all_tasks(loop) # pyre-ignore loop.run_until_complete(loop.shutdown_asyncgens()) if hasattr(loop, "shutdown_default_executor"): - loop.run_until_complete(loop.__getattribute__("shutdown_default_executor")) + loop.run_until_complete(getattr(loop, "shutdown_default_executor")()) finally: asyncio.set_event_loop(None) loop.close() From bf04dfb872cf553b5d0da669346962b6dc5f399f Mon Sep 17 00:00:00 2001 From: janhviacn Date: Tue, 17 Jan 2023 10:23:32 +0000 Subject: [PATCH 21/22] reformated client.py file for fixing build issue --- src/diem/jsonrpc/client.py | 46 ++++++++------------------------------ 1 file changed, 9 insertions(+), 37 deletions(-) diff --git a/src/diem/jsonrpc/client.py b/src/diem/jsonrpc/client.py index d26be866..20babb3a 100644 --- a/src/diem/jsonrpc/client.py +++ b/src/diem/jsonrpc/client.py @@ -108,12 +108,7 @@ class RequestWithBackups(RequestStrategy): ``` """ - def __init__( - self, - backups: typing.List[str], - executor: ThreadPoolExecutor, - fallback: bool = False, - ) -> None: + def __init__(self, backups: typing.List[str], executor: ThreadPoolExecutor, fallback: bool = False) -> None: self._backups = backups self._executor = executor self._fallback = fallback @@ -268,16 +263,9 @@ def update_last_known_state(self, chain_id: int, version: int, timestamp_usecs: if curr.timestamp_usecs > timestamp_usecs: raise StaleResponseError(f"last known timestamp_usecs {curr.timestamp_usecs} > {timestamp_usecs}") - self._last_known_server_state = State( - chain_id=chain_id, - version=version, - timestamp_usecs=timestamp_usecs, - ) + self._last_known_server_state = State(chain_id=chain_id, version=version, timestamp_usecs=timestamp_usecs) - def get_metadata( - self, - version: typing.Optional[int] = None, - ) -> rpc.Metadata: + def get_metadata(self, version: typing.Optional[int] = None) -> rpc.Metadata: """get block metadata See [JSON-RPC API Doc](https://github.com/diem/diem/blob/master/json-rpc/docs/method_get_metadata.md) @@ -342,10 +330,7 @@ def get_account_transactions( return self.execute("get_account_transactions", params, _parse_list(lambda: rpc.Transaction())) def get_transactions( - self, - start_version: int, - limit: int, - include_events: typing.Optional[bool] = None, + self, start_version: int, limit: int, include_events: typing.Optional[bool] = None ) -> typing.List[rpc.Transaction]: """get transactions @@ -403,10 +388,7 @@ def support_diem_id(self) -> bool: tc_account = self.must_get_account(TREASURY_ADDRESS) return bool(tc_account.role.vasp_domain_events_key) - def submit( - self, - txn: typing.Union[diem_types.SignedTransaction, str], - ) -> None: + def submit(self, txn: typing.Union[diem_types.SignedTransaction, str]) -> None: """submit signed transaction See [JSON-RPC API Doc](https://github.com/diem/diem/blob/master/json-rpc/docs/method_submit.md) @@ -564,13 +546,8 @@ def execute_without_retry( Raises NetworkError if send http request failed, or received server response status is not 200. """ - request = { - "jsonrpc": "2.0", - "id": 1, - "method": method, - "params": params or [], - } - + request = {"jsonrpc": "2.0", "id": 1, "method": method, "params": params or []} + json = {} try: json = self._rs.send_request(self, request, ignore_stale_response or False) @@ -590,10 +567,7 @@ def execute_without_retry( raise InvalidServerResponse(f"Parse result failed: {e}, response: {json}") def _send_http_request( - self, - url: str, - request: typing.Dict[str, typing.Any], - ignore_stale_response: bool, + self, url: str, request: typing.Dict[str, typing.Any], ignore_stale_response: bool ) -> typing.Dict[str, typing.Any]: self._logger.debug("http request body: %s", request) response = self._session.post(url, json=request, timeout=self._timeout) @@ -607,9 +581,7 @@ def _send_http_request( # check stable response before check jsonrpc error try: self.update_last_known_state( - json.get("diem_chain_id"), - json.get("diem_ledger_version"), - json.get("diem_ledger_timestampusec"), + json.get("diem_chain_id"), json.get("diem_ledger_version"), json.get("diem_ledger_timestampusec") ) except StaleResponseError as e: if not ignore_stale_response: From 1078353f85195038f443c71b18508d46d44e208c Mon Sep 17 00:00:00 2001 From: janhviacn Date: Wed, 18 Jan 2023 17:44:38 +0000 Subject: [PATCH 22/22] updated utils file --- src/diem/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/diem/utils.py b/src/diem/utils.py index ba93923f..c7c2c071 100644 --- a/src/diem/utils.py +++ b/src/diem/utils.py @@ -3,6 +3,7 @@ """Utilities for data type converting, construction and hashing.""" +import sys from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey, Ed25519PrivateKey import hashlib, typing, time, socket, asyncio @@ -222,8 +223,9 @@ def shutdown_event_loop(loop: asyncio.events.AbstractEventLoop) -> None: try: asyncio.runners._cancel_all_tasks(loop) # pyre-ignore loop.run_until_complete(loop.shutdown_asyncgens()) - if hasattr(loop, "shutdown_default_executor"): - loop.run_until_complete(getattr(loop, "shutdown_default_executor")()) + if sys.version_info >= (3, 9): + if hasattr(loop, "shutdown_default_executor"): + loop.run_until_complete(getattr(loop, "shutdown_default_executor")()) finally: asyncio.set_event_loop(None) loop.close()