1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-17 21:22:10 +00:00

chore(tests): adding type hints to helper functions used in sign_tx tests

This commit is contained in:
grdddj 2022-01-25 18:20:05 +01:00 committed by matejcik
parent 2f282f7a0c
commit 9cf5fd351a
2 changed files with 11 additions and 11 deletions

View File

@ -3,46 +3,46 @@ from trezorlib import messages
T = messages.RequestType
def request_input(n, tx_hash=None):
def request_input(n: int, tx_hash: bytes = None) -> messages.TxRequest:
return messages.TxRequest(
request_type=T.TXINPUT,
details=messages.TxRequestDetailsType(request_index=n, tx_hash=tx_hash),
)
def request_output(n, tx_hash=None):
def request_output(n: int, tx_hash: bytes = None) -> messages.TxRequest:
return messages.TxRequest(
request_type=T.TXOUTPUT,
details=messages.TxRequestDetailsType(request_index=n, tx_hash=tx_hash),
)
def request_orig_input(n, tx_hash):
def request_orig_input(n: int, tx_hash: bytes) -> messages.TxRequest:
return messages.TxRequest(
request_type=T.TXORIGINPUT,
details=messages.TxRequestDetailsType(request_index=n, tx_hash=tx_hash),
)
def request_orig_output(n, tx_hash):
def request_orig_output(n: int, tx_hash: bytes) -> messages.TxRequest:
return messages.TxRequest(
request_type=T.TXORIGOUTPUT,
details=messages.TxRequestDetailsType(request_index=n, tx_hash=tx_hash),
)
def request_meta(tx_hash):
def request_meta(tx_hash: bytes) -> messages.TxRequest:
return messages.TxRequest(
request_type=T.TXMETA,
details=messages.TxRequestDetailsType(tx_hash=tx_hash),
)
def request_finished():
def request_finished() -> messages.TxRequest:
return messages.TxRequest(request_type=T.TXFINISHED)
def request_extra_data(ofs, len, tx_hash):
def request_extra_data(ofs: int, len: int, tx_hash: bytes) -> messages.TxRequest:
return messages.TxRequest(
request_type=T.TXEXTRADATA,
details=messages.TxRequestDetailsType(

View File

@ -52,10 +52,10 @@ BLOCKBOOKS = _get_blockbooks()
class TxCache:
def __init__(self, coin_name):
def __init__(self, coin_name: str) -> None:
self.slug = coin_name.lower().replace(" ", "_")
def get_tx(self, txhash):
def get_tx(self, txhash: str) -> messages.TransactionType:
try:
(CACHE_PATH / self.slug).mkdir()
except Exception:
@ -71,10 +71,10 @@ class TxCache:
txdict = json.loads(cache_file.read_text())
return protobuf.dict_to_proto(messages.TransactionType, txdict)
def __getitem__(self, key):
def __getitem__(self, key: bytes) -> messages.TransactionType:
return self.get_tx(key.hex())
def __contains__(self, key):
def __contains__(self, key: bytes) -> bool:
try:
self.get_tx(key.hex())
return True