Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update click and black version to latest. #328

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "diem"]
[submodule "diem_testnet_tag"]
path = diem
url = https://github.com/diem/diem.git
2 changes: 1 addition & 1 deletion diem
Submodule diem updated 2836 files
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/diem/identifier/bech32.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class Bech32Error(Exception):
""" Represents an error when creating a Diem address. """
"""Represents an error when creating a Diem address."""

pass

Expand Down
1 change: 1 addition & 0 deletions src/diem/jsonrpc/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
46 changes: 10 additions & 36 deletions src/diem/jsonrpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -564,12 +546,9 @@ 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)
if "error" in json:
Expand All @@ -588,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)
Expand All @@ -605,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:
Expand Down
2 changes: 1 addition & 1 deletion src/diem/offchain/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
38 changes: 8 additions & 30 deletions src/diem/offchain/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand All @@ -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)),
)


Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/diem/offchain/types/command_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class OffChainErrorType:


class OffChainCommandResponseResultType:
""" Type of result in a CommandResponseObject"""
"""Type of result in a CommandResponseObject"""

ReferenceIDCommandResponse = "ReferenceIDCommandResponse"

Expand Down
10 changes: 2 additions & 8 deletions src/diem/testing/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/diem/testing/miniwallet/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/diem/testing/miniwallet/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions src/diem/testing/suites/basic/test_create_test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 4 additions & 7 deletions src/diem/testing/suites/basic/test_receive_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Loading