Skip to content

Commit 9422dae

Browse files
authored
Fixing Dependabot alerts in client sdk python (#331)
* Update click and black version to latest. * updating click & black version * Updating to new diem branch link * Updating to submodule name diem_testnet_tag * Updating diem_testnet_tag url * updating build37 submodule command * build37 submodule command update * updating build37 submodule command * updating url to diem * updating build38 & 39 submodule command * updating gitmodules file * updated diem repo to latest commit * updated runner version * reverted runner version * removed json variable and pyre-ignore comment * Reformatted __init__.py file * build issue fixing * updated files * updated files * updating changes * reformated client.py file for fixing build issue * updated utils file * dependabot alert fixing * dependabot alert fix * updated numpy * testing build * updated cryptography & protobuf version * updated the numpy version to 1.22.0 * updated setup.py
1 parent 5f51508 commit 9422dae

18 files changed

+78
-219
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "diem"]
1+
[submodule "diem_testnet_tag"]
22
path = diem
33
url = https://github.com/diem/diem.git

diem

Submodule diem updated 2836 files

requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
requests==2.20.0
2-
cryptography==3.3.2
3-
numpy==1.18
4-
protobuf==3.12.4
2+
cryptography==39.0.1
3+
numpy==1.19.0
4+
protobuf==3.18.3
55
pytest==6.2.1
66
pytest-asyncio==0.14.0
7-
click==7.1
7+
click==8.1.3
88
aiohttp==3.7.4.post0
99
pylama
10-
black
10+
black==22.10.0
1111
pyre-check
1212
pytest-cov
1313
mypy-protobuf
1414
pdoc3
15-
pygount
15+
pygount

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
[console_scripts]
3030
dmw=diem.testing.cli:main
3131
''',
32-
python_requires=">=3.7", # requires dataclasses
32+
python_requires=">=3.8", # requires dataclasses
3333
packages=["diem"],
3434
# package_data={"": ["src/diem/jsonrpc/*.pyi"]},
3535
package_dir={"": "src"},

src/diem/identifier/bech32.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
class Bech32Error(Exception):
26-
""" Represents an error when creating a Diem address. """
26+
"""Represents an error when creating a Diem address."""
2727

2828
pass
2929

src/diem/jsonrpc/async_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ async def execute_without_retry(
564564
"method": method,
565565
"params": params or [],
566566
}
567+
json = {}
567568
try:
568569
json = await self._rs.send_request(self, request, ignore_stale_response or False)
569570
if "error" in json:

src/diem/jsonrpc/client.py

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ class RequestWithBackups(RequestStrategy):
108108
```
109109
"""
110110

111-
def __init__(
112-
self,
113-
backups: typing.List[str],
114-
executor: ThreadPoolExecutor,
115-
fallback: bool = False,
116-
) -> None:
111+
def __init__(self, backups: typing.List[str], executor: ThreadPoolExecutor, fallback: bool = False) -> None:
117112
self._backups = backups
118113
self._executor = executor
119114
self._fallback = fallback
@@ -268,16 +263,9 @@ def update_last_known_state(self, chain_id: int, version: int, timestamp_usecs:
268263
if curr.timestamp_usecs > timestamp_usecs:
269264
raise StaleResponseError(f"last known timestamp_usecs {curr.timestamp_usecs} > {timestamp_usecs}")
270265

271-
self._last_known_server_state = State(
272-
chain_id=chain_id,
273-
version=version,
274-
timestamp_usecs=timestamp_usecs,
275-
)
266+
self._last_known_server_state = State(chain_id=chain_id, version=version, timestamp_usecs=timestamp_usecs)
276267

277-
def get_metadata(
278-
self,
279-
version: typing.Optional[int] = None,
280-
) -> rpc.Metadata:
268+
def get_metadata(self, version: typing.Optional[int] = None) -> rpc.Metadata:
281269
"""get block metadata
282270
283271
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(
342330
return self.execute("get_account_transactions", params, _parse_list(lambda: rpc.Transaction()))
343331

344332
def get_transactions(
345-
self,
346-
start_version: int,
347-
limit: int,
348-
include_events: typing.Optional[bool] = None,
333+
self, start_version: int, limit: int, include_events: typing.Optional[bool] = None
349334
) -> typing.List[rpc.Transaction]:
350335
"""get transactions
351336
@@ -403,10 +388,7 @@ def support_diem_id(self) -> bool:
403388
tc_account = self.must_get_account(TREASURY_ADDRESS)
404389
return bool(tc_account.role.vasp_domain_events_key)
405390

406-
def submit(
407-
self,
408-
txn: typing.Union[diem_types.SignedTransaction, str],
409-
) -> None:
391+
def submit(self, txn: typing.Union[diem_types.SignedTransaction, str]) -> None:
410392
"""submit signed transaction
411393
412394
See [JSON-RPC API Doc](https://github.com/diem/diem/blob/master/json-rpc/docs/method_submit.md)
@@ -564,12 +546,9 @@ def execute_without_retry(
564546
Raises NetworkError if send http request failed, or received server response status is not 200.
565547
"""
566548

567-
request = {
568-
"jsonrpc": "2.0",
569-
"id": 1,
570-
"method": method,
571-
"params": params or [],
572-
}
549+
request = {"jsonrpc": "2.0", "id": 1, "method": method, "params": params or []}
550+
551+
json = {}
573552
try:
574553
json = self._rs.send_request(self, request, ignore_stale_response or False)
575554
if "error" in json:
@@ -588,10 +567,7 @@ def execute_without_retry(
588567
raise InvalidServerResponse(f"Parse result failed: {e}, response: {json}")
589568

590569
def _send_http_request(
591-
self,
592-
url: str,
593-
request: typing.Dict[str, typing.Any],
594-
ignore_stale_response: bool,
570+
self, url: str, request: typing.Dict[str, typing.Any], ignore_stale_response: bool
595571
) -> typing.Dict[str, typing.Any]:
596572
self._logger.debug("http request body: %s", request)
597573
response = self._session.post(url, json=request, timeout=self._timeout)
@@ -605,9 +581,7 @@ def _send_http_request(
605581
# check stable response before check jsonrpc error
606582
try:
607583
self.update_last_known_state(
608-
json.get("diem_chain_id"),
609-
json.get("diem_ledger_version"),
610-
json.get("diem_ledger_timestampusec"),
584+
json.get("diem_chain_id"), json.get("diem_ledger_version"), json.get("diem_ledger_timestampusec")
611585
)
612586
except StaleResponseError as e:
613587
if not ignore_stale_response:

src/diem/offchain/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class Command(ABC):
12-
"""Command defines common interface for all commands """
12+
"""Command defines common interface for all commands"""
1313

1414
@abstractmethod
1515
def id(self) -> str:

src/diem/offchain/types/__init__.py

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def _field_value_from_dict(field: dataclasses.Field, obj: typing.Any, field_path
124124
full_name = _join_field_path(field_path, field.name)
125125
field_type = field.type
126126
args = field.type.__args__ if hasattr(field.type, "__args__") else []
127-
is_optional = len(args) == 2 and isinstance(None, args[1]) # pyre-ignore
127+
is_optional = len(args) == 2 and isinstance(None, args[1])
128128
if is_optional:
129129
field_type = args[0]
130130
val = obj.get(field.name)
@@ -166,14 +166,9 @@ def new_payment_object(
166166
return PaymentObject(
167167
reference_id=reference_id or str(uuid.uuid4()),
168168
sender=PaymentActorObject(
169-
address=sender_account_id,
170-
kyc_data=sender_kyc_data,
171-
status=StatusObject(status=Status.needs_kyc_data),
172-
),
173-
receiver=PaymentActorObject(
174-
address=receiver_account_id,
175-
status=StatusObject(status=Status.none),
169+
address=sender_account_id, kyc_data=sender_kyc_data, status=StatusObject(status=Status.needs_kyc_data)
176170
),
171+
receiver=PaymentActorObject(address=receiver_account_id, status=StatusObject(status=Status.none)),
177172
action=PaymentActionObject(amount=amount, currency=currency),
178173
description=description,
179174
original_payment_reference_id=original_payment_reference_id,
@@ -196,10 +191,7 @@ def replace_payment_actor(
196191
changes["additional_kyc_data"] = additional_kyc_data
197192
if status or abort_code or abort_message:
198193
changes["status"] = replace_payment_status(
199-
actor.status,
200-
status=status,
201-
abort_code=abort_code,
202-
abort_message=abort_message,
194+
actor.status, status=status, abort_code=abort_code, abort_message=abort_message
203195
)
204196
if metadata:
205197
if not isinstance(metadata, list):
@@ -224,19 +216,11 @@ def replace_payment_status(
224216
return dataclasses.replace(status_obj, **changes)
225217

226218

227-
def new_payment_request(
228-
payment: PaymentObject,
229-
cid: typing.Optional[str] = None,
230-
) -> CommandRequestObject:
219+
def new_payment_request(payment: PaymentObject, cid: typing.Optional[str] = None) -> CommandRequestObject:
231220
return CommandRequestObject(
232221
cid=cid or str(uuid.uuid4()),
233222
command_type=CommandType.PaymentCommand,
234-
command=to_dict(
235-
PaymentCommandObject(
236-
_ObjectType=CommandType.PaymentCommand,
237-
payment=payment,
238-
)
239-
),
223+
command=to_dict(PaymentCommandObject(_ObjectType=CommandType.PaymentCommand, payment=payment)),
240224
)
241225

242226

@@ -254,17 +238,11 @@ def reply_request(
254238

255239

256240
def individual_kyc_data(**kwargs) -> KycDataObject: # pyre-ignore
257-
return KycDataObject(
258-
type=KycDataObjectType.individual,
259-
**kwargs,
260-
)
241+
return KycDataObject(type=KycDataObjectType.individual, **kwargs)
261242

262243

263244
def entity_kyc_data(**kwargs) -> KycDataObject: # pyre-ignore
264-
return KycDataObject(
265-
type=KycDataObjectType.entity,
266-
**kwargs,
267-
)
245+
return KycDataObject(type=KycDataObjectType.entity, **kwargs)
268246

269247

270248
def validate_write_once_fields(path: str, new: typing.Any, prior: typing.Any) -> None: # pyre-ignore

src/diem/offchain/types/command_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class OffChainErrorType:
9898

9999

100100
class OffChainCommandResponseResultType:
101-
""" Type of result in a CommandResponseObject"""
101+
"""Type of result in a CommandResponseObject"""
102102

103103
ReferenceIDCommandResponse = "ReferenceIDCommandResponse"
104104

src/diem/testing/cli.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
log_format: str = "%(name)s [%(asctime)s] %(levelname)s: %(message)s"
17-
click.option = functools.partial(click.option, show_default=True) # pyre-ignore
17+
click.option = functools.partial(click.option, show_default=True)
1818

1919

2020
def coro(f): # pyre-ignore
@@ -187,13 +187,7 @@ async def start_server(
187187
help="Before start test, the target wallet application host port should be ready for connection. This is wait timeout (seconds) for the port ready.",
188188
type=int,
189189
)
190-
@click.option(
191-
"--include-offchain-v2",
192-
type=bool,
193-
is_flag=True,
194-
default=False,
195-
help="Include offchain v2 test suites",
196-
)
190+
@click.option("--include-offchain-v2", type=bool, is_flag=True, default=False, help="Include offchain v2 test suites")
197191
@click.help_option("-h", "--help")
198192
def test(
199193
target: str,

src/diem/testing/miniwallet/app/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ async def worker() -> None:
149149
async def txn_metadata(self, txn: Transaction) -> Tuple[bytes, bytes]:
150150
if await self.offchain.is_under_dual_attestation_limit(txn.currency, txn.amount):
151151
if txn.refund_diem_txn_version and txn.refund_reason:
152-
return self.diem_account.refund_metadata(txn.refund_diem_txn_version, txn.refund_reason) # pyre-ignore
152+
return self.diem_account.refund_metadata(txn.refund_diem_txn_version, txn.refund_reason)
153153
if txn.subaddress_hex:
154154
return self.diem_account.general_metadata(txn.subaddress(), str(txn.payee))
155155
if txn.reference_id:

src/diem/testing/miniwallet/app/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __post_init__(self) -> None:
2626
self.diem_id = create_diem_id(self.id, str(self.vasp_domain)) if self.vasp_domain else None
2727

2828
def kyc_data_object(self) -> offchain.KycDataObject:
29-
return self.kyc_data if self.kyc_data else offchain.individual_kyc_data() # pyre-ignore
29+
return self.kyc_data if self.kyc_data else offchain.individual_kyc_data()
3030

3131

3232
@dataclass

src/diem/testing/suites/basic/test_create_test_account.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@ async def test_create_an_account_with_initial_deposit_balances(
2626
assert await account.balance(currency) == amount
2727

2828

29-
@pytest.mark.parametrize( # pyre-ignore
30-
"kyc_data",
31-
[
32-
offchain.individual_kyc_data(),
33-
offchain.entity_kyc_data(),
34-
],
35-
)
29+
@pytest.mark.parametrize("kyc_data", [offchain.individual_kyc_data(), offchain.entity_kyc_data()])
3630
async def test_create_an_account_with_minimum_valid_kyc_data(
3731
target_client: RestClient, kyc_data: offchain.KycDataObject
3832
) -> None:

src/diem/testing/suites/basic/test_receive_payment.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ async def test_receive_payment_with_invalid_metadata(
7474

7575
@pytest.mark.parametrize("amount", [10_000, 1200_000, 125550_000])
7676
async def test_receive_payment_with_general_metadata_and_valid_from_and_to_subaddresses(
77-
stub_client: RestClient,
78-
target_client: RestClient,
79-
currency: str,
80-
amount: int,
77+
stub_client: RestClient, target_client: RestClient, currency: str, amount: int
8178
) -> None:
8279
"""
8380
Test Plan:
@@ -101,7 +98,7 @@ async def test_receive_payment_with_general_metadata_and_valid_from_and_to_subad
10198
await sender_account.log_events()
10299

103100

104-
@pytest.mark.parametrize( # pyre-ignore
101+
@pytest.mark.parametrize(
105102
"invalid_to_subaddress", [None, b"", b"bb4a3ba109a3175f", b"subaddress_more_than_8_bytes", b"too_short"]
106103
)
107104
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(
163160
await sender_account.log_events()
164161

165162

166-
@pytest.mark.parametrize( # pyre-ignore
163+
@pytest.mark.parametrize(
167164
"invalid_from_subaddress", [None, b"", b"bb4a3ba109a3175f", b"subaddress_more_than_8_bytes", b"too_short"]
168165
)
169166
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
216213
@pytest.mark.parametrize(
217214
"invalid_from_subaddress", [None, b"", b"bb4a3ba109a3175f", b"subaddress_more_than_8_bytes", b"too_short"]
218215
)
219-
@pytest.mark.parametrize( # pyre-ignore
216+
@pytest.mark.parametrize(
220217
"invalid_to_subaddress", [None, b"", b"bb4a3ba109a3175f", b"subaddress_more_than_8_bytes", b"too_short"]
221218
)
222219
async def test_receive_payment_with_general_metadata_and_invalid_subaddresses(

0 commit comments

Comments
 (0)