1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-04 05:42:34 +00:00

chore(tests): add type hints and improve styling in device test files

This commit is contained in:
grdddj 2022-01-31 13:25:30 +01:00 committed by matejcik
parent c755c4177f
commit 9a71ac74c9
117 changed files with 1597 additions and 1463 deletions

View File

@ -21,7 +21,7 @@ import random
import string
from trezorlib import device
from trezorlib.debuglink import TrezorClientDebugLink
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.transport import enumerate_devices, get_transport
@ -37,7 +37,7 @@ def get_device():
raise RuntimeError("No debuggable device found")
def pin_input_flow(client, old_pin, new_pin):
def pin_input_flow(client: Client, old_pin: str, new_pin: str):
# do you want to change pin?
yield
client.debug.press_yes()
@ -55,7 +55,7 @@ def pin_input_flow(client, old_pin, new_pin):
if __name__ == "__main__":
wirelink = get_device()
client = TrezorClientDebugLink(wirelink)
client = Client(wirelink)
client.open()
i = 0

View File

@ -21,7 +21,7 @@ import random
import string
from trezorlib import device
from trezorlib.debuglink import TrezorClientDebugLink
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.transport import enumerate_devices, get_transport
@ -37,7 +37,7 @@ def get_device():
raise RuntimeError("No debuggable device found")
def pin_input_flow(client, old_pin, new_pin):
def pin_input_flow(client: Client, old_pin: str, new_pin: str):
# do you want to change pin?
yield
client.debug.press_yes()
@ -55,7 +55,7 @@ def pin_input_flow(client, old_pin, new_pin):
if __name__ == "__main__":
wirelink = get_device()
client = TrezorClientDebugLink(wirelink)
client = Client(wirelink)
client.open()
i = 0

View File

@ -245,9 +245,7 @@ def get_test_address(client: "Client") -> str:
return btc.get_address(client, "Testnet", TEST_ADDRESS_N)
def assert_tx_matches(
serialized_tx: bytes, hash_link: str, tx_hex: str = None
) -> None:
def assert_tx_matches(serialized_tx: bytes, hash_link: str, tx_hex: str = None) -> None:
"""Verifies if a transaction is correctly formed."""
hash_str = hash_link.split("/")[-1]
assert tools.tx_hash(serialized_tx).hex() == hash_str

View File

@ -20,7 +20,7 @@ from typing import TYPE_CHECKING
import pytest
from trezorlib import debuglink, log
from trezorlib.debuglink import TrezorClientDebugLink
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.device import apply_settings, wipe as wipe_device
from trezorlib.transport import enumerate_devices, get_transport
@ -38,13 +38,13 @@ pytest.register_assert_rewrite("tests.common")
@pytest.fixture(scope="session")
def _raw_client(request: pytest.FixtureRequest) -> TrezorClientDebugLink:
def _raw_client(request: pytest.FixtureRequest) -> Client:
path = os.environ.get("TREZOR_PATH")
interact = int(os.environ.get("INTERACT", 0))
if path:
try:
transport = get_transport(path)
return TrezorClientDebugLink(transport, auto_interact=not interact)
return Client(transport, auto_interact=not interact)
except Exception as e:
request.session.shouldstop = "Failed to communicate with Trezor"
raise RuntimeError(f"Failed to open debuglink for {path}") from e
@ -53,7 +53,7 @@ def _raw_client(request: pytest.FixtureRequest) -> TrezorClientDebugLink:
devices = enumerate_devices()
for device in devices:
try:
return TrezorClientDebugLink(device, auto_interact=not interact)
return Client(device, auto_interact=not interact)
except Exception:
pass
@ -62,9 +62,7 @@ def _raw_client(request: pytest.FixtureRequest) -> TrezorClientDebugLink:
@pytest.fixture(scope="function")
def client(
request: pytest.FixtureRequest, _raw_client: TrezorClientDebugLink
) -> TrezorClientDebugLink:
def client(request: pytest.FixtureRequest, _raw_client: Client) -> Client:
"""Client fixture.
Every test function that requires a client instance will get it from here.
@ -298,9 +296,7 @@ def pytest_runtest_makereport(item: pytest.Item, call) -> None:
@pytest.fixture
def device_handler(
client: TrezorClientDebugLink, request: pytest.FixtureRequest
) -> None:
def device_handler(client: Client, request: pytest.FixtureRequest) -> None:
device_handler = BackgroundDeviceHandler(client)
yield device_handler

View File

@ -6,7 +6,7 @@ from trezorlib.transport import udp
if TYPE_CHECKING:
from trezorlib.messages import Features
from trezorlib.debuglink import TrezorClientDebugLink, DebugLink
from trezorlib.debuglink import DebugLink, TrezorClientDebugLink as Client
from trezorlib._internal.emulator import Emulator
@ -33,11 +33,11 @@ class NullUI:
class BackgroundDeviceHandler:
_pool = ThreadPoolExecutor()
def __init__(self, client: "TrezorClientDebugLink") -> None:
def __init__(self, client: "Client") -> None:
self._configure_client(client)
self.task = None
def _configure_client(self, client: "TrezorClientDebugLink") -> None:
def _configure_client(self, client: "Client") -> None:
self.client = client
self.client.ui = NullUI # type: ignore [NullUI is OK UI]
self.client.watch_layout(True)

View File

@ -17,11 +17,12 @@
import pytest
from trezorlib.binance import get_address
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
BINANCE_ADDRESS_TEST_VECTORS = [
("m/44'/714'/0'/0/0", "bnb1hgm0p7khfk85zpz5v0j8wnej3a90w709vhkdfu"),
("m/44'/714'/0'/0/1", "bnb1egswqkszzfc2uq78zjslc6u2uky4pw46x4rstd"),
("m/44h/714h/0h/0/0", "bnb1hgm0p7khfk85zpz5v0j8wnej3a90w709vhkdfu"),
("m/44h/714h/0h/0/1", "bnb1egswqkszzfc2uq78zjslc6u2uky4pw46x4rstd"),
]
@ -32,7 +33,7 @@ BINANCE_ADDRESS_TEST_VECTORS = [
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin"
)
@pytest.mark.parametrize("path, expected_address", BINANCE_ADDRESS_TEST_VECTORS)
def test_binance_get_address(client, path, expected_address):
def test_binance_get_address(client: Client, path, expected_address):
# data from https://github.com/binance-chain/javascript-sdk/blob/master/__tests__/crypto.test.js#L50
address = get_address(client, parse_path(path), show_display=True)

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import binance
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
BINANCE_PATH = parse_path("m/44h/714h/0h/0/0")
@ -28,7 +29,7 @@ BINANCE_PATH = parse_path("m/44h/714h/0h/0/0")
@pytest.mark.setup_client(
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin"
)
def test_binance_get_public_key(client):
def test_binance_get_public_key(client: Client):
sig = binance.get_public_key(client, BINANCE_PATH, show_display=True)
assert (
sig.hex()

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import binance
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
BINANCE_TEST_VECTORS = [
@ -107,8 +108,8 @@ BINANCE_TEST_VECTORS = [
mnemonic="offer caution gift cross surge pretty orange during eye soldier popular holiday mention east eight office fashion ill parrot vault rent devote earth cousin"
)
@pytest.mark.parametrize("message, expected_response", BINANCE_TEST_VECTORS)
def test_binance_sign_message(client, message, expected_response):
response = binance.sign_tx(client, parse_path("m/44'/714'/0'/0/0"), message)
def test_binance_sign_message(client: Client, message, expected_response):
response = binance.sign_tx(client, parse_path("m/44h/714h/0h/0/0"), message)
assert response.public_key.hex() == expected_response["public_key"]

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
@ -49,7 +50,7 @@ pytestmark = pytest.mark.skip_t1
@pytest.mark.setup_client(pin=PIN)
def test_sign_tx(client):
def test_sign_tx(client: Client):
commitment_data = b"www.example.com" + (1).to_bytes(ROUND_ID_LEN, "big")
with client:
@ -57,9 +58,9 @@ def test_sign_tx(client):
btc.authorize_coinjoin(
client,
coordinator="www.example.com",
max_total_fee=10010,
fee_per_anonymity=5000000, # 0.005 %
n=parse_path("m/84'/1'/0'"),
max_total_fee=10_010,
fee_per_anonymity=5_000_000, # 0.005 %
n=parse_path("m/84h/1h/0h"),
coin_name="Testnet",
script_type=messages.InputScriptType.SPENDWITNESS,
)
@ -73,7 +74,7 @@ def test_sign_tx(client):
btc.get_ownership_proof(
client,
"Testnet",
parse_path("84'/1'/0'/1/0"),
parse_path("m/84h/1h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
commitment_data=commitment_data,
@ -87,7 +88,7 @@ def test_sign_tx(client):
btc.get_ownership_proof(
client,
"Testnet",
parse_path("84'/1'/0'/1/5"),
parse_path("m/84h/1h/0h/1/5"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
commitment_data=commitment_data,
@ -99,7 +100,7 @@ def test_sign_tx(client):
# seed "alcohol woman abuse must during monitor noble actual mixed trade anger aisle"
# 84'/1'/0'/0/0
# tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2
amount=100000,
amount=100_000,
prev_hash=TXHASH_e5b7e2,
prev_index=0,
script_type=messages.InputScriptType.EXTERNAL,
@ -110,8 +111,8 @@ def test_sign_tx(client):
commitment_data=commitment_data,
),
messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=7_289_000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -122,30 +123,30 @@ def test_sign_tx(client):
# Other's coinjoined output.
messages.TxOutputType(
address="tb1qk7j3ahs2v6hrv4v282cf0tvxh0vqq7rpt3zcml",
amount=50000,
amount=50_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
# Our coinjoined output.
messages.TxOutputType(
# tb1qze76uzqteg6un6jfcryrxhwvfvjj58ts0swg3d
address_n=parse_path("84'/1'/0'/1/1"),
amount=50000,
address_n=parse_path("m/84h/1h/0h/1/1"),
amount=50_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
# Our change output.
messages.TxOutputType(
# tb1qr5p6f5sk09sms57ket074vywfymuthlgud7xyx
address_n=parse_path("84'/1'/0'/1/2"),
amount=7289000 - 50000 - 5 - 5000,
address_n=parse_path("m/84h/1h/0h/1/2"),
amount=7_289_000 - 50_000 - 5 - 5_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
# Other's change output.
messages.TxOutputType(
address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk",
amount=100000 - 50000 - 5 - 5000,
amount=100_000 - 50_000 - 5 - 5_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
@ -241,16 +242,16 @@ def test_sign_tx(client):
)
def test_unfair_fee(client):
def test_unfair_fee(client: Client):
# Test unfair mining fee distribution amongst participants.
with client:
btc.authorize_coinjoin(
client,
coordinator="www.example.com",
max_total_fee=10000,
fee_per_anonymity=5000000, # 0.005 %
n=parse_path("m/84'/1'/0'"),
max_total_fee=10_000,
fee_per_anonymity=5_000_000, # 0.005 %
n=parse_path("m/84h/1h/0h"),
coin_name="Testnet",
script_type=messages.InputScriptType.SPENDWITNESS,
)
@ -260,7 +261,7 @@ def test_unfair_fee(client):
# seed "alcohol woman abuse must during monitor noble actual mixed trade anger aisle"
# 84'/1'/0'/0/0
# tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2
amount=100000,
amount=100_000,
prev_hash=TXHASH_e5b7e2,
prev_index=0,
script_type=messages.InputScriptType.EXTERNAL,
@ -271,8 +272,8 @@ def test_unfair_fee(client):
commitment_data=b"www.example.org" + (1).to_bytes(ROUND_ID_LEN, "big"),
),
messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=7_289_000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -283,30 +284,30 @@ def test_unfair_fee(client):
# Other's coinjoined output.
messages.TxOutputType(
address="tb1qk7j3ahs2v6hrv4v282cf0tvxh0vqq7rpt3zcml",
amount=50000,
amount=50_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
# Our coinjoined output.
messages.TxOutputType(
# tb1qze76uzqteg6un6jfcryrxhwvfvjj58ts0swg3d
address_n=parse_path("84'/1'/0'/1/1"),
amount=50000,
address_n=parse_path("m/84h/1h/0h/1/1"),
amount=50_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
# Our change output.
messages.TxOutputType(
# tb1qr5p6f5sk09sms57ket074vywfymuthlgud7xyx
address_n=parse_path("84'/1'/0'/1/2"),
amount=7289000 - 50000 - 5 - 6000, # unfair mining fee
address_n=parse_path("m/84h/1h/0h/1/2"),
amount=7_289_000 - 50_000 - 5 - 6_000, # unfair mining fee
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
# Other's change output.
messages.TxOutputType(
address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk",
amount=100000 - 50000 - 5 - 4000,
amount=100_000 - 50_000 - 5 - 4_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
@ -342,16 +343,16 @@ def test_unfair_fee(client):
)
def test_no_anonymity(client):
def test_no_anonymity(client: Client):
# Test CoinJoin transaction giving the user's outputs no gain in anonymity.
with client:
btc.authorize_coinjoin(
client,
coordinator="www.example.com",
max_total_fee=5005,
fee_per_anonymity=5000000, # 0.005 %
n=parse_path("m/84'/1'/0'"),
max_total_fee=5_005,
fee_per_anonymity=5_000_000, # 0.005 %
n=parse_path("m/84h/1h/0h"),
coin_name="Testnet",
script_type=messages.InputScriptType.SPENDWITNESS,
)
@ -361,7 +362,7 @@ def test_no_anonymity(client):
# seed "alcohol woman abuse must during monitor noble actual mixed trade anger aisle"
# 84'/1'/0'/0/0
# tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2
amount=100000,
amount=100_000,
prev_hash=TXHASH_e5b7e2,
prev_index=0,
script_type=messages.InputScriptType.EXTERNAL,
@ -372,8 +373,8 @@ def test_no_anonymity(client):
commitment_data=b"www.example.org" + (1).to_bytes(ROUND_ID_LEN, "big"),
),
messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=7_289_000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -384,45 +385,45 @@ def test_no_anonymity(client):
# Other's coinjoined output.
messages.TxOutputType(
address="tb1qk7j3ahs2v6hrv4v282cf0tvxh0vqq7rpt3zcml",
amount=30000,
amount=30_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
# Other's coinjoined output.
messages.TxOutputType(
address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk",
amount=30000,
amount=30_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
# Our coinjoined output.
messages.TxOutputType(
# tb1qze76uzqteg6un6jfcryrxhwvfvjj58ts0swg3d
address_n=parse_path("84'/1'/0'/1/1"),
amount=50000,
address_n=parse_path("m/84h/1h/0h/1/1"),
amount=50_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
# Our coinjoined output.
messages.TxOutputType(
# tb1qr5p6f5sk09sms57ket074vywfymuthlgud7xyx
address_n=parse_path("84'/1'/0'/1/2"),
amount=50000,
address_n=parse_path("m/84h/1h/0h/1/2"),
amount=50_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
# Our change output.
messages.TxOutputType(
# tb1qwn0s88t9r39g72m78mcaxj72sy3ct4m404xsmq
address_n=parse_path("84'/1'/0'/1/3"),
amount=7289000 - 50000 - 50000 - 10 - 5000,
address_n=parse_path("m/84h/1h/0h/1/3"),
amount=7_289_000 - 50_000 - 50_000 - 10 - 5_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
# Other's change output.
messages.TxOutputType(
address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk",
amount=100000 - 30000 - 30000 - 6 - 5000,
amount=100_000 - 30_000 - 30_000 - 6 - 5_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
@ -459,14 +460,14 @@ def test_no_anonymity(client):
)
def test_wrong_coordinator(client):
def test_wrong_coordinator(client: Client):
# Ensure that a preauthorized GetOwnershipProof fails if the commitment_data doesn't match the coordinator.
btc.authorize_coinjoin(
client,
max_total_fee=50000,
max_total_fee=50_000,
coordinator="www.example.com",
n=parse_path("m/84'/1'/0'"),
n=parse_path("m/84h/1h/0h"),
coin_name="Testnet",
script_type=messages.InputScriptType.SPENDWITNESS,
)
@ -475,7 +476,7 @@ def test_wrong_coordinator(client):
btc.get_ownership_proof(
client,
"Testnet",
parse_path("84'/1'/0'/1/0"),
parse_path("m/84h/1h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
commitment_data=b"www.example.org" + (1).to_bytes(ROUND_ID_LEN, "big"),
@ -483,14 +484,14 @@ def test_wrong_coordinator(client):
)
def test_cancel_authorization(client):
def test_cancel_authorization(client: Client):
# Ensure that a preauthorized GetOwnershipProof fails if the commitment_data doesn't match the coordinator.
btc.authorize_coinjoin(
client,
max_total_fee=50000,
max_total_fee=50_000,
coordinator="www.example.com",
n=parse_path("m/84'/1'/0'"),
n=parse_path("m/84h/1h/0h"),
coin_name="Testnet",
script_type=messages.InputScriptType.SPENDWITNESS,
)
@ -501,7 +502,7 @@ def test_cancel_authorization(client):
btc.get_ownership_proof(
client,
"Testnet",
parse_path("84'/1'/0'/1/0"),
parse_path("m/84h/1h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
commitment_data=b"www.example.com" + (1).to_bytes(ROUND_ID_LEN, "big"),
@ -509,13 +510,13 @@ def test_cancel_authorization(client):
)
def test_multisession_authorization(client):
def test_multisession_authorization(client: Client):
# Authorize CoinJoin with www.example1.com in session 1.
btc.authorize_coinjoin(
client,
max_total_fee=50000,
max_total_fee=50_000,
coordinator="www.example1.com",
n=parse_path("m/84'/1'/0'"),
n=parse_path("m/84h/1h/0h"),
coin_name="Testnet",
script_type=messages.InputScriptType.SPENDWITNESS,
)
@ -527,9 +528,9 @@ def test_multisession_authorization(client):
# Authorize CoinJoin with www.example2.com in session 2.
btc.authorize_coinjoin(
client,
max_total_fee=50000,
max_total_fee=50_000,
coordinator="www.example2.com",
n=parse_path("m/84'/1'/0'"),
n=parse_path("m/84h/1h/0h"),
coin_name="Testnet",
script_type=messages.InputScriptType.SPENDWITNESS,
)
@ -539,7 +540,7 @@ def test_multisession_authorization(client):
ownership_proof, _ = btc.get_ownership_proof(
client,
"Testnet",
parse_path("84'/1'/0'/1/0"),
parse_path("m/84h/1h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
commitment_data=b"www.example1.com" + (1).to_bytes(ROUND_ID_LEN, "big"),
@ -550,7 +551,7 @@ def test_multisession_authorization(client):
ownership_proof, _ = btc.get_ownership_proof(
client,
"Testnet",
parse_path("84'/1'/0'/1/0"),
parse_path("m/84h/1h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
commitment_data=b"www.example2.com" + (1).to_bytes(ROUND_ID_LEN, "big"),
@ -570,7 +571,7 @@ def test_multisession_authorization(client):
ownership_proof, _ = btc.get_ownership_proof(
client,
"Testnet",
parse_path("84'/1'/0'/1/0"),
parse_path("m/84h/1h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
commitment_data=b"www.example1.com" + (1).to_bytes(ROUND_ID_LEN, "big"),
@ -587,7 +588,7 @@ def test_multisession_authorization(client):
ownership_proof, _ = btc.get_ownership_proof(
client,
"Testnet",
parse_path("84'/1'/0'/1/0"),
parse_path("m/84h/1h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
commitment_data=b"www.example2.com" + (1).to_bytes(ROUND_ID_LEN, "big"),
@ -602,7 +603,7 @@ def test_multisession_authorization(client):
ownership_proof, _ = btc.get_ownership_proof(
client,
"Testnet",
parse_path("84'/1'/0'/1/0"),
parse_path("m/84h/1h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
commitment_data=b"www.example1.com" + (1).to_bytes(ROUND_ID_LEN, "big"),
@ -616,7 +617,7 @@ def test_multisession_authorization(client):
ownership_proof, _ = btc.get_ownership_proof(
client,
"Testnet",
parse_path("84'/1'/0'/1/0"),
parse_path("m/84h/1h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
commitment_data=b"www.example2.com" + (1).to_bytes(ROUND_ID_LEN, "big"),

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import H_, parse_path
@ -42,23 +43,23 @@ TXHASH_8b6db9 = bytes.fromhex(
pytestmark = pytest.mark.altcoin
def test_send_bch_change(client):
def test_send_bch_change(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/145'/0'/0/0"),
address_n=parse_path("m/44h/145h/0h/0/0"),
# bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv
amount=1995344,
amount=1_995_344,
prev_hash=TXHASH_bc37c2,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
)
out1 = messages.TxOutputType(
address_n=parse_path("44'/145'/0'/1/0"),
amount=1896050,
address_n=parse_path("m/44h/145h/0h/1/0"),
amount=1_896_050,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="bitcoincash:qr23ajjfd9wd73l87j642puf8cad20lfmqdgwvpat4",
amount=73452,
amount=73_452,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
with client:
@ -89,26 +90,26 @@ def test_send_bch_change(client):
)
def test_send_bch_nochange(client):
def test_send_bch_nochange(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/145'/0'/1/0"),
address_n=parse_path("m/44h/145h/0h/1/0"),
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
amount=1896050,
amount=1_896_050,
prev_hash=TXHASH_502e85,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
)
inp2 = messages.TxInputType(
address_n=parse_path("44'/145'/0'/0/1"),
address_n=parse_path("m/44h/145h/0h/0/1"),
# bitcoincash:qr23ajjfd9wd73l87j642puf8cad20lfmqdgwvpat4
amount=73452,
amount=73_452,
prev_hash=TXHASH_502e85,
prev_index=1,
script_type=messages.InputScriptType.SPENDADDRESS,
)
out1 = messages.TxOutputType(
address="bitcoincash:qq6wnnkrz7ykaqvxrx4hmjvayvzjzml54uyk76arx4",
amount=1934960,
amount=1_934_960,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
with client:
@ -145,26 +146,26 @@ def test_send_bch_nochange(client):
)
def test_send_bch_oldaddr(client):
def test_send_bch_oldaddr(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/145'/0'/1/0"),
address_n=parse_path("m/44h/145h/0h/1/0"),
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
amount=1896050,
amount=1_896_050,
prev_hash=TXHASH_502e85,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
)
inp2 = messages.TxInputType(
address_n=parse_path("44'/145'/0'/0/1"),
address_n=parse_path("m/44h/145h/0h/0/1"),
# bitcoincash:qr23ajjfd9wd73l87j642puf8cad20lfmqdgwvpat4
amount=73452,
amount=73_452,
prev_hash=TXHASH_502e85,
prev_index=1,
script_type=messages.InputScriptType.SPENDADDRESS,
)
out1 = messages.TxOutputType(
address="15pnEDZJo3ycPUamqP3tEDnEju1oW5fBCz",
amount=1934960,
amount=1_934_960,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
with client:
@ -201,22 +202,22 @@ def test_send_bch_oldaddr(client):
)
def test_attack_change_input(client):
def test_attack_change_input(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/145'/10'/0/0"),
amount=1995344,
address_n=parse_path("m/44h/145h/10h/0/0"),
amount=1_995_344,
prev_hash=TXHASH_bc37c2,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
)
out1 = messages.TxOutputType(
address_n=parse_path("44'/145'/10'/1/0"),
amount=1896050,
address_n=parse_path("m/44h/145h/10h/1/0"),
amount=1_896_050,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="bitcoincash:qr23ajjfd9wd73l87j642puf8cad20lfmqdgwvpat4",
amount=73452,
amount=73_452,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -255,10 +256,10 @@ def test_attack_change_input(client):
@pytest.mark.multisig
def test_send_bch_multisig_wrongchange(client):
def test_send_bch_multisig_wrongchange(client: Client):
nodes = [
btc.get_public_node(
client, parse_path(f"48'/145'/{i}'/0'"), coin_name="Bcash"
client, parse_path(f"m/48h/145h/{i}h/0h"), coin_name="Bcash"
).node
for i in range(1, 4)
]
@ -283,16 +284,16 @@ def test_send_bch_multisig_wrongchange(client):
"304402207274b5a4d15e75f3df7319a375557b0efba9b27bc63f9f183a17da95a6125c94022000efac57629f1522e2d3958430e2ef073b0706cfac06cce492651b79858f09ae"
)
inp1 = messages.TxInputType(
address_n=parse_path("48'/145'/1'/0'/1/0"),
address_n=parse_path("m/48h/145h/1h/0h/1/0"),
multisig=getmultisig(1, 0, [b"", sig, b""]),
# bitcoincash:pp6kcpkhua7789g2vyj0qfkcux3yvje7euhyhltn0a
amount=24000,
amount=24_000,
prev_hash=TXHASH_f68caf,
prev_index=1,
script_type=messages.InputScriptType.SPENDMULTISIG,
)
out1 = messages.TxOutputType(
address_n=parse_path("48'/145'/1'/0'/1/1"),
address_n=parse_path("m/48h/145h/1h/0h/1/1"),
multisig=messages.MultisigRedeemScriptType(
pubkeys=[
messages.HDNodePathType(node=nodes[0], address_n=[1, 1]),
@ -303,7 +304,7 @@ def test_send_bch_multisig_wrongchange(client):
m=2,
),
script_type=messages.OutputScriptType.PAYTOMULTISIG,
amount=23000,
amount=23_000,
)
with client:
client.set_expected_responses(
@ -336,10 +337,10 @@ def test_send_bch_multisig_wrongchange(client):
@pytest.mark.multisig
def test_send_bch_multisig_change(client):
def test_send_bch_multisig_change(client: Client):
nodes = [
btc.get_public_node(
client, parse_path(f"48'/145'/{i}'/0'"), coin_name="Bcash"
client, parse_path(f"m/48h/145h/{i}h/0h"), coin_name="Bcash"
).node
for i in range(1, 4)
]
@ -352,23 +353,23 @@ def test_send_bch_multisig_change(client):
)
inp1 = messages.TxInputType(
address_n=parse_path("48'/145'/3'/0'/0/0"),
address_n=parse_path("m/48h/145h/3h/0h/0/0"),
multisig=getmultisig(0, 0, EMPTY_SIGNATURES),
amount=48490,
amount=48_490,
prev_hash=TXHASH_8b6db9,
prev_index=0,
script_type=messages.InputScriptType.SPENDMULTISIG,
)
out1 = messages.TxOutputType(
address="bitcoincash:qqq8gx2j76nw4dfefumxmdwvtf2tpsjznusgsmzex9",
amount=24000,
amount=24_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("48'/145'/3'/0'/1/0"),
address_n=parse_path("m/48h/145h/3h/0h/1/0"),
multisig=getmultisig(1, 0, EMPTY_SIGNATURES),
script_type=messages.OutputScriptType.PAYTOMULTISIG,
amount=24000,
amount=24_000,
)
with client:
client.set_expected_responses(
@ -398,10 +399,10 @@ def test_send_bch_multisig_change(client):
)
inp1 = messages.TxInputType(
address_n=parse_path("48'/145'/1'/0'/0/0"),
address_n=parse_path("m/48h/145h/1h/0h/0/0"),
multisig=getmultisig(0, 0, [b"", b"", signatures1[0]]),
# bitcoincash:pqguz4nqq64jhr5v3kvpq4dsjrkda75hwy86gq0qzw
amount=48490,
amount=48_490,
prev_hash=TXHASH_8b6db9,
prev_index=0,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -441,11 +442,11 @@ def test_send_bch_multisig_change(client):
@pytest.mark.skip_t1
def test_send_bch_external_presigned(client):
def test_send_bch_external_presigned(client: Client):
inp1 = messages.TxInputType(
# address_n=parse_path("44'/145'/0'/1/0"),
# bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw
amount=1896050,
amount=1_896_050,
prev_hash=TXHASH_502e85,
prev_index=0,
script_type=messages.InputScriptType.EXTERNAL,
@ -457,16 +458,16 @@ def test_send_bch_external_presigned(client):
),
)
inp2 = messages.TxInputType(
address_n=parse_path("44'/145'/0'/0/1"),
address_n=parse_path("m/44h/145h/0h/0/1"),
# bitcoincash:qr23ajjfd9wd73l87j642puf8cad20lfmqdgwvpat4
amount=73452,
amount=73_452,
prev_hash=TXHASH_502e85,
prev_index=1,
script_type=messages.InputScriptType.SPENDADDRESS,
)
out1 = messages.TxOutputType(
address="bitcoincash:qq6wnnkrz7ykaqvxrx4hmjvayvzjzml54uyk76arx4",
amount=1934960,
amount=1_934_960,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
with client:

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import H_, btc_hash, parse_path
@ -40,22 +41,22 @@ pytestmark = pytest.mark.altcoin
# All data taken from T1
def test_send_bitcoin_gold_change(client):
def test_send_bitcoin_gold_change(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/156'/0'/0/0"),
amount=1252382934,
address_n=parse_path("m/44h/156h/0h/0/0"),
amount=1_252_382_934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
)
out1 = messages.TxOutputType(
address_n=parse_path("44'/156'/0'/1/0"),
amount=1896050,
address_n=parse_path("m/44h/156h/0h/1/0"),
amount=1_896_050,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=1252382934 - 1896050 - 1000,
amount=1_252_382_934 - 1_896_050 - 1_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
with client:
@ -87,25 +88,25 @@ def test_send_bitcoin_gold_change(client):
)
def test_send_bitcoin_gold_nochange(client):
def test_send_bitcoin_gold_nochange(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/156'/0'/1/0"),
amount=1252382934,
address_n=parse_path("m/44h/156h/0h/1/0"),
amount=1_252_382_934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
)
inp2 = messages.TxInputType(
address_n=parse_path("44'/156'/0'/0/1"),
address_n=parse_path("m/44h/156h/0h/0/1"),
# 1LRspCZNFJcbuNKQkXgHMDucctFRQya5a3
amount=38448607,
amount=38_448_607,
prev_hash=TXHASH_db77c2,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
)
out1 = messages.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=1252382934 + 38448607 - 1000,
amount=1_252_382_934 + 38_448_607 - 1_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
with client:
@ -142,22 +143,22 @@ def test_send_bitcoin_gold_nochange(client):
)
def test_attack_change_input(client):
def test_attack_change_input(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/156'/11'/0/0"),
amount=1252382934,
address_n=parse_path("m/44h/156h/11h/0/0"),
amount=1_252_382_934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
)
out1 = messages.TxOutputType(
address_n=parse_path("44'/156'/11'/1/0"),
amount=1896050,
address_n=parse_path("m/44h/156h/11h/1/0"),
amount=1_896_050,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=1252382934 - 1896050 - 1000,
amount=1_252_382_934 - 1_896_050 - 1_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -197,10 +198,10 @@ def test_attack_change_input(client):
@pytest.mark.multisig
def test_send_btg_multisig_change(client):
def test_send_btg_multisig_change(client: Client):
nodes = [
btc.get_public_node(
client, parse_path(f"48'/156'/{i}'/0'"), coin_name="Bgold"
client, parse_path(f"m/48h/156h/{i}h/0h"), coin_name="Bgold"
).node
for i in range(1, 4)
]
@ -213,24 +214,24 @@ def test_send_btg_multisig_change(client):
)
inp1 = messages.TxInputType(
address_n=parse_path("48'/156'/3'/0'/0/0"),
address_n=parse_path("m/48h/156h/3h/0h/0/0"),
multisig=getmultisig(0, 0, EMPTY_SIGS),
# 33Ju286QvonBz5N1V754ZekQv4GLJqcc5R
amount=1252382934,
amount=1_252_382_934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=messages.InputScriptType.SPENDMULTISIG,
)
out1 = messages.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=24000,
amount=24_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("48'/156'/3'/0'/1/0"),
address_n=parse_path("m/48h/156h/3h/0h/1/0"),
multisig=getmultisig(1, 0, EMPTY_SIGS),
script_type=messages.OutputScriptType.PAYTOMULTISIG,
amount=1252382934 - 24000 - 1000,
amount=1_252_382_934 - 24_000 - 1_000,
)
with client:
client.set_expected_responses(
@ -261,9 +262,9 @@ def test_send_btg_multisig_change(client):
)
inp1 = messages.TxInputType(
address_n=parse_path("48'/156'/1'/0'/0/0"),
address_n=parse_path("m/48h/156h/1h/0h/0/0"),
multisig=getmultisig(0, 0, [b"", b"", signatures[0]]),
amount=1252382934,
amount=1_252_382_934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -303,23 +304,23 @@ def test_send_btg_multisig_change(client):
)
def test_send_p2sh(client):
def test_send_p2sh(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("49'/156'/0'/1/0"),
amount=1252382934,
address_n=parse_path("m/49h/156h/0h/1/0"),
amount=1_252_382_934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
out1 = messages.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="GZFLExxrvWFuFT1xRzhfwQWSE2bPDedBfn",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=1252382934 - 11000 - 12300000,
amount=1_252_382_934 - 11_000 - 12_300_000,
)
with client:
client.set_expected_responses(
@ -352,23 +353,23 @@ def test_send_p2sh(client):
)
def test_send_p2sh_witness_change(client):
def test_send_p2sh_witness_change(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("49'/156'/0'/1/0"),
amount=1252382934,
address_n=parse_path("m/49h/156h/0h/1/0"),
amount=1_252_382_934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
out1 = messages.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("49'/156'/0'/1/0"),
address_n=parse_path("m/49h/156h/0h/1/0"),
script_type=messages.OutputScriptType.PAYTOP2SHWITNESS,
amount=1252382934 - 11000 - 12300000,
amount=1_252_382_934 - 11_000 - 12_300_000,
)
with client:
client.set_expected_responses(
@ -401,10 +402,10 @@ def test_send_p2sh_witness_change(client):
@pytest.mark.multisig
def test_send_multisig_1(client):
def test_send_multisig_1(client: Client):
nodes = [
btc.get_public_node(
client, parse_path(f"49'/156'/{i}'"), coin_name="Bgold"
client, parse_path(f"m/49h/156h/{i}h"), coin_name="Bgold"
).node
for i in range(1, 4)
]
@ -413,17 +414,17 @@ def test_send_multisig_1(client):
)
inp1 = messages.TxInputType(
address_n=parse_path("49'/156'/1'/1/0"),
address_n=parse_path("m/49h/156h/1h/1/0"),
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
multisig=multisig,
amount=1252382934,
amount=1_252_382_934,
)
out1 = messages.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=1252382934 - 1000,
amount=1_252_382_934 - 1_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -477,26 +478,26 @@ def test_send_multisig_1(client):
)
def test_send_mixed_inputs(client):
def test_send_mixed_inputs(client: Client):
# First is non-segwit, second is segwit.
inp1 = messages.TxInputType(
address_n=parse_path("44'/156'/11'/0/0"),
amount=38448607,
address_n=parse_path("m/44h/156h/11h/0/0"),
amount=38_448_607,
prev_hash=TXHASH_db77c2,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
)
inp2 = messages.TxInputType(
address_n=parse_path("49'/156'/0'/1/0"),
amount=1252382934,
address_n=parse_path("m/49h/156h/0h/1/0"),
amount=1_252_382_934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
out1 = messages.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=38448607 + 1252382934 - 1000,
amount=38_448_607 + 1_252_382_934 - 1_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -512,10 +513,10 @@ def test_send_mixed_inputs(client):
@pytest.mark.skip_t1
def test_send_btg_external_presigned(client):
def test_send_btg_external_presigned(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/156'/0'/1/0"),
amount=1252382934,
address_n=parse_path("m/44h/156h/0h/1/0"),
amount=1_252_382_934,
prev_hash=TXHASH_25526b,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
@ -523,7 +524,7 @@ def test_send_btg_external_presigned(client):
inp2 = messages.TxInputType(
# address_n=parse_path("49'/156'/0'/0/0"),
# AXibjT5r96ZaVA8Lu4BQZocdTx7p5Ud8ZP
amount=58456,
amount=58_456,
prev_hash=TXHASH_f55c5b,
prev_index=0,
script_type=messages.InputScriptType.EXTERNAL,
@ -535,7 +536,7 @@ def test_send_btg_external_presigned(client):
)
out1 = messages.TxOutputType(
address="GfDB1tvjfm3bukeoBTtfNqrJVFohS2kCTe",
amount=1252382934 + 58456 - 1000,
amount=1_252_382_934 + 58_456 - 1_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
with client:

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...tx_cache import TxCache
@ -41,18 +42,18 @@ TXHASH_15575a = bytes.fromhex(
pytestmark = pytest.mark.altcoin
def test_send_dash(client):
def test_send_dash(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/5'/0'/0/0"),
address_n=parse_path("m/44h/5h/0h/0/0"),
# dash:XdTw4G5AWW4cogGd7ayybyBNDbuB45UpgH
amount=1000000000,
amount=1_000_000_000,
prev_hash=TXHASH_5579ea,
prev_index=1,
script_type=messages.InputScriptType.SPENDADDRESS,
)
out1 = messages.TxOutputType(
address="XpTc36DPAeWmaueNBA9JqCg2GC8XDLKSYe",
amount=999999000,
amount=999_999_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
with client:
@ -82,23 +83,23 @@ def test_send_dash(client):
)
def test_send_dash_dip2_input(client):
def test_send_dash_dip2_input(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/5'/0'/0/0"),
address_n=parse_path("m/44h/5h/0h/0/0"),
# dash:XdTw4G5AWW4cogGd7ayybyBNDbuB45UpgH
amount=4095000260,
amount=4_095_000_260,
prev_hash=TXHASH_15575a,
prev_index=1,
script_type=messages.InputScriptType.SPENDADDRESS,
)
out1 = messages.TxOutputType(
address_n=parse_path("44'/5'/0'/1/0"),
amount=4000000000,
address_n=parse_path("m/44h/5h/0h/1/0"),
amount=4_000_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="XrEFMNkxeipYHgEQKiJuqch8XzwrtfH5fm",
amount=95000000,
amount=95_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
with client:

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...tx_cache import TxCache
@ -54,20 +55,20 @@ TXHASH_1f00fc = bytes.fromhex(
pytestmark = [pytest.mark.altcoin, pytest.mark.decred]
def test_send_decred(client):
def test_send_decred(client: Client):
inp1 = messages.TxInputType(
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
address_n=parse_path("m/44'/1'/0'/0/0"),
address_n=parse_path("m/44h/1h/0h/0/0"),
prev_hash=TXHASH_e16248,
prev_index=1,
amount=200000000,
amount=200_000_000,
script_type=messages.InputScriptType.SPENDADDRESS,
decred_tree=0,
)
out1 = messages.TxOutputType(
address="TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz",
amount=190000000,
amount=190_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -99,12 +100,12 @@ def test_send_decred(client):
@pytest.mark.skip_t1
def test_purchase_ticket_decred(client):
def test_purchase_ticket_decred(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("m/44'/1'/0'/0/0"),
address_n=parse_path("m/44h/1h/0h/0/0"),
prev_hash=TXHASH_e16248,
prev_index=1,
amount=200000000,
amount=200_000_000,
decred_tree=0,
script_type=messages.InputScriptType.SPENDADDRESS,
)
@ -112,11 +113,11 @@ def test_purchase_ticket_decred(client):
out1 = messages.TxOutputType(
address="TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=199900000,
amount=199_900_000,
)
out2 = messages.TxOutputType(
address_n=parse_path("m/44'/1'/0'/0/0"),
amount=200000000,
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=200_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out3 = messages.TxOutputType(
@ -159,22 +160,22 @@ def test_purchase_ticket_decred(client):
@pytest.mark.skip_t1
def test_spend_from_stake_generation_and_revocation_decred(client):
def test_spend_from_stake_generation_and_revocation_decred(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("m/44'/1'/0'/0/0"),
address_n=parse_path("m/44h/1h/0h/0/0"),
prev_hash=TXHASH_8b6890,
prev_index=2,
amount=200000000,
amount=200_000_000,
script_type=messages.InputScriptType.SPENDADDRESS,
decred_staking_spend=messages.DecredStakingSpendType.SSGen,
decred_tree=1,
)
inp2 = messages.TxInputType(
address_n=parse_path("m/44'/1'/0'/0/0"),
address_n=parse_path("m/44h/1h/0h/0/0"),
prev_hash=TXHASH_1f00fc,
prev_index=0,
amount=200000000,
amount=200_000_000,
script_type=messages.InputScriptType.SPENDADDRESS,
decred_staking_spend=messages.DecredStakingSpendType.SSRTX,
decred_tree=1,
@ -182,7 +183,7 @@ def test_spend_from_stake_generation_and_revocation_decred(client):
out1 = messages.TxOutputType(
address="TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz",
amount=399900000,
amount=399_900_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -220,11 +221,11 @@ def test_spend_from_stake_generation_and_revocation_decred(client):
)
def test_send_decred_change(client):
def test_send_decred_change(client: Client):
inp1 = messages.TxInputType(
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
address_n=parse_path("m/44'/1'/0'/0/0"),
amount=190000000,
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=190_000_000,
prev_hash=TXHASH_5e6e35,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
@ -233,8 +234,8 @@ def test_send_decred_change(client):
inp2 = messages.TxInputType(
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
address_n=parse_path("m/44'/1'/0'/0/0"),
amount=200000000,
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=200_000_000,
prev_hash=TXHASH_ccf95b,
prev_index=1,
script_type=messages.InputScriptType.SPENDADDRESS,
@ -243,8 +244,8 @@ def test_send_decred_change(client):
inp3 = messages.TxInputType(
# Tskt39YEvzoJ5KBDH4f1auNzG3jViVjZ2RV
address_n=parse_path("m/44'/1'/0'/0/1"),
amount=200000000,
address_n=parse_path("m/44h/1h/0h/0/1"),
amount=200_000_000,
prev_hash=TXHASH_f395ef,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
@ -253,14 +254,14 @@ def test_send_decred_change(client):
out1 = messages.TxOutputType(
address="TsWjioPrP8E1TuTMmTrVMM2BA4iPrjQXBpR",
amount=489975000,
amount=489_975_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
# TsaSFRwfN9muW5F6ZX36iSksc9hruiC5F97
address_n=parse_path("m/44'/1'/0'/1/0"),
amount=100000000,
address_n=parse_path("m/44h/1h/0h/1/0"),
amount=100_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -309,8 +310,8 @@ def test_send_decred_change(client):
@pytest.mark.multisig
def test_decred_multisig_change(client):
paths = [parse_path(f"m/48'/1'/{index}'/0'") for index in range(3)]
def test_decred_multisig_change(client: Client):
paths = [parse_path(f"m/48h/1h/{index}h/0h") for index in range(3)]
nodes = [
btc.get_public_node(client, address_n, coin_name="Decred Testnet").node
for address_n in paths
@ -332,7 +333,7 @@ def test_decred_multisig_change(client):
address_n=address_n,
# TchpthUkRys1VQWgnQyLJNaA4MLBjVmRL2c
multisig=multisig,
amount=200000000,
amount=200_000_000,
prev_hash=TXHASH_3f7c39,
prev_index=1,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -344,7 +345,7 @@ def test_decred_multisig_change(client):
address_n=address_n,
# TcnfDEfMhkM3oLWqiq9v9GmYgLK7qfjitKG
multisig=multisig,
amount=200000000,
amount=200_000_000,
prev_hash=TXHASH_16da18,
prev_index=0,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -356,13 +357,13 @@ def test_decred_multisig_change(client):
address_n=address_n,
# TcrrURA3Bzj4isGU48PdSP9SDoU5oCpjEcb
multisig=multisig,
amount=99900000,
amount=99_900_000,
script_type=messages.OutputScriptType.PAYTOMULTISIG,
)
out2 = messages.TxOutputType(
address="TsWjioPrP8E1TuTMmTrVMM2BA4iPrjQXBpR",
amount=300000000,
amount=300_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)

View File

@ -18,6 +18,7 @@ import pytest
from trezorlib import messages
from trezorlib.cli import btc
from trezorlib.debuglink import TrezorClientDebugLink as Client
VECTORS_DESCRIPTORS = ( # coin, account, script_type, descriptors
(
@ -120,6 +121,6 @@ VECTORS_DESCRIPTORS = ( # coin, account, script_type, descriptors
@pytest.mark.parametrize("coin, account, script_type, descriptors", VECTORS_DESCRIPTORS)
def test_descriptors(client, coin, account, script_type, descriptors):
def test_descriptors(client: Client, coin, account, script_type, descriptors):
res = btc._get_descriptor(client, coin, account, script_type, show_display=True)
assert res == descriptors

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import btc_hash, parse_path
from ...tx_cache import TxCache
@ -28,10 +29,10 @@ TXHASH_8a34cc = bytes.fromhex(
@pytest.mark.altcoin
def test_spend_lelantus(client):
def test_spend_lelantus(client: Client):
inp1 = messages.TxInputType(
# THgGLVqfzJcaxRVPWE5fd8YJ1GpVePq2Uk
address_n=parse_path("m/44'/1'/0'/0/4"),
address_n=parse_path("m/44h/1h/0h/0/4"),
amount=1_000_000_000,
prev_hash=TXHASH_8a34cc,
prev_index=0,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
TXHASH_33043a = bytes.fromhex(
@ -26,11 +27,11 @@ TXHASH_33043a = bytes.fromhex(
pytestmark = pytest.mark.altcoin
def test_send_p2tr(client):
def test_send_p2tr(client: Client):
inp1 = messages.TxInputType(
# fc1prr07akly3xjtmggue0p04vghr8pdcgxrye2s00sahptwjeawxrkq2rxzr7
address_n=parse_path("86'/75'/0'/0/1"),
amount=99997780000,
address_n=parse_path("m/86h/75h/0h/0/1"),
amount=99_997_780_000,
prev_hash=TXHASH_33043a,
prev_index=0,
script_type=messages.InputScriptType.SPENDTAPROOT,
@ -38,7 +39,7 @@ def test_send_p2tr(client):
out1 = messages.TxOutputType(
# 86'/75'/0'/0/0
address="fc1pxax0eaemn9fg2vfwvnz8wr2fjtr5e8junp50vx3yvx8aauv0hcvql824ml",
amount=99996670000,
amount=99_996_670_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
_, serialized_tx = btc.sign_tx(client, "Fujicoin", [inp1], [out1])

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.messages import SafetyCheckLevel
from trezorlib.tools import parse_path
@ -33,112 +34,112 @@ def getmultisig(chain, nr, xpubs):
)
def test_btc(client):
def test_btc(client: Client):
assert (
btc.get_address(client, "Bitcoin", parse_path("m/44'/0'/0'/0/0"))
btc.get_address(client, "Bitcoin", parse_path("m/44h/0h/0h/0/0"))
== "1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL"
)
assert (
btc.get_address(client, "Bitcoin", parse_path("m/44'/0'/0'/0/1"))
btc.get_address(client, "Bitcoin", parse_path("m/44h/0h/0h/0/1"))
== "1GWFxtwWmNVqotUPXLcKVL2mUKpshuJYo"
)
assert (
btc.get_address(client, "Bitcoin", parse_path("m/44'/0'/0'/1/0"))
btc.get_address(client, "Bitcoin", parse_path("m/44h/0h/0h/1/0"))
== "1DyHzbQUoQEsLxJn6M7fMD8Xdt1XvNiwNE"
)
@pytest.mark.altcoin
def test_ltc(client):
def test_ltc(client: Client):
assert (
btc.get_address(client, "Litecoin", parse_path("m/44'/2'/0'/0/0"))
btc.get_address(client, "Litecoin", parse_path("m/44h/2h/0h/0/0"))
== "LcubERmHD31PWup1fbozpKuiqjHZ4anxcL"
)
assert (
btc.get_address(client, "Litecoin", parse_path("m/44'/2'/0'/0/1"))
btc.get_address(client, "Litecoin", parse_path("m/44h/2h/0h/0/1"))
== "LVWBmHBkCGNjSPHucvL2PmnuRAJnucmRE6"
)
assert (
btc.get_address(client, "Litecoin", parse_path("m/44'/2'/0'/1/0"))
btc.get_address(client, "Litecoin", parse_path("m/44h/2h/0h/1/0"))
== "LWj6ApswZxay4cJEJES2sGe7fLMLRvvv8h"
)
def test_tbtc(client):
def test_tbtc(client: Client):
assert (
btc.get_address(client, "Testnet", parse_path("m/44'/1'/0'/0/0"))
btc.get_address(client, "Testnet", parse_path("m/44h/1h/0h/0/0"))
== "mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q"
)
assert (
btc.get_address(client, "Testnet", parse_path("m/44'/1'/0'/0/1"))
btc.get_address(client, "Testnet", parse_path("m/44h/1h/0h/0/1"))
== "mopZWqZZyQc3F2Sy33cvDtJchSAMsnLi7b"
)
assert (
btc.get_address(client, "Testnet", parse_path("m/44'/1'/0'/1/0"))
btc.get_address(client, "Testnet", parse_path("m/44h/1h/0h/1/0"))
== "mm6kLYbGEL1tGe4ZA8xacfgRPdW1NLjCbZ"
)
@pytest.mark.altcoin
def test_bch(client):
def test_bch(client: Client):
assert (
btc.get_address(client, "Bcash", parse_path("44'/145'/0'/0/0"))
btc.get_address(client, "Bcash", parse_path("m/44h/145h/0h/0/0"))
== "bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv"
)
assert (
btc.get_address(client, "Bcash", parse_path("44'/145'/0'/0/1"))
btc.get_address(client, "Bcash", parse_path("m/44h/145h/0h/0/1"))
== "bitcoincash:qr23ajjfd9wd73l87j642puf8cad20lfmqdgwvpat4"
)
assert (
btc.get_address(client, "Bcash", parse_path("44'/145'/0'/1/0"))
btc.get_address(client, "Bcash", parse_path("m/44h/145h/0h/1/0"))
== "bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw"
)
@pytest.mark.altcoin
def test_grs(client):
def test_grs(client: Client):
assert (
btc.get_address(client, "Groestlcoin", parse_path("44'/17'/0'/0/0"))
btc.get_address(client, "Groestlcoin", parse_path("m/44h/17h/0h/0/0"))
== "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM"
)
assert (
btc.get_address(client, "Groestlcoin", parse_path("44'/17'/0'/1/0"))
btc.get_address(client, "Groestlcoin", parse_path("m/44h/17h/0h/1/0"))
== "FmRaqvVBRrAp2Umfqx9V1ectZy8gw54QDN"
)
assert (
btc.get_address(client, "Groestlcoin", parse_path("44'/17'/0'/1/1"))
btc.get_address(client, "Groestlcoin", parse_path("m/44h/17h/0h/1/1"))
== "Fmhtxeh7YdCBkyQF7AQG4QnY8y3rJg89di"
)
@pytest.mark.altcoin
def test_tgrs(client):
def test_tgrs(client: Client):
assert (
btc.get_address(client, "Groestlcoin Testnet", parse_path("44'/1'/0'/0/0"))
btc.get_address(client, "Groestlcoin Testnet", parse_path("m/44h/1h/0h/0/0"))
== "mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y"
)
assert (
btc.get_address(client, "Groestlcoin Testnet", parse_path("44'/1'/0'/1/0"))
btc.get_address(client, "Groestlcoin Testnet", parse_path("m/44h/1h/0h/1/0"))
== "mm6kLYbGEL1tGe4ZA8xacfgRPdW1LMq8cN"
)
assert (
btc.get_address(client, "Groestlcoin Testnet", parse_path("44'/1'/0'/1/1"))
btc.get_address(client, "Groestlcoin Testnet", parse_path("m/44h/1h/0h/1/1"))
== "mjXZwmEi1z1MzveZrKUAo4DBgbdq6ZhGD6"
)
@pytest.mark.altcoin
def test_elements(client):
def test_elements(client: Client):
assert (
btc.get_address(client, "Elements", parse_path("m/44'/1'/0'/0/0"))
btc.get_address(client, "Elements", parse_path("m/44h/1h/0h/0/0"))
== "2dpWh6jbhAowNsQ5agtFzi7j6nKscj6UnEr"
)
@pytest.mark.skip_t1
def test_address_mac(client):
def test_address_mac(client: Client):
resp = btc.get_authenticated_address(
client, "Bitcoin", parse_path("m/44'/0'/0'/1/0")
client, "Bitcoin", parse_path("m/44h/0h/0h/1/0")
)
assert resp.address == "1DyHzbQUoQEsLxJn6M7fMD8Xdt1XvNiwNE"
assert (
@ -147,7 +148,7 @@ def test_address_mac(client):
)
resp = btc.get_authenticated_address(
client, "Testnet", parse_path("m/44'/1'/0'/1/0")
client, "Testnet", parse_path("m/44h/1h/0h/1/0")
)
assert resp.address == "mm6kLYbGEL1tGe4ZA8xacfgRPdW1NLjCbZ"
assert (
@ -157,16 +158,16 @@ def test_address_mac(client):
# Script type mismatch.
resp = btc.get_authenticated_address(
client, "Bitcoin", parse_path("84'/0'/0'/0/0"), show_display=False
client, "Bitcoin", parse_path("m/84h/0h/0h/0/0"), show_display=False
)
assert resp.mac is None
@pytest.mark.skip_t1
@pytest.mark.altcoin
def test_altcoin_address_mac(client):
def test_altcoin_address_mac(client: Client):
resp = btc.get_authenticated_address(
client, "Litecoin", parse_path("m/44'/2'/0'/1/0")
client, "Litecoin", parse_path("m/44h/2h/0h/1/0")
)
assert resp.address == "LWj6ApswZxay4cJEJES2sGe7fLMLRvvv8h"
assert (
@ -174,7 +175,9 @@ def test_altcoin_address_mac(client):
== "eaf47182d7ae17d2046ec2e204bc5b67477db20a5eaea3cec5393c25664bc4d2"
)
resp = btc.get_authenticated_address(client, "Bcash", parse_path("44'/145'/0'/1/0"))
resp = btc.get_authenticated_address(
client, "Bcash", parse_path("m/44h/145h/0h/1/0")
)
assert resp.address == "bitcoincash:qzc5q87w069lzg7g3gzx0c8dz83mn7l02scej5aluw"
assert (
resp.mac.hex()
@ -182,7 +185,7 @@ def test_altcoin_address_mac(client):
)
resp = btc.get_authenticated_address(
client, "Groestlcoin", parse_path("44'/17'/0'/1/1")
client, "Groestlcoin", parse_path("m/44h/17h/0h/1/1")
)
assert resp.address == "Fmhtxeh7YdCBkyQF7AQG4QnY8y3rJg89di"
assert (
@ -192,10 +195,10 @@ def test_altcoin_address_mac(client):
@pytest.mark.multisig
def test_multisig(client):
def test_multisig(client: Client):
xpubs = []
for n in range(1, 4):
node = btc.get_public_node(client, parse_path(f"44'/0'/{n}'"))
node = btc.get_public_node(client, parse_path(f"m/44h/0h/{n}h"))
xpubs.append(node.xpub)
for nr in range(1, 4):
@ -203,7 +206,7 @@ def test_multisig(client):
btc.get_address(
client,
"Bitcoin",
parse_path(f"44'/0'/{nr}'/0/0"),
parse_path(f"m/44h/0h/{nr}h/0/0"),
show_display=(nr == 1),
multisig=getmultisig(0, 0, xpubs=xpubs),
)
@ -213,7 +216,7 @@ def test_multisig(client):
btc.get_address(
client,
"Bitcoin",
parse_path(f"44'/0'/{nr}'/1/0"),
parse_path(f"m/44h/0h/{nr}h/1/0"),
show_display=(nr == 1),
multisig=getmultisig(1, 0, xpubs=xpubs),
)
@ -223,12 +226,12 @@ def test_multisig(client):
@pytest.mark.multisig
@pytest.mark.parametrize("show_display", (True, False))
def test_multisig_missing(client, show_display):
def test_multisig_missing(client: Client, show_display):
# Multisig with global suffix specification.
# Use account numbers 1, 2 and 3 to create a valid multisig,
# but not containing the keys from account 0 used below.
nodes = [
btc.get_public_node(client, parse_path(f"44'/0'/{i}'")).node
btc.get_public_node(client, parse_path(f"m/44h/0h/{i}h")).node
for i in range(1, 4)
]
multisig1 = messages.MultisigRedeemScriptType(
@ -237,7 +240,7 @@ def test_multisig_missing(client, show_display):
# Multisig with per-node suffix specification.
node = btc.get_public_node(
client, parse_path("44h/0h/0h/0"), coin_name="Bitcoin"
client, parse_path("m/44h/0h/0h/0"), coin_name="Bitcoin"
).node
multisig2 = messages.MultisigRedeemScriptType(
@ -255,7 +258,7 @@ def test_multisig_missing(client, show_display):
btc.get_address(
client,
"Bitcoin",
parse_path("44'/0'/0'/0/0"),
parse_path("m/44h/0h/0h/0/0"),
show_display=show_display,
multisig=multisig,
)
@ -263,11 +266,11 @@ def test_multisig_missing(client, show_display):
@pytest.mark.altcoin
@pytest.mark.multisig
def test_bch_multisig(client):
def test_bch_multisig(client: Client):
xpubs = []
for n in range(1, 4):
node = btc.get_public_node(
client, parse_path(f"44'/145'/{n}'"), coin_name="Bcash"
client, parse_path(f"m/44h/145h/{n}h"), coin_name="Bcash"
)
xpubs.append(node.xpub)
@ -276,7 +279,7 @@ def test_bch_multisig(client):
btc.get_address(
client,
"Bcash",
parse_path(f"44'/145'/{nr}'/0/0"),
parse_path(f"m/44h/145h/{nr}h/0/0"),
show_display=(nr == 1),
multisig=getmultisig(0, 0, xpubs=xpubs),
)
@ -286,7 +289,7 @@ def test_bch_multisig(client):
btc.get_address(
client,
"Bcash",
parse_path(f"44'/145'/{nr}'/1/0"),
parse_path(f"m/44h/145h/{nr}h/1/0"),
show_display=(nr == 1),
multisig=getmultisig(1, 0, xpubs=xpubs),
)
@ -294,31 +297,31 @@ def test_bch_multisig(client):
)
def test_public_ckd(client):
node = btc.get_public_node(client, parse_path("m/44'/0'/0'")).node
node_sub1 = btc.get_public_node(client, parse_path("m/44'/0'/0'/1/0")).node
def test_public_ckd(client: Client):
node = btc.get_public_node(client, parse_path("m/44h/0h/0h")).node
node_sub1 = btc.get_public_node(client, parse_path("m/44h/0h/0h/1/0")).node
node_sub2 = bip32.public_ckd(node, [1, 0])
assert node_sub1.chain_code == node_sub2.chain_code
assert node_sub1.public_key == node_sub2.public_key
address1 = btc.get_address(client, "Bitcoin", parse_path("m/44'/0'/0'/1/0"))
address1 = btc.get_address(client, "Bitcoin", parse_path("m/44h/0h/0h/1/0"))
address2 = bip32.get_address(node_sub2, 0)
assert address2 == "1DyHzbQUoQEsLxJn6M7fMD8Xdt1XvNiwNE"
assert address1 == address2
def test_invalid_path(client):
def test_invalid_path(client: Client):
with pytest.raises(TrezorFailure, match="Forbidden key path"):
# slip44 id mismatch
btc.get_address(
client, "Bitcoin", parse_path("m/44'/111'/0'/0/0"), show_display=True
client, "Bitcoin", parse_path("m/44h/111h/0h/0/0"), show_display=True
)
def test_unknown_path(client):
UNKNOWN_PATH = parse_path("m/44'/9'/0'/0/0")
def test_unknown_path(client: Client):
UNKNOWN_PATH = parse_path("m/44h/9h/0h/0/0")
with client:
client.set_expected_responses([messages.Failure])
@ -349,8 +352,8 @@ def test_unknown_path(client):
@pytest.mark.altcoin
def test_crw(client):
def test_crw(client: Client):
assert (
btc.get_address(client, "Crown", parse_path("44'/72'/0'/0/0"))
btc.get_address(client, "Crown", parse_path("m/44h/72h/0h/0/0"))
== "CRWYdvZM1yXMKQxeN3hRsAbwa7drfvTwys48"
)

View File

@ -17,16 +17,17 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
def test_show_segwit(client):
def test_show_segwit(client: Client):
assert (
btc.get_address(
client,
"Testnet",
parse_path("49'/1'/0'/1/0"),
parse_path("m/49h/1h/0h/1/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
@ -37,7 +38,7 @@ def test_show_segwit(client):
btc.get_address(
client,
"Testnet",
parse_path("49'/1'/0'/0/0"),
parse_path("m/49h/1h/0h/0/0"),
False,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
@ -48,7 +49,7 @@ def test_show_segwit(client):
btc.get_address(
client,
"Testnet",
parse_path("44'/1'/0'/0/0"),
parse_path("m/44h/1h/0h/0/0"),
False,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
@ -59,7 +60,7 @@ def test_show_segwit(client):
btc.get_address(
client,
"Testnet",
parse_path("44'/1'/0'/0/0"),
parse_path("m/44h/1h/0h/0/0"),
False,
None,
script_type=messages.InputScriptType.SPENDADDRESS,
@ -69,12 +70,12 @@ def test_show_segwit(client):
@pytest.mark.altcoin
def test_show_segwit_altcoin(client):
def test_show_segwit_altcoin(client: Client):
assert (
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("49'/1'/0'/1/0"),
parse_path("m/49h/1h/0h/1/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
@ -85,7 +86,7 @@ def test_show_segwit_altcoin(client):
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("49'/1'/0'/0/0"),
parse_path("m/49h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
@ -96,7 +97,7 @@ def test_show_segwit_altcoin(client):
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("44'/1'/0'/0/0"),
parse_path("m/44h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
@ -107,7 +108,7 @@ def test_show_segwit_altcoin(client):
btc.get_address(
client,
"Groestlcoin Testnet",
parse_path("44'/1'/0'/0/0"),
parse_path("m/44h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDADDRESS,
@ -118,7 +119,7 @@ def test_show_segwit_altcoin(client):
btc.get_address(
client,
"Elements",
parse_path("m/49'/1'/0'/0/0"),
parse_path("m/49h/1h/0h/0/0"),
True,
None,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
@ -128,10 +129,10 @@ def test_show_segwit_altcoin(client):
@pytest.mark.multisig
def test_show_multisig_3(client):
def test_show_multisig_3(client: Client):
nodes = [
btc.get_public_node(
client, parse_path(f"49'/1'/{i}'"), coin_name="Testnet"
client, parse_path(f"m/49h/1h/{i}h"), coin_name="Testnet"
).node
for i in range(1, 4)
]
@ -149,7 +150,7 @@ def test_show_multisig_3(client):
btc.get_address(
client,
"Testnet",
parse_path(f"49'/1'/{i}'/0/7"),
parse_path(f"m/49h/1h/{i}h/0/7"),
False,
multisig1,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
@ -160,12 +161,12 @@ def test_show_multisig_3(client):
@pytest.mark.multisig
@pytest.mark.parametrize("show_display", (True, False))
def test_multisig_missing(client, show_display):
def test_multisig_missing(client: Client, show_display):
# Multisig with global suffix specification.
# Use account numbers 1, 2 and 3 to create a valid multisig,
# but not containing the keys from account 0 used below.
nodes = [
btc.get_public_node(client, parse_path(f"49'/0'/{i}'")).node
btc.get_public_node(client, parse_path(f"m/49h/0h/{i}h")).node
for i in range(1, 4)
]
multisig1 = messages.MultisigRedeemScriptType(
@ -174,7 +175,7 @@ def test_multisig_missing(client, show_display):
# Multisig with per-node suffix specification.
node = btc.get_public_node(
client, parse_path("49h/0h/0h/0"), coin_name="Bitcoin"
client, parse_path("m/49h/0h/0h/0"), coin_name="Bitcoin"
).node
multisig2 = messages.MultisigRedeemScriptType(
pubkeys=[
@ -191,7 +192,7 @@ def test_multisig_missing(client, show_display):
btc.get_address(
client,
"Bitcoin",
parse_path("49'/0'/0'/0/0"),
parse_path("m/49h/0h/0h/0/0"),
show_display=show_display,
multisig=multisig,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,

View File

@ -17,103 +17,104 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
VECTORS = ( # coin, path, script_type, address
(
"Testnet",
"84'/1'/0'/0/0",
"m/84h/1h/0h/0/0",
messages.InputScriptType.SPENDWITNESS,
"tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9",
),
(
"Testnet",
"84'/1'/0'/1/0",
"m/84h/1h/0h/1/0",
messages.InputScriptType.SPENDWITNESS,
"tb1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt96jk9x",
),
(
"Bitcoin",
"84'/0'/0'/0/0",
"m/84h/0h/0h/0/0",
messages.InputScriptType.SPENDWITNESS,
"bc1qannfxke2tfd4l7vhepehpvt05y83v3qsf6nfkk",
),
(
"Bitcoin",
"84'/0'/0'/1/0",
"m/84h/0h/0h/1/0",
messages.InputScriptType.SPENDWITNESS,
"bc1qktmhrsmsenepnnfst8x6j27l0uqv7ggrg8x38q",
),
(
"Testnet",
"86'/1'/0'/0/0",
"m/86h/1h/0h/0/0",
messages.InputScriptType.SPENDTAPROOT,
"tb1pswrqtykue8r89t9u4rprjs0gt4qzkdfuursfnvqaa3f2yql07zmq8s8a5u",
),
(
"Testnet",
"86'/1'/0'/1/0",
"m/86h/1h/0h/1/0",
messages.InputScriptType.SPENDTAPROOT,
"tb1pn2d0yjeedavnkd8z8lhm566p0f2utm3lgvxrsdehnl94y34txmts5s7t4c",
),
(
"Bitcoin",
"86'/0'/0'/0/0",
"m/86h/0h/0h/0/0",
messages.InputScriptType.SPENDTAPROOT,
"bc1ptxs597p3fnpd8gwut5p467ulsydae3rp9z75hd99w8k3ljr9g9rqx6ynaw",
),
(
"Bitcoin",
"86'/0'/0'/1/0",
"m/86h/0h/0h/1/0",
messages.InputScriptType.SPENDTAPROOT,
"bc1pgypgja2hmcx2l6s2ssq75k6ev68ved6nujcspt47dgvkp8euc70s6uegk6",
),
pytest.param(
"Groestlcoin Testnet",
"84'/1'/0'/0/0",
"m/84h/1h/0h/0/0",
messages.InputScriptType.SPENDWITNESS,
"tgrs1qkvwu9g3k2pdxewfqr7syz89r3gj557l3ued7ja",
marks=pytest.mark.altcoin,
),
pytest.param(
"Groestlcoin Testnet",
"84'/1'/0'/1/0",
"m/84h/1h/0h/1/0",
messages.InputScriptType.SPENDWITNESS,
"tgrs1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt9lkd57",
marks=pytest.mark.altcoin,
),
pytest.param(
"Groestlcoin",
"84'/17'/0'/0/0",
"m/84h/17h/0h/0/0",
messages.InputScriptType.SPENDWITNESS,
"grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne",
marks=pytest.mark.altcoin,
),
pytest.param(
"Groestlcoin",
"84'/17'/0'/1/0",
"m/84h/17h/0h/1/0",
messages.InputScriptType.SPENDWITNESS,
"grs1qzfpwn55tvkxcw0xwfa0g8k2gtlzlgkcq3z000e",
marks=pytest.mark.altcoin,
),
pytest.param(
"Groestlcoin Testnet",
"86'/1'/0'/0/0",
"m/86h/1h/0h/0/0",
messages.InputScriptType.SPENDTAPROOT,
"tgrs1pswrqtykue8r89t9u4rprjs0gt4qzkdfuursfnvqaa3f2yql07zmq5v2q7z",
marks=pytest.mark.altcoin,
),
pytest.param(
"Groestlcoin",
"86'/17'/0'/0/0",
"m/86h/17h/0h/0/0",
messages.InputScriptType.SPENDTAPROOT,
"grs1pnacleslusvh6gdjd3j2y5kv3drq09038sww2zx4za68jssndmu6qkm698g",
marks=pytest.mark.altcoin,
),
pytest.param(
"Elements",
"84'/1'/0'/0/0",
"m/84h/1h/0h/0/0",
messages.InputScriptType.SPENDWITNESS,
"ert1qkvwu9g3k2pdxewfqr7syz89r3gj557l3xp9k2v",
marks=pytest.mark.altcoin,
@ -122,15 +123,24 @@ VECTORS = ( # coin, path, script_type, address
BIP86_VECTORS = ( # path, address for "abandon ... abandon about" seed
("86'/0'/0'/0/0", "bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr"),
("86'/0'/0'/0/1", "bc1p4qhjn9zdvkux4e44uhx8tc55attvtyu358kutcqkudyccelu0was9fqzwh"),
("86'/0'/0'/1/0", "bc1p3qkhfews2uk44qtvauqyr2ttdsw7svhkl9nkm9s9c3x4ax5h60wqwruhk7"),
(
"m/86h/0h/0h/0/0",
"bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr",
),
(
"m/86h/0h/0h/0/1",
"bc1p4qhjn9zdvkux4e44uhx8tc55attvtyu358kutcqkudyccelu0was9fqzwh",
),
(
"m/86h/0h/0h/1/0",
"bc1p3qkhfews2uk44qtvauqyr2ttdsw7svhkl9nkm9s9c3x4ax5h60wqwruhk7",
),
)
@pytest.mark.parametrize("show_display", (True, False))
@pytest.mark.parametrize("coin, path, script_type, address", VECTORS)
def test_show_segwit(client, show_display, coin, path, script_type, address):
def test_show_segwit(client: Client, show_display, coin, path, script_type, address):
assert (
btc.get_address(
client,
@ -149,7 +159,7 @@ def test_show_segwit(client, show_display, coin, path, script_type, address):
mnemonic="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
)
@pytest.mark.parametrize("path, address", BIP86_VECTORS)
def test_bip86(client, path, address):
def test_bip86(client: Client, path, address):
assert (
btc.get_address(
client,
@ -164,10 +174,10 @@ def test_bip86(client, path, address):
@pytest.mark.multisig
def test_show_multisig_3(client):
def test_show_multisig_3(client: Client):
nodes = [
btc.get_public_node(
client, parse_path(f"84'/1'/{index}'"), coin_name="Testnet"
client, parse_path(f"m/84h/1h/{index}h"), coin_name="Testnet"
).node
for index in range(1, 4)
]
@ -182,7 +192,7 @@ def test_show_multisig_3(client):
btc.get_address(
client,
"Testnet",
parse_path(f"84'/1'/{i}'/0/1"),
parse_path(f"m/84h/1h/{i}h/0/1"),
False,
multisig2,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -193,7 +203,7 @@ def test_show_multisig_3(client):
btc.get_address(
client,
"Testnet",
parse_path(f"84'/1'/{i}'/0/0"),
parse_path(f"m/84h/1h/{i}h/0/0"),
False,
multisig1,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -204,12 +214,12 @@ def test_show_multisig_3(client):
@pytest.mark.multisig
@pytest.mark.parametrize("show_display", (True, False))
def test_multisig_missing(client, show_display):
def test_multisig_missing(client: Client, show_display):
# Multisig with global suffix specification.
# Use account numbers 1, 2 and 3 to create a valid multisig,
# but not containing the keys from account 0 used below.
nodes = [
btc.get_public_node(client, parse_path(f"84'/0'/{i}'")).node
btc.get_public_node(client, parse_path(f"m/84h/0h/{i}h")).node
for i in range(1, 4)
]
multisig1 = messages.MultisigRedeemScriptType(
@ -218,7 +228,7 @@ def test_multisig_missing(client, show_display):
# Multisig with per-node suffix specification.
node = btc.get_public_node(
client, parse_path("84h/0h/0h/0"), coin_name="Bitcoin"
client, parse_path("m/84h/0h/0h/0"), coin_name="Bitcoin"
).node
multisig2 = messages.MultisigRedeemScriptType(
pubkeys=[
@ -235,7 +245,7 @@ def test_multisig_missing(client, show_display):
btc.get_address(
client,
"Bitcoin",
parse_path("84'/0'/0'/0/0"),
parse_path("m/84h/0h/0h/0/0"),
show_display=show_display,
multisig=multisig,
script_type=messages.InputScriptType.SPENDWITNESS,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages, tools
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
VECTORS = ( # path, script_type, address
@ -39,7 +40,7 @@ VECTORS = ( # path, script_type, address
@pytest.mark.parametrize("path, script_type, address", VECTORS)
def test_show(client, path, script_type, address):
def test_show(client: Client, path, script_type, address):
assert (
btc.get_address(
client,
@ -52,7 +53,7 @@ def test_show(client, path, script_type, address):
)
def test_show_unrecognized_path(client):
def test_show_unrecognized_path(client: Client):
with pytest.raises(TrezorFailure):
btc.get_address(
client,
@ -64,9 +65,9 @@ def test_show_unrecognized_path(client):
@pytest.mark.multisig
def test_show_multisig_3(client):
def test_show_multisig_3(client: Client):
node = btc.get_public_node(
client, tools.parse_path("45h/0/0"), coin_name="Bitcoin"
client, tools.parse_path("m/45h/0/0"), coin_name="Bitcoin"
).node
multisig = messages.MultisigRedeemScriptType(
pubkeys=[
@ -83,7 +84,7 @@ def test_show_multisig_3(client):
btc.get_address(
client,
"Bitcoin",
tools.parse_path(f"45h/0/0/{i}"),
tools.parse_path(f"m/45h/0/0/{i}"),
show_display=True,
multisig=multisig,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -173,7 +174,7 @@ def test_show_multisig_xpubs(
nodes = [
btc.get_public_node(
client,
tools.parse_path(f"48h/0h/{i}h/{bip48_type}h"),
tools.parse_path(f"m/48h/0h/{i}h/{bip48_type}h"),
coin_name="Bitcoin",
)
for i in range(3)
@ -235,7 +236,7 @@ def test_show_multisig_xpubs(
btc.get_address(
client,
"Bitcoin",
tools.parse_path(f"48h/0h/{i}h/{bip48_type}h/0/0"),
tools.parse_path(f"m/48h/0h/{i}h/{bip48_type}h/0/0"),
show_display=True,
multisig=multisig,
script_type=script_type,
@ -244,9 +245,9 @@ def test_show_multisig_xpubs(
@pytest.mark.multisig
def test_show_multisig_15(client):
def test_show_multisig_15(client: Client):
node = btc.get_public_node(
client, tools.parse_path("45h/0/0"), coin_name="Bitcoin"
client, tools.parse_path("m/45h/0/0"), coin_name="Bitcoin"
).node
pubs = [messages.HDNodePathType(node=node, address_n=[x]) for x in range(15)]
@ -260,7 +261,7 @@ def test_show_multisig_15(client):
btc.get_address(
client,
"Bitcoin",
tools.parse_path(f"45h/0/0/{i}"),
tools.parse_path(f"m/45h/0/0/{i}"),
show_display=True,
multisig=multisig,
script_type=messages.InputScriptType.SPENDMULTISIG,

View File

@ -17,17 +17,18 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
pytestmark = pytest.mark.skip_t1
def test_p2wpkh_ownership_id(client):
def test_p2wpkh_ownership_id(client: Client):
ownership_id = btc.get_ownership_id(
client,
"Bitcoin",
parse_path("m/84'/0'/0'/1/0"),
parse_path("m/84h/0h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
)
assert (
@ -36,11 +37,11 @@ def test_p2wpkh_ownership_id(client):
)
def test_p2tr_ownership_id(client):
def test_p2tr_ownership_id(client: Client):
ownership_id = btc.get_ownership_id(
client,
"Bitcoin",
parse_path("m/86'/0'/0'/1/0"),
parse_path("m/86h/0h/0h/1/0"),
script_type=messages.InputScriptType.SPENDTAPROOT,
)
assert (
@ -49,12 +50,12 @@ def test_p2tr_ownership_id(client):
)
def test_attack_ownership_id(client):
def test_attack_ownership_id(client: Client):
# Multisig with global suffix specification.
# Use account numbers 1, 2 and 3 to create a valid multisig,
# but not containing the keys from account 0 used below.
nodes = [
btc.get_public_node(client, parse_path(f"84'/0'/{i}'")).node
btc.get_public_node(client, parse_path(f"m/84h/0h/{i}h")).node
for i in range(1, 4)
]
multisig1 = messages.MultisigRedeemScriptType(
@ -63,7 +64,7 @@ def test_attack_ownership_id(client):
# Multisig with per-node suffix specification.
node = btc.get_public_node(
client, parse_path("84h/0h/0h/0"), coin_name="Bitcoin"
client, parse_path("m/84h/0h/0h/0"), coin_name="Bitcoin"
).node
multisig2 = messages.MultisigRedeemScriptType(
pubkeys=[
@ -80,17 +81,17 @@ def test_attack_ownership_id(client):
btc.get_ownership_id(
client,
"Bitcoin",
parse_path("84'/0'/0'/0/0"),
parse_path("m/84h/0h/0h/0/0"),
multisig=multisig,
script_type=messages.InputScriptType.SPENDWITNESS,
)
def test_p2wpkh_ownership_proof(client):
def test_p2wpkh_ownership_proof(client: Client):
ownership_proof, _ = btc.get_ownership_proof(
client,
"Bitcoin",
parse_path("m/84'/0'/0'/1/0"),
parse_path("m/84h/0h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
)
assert (
@ -99,11 +100,11 @@ def test_p2wpkh_ownership_proof(client):
)
def test_p2tr_ownership_proof(client):
def test_p2tr_ownership_proof(client: Client):
ownership_proof, _ = btc.get_ownership_proof(
client,
"Bitcoin",
parse_path("m/86'/0'/0'/1/0"),
parse_path("m/86h/0h/0h/1/0"),
script_type=messages.InputScriptType.SPENDTAPROOT,
)
assert (
@ -112,12 +113,12 @@ def test_p2tr_ownership_proof(client):
)
def test_fake_ownership_id(client):
def test_fake_ownership_id(client: Client):
with pytest.raises(TrezorFailure, match="Invalid ownership identifier"):
btc.get_ownership_proof(
client,
"Bitcoin",
parse_path("m/84'/0'/0'/1/0"),
parse_path("m/84h/0h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
ownership_ids=[
b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
@ -125,11 +126,11 @@ def test_fake_ownership_id(client):
)
def test_confirm_ownership_proof(client):
def test_confirm_ownership_proof(client: Client):
ownership_proof, _ = btc.get_ownership_proof(
client,
"Bitcoin",
parse_path("m/84'/0'/0'/1/0"),
parse_path("m/84h/0h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
)
@ -140,11 +141,11 @@ def test_confirm_ownership_proof(client):
)
def test_confirm_ownership_proof_with_data(client):
def test_confirm_ownership_proof_with_data(client: Client):
ownership_proof, _ = btc.get_ownership_proof(
client,
"Bitcoin",
parse_path("m/84'/0'/0'/1/0"),
parse_path("m/84h/0h/0h/1/0"),
script_type=messages.InputScriptType.SPENDWITNESS,
user_confirmation=True,
commitment_data=b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
@ -108,7 +109,7 @@ VECTORS_INVALID = ( # coin_name, path
@pytest.mark.parametrize("coin_name, xpub_magic, path, xpub", VECTORS_BITCOIN)
def test_get_public_node(client, coin_name, xpub_magic, path, xpub):
def test_get_public_node(client: Client, coin_name, xpub_magic, path, xpub):
res = btc.get_public_node(client, path, coin_name=coin_name)
assert res.xpub == xpub
assert bip32.serialize(res.node, xpub_magic) == xpub
@ -116,7 +117,7 @@ def test_get_public_node(client, coin_name, xpub_magic, path, xpub):
@pytest.mark.xfail(reason="Currently path validation on get_public_node is disabled.")
@pytest.mark.parametrize("coin_name, path", VECTORS_INVALID)
def test_invalid_path(client, coin_name, path):
def test_invalid_path(client: Client, coin_name, path):
with pytest.raises(TrezorFailure, match="Forbidden key path"):
btc.get_public_node(client, path, coin_name=coin_name)
@ -146,7 +147,7 @@ VECTORS_SCRIPT_TYPES = ( # script_type, xpub, xpub_ignored_magic
@pytest.mark.parametrize("script_type, xpub, xpub_ignored_magic", VECTORS_SCRIPT_TYPES)
def test_script_type(client, script_type, xpub, xpub_ignored_magic):
def test_script_type(client: Client, script_type, xpub, xpub_ignored_magic):
path = parse_path("m/44h/0h/0")
res = btc.get_public_node(
client, path, coin_name="Bitcoin", script_type=script_type

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
@ -53,18 +54,18 @@ VECTORS = ( # curve, path, pubkey
@pytest.mark.parametrize("curve, path, pubkey", VECTORS)
def test_publickey_curve(client, curve, path, pubkey):
def test_publickey_curve(client: Client, curve, path, pubkey):
resp = btc.get_public_node(client, path, ecdsa_curve_name=curve)
assert resp.node.public_key.hex() == pubkey
def test_ed25519_public(client):
def test_ed25519_public(client: Client):
with pytest.raises(TrezorFailure):
btc.get_public_node(client, PATH_PUBLIC, ecdsa_curve_name="ed25519")
@pytest.mark.xfail(reason="Currently path validation on get_public_node is disabled.")
def test_coin_and_curve(client):
def test_coin_and_curve(client: Client):
with pytest.raises(
TrezorFailure, match="Cannot use coin_name or script_type with ecdsa_curve_name"
):

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...tx_cache import TxCache
@ -41,17 +42,17 @@ TXHASH_45aeb9 = bytes.fromhex(
pytestmark = pytest.mark.altcoin
def test_legacy(client):
def test_legacy(client: Client):
inp1 = messages.TxInputType(
# FXHDsC5ZqWQHkDmShzgRVZ1MatpWhwxTAA
address_n=parse_path("44'/17'/0'/0/2"),
amount=210016,
address_n=parse_path("m/44h/17h/0h/0/2"),
amount=210_016,
prev_hash=TXHASH_cb74c8,
prev_index=0,
)
out1 = messages.TxOutputType(
address="FtM4zAn9aVYgHgxmamWBgWPyZsb6RhvkA9",
amount=210016 - 192,
amount=210_016 - 192,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
_, serialized_tx = btc.sign_tx(
@ -63,17 +64,17 @@ def test_legacy(client):
)
def test_legacy_change(client):
def test_legacy_change(client: Client):
inp1 = messages.TxInputType(
# FXHDsC5ZqWQHkDmShzgRVZ1MatpWhwxTAA
address_n=parse_path("44'/17'/0'/0/2"),
amount=210016,
address_n=parse_path("m/44h/17h/0h/0/2"),
amount=210_016,
prev_hash=TXHASH_cb74c8,
prev_index=0,
)
out1 = messages.TxOutputType(
address_n=parse_path("44'/17'/0'/0/3"), # FtM4zAn9aVYgHgxmamWBgWPyZsb6RhvkA9
amount=210016 - 192,
address_n=parse_path("m/44h/17h/0h/0/3"), # FtM4zAn9aVYgHgxmamWBgWPyZsb6RhvkA9
amount=210_016 - 192,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
_, serialized_tx = btc.sign_tx(
@ -85,11 +86,11 @@ def test_legacy_change(client):
)
def test_send_segwit_p2sh(client):
def test_send_segwit_p2sh(client: Client):
inp1 = messages.TxInputType(
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7
address_n=parse_path("49'/1'/0'/1/0"),
amount=123456789,
address_n=parse_path("m/49h/1h/0h/1/0"),
amount=123_456_789,
prev_hash=TXHASH_09a48b,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
@ -97,12 +98,12 @@ def test_send_segwit_p2sh(client):
)
out1 = messages.TxOutputType(
address="mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7",
amount=123456789 - 11000 - 12300000,
amount=123_456_789 - 11_000 - 12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
_, serialized_tx = btc.sign_tx(
@ -110,7 +111,7 @@ def test_send_segwit_p2sh(client):
"Groestlcoin Testnet",
[inp1],
[out1, out2],
lock_time=650756,
lock_time=650_756,
prev_txes=TX_API_TESTNET,
)
assert (
@ -119,11 +120,11 @@ def test_send_segwit_p2sh(client):
)
def test_send_segwit_p2sh_change(client):
def test_send_segwit_p2sh_change(client: Client):
inp1 = messages.TxInputType(
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7
address_n=parse_path("49'/1'/0'/1/0"),
amount=123456789,
address_n=parse_path("m/49h/1h/0h/1/0"),
amount=123_456_789,
prev_hash=TXHASH_09a48b,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
@ -131,20 +132,20 @@ def test_send_segwit_p2sh_change(client):
)
out1 = messages.TxOutputType(
address="mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("49'/1'/0'/1/0"),
address_n=parse_path("m/49h/1h/0h/1/0"),
script_type=messages.OutputScriptType.PAYTOP2SHWITNESS,
amount=123456789 - 11000 - 12300000,
amount=123_456_789 - 11_000 - 12_300_000,
)
_, serialized_tx = btc.sign_tx(
client,
"Groestlcoin Testnet",
[inp1],
[out1, out2],
lock_time=650756,
lock_time=650_756,
prev_txes=TX_API_TESTNET,
)
assert (
@ -153,10 +154,10 @@ def test_send_segwit_p2sh_change(client):
)
def test_send_segwit_native(client):
def test_send_segwit_native(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=12_300_000,
prev_hash=TXHASH_4f2f85,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -164,20 +165,20 @@ def test_send_segwit_native(client):
)
out1 = messages.TxOutputType(
address="2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e",
amount=5000000,
amount=5_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="tgrs1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt9lkd57",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=12300000 - 11000 - 5000000,
amount=12_300_000 - 11_000 - 5_000_000,
)
_, serialized_tx = btc.sign_tx(
client,
"Groestlcoin Testnet",
[inp1],
[out1, out2],
lock_time=650713,
lock_time=650_713,
prev_txes=TX_API_TESTNET,
)
assert (
@ -186,10 +187,10 @@ def test_send_segwit_native(client):
)
def test_send_segwit_native_change(client):
def test_send_segwit_native_change(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=12_300_000,
prev_hash=TXHASH_4f2f85,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -197,20 +198,20 @@ def test_send_segwit_native_change(client):
)
out1 = messages.TxOutputType(
address="2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e",
amount=5000000,
amount=5_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("84'/1'/0'/1/0"),
address_n=parse_path("m/84h/1h/0h/1/0"),
script_type=messages.OutputScriptType.PAYTOWITNESS,
amount=12300000 - 11000 - 5000000,
amount=12_300_000 - 11_000 - 5_000_000,
)
_, serialized_tx = btc.sign_tx(
client,
"Groestlcoin Testnet",
[inp1],
[out1, out2],
lock_time=650713,
lock_time=650_713,
prev_txes=TX_API_TESTNET,
)
assert (
@ -219,11 +220,11 @@ def test_send_segwit_native_change(client):
)
def test_send_p2tr(client):
def test_send_p2tr(client: Client):
inp1 = messages.TxInputType(
# tgrs1paxhjl357yzctuf3fe58fcdx6nul026hhh6kyldpfsf3tckj9a3wsvuqrgn
address_n=parse_path("86'/1'/1'/0/0"),
amount=4450,
address_n=parse_path("m/86h/1h/1h/0/0"),
amount=4_450,
prev_hash=TXHASH_45aeb9,
prev_index=0,
script_type=messages.InputScriptType.SPENDTAPROOT,
@ -231,7 +232,7 @@ def test_send_p2tr(client):
out1 = messages.TxOutputType(
# 86'/1'/0'/0/0
address="tgrs1pswrqtykue8r89t9u4rprjs0gt4qzkdfuursfnvqaa3f2yql07zmq5v2q7z",
amount=4300,
amount=4_300,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
_, serialized_tx = btc.sign_tx(

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...tx_cache import TxCache
@ -41,21 +42,21 @@ TXHASH_7b28bd = bytes.fromhex(
pytestmark = [pytest.mark.altcoin, pytest.mark.komodo]
def test_one_one_fee_sapling(client):
def test_one_one_fee_sapling(client: Client):
# prevout: 2807c5b126ec8e2b078cab0f12e4c8b4ce1d7724905f8ebef8dca26b0c8e0f1d:0
# input 1: 10.9998 KMD
inp1 = messages.TxInputType(
# R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi
address_n=parse_path("44'/141'/0'/0/0"),
amount=1099980000,
address_n=parse_path("m/44h/141h/0h/0/0"),
amount=1_099_980_000,
prev_hash=TXHASH_2807c,
prev_index=0,
)
out1 = messages.TxOutputType(
address="R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi",
amount=1099980000 - 10000,
amount=1_099_980_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -97,28 +98,28 @@ def test_one_one_fee_sapling(client):
)
def test_one_one_rewards_claim(client):
def test_one_one_rewards_claim(client: Client):
# prevout: 7b28bd91119e9776f0d4ebd80e570165818a829bbf4477cd1afe5149dbcd34b1:0
# input 1: 10.9997 KMD
inp1 = messages.TxInputType(
# R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi
address_n=parse_path("44'/141'/0'/0/0"),
amount=1099970000,
address_n=parse_path("m/44h/141h/0h/0/0"),
amount=1_099_970_000,
prev_hash=TXHASH_7b28bd,
prev_index=0,
)
out1 = messages.TxOutputType(
address="R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi",
amount=1099970000 - 10000,
amount=1_099_970_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
# kmd interest, vout sum > vin sum
out2 = messages.TxOutputType(
address="R9HgJZo6JBKmPvhm7whLSR8wiHyZrEDVRi",
amount=79605,
amount=79_605,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path, tx_hash
@ -40,9 +41,9 @@ TXHASH_fbbff7 = bytes.fromhex(
pytestmark = pytest.mark.multisig
def test_2_of_3(client):
def test_2_of_3(client: Client):
nodes = [
btc.get_public_node(client, parse_path(f"48'/0'/{index}'/0'")).node
btc.get_public_node(client, parse_path(f"m/48h/0h/{index}h/0h")).node
for index in range(1, 4)
]
@ -51,8 +52,8 @@ def test_2_of_3(client):
)
# Let's go to sign with key 1
inp1 = messages.TxInputType(
address_n=parse_path("48'/0'/1'/0'/0/0"),
amount=100000,
address_n=parse_path("m/48h/0h/1h/0h/0/0"),
amount=100_000,
prev_hash=TXHASH_c6091a,
prev_index=1,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -61,7 +62,7 @@ def test_2_of_3(client):
out1 = messages.TxOutputType(
address="12iyMbUb4R2K3gre4dHSrbu5azG5KaqVss",
amount=100000,
amount=100_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -110,8 +111,8 @@ def test_2_of_3(client):
# Let's do a second signature with key 3
inp3 = messages.TxInputType(
address_n=parse_path("48'/0'/3'/0'/0/0"),
amount=100000,
address_n=parse_path("m/48h/0h/3h/0h/0/0"),
amount=100_000,
prev_hash=TXHASH_c6091a,
prev_index=1,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -152,9 +153,9 @@ def test_2_of_3(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_15_of_15(client):
def test_15_of_15(client: Client):
node = btc.get_public_node(
client, parse_path("48h/0h/1h/0h"), coin_name="Bitcoin"
client, parse_path("m/48h/0h/1h/0h"), coin_name="Bitcoin"
).node
pubs = [messages.HDNodePathType(node=node, address_n=[0, x]) for x in range(15)]
@ -162,7 +163,7 @@ def test_15_of_15(client):
out1 = messages.TxOutputType(
address="17kTB7qSk3MupQxWdiv5ZU3zcrZc2Azes1",
amount=10000,
amount=10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -172,8 +173,8 @@ def test_15_of_15(client):
)
inp1 = messages.TxInputType(
address_n=parse_path(f"48h/0h/1h/0h/0/{x}"),
amount=20000,
address_n=parse_path(f"m/48h/0h/1h/0h/0/{x}"),
amount=20_000,
prev_hash=TXHASH_6189e3,
prev_index=1,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -193,9 +194,9 @@ def test_15_of_15(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_missing_pubkey(client):
def test_missing_pubkey(client: Client):
node = btc.get_public_node(
client, parse_path("48h/0h/1h/0h/0"), coin_name="Bitcoin"
client, parse_path("m/48h/0h/1h/0h/0"), coin_name="Bitcoin"
).node
multisig = messages.MultisigRedeemScriptType(
@ -210,8 +211,8 @@ def test_missing_pubkey(client):
# Let's go to sign with key 10, which is NOT in pubkeys
inp1 = messages.TxInputType(
address_n=parse_path("48h/0h/1h/0h/0/10"),
amount=100000,
address_n=parse_path("m/48h/0h/1h/0h/0/10"),
amount=100_000,
prev_hash=TXHASH_c6091a,
prev_index=1,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -220,7 +221,7 @@ def test_missing_pubkey(client):
out1 = messages.TxOutputType(
address="12iyMbUb4R2K3gre4dHSrbu5azG5KaqVss",
amount=100000,
amount=100_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -233,14 +234,14 @@ def test_missing_pubkey(client):
assert exc.value.message.endswith("Pubkey not found in multisig script")
def test_attack_change_input(client):
def test_attack_change_input(client: Client):
"""
In Phases 1 and 2 the attacker replaces a non-multisig input
`input_real` with a multisig input `input_fake`, which allows the
attacker to provide a 1-of-2 multisig change address. When `input_real`
is provided in the signing phase, an error must occur.
"""
address_n = parse_path("48'/1'/0'/1'/0/0")
address_n = parse_path("m/48h/1h/0h/1h/0/0")
attacker_multisig_public_key = bytes.fromhex(
"03653a148b68584acb97947344a7d4fd6a6f8b8485cad12987ff8edac874268088"
)
@ -250,7 +251,7 @@ def test_attack_change_input(client):
prev_hash=TXHASH_fbbff7,
prev_index=1,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
amount=1000000,
amount=1_000_000,
)
multisig_fake = messages.MultisigRedeemScriptType(
@ -279,13 +280,13 @@ def test_attack_change_input(client):
output_payee = messages.TxOutputType(
address="n2eMqTT929pb1RDNuqEnxdaLau1rxy3efi",
amount=1000,
amount=1_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
output_change = messages.TxOutputType(
address_n=address_n,
amount=input_real.amount - output_payee.amount - 1000,
amount=input_real.amount - output_payee.amount - 1_000,
script_type=messages.OutputScriptType.PAYTOP2SHWITNESS,
multisig=multisig_fake,
)

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import H_, parse_path
from ... import bip32
@ -109,7 +110,7 @@ multisig_in3 = messages.MultisigRedeemScriptType(
# 2N9W4z9AhAPaHghtqVQPbaTAGHdbrhKeBQw
INP1 = messages.TxInputType(
address_n=[H_(45), 0, 0, 0],
amount=50000000,
amount=50_000_000,
prev_hash=TXHASH_16c6c8,
prev_index=1,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -119,7 +120,7 @@ INP1 = messages.TxInputType(
# 2NDBG6QXQLtnQ3jRGkrqo53BiCeXfQXLdj4
INP2 = messages.TxInputType(
address_n=[H_(45), 0, 0, 1],
amount=34500000,
amount=34_500_000,
prev_hash=TXHASH_d80c34,
prev_index=0,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -129,7 +130,7 @@ INP2 = messages.TxInputType(
# 2MvwPWfp2XPU3S1cMwgEMKBPUw38VP5SBE4
INP3 = messages.TxInputType(
address_n=[H_(45), 0, 0, 1],
amount=55500000,
amount=55_500_000,
prev_hash=TXHASH_b0946d,
prev_index=0,
script_type=messages.InputScriptType.SPENDMULTISIG,
@ -176,16 +177,16 @@ def _responses(INP1, INP2, change=0):
# both outputs are external
def test_external_external(client):
def test_external_external(client: Client):
out1 = messages.TxOutputType(
address="1F8yBZB2NZhPZvJekhjTwjhQRRvQeTjjXr",
amount=40000000,
amount=40_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="1H7uXJQTVwXca2BXF2opTrvuZapk8Cm8zY",
amount=44000000,
amount=44_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -206,16 +207,16 @@ def test_external_external(client):
# first external, second internal
def test_external_internal(client):
def test_external_internal(client: Client):
out1 = messages.TxOutputType(
address="1F8yBZB2NZhPZvJekhjTwjhQRRvQeTjjXr",
amount=40000000,
amount=40_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("45'/0/1/1"),
amount=44000000,
address_n=parse_path("m/45h/0/1/1"),
amount=44_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -236,16 +237,16 @@ def test_external_internal(client):
# first internal, second external
def test_internal_external(client):
def test_internal_external(client: Client):
out1 = messages.TxOutputType(
address_n=parse_path("45'/0/1/0"),
amount=40000000,
address_n=parse_path("m/45h/0/1/0"),
amount=40_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="1H7uXJQTVwXca2BXF2opTrvuZapk8Cm8zY",
amount=44000000,
amount=44_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -266,16 +267,16 @@ def test_internal_external(client):
# both outputs are external
def test_multisig_external_external(client):
def test_multisig_external_external(client: Client):
out1 = messages.TxOutputType(
address="3B23k4kFBRtu49zvpG3Z9xuFzfpHvxBcwt",
amount=40000000,
amount=40_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="3PkXLsY7AUZCrCKGvX8FfP2EawowUBMbcg",
amount=44000000,
amount=44_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -296,7 +297,7 @@ def test_multisig_external_external(client):
# inputs match, change matches (first is change)
def test_multisig_change_match_first(client):
def test_multisig_change_match_first(client: Client):
multisig_out1 = messages.MultisigRedeemScriptType(
nodes=[NODE_EXT2, NODE_EXT1, NODE_INT],
address_n=[1, 0],
@ -307,13 +308,13 @@ def test_multisig_change_match_first(client):
out1 = messages.TxOutputType(
address_n=[H_(45), 0, 1, 0],
multisig=multisig_out1,
amount=40000000,
amount=40_000_000,
script_type=messages.OutputScriptType.PAYTOMULTISIG,
)
out2 = messages.TxOutputType(
address="3PkXLsY7AUZCrCKGvX8FfP2EawowUBMbcg",
amount=44000000,
amount=44_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -334,7 +335,7 @@ def test_multisig_change_match_first(client):
# inputs match, change matches (second is change)
def test_multisig_change_match_second(client):
def test_multisig_change_match_second(client: Client):
multisig_out2 = messages.MultisigRedeemScriptType(
nodes=[NODE_EXT1, NODE_EXT2, NODE_INT],
address_n=[1, 1],
@ -344,14 +345,14 @@ def test_multisig_change_match_second(client):
out1 = messages.TxOutputType(
address="3B23k4kFBRtu49zvpG3Z9xuFzfpHvxBcwt",
amount=40000000,
amount=40_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=[H_(45), 0, 1, 1],
multisig=multisig_out2,
amount=44000000,
amount=44_000_000,
script_type=messages.OutputScriptType.PAYTOMULTISIG,
)
@ -372,7 +373,7 @@ def test_multisig_change_match_second(client):
# inputs match, change mismatches (second tries to be change but isn't)
def test_multisig_mismatch_change(client):
def test_multisig_mismatch_change(client: Client):
multisig_out2 = messages.MultisigRedeemScriptType(
nodes=[NODE_EXT1, NODE_INT, NODE_EXT3],
address_n=[1, 0],
@ -382,14 +383,14 @@ def test_multisig_mismatch_change(client):
out1 = messages.TxOutputType(
address="3B23k4kFBRtu49zvpG3Z9xuFzfpHvxBcwt",
amount=40000000,
amount=40_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=[H_(45), 0, 1, 0],
multisig=multisig_out2,
amount=44000000,
amount=44_000_000,
script_type=messages.OutputScriptType.PAYTOMULTISIG,
)
@ -410,7 +411,7 @@ def test_multisig_mismatch_change(client):
# inputs mismatch, change matches with first input
def test_multisig_mismatch_inputs(client):
def test_multisig_mismatch_inputs(client: Client):
multisig_out1 = messages.MultisigRedeemScriptType(
nodes=[NODE_EXT2, NODE_EXT1, NODE_INT],
address_n=[1, 0],
@ -421,13 +422,13 @@ def test_multisig_mismatch_inputs(client):
out1 = messages.TxOutputType(
address_n=[H_(45), 0, 1, 0],
multisig=multisig_out1,
amount=40000000,
amount=40_000_000,
script_type=messages.OutputScriptType.PAYTOMULTISIG,
)
out2 = messages.TxOutputType(
address="3PkXLsY7AUZCrCKGvX8FfP2EawowUBMbcg",
amount=65000000,
amount=65_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...tx_cache import TxCache
@ -43,7 +44,7 @@ VECTORS = (
),
# GreenAddress B m/3'/[1-100]'/[1,4]/address_index
(
"m/3'/100'/4/255",
"m/3h/100h/4/255",
(
messages.InputScriptType.SPENDADDRESS,
messages.InputScriptType.SPENDWITNESS,
@ -80,27 +81,27 @@ VECTORS_MULTISIG = (
# GreenAddress A m/[1,4]/address_index
(("m/1", "m/1", "m/4"), [255]),
# GreenAddress B m/3'/[1-100]'/[1,4]/address_index
(("m/3'/100'/1", "m/3'/99'/1", "m/3'/98'/1"), [255]),
(("m/3h/100h/1", "m/3h/99h/1", "m/3h/98h/1"), [255]),
# GreenAdress Sign A m/1195487518
(("m/1195487518", "m/1195487518", "m/1195487518"), []),
# GreenAdress Sign B m/1195487518/6/address_index
(("m/1195487518/6", "m/1195487518/6", "m/1195487518/6"), [255]),
# Unchained hardened m/45'/coin_type'/account'/[0-1000000]/change/address_index
(
("m/45'/0'/63'/1000000", "m/45'/0'/62'/1000000", "m/45'/0'/61'/1000000"),
("m/45h/0h/63h/1000000", "m/45h/0h/62h/1000000", "m/45h/0h/61h/1000000"),
[0, 255],
),
# Unchained unhardened m/45'/coin_type/account/[0-1000000]/change/address_index
(("m/45'/0/63/1000000", "m/45'/0/62/1000000", "m/45'/0/61/1000000"), [0, 255]),
(("m/45h/0/63/1000000", "m/45h/0/62/1000000", "m/45h/0/61/1000000"), [0, 255]),
# Unchained deprecated m/45'/coin_type'/account'/[0-1000000]/address_index
(("m/45'/0'/63'/1000000", "m/45'/0'/62'/1000000", "m/45'/0/61/1000000"), [255]),
(("m/45h/0h/63h/1000000", "m/45h/0h/62h/1000000", "m/45h/0/61/1000000"), [255]),
)
# Has AlwaysMatchingSchema but let's make sure the nonstandard paths are
# accepted in case we make this more restrictive in the future.
@pytest.mark.parametrize("path, script_types", VECTORS)
def test_getpublicnode(client, path, script_types):
def test_getpublicnode(client: Client, path, script_types):
for script_type in script_types:
res = btc.get_public_node(
client, parse_path(path), coin_name="Bitcoin", script_type=script_type
@ -110,7 +111,7 @@ def test_getpublicnode(client, path, script_types):
@pytest.mark.parametrize("path, script_types", VECTORS)
def test_getaddress(client, path, script_types):
def test_getaddress(client: Client, path, script_types):
for script_type in script_types:
res = btc.get_address(
client,
@ -124,7 +125,7 @@ def test_getaddress(client, path, script_types):
@pytest.mark.parametrize("path, script_types", VECTORS)
def test_signmessage(client, path, script_types):
def test_signmessage(client: Client, path, script_types):
for script_type in script_types:
sig = btc.sign_message(
client,
@ -138,14 +139,14 @@ def test_signmessage(client, path, script_types):
@pytest.mark.parametrize("path, script_types", VECTORS)
def test_signtx(client, path, script_types):
def test_signtx(client: Client, path, script_types):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
for script_type in script_types:
inp1 = messages.TxInputType(
address_n=parse_path(path),
amount=390000,
amount=390_000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
script_type=script_type,
@ -153,7 +154,7 @@ def test_signtx(client, path, script_types):
out1 = messages.TxOutputType(
address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1",
amount=390000 - 10000,
amount=390_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -166,7 +167,7 @@ def test_signtx(client, path, script_types):
@pytest.mark.multisig
@pytest.mark.parametrize("paths, address_index", VECTORS_MULTISIG)
def test_getaddress_multisig(client, paths, address_index):
def test_getaddress_multisig(client: Client, paths, address_index):
pubs = [
messages.HDNodePathType(
node=btc.get_public_node(
@ -194,7 +195,7 @@ def test_getaddress_multisig(client, paths, address_index):
# the test is going to fail if we make firmware stricter about this
@pytest.mark.multisig
@pytest.mark.parametrize("paths, address_index", VECTORS_MULTISIG)
def test_signtx_multisig(client, paths, address_index):
def test_signtx_multisig(client: Client, paths, address_index):
pubs = [
messages.HDNodePathType(
node=btc.get_public_node(
@ -211,13 +212,13 @@ def test_signtx_multisig(client, paths, address_index):
out1 = messages.TxOutputType(
address="17kTB7qSk3MupQxWdiv5ZU3zcrZc2Azes1",
amount=10000,
amount=10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
inp1 = messages.TxInputType(
address_n=parse_path(paths[0]) + address_index,
amount=20000,
amount=20_000,
prev_hash=TXHASH_6189e3,
prev_index=1,
script_type=messages.InputScriptType.SPENDMULTISIG,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
@ -31,17 +32,17 @@ TXHASH_d5f65e = bytes.fromhex(
)
def test_opreturn(client):
def test_opreturn(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/0'/0'/0/2"),
amount=390000,
address_n=parse_path("m/44h/0h/0h/0/2"),
amount=390_000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
out1 = messages.TxOutputType(
address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1",
amount=390000 - 10000,
amount=390_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -83,17 +84,17 @@ def test_opreturn(client):
)
def test_nonzero_opreturn(client):
def test_nonzero_opreturn(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/0'/10'/0/5"),
amount=390000,
address_n=parse_path("m/44h/0h/10h/0/5"),
amount=390_000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
out1 = messages.TxOutputType(
op_return_data=b"test of the op_return data",
amount=10000,
amount=10_000,
script_type=messages.OutputScriptType.PAYTOOPRETURN,
)
@ -108,16 +109,16 @@ def test_nonzero_opreturn(client):
btc.sign_tx(client, "Bitcoin", [inp1], [out1], prev_txes=TX_API)
def test_opreturn_address(client):
def test_opreturn_address(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44'/0'/0'/0/2"),
amount=390000,
address_n=parse_path("m/44h/0h/0h/0/2"),
amount=390_000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
out1 = messages.TxOutputType(
address_n=parse_path("44'/0'/0'/1/2"),
address_n=parse_path("m/44h/0h/0h/1/2"),
amount=0,
op_return_data=b"OMNI TRANSACTION GOES HERE",
script_type=messages.OutputScriptType.PAYTOOPRETURN,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
@ -31,20 +32,20 @@ TXHASH_41b29a = bytes.fromhex(
@pytest.mark.altcoin
@pytest.mark.peercoin
def test_timestamp_included(client):
def test_timestamp_included(client: Client):
# tx: 41b29ad615d8eea40a4654a052d18bb10cd08f203c351f4d241f88b031357d3d
# input 0: 0.1 PPC
inp1 = messages.TxInputType(
address_n=parse_path("m/44'/6'/0'/0/0"),
amount=100000,
address_n=parse_path("m/44h/6h/0h/0/0"),
amount=100_000,
prev_hash=TXHASH_41b29a,
prev_index=0,
)
out1 = messages.TxOutputType(
address="PXtfyTjzgXSgTwK5AbszdHQSSxyQN3BLM5",
amount=100000 - 10000,
amount=100_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -65,16 +66,16 @@ def test_timestamp_included(client):
@pytest.mark.altcoin
@pytest.mark.peercoin
def test_timestamp_missing(client):
def test_timestamp_missing(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("m/44'/6'/0'/0/0"),
amount=100000,
address_n=parse_path("m/44h/6h/0h/0/0"),
amount=100_000,
prev_hash=TXHASH_41b29a,
prev_index=0,
)
out1 = messages.TxOutputType(
address="PXtfyTjzgXSgTwK5AbszdHQSSxyQN3BLM5",
amount=100000 - 10000,
amount=100_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -103,16 +104,16 @@ def test_timestamp_missing(client):
@pytest.mark.altcoin
@pytest.mark.peercoin
def test_timestamp_missing_prevtx(client):
def test_timestamp_missing_prevtx(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("m/44'/6'/0'/0/0"),
amount=100000,
address_n=parse_path("m/44h/6h/0h/0/0"),
amount=100_000,
prev_hash=TXHASH_41b29a,
prev_index=0,
)
out1 = messages.TxOutputType(
address="PXtfyTjzgXSgTwK5AbszdHQSSxyQN3BLM5",
amount=100000 - 10000,
amount=100_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)

View File

@ -18,7 +18,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import message_filters
from trezorlib.debuglink import TrezorClientDebugLink as Client, message_filters
from trezorlib.tools import parse_path
S = messages.InputScriptType
@ -41,7 +41,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"p2pkh",
"Bitcoin",
"44h/0h/0h/0/0",
"m/44h/0h/0h/0/0",
S.SPENDADDRESS,
False,
"1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL",
@ -51,7 +51,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"segwit-p2sh",
"Bitcoin",
"49h/0h/0h/0/0",
"m/49h/0h/0h/0/0",
S.SPENDP2SHWITNESS,
False,
"3L6TyTisPBmrDAj6RoKmDzNnj4eQi54gD2",
@ -61,7 +61,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"segwit-native",
"Bitcoin",
"84h/0h/0h/0/0",
"m/84h/0h/0h/0/0",
S.SPENDWITNESS,
False,
"bc1qannfxke2tfd4l7vhepehpvt05y83v3qsf6nfkk",
@ -71,7 +71,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"p2pkh",
"Bitcoin",
"44h/0h/0h/0/0",
"m/44h/0h/0h/0/0",
S.SPENDADDRESS,
True,
"1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL",
@ -81,7 +81,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"segwit-p2sh",
"Bitcoin",
"49h/0h/0h/0/0",
"m/49h/0h/0h/0/0",
S.SPENDP2SHWITNESS,
True,
"3L6TyTisPBmrDAj6RoKmDzNnj4eQi54gD2",
@ -91,7 +91,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"segwit-native",
"Bitcoin",
"84h/0h/0h/0/0",
"m/84h/0h/0h/0/0",
S.SPENDWITNESS,
True,
"bc1qannfxke2tfd4l7vhepehpvt05y83v3qsf6nfkk",
@ -102,7 +102,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"p2pkh long message",
"Bitcoin",
"44h/0h/0h/0/0",
"m/44h/0h/0h/0/0",
S.SPENDADDRESS,
False,
"1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL",
@ -112,7 +112,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"segwit-p2sh long message",
"Bitcoin",
"49h/0h/0h/0/0",
"m/49h/0h/0h/0/0",
S.SPENDP2SHWITNESS,
False,
"3L6TyTisPBmrDAj6RoKmDzNnj4eQi54gD2",
@ -122,7 +122,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"segwit-native long message",
"Bitcoin",
"84h/0h/0h/0/0",
"m/84h/0h/0h/0/0",
S.SPENDWITNESS,
False,
"bc1qannfxke2tfd4l7vhepehpvt05y83v3qsf6nfkk",
@ -133,7 +133,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"NFKD message",
"Bitcoin",
"44h/0h/0h/0/1",
"m/44h/0h/0h/0/1",
S.SPENDADDRESS,
False,
"1GWFxtwWmNVqotUPXLcKVL2mUKpshuJYo",
@ -143,7 +143,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"NFC message",
"Bitcoin",
"44h/0h/0h/0/1",
"m/44h/0h/0h/0/1",
S.SPENDADDRESS,
False,
"1GWFxtwWmNVqotUPXLcKVL2mUKpshuJYo",
@ -154,7 +154,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"p2pkh",
"Testnet",
"44h/1h/0h/0/0",
"m/44h/1h/0h/0/0",
S.SPENDADDRESS,
False,
"mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q",
@ -164,7 +164,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"segwit-p2sh",
"Testnet",
"49h/1h/0h/0/0",
"m/49h/1h/0h/0/0",
S.SPENDP2SHWITNESS,
False,
"2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp",
@ -174,7 +174,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"segwit-native",
"Testnet",
"84h/1h/0h/0/0",
"m/84h/1h/0h/0/0",
S.SPENDWITNESS,
False,
"tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9",
@ -185,7 +185,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"bcash",
"Bcash",
"44h/145h/0h/0/0",
"m/44h/145h/0h/0/0",
S.SPENDADDRESS,
False,
"bitcoincash:qr08q88p9etk89wgv05nwlrkm4l0urz4cyl36hh9sv",
@ -196,7 +196,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"grs-p2pkh",
"Groestlcoin",
"44h/17h/0h/0/0",
"m/44h/17h/0h/0/0",
S.SPENDADDRESS,
False,
"Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM",
@ -207,7 +207,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"grs-segwit-p2sh",
"Groestlcoin",
"49h/17h/0h/0/0",
"m/49h/17h/0h/0/0",
S.SPENDP2SHWITNESS,
False,
"31inaRqambLsd9D7Ke4USZmGEVd3PHkh7P",
@ -218,7 +218,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"grs-segwit-native",
"Groestlcoin",
"84h/17h/0h/0/0",
"m/84h/17h/0h/0/0",
S.SPENDWITNESS,
False,
"grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne",
@ -229,7 +229,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"decred",
"Decred",
"44h/42h/0h/0/0",
"m/44h/42h/0h/0/0",
S.SPENDADDRESS,
False,
"DsZtHtXHwvNR3nWf1PqfxrEdnRJisKEyzp1",
@ -240,7 +240,7 @@ VECTORS = ( # case name, coin_name, path, script_type, address, message, signat
case(
"decred-empty",
"Decred",
"44h/42h/0h/0/0",
"m/44h/42h/0h/0/0",
S.SPENDADDRESS,
False,
"DsZtHtXHwvNR3nWf1PqfxrEdnRJisKEyzp1",
@ -282,7 +282,7 @@ MESSAGE_LENGTHS = (
@pytest.mark.skip_t1
@pytest.mark.parametrize("message", MESSAGE_LENGTHS)
def test_signmessage_pagination(client, message):
def test_signmessage_pagination(client: Client, message):
message_read = ""
def input_flow():
@ -330,7 +330,7 @@ def test_signmessage_pagination(client, message):
@pytest.mark.skip_t1
def test_signmessage_pagination_trailing_newline(client):
def test_signmessage_pagination_trailing_newline(client: Client):
message = "THIS\nMUST NOT\nBE\nPAGINATED\n"
# The trailing newline must not cause a new paginated screen to appear.
# The UI must be a single dialog without pagination.
@ -352,7 +352,7 @@ def test_signmessage_pagination_trailing_newline(client):
)
def test_signmessage_path_warning(client):
def test_signmessage_path_warning(client: Client):
message = "This is an example of a signed message."
with client:

View File

@ -19,6 +19,7 @@ from datetime import datetime, timezone
import pytest
from trezorlib import btc, device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import H_, parse_path, tx_hash
@ -81,11 +82,11 @@ TXHASH_1f326f = bytes.fromhex(
)
def test_one_one_fee(client):
def test_one_one_fee(client: Client):
# input tx: 0dac366fd8a67b2a89fbb0d31086e7acded7a5bbf9ef9daa935bc873229ef5b5
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/5h/0/9"), # 1H2CRJBrDMhkvCGZMW7T4oQwYbL8eVuh7p
address_n=parse_path("m/44h/0h/5h/0/9"), # 1H2CRJBrDMhkvCGZMW7T4oQwYbL8eVuh7p
amount=63_988,
prev_hash=TXHASH_0dac36,
prev_index=0,
@ -127,11 +128,11 @@ def test_one_one_fee(client):
)
def test_testnet_one_two_fee(client):
def test_testnet_one_two_fee(client: Client):
# input tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
address_n=parse_path("m/44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
amount=31_000_000,
prev_hash=TXHASH_e5040e,
prev_index=0,
@ -144,7 +145,7 @@ def test_testnet_one_two_fee(client):
)
out2 = messages.TxOutputType(
address_n=parse_path("44h/1h/0h/1/0"), # mm6kLYbGEL1tGe4ZA8xacfgRPdW1NLjCbZ
address_n=parse_path("m/44h/1h/0h/1/0"), # mm6kLYbGEL1tGe4ZA8xacfgRPdW1NLjCbZ
amount=900_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -181,19 +182,19 @@ def test_testnet_one_two_fee(client):
)
def test_testnet_fee_high_warning(client):
def test_testnet_fee_high_warning(client: Client):
# input tx: 25fee583181847cbe9d9fd9a483a8b8626c99854a72d01de848ef40508d0f3bc
# (The "25fee" tx hash is very suitable for testing high fees)
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/0h/0/7"), # mgV9Z3YuSbxGb2b2Y1T6VCqtU2osui7vhG
address_n=parse_path("m/44h/1h/0h/0/7"), # mgV9Z3YuSbxGb2b2Y1T6VCqtU2osui7vhG
amount=129_999_808,
prev_hash=TXHASH_25fee5,
prev_index=0,
)
out1 = messages.TxOutputType(
address="mnY26FLTzfC94mDoUcyDJh1GVE3LuAUMbs", # "44h/1h/0h/0/6"
address="mnY26FLTzfC94mDoUcyDJh1GVE3LuAUMbs", # "m/44h/1h/0h/0/6"
amount=129_999_808 - 2_500_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -227,18 +228,18 @@ def test_testnet_fee_high_warning(client):
)
def test_one_two_fee(client):
def test_one_two_fee(client: Client):
# input tx: 50f6f1209ca92d7359564be803cb2c932cde7d370f7cee50fd1fad6790f6206d
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/5"), # 1GA9u9TfCG7SWmKCveBumdA1TZpfom6ZdJ
address_n=parse_path("m/44h/0h/0h/0/5"), # 1GA9u9TfCG7SWmKCveBumdA1TZpfom6ZdJ
amount=50_000,
prev_hash=TXHASH_50f6f1,
prev_index=1,
)
out1 = messages.TxOutputType(
address_n=parse_path("44h/0h/0h/1/3"), # 1EcL6AyfQTyWKGvXwNSfsWoYnD3whzVFdu
address_n=parse_path("m/44h/0h/0h/1/3"), # 1EcL6AyfQTyWKGvXwNSfsWoYnD3whzVFdu
amount=30_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -281,30 +282,30 @@ def test_one_two_fee(client):
)
def test_one_three_fee(client):
def test_one_three_fee(client: Client):
# input tx: bb5169091f09e833e155b291b662019df56870effe388c626221c5ea84274bc4
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/1h/0/21"), # mvukVu96xM1QJ971w4Z5cdX4tsJwDyQy2L
address_n=parse_path("m/44h/1h/1h/0/21"), # mvukVu96xM1QJ971w4Z5cdX4tsJwDyQy2L
amount=1_183_825,
prev_hash=TXHASH_bb5169,
prev_index=0,
)
out1 = messages.TxOutputType(
address="mgCyjvJaTgVwKoxEaFaDLeFQpZc7qdKXpZ", # 44h/1h/1h/0/20
address="mgCyjvJaTgVwKoxEaFaDLeFQpZc7qdKXpZ", # m/44h/1h/1h/0/20
amount=100_100,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="n4qJziM7S8ydGbXKKRJADHuSeAjbx5c1Dp", # 44h/1h/1h/0/22
address="n4qJziM7S8ydGbXKKRJADHuSeAjbx5c1Dp", # m/44h/1h/1h/0/22
amount=100_100,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out3 = messages.TxOutputType(
address_n=parse_path("44h/1h/1h/1/21"), # n1CFre3Ai975UiWJrjZnFxTVrPkxCVkm8U
address_n=parse_path("m/44h/1h/1h/1/21"), # n1CFre3Ai975UiWJrjZnFxTVrPkxCVkm8U
amount=1_183_825 - 100_100 - 100_100 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -348,31 +349,31 @@ def test_one_three_fee(client):
)
def test_two_two(client):
def test_two_two(client: Client):
# input tx: ac4ca0e7827a1228f44449cb57b4b9a809a667ca044dc43bb124627fed4bc10a
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/55"), # 14nw9rFTWGUncHZjSqpPSJQaptWW7iRRB8
address_n=parse_path("m/44h/0h/0h/0/55"), # 14nw9rFTWGUncHZjSqpPSJQaptWW7iRRB8
amount=10_000,
prev_hash=TXHASH_ac4ca0,
prev_index=1,
)
inp2 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/1/7"), # 16hgR6bjr99X6NhrsWuDR6NLpCLEacUNk
address_n=parse_path("m/44h/0h/0h/1/7"), # 16hgR6bjr99X6NhrsWuDR6NLpCLEacUNk
amount=83_130,
prev_hash=TXHASH_ac4ca0,
prev_index=0,
)
out1 = messages.TxOutputType(
address_n=parse_path("44h/0h/0h/1/8"), # 1CJzc38F82zBUnMKWxeUqMepkPRmo2BGHt
address_n=parse_path("m/44h/0h/0h/1/8"), # 1CJzc38F82zBUnMKWxeUqMepkPRmo2BGHt
amount=71_790,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="1ByqmhXkC6U5GuUNnAhJsuEVjHt5GhEuJL", # 44h/0h/1h/0/17
address="1ByqmhXkC6U5GuUNnAhJsuEVjHt5GhEuJL", # m/44h/0h/1h/0/17
amount=10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -425,7 +426,7 @@ def test_two_two(client):
@pytest.mark.slow
def test_lots_of_inputs(client):
def test_lots_of_inputs(client: Client):
# Tests if device implements serialization of len(inputs) correctly
# input tx: 3019487f064329247daad245aed7a75349d09c14b1d24f170947690e030f5b20
@ -434,14 +435,14 @@ def test_lots_of_inputs(client):
for i in range(100):
inputs.append(
messages.TxInputType(
address_n=parse_path(f"44h/1h/1h/0/{i}"),
address_n=parse_path(f"m/44h/1h/1h/0/{i}"),
amount=14_598,
prev_hash=TXHASH_301948,
prev_index=i,
)
)
out = messages.TxOutputType(
address="mnY26FLTzfC94mDoUcyDJh1GVE3LuAUMbs", # "44h/1h/0h/0/6"
address="mnY26FLTzfC94mDoUcyDJh1GVE3LuAUMbs", # "m/44h/1h/0h/0/6"
amount=100 * 14_598 - 60_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -456,13 +457,13 @@ def test_lots_of_inputs(client):
@pytest.mark.slow
def test_lots_of_outputs(client):
def test_lots_of_outputs(client: Client):
# Tests if device implements serialization of len(outputs) correctly
# input tx: 58d56a5d1325cf83543ee4c87fd73a784e4ba1499ced574be359fa2bdcb9ac8e
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
address_n=parse_path("m/44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
amount=1_827_955,
prev_hash=TXHASH_58d56a,
prev_index=1,
@ -472,7 +473,7 @@ def test_lots_of_outputs(client):
cnt = 255
for _ in range(cnt):
out = messages.TxOutputType(
address="momtnzR3XqXgDSsFmd8gkGxUiHZLde3RmA", # "44h/1h/0h/0/3"
address="momtnzR3XqXgDSsFmd8gkGxUiHZLde3RmA", # "m/44h/1h/0h/0/3"
amount=(1_827_955 - 10_000) // cnt,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -489,13 +490,13 @@ def test_lots_of_outputs(client):
@pytest.mark.slow
def test_lots_of_change(client):
def test_lots_of_change(client: Client):
# Tests if device implements prompting for multiple change addresses correctly
# input tx: 892d06cb3394b8e6006eec9a2aa90692b718a29be6844b6c6a9e89ec3aa6aac4
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/0h/0/6"), # mnY26FLTzfC94mDoUcyDJh1GVE3LuAUMbs
address_n=parse_path("m/44h/1h/0h/0/6"), # mnY26FLTzfC94mDoUcyDJh1GVE3LuAUMbs
amount=1_553_800,
prev_hash=TXHASH_892d06,
prev_index=0,
@ -503,7 +504,7 @@ def test_lots_of_change(client):
outputs = [
messages.TxOutputType(
address="mgV9Z3YuSbxGb2b2Y1T6VCqtU2osui7vhG", # "44h/1h/0h/0/7"
address="mgV9Z3YuSbxGb2b2Y1T6VCqtU2osui7vhG", # "m/44h/1h/0h/0/7"
amount=500_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -512,7 +513,7 @@ def test_lots_of_change(client):
cnt = 20
for i in range(cnt):
out = messages.TxOutputType(
address_n=parse_path(f"44h/1h/0h/1/{i}"),
address_n=parse_path(f"m/44h/1h/0h/1/{i}"),
amount=(1_553_800 - 500_000 - 29_000) // cnt,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -554,18 +555,18 @@ def test_lots_of_change(client):
)
def test_fee_high_warning(client):
def test_fee_high_warning(client: Client):
# input tx: 1f326f65768d55ef146efbb345bd87abe84ac7185726d0457a026fc347a26ef3
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/10"), # 1JL3nCw76rhwK6EguU6uhe7GCa7Mq88kXg
address_n=parse_path("m/44h/0h/0h/0/10"), # 1JL3nCw76rhwK6EguU6uhe7GCa7Mq88kXg
amount=3_801_747,
prev_hash=TXHASH_1f326f,
prev_index=0,
)
out1 = messages.TxOutputType(
address="1DXKPgQU6ACQiww48chz7iPJhoV5L5bjRC", # 44h/0h/0h/0/11
address="1DXKPgQU6ACQiww48chz7iPJhoV5L5bjRC", # m/44h/0h/0h/0/11
amount=3_801_747 - 510_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -601,19 +602,19 @@ def test_fee_high_warning(client):
@pytest.mark.skip_t1
def test_fee_high_hardfail(client):
def test_fee_high_hardfail(client: Client):
# input tx: 25fee583181847cbe9d9fd9a483a8b8626c99854a72d01de848ef40508d0f3bc
# (The "25fee" tx hash is very suitable for testing high fees)
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/0h/0/7"), # mgV9Z3YuSbxGb2b2Y1T6VCqtU2osui7vhG
address_n=parse_path("m/44h/1h/0h/0/7"), # mgV9Z3YuSbxGb2b2Y1T6VCqtU2osui7vhG
amount=129_999_808,
prev_hash=TXHASH_25fee5,
prev_index=0,
)
out1 = messages.TxOutputType(
address="mnY26FLTzfC94mDoUcyDJh1GVE3LuAUMbs", # "44h/1h/0h/0/6"
address="mnY26FLTzfC94mDoUcyDJh1GVE3LuAUMbs", # "m/44h/1h/0h/0/6"
amount=129_999_808 - 25_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -650,11 +651,11 @@ def test_fee_high_hardfail(client):
)
def test_not_enough_funds(client):
def test_not_enough_funds(client: Client):
# input tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/0"), # 1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL
address_n=parse_path("m/44h/0h/0h/0/0"), # 1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL
amount=390_000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
@ -679,11 +680,11 @@ def test_not_enough_funds(client):
btc.sign_tx(client, "Bitcoin", [inp1], [out1], prev_txes=TX_CACHE_MAINNET)
def test_p2sh(client):
def test_p2sh(client: Client):
# input tx: 58d56a5d1325cf83543ee4c87fd73a784e4ba1499ced574be359fa2bdcb9ac8e
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/0h/0/2"), # mgswWyysmViMqYmn5XEj1pVz7rVUftVEBP
address_n=parse_path("m/44h/1h/0h/0/2"), # mgswWyysmViMqYmn5XEj1pVz7rVUftVEBP
amount=50_000,
prev_hash=TXHASH_58d56a,
prev_index=0,
@ -724,13 +725,13 @@ def test_p2sh(client):
)
def test_testnet_big_amount(client):
def test_testnet_big_amount(client: Client):
# This test is testing transaction with amount bigger than fits to uint32
# input tx: 074b0070939db4c2635c1bef0c8e68412ccc8d3c8782137547c7a2bbde073fc0
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/0h/0/6"), # mnY26FLTzfC94mDoUcyDJh1GVE3LuAUMbs
address_n=parse_path("m/44h/1h/0h/0/6"), # mnY26FLTzfC94mDoUcyDJh1GVE3LuAUMbs
amount=4_500_000_000,
prev_hash=TXHASH_074b00,
prev_index=1,
@ -751,31 +752,31 @@ def test_testnet_big_amount(client):
)
def test_attack_change_outputs(client):
def test_attack_change_outputs(client: Client):
# input tx: ac4ca0e7827a1228f44449cb57b4b9a809a667ca044dc43bb124627fed4bc10a
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/55"), # 14nw9rFTWGUncHZjSqpPSJQaptWW7iRRB8
address_n=parse_path("m/44h/0h/0h/0/55"), # 14nw9rFTWGUncHZjSqpPSJQaptWW7iRRB8
amount=10_000,
prev_hash=TXHASH_ac4ca0,
prev_index=1,
)
inp2 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/1/7"), # 16hgR6bjr99X6NhrsWuDR6NLpCLEacUNk
address_n=parse_path("m/44h/0h/0h/1/7"), # 16hgR6bjr99X6NhrsWuDR6NLpCLEacUNk
amount=83_130,
prev_hash=TXHASH_ac4ca0,
prev_index=0,
)
out1 = messages.TxOutputType(
address_n=parse_path("44h/0h/0h/1/8"), # 1CJzc38F82zBUnMKWxeUqMepkPRmo2BGHt
address_n=parse_path("m/44h/0h/0h/1/8"), # 1CJzc38F82zBUnMKWxeUqMepkPRmo2BGHt
amount=71_790,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="1ByqmhXkC6U5GuUNnAhJsuEVjHt5GhEuJL", # 44h/0h/1h/0/17
address="1ByqmhXkC6U5GuUNnAhJsuEVjHt5GhEuJL", # m/44h/0h/1h/0/17
amount=10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -851,7 +852,7 @@ def test_attack_change_outputs(client):
)
def test_attack_modify_change_address(client):
def test_attack_modify_change_address(client: Client):
# Ensure that if the change output is modified after the user confirms the
# transaction, then signing fails.
@ -859,7 +860,7 @@ def test_attack_modify_change_address(client):
# output tx 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
address_n=parse_path("m/44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
amount=31_000_000,
prev_hash=TXHASH_e5040e,
prev_index=0,
@ -872,7 +873,7 @@ def test_attack_modify_change_address(client):
)
out2 = messages.TxOutputType(
address_n=parse_path("44h/1h/0h/1/0"), # mm6kLYbGEL1tGe4ZA8xacfgRPdW1NLjCbZ
address_n=parse_path("m/44h/1h/0h/1/0"), # mm6kLYbGEL1tGe4ZA8xacfgRPdW1NLjCbZ
amount=900_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -900,11 +901,11 @@ def test_attack_modify_change_address(client):
btc.sign_tx(client, "Testnet", [inp1], [out1, out2], prev_txes=TX_CACHE_TESTNET)
def test_attack_change_input_address(client):
def test_attack_change_input_address(client: Client):
# input tx: d2dcdaf547ea7f57a713c607f15e883ddc4a98167ee2c43ed953c53cb5153e24
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/4h/0/0"), # moUJnmge8SRXuediK7bW6t4YfrPqbE6hD7
address_n=parse_path("m/44h/1h/4h/0/0"), # moUJnmge8SRXuediK7bW6t4YfrPqbE6hD7
prev_hash=TXHASH_d2dcda,
amount=123_400_000,
prev_index=1,
@ -912,13 +913,13 @@ def test_attack_change_input_address(client):
)
out1 = messages.TxOutputType(
address="mwue7mokpBRAsJtHqEMcRPanYBmsSmYKvY", # 44h/1h/4h/0/2
address="mwue7mokpBRAsJtHqEMcRPanYBmsSmYKvY", # m/44h/1h/4h/0/2
amount=100_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("44h/1h/4h/1/0"), # n48agDCKBPbMLu1FYSKEpFJLradG3wgdY9
address_n=parse_path("m/44h/1h/4h/1/0"), # n48agDCKBPbMLu1FYSKEpFJLradG3wgdY9
amount=123_400_000 - 5_000 - 100_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -979,9 +980,9 @@ def test_attack_change_input_address(client):
assert exc.value.message.endswith("Transaction has changed during signing")
def test_spend_coinbase(client):
def test_spend_coinbase(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
address_n=parse_path("m/44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
amount=2_500_278_230,
prev_hash=TXHASH_d6da21,
prev_index=0,
@ -1021,12 +1022,12 @@ def test_spend_coinbase(client):
)
def test_two_changes(client):
def test_two_changes(client: Client):
# input tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
# see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
address_n=parse_path("m/44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
amount=31_000_000,
prev_hash=TXHASH_e5040e,
prev_index=0,
@ -1039,13 +1040,13 @@ def test_two_changes(client):
)
out_change1 = messages.TxOutputType(
address_n=parse_path("44h/1h/0h/1/0"), # mm6kLYbGEL1tGe4ZA8xacfgRPdW1NLjCbZ
address_n=parse_path("m/44h/1h/0h/1/0"), # mm6kLYbGEL1tGe4ZA8xacfgRPdW1NLjCbZ
amount=900_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out_change2 = messages.TxOutputType(
address_n=parse_path("44h/1h/0h/1/1"), # mjXZwmEi1z1MzveZrKUAo4DBgbdq4sBYT6
address_n=parse_path("m/44h/1h/0h/1/1"), # mjXZwmEi1z1MzveZrKUAo4DBgbdq4sBYT6
amount=10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -1084,12 +1085,12 @@ def test_two_changes(client):
)
def test_change_on_main_chain_allowed(client):
def test_change_on_main_chain_allowed(client: Client):
# input tx: e5040e1bc1ae7667ffb9e5248e90b2fb93cd9150234151ce90e14ab2f5933bcd
# see 87be0736f202f7c2bff0781b42bad3e0cdcb54761939da69ea793a3735552c56
inp1 = messages.TxInputType(
address_n=parse_path("44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
address_n=parse_path("m/44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
amount=31_000_000,
prev_hash=TXHASH_e5040e,
prev_index=0,
@ -1103,7 +1104,7 @@ def test_change_on_main_chain_allowed(client):
# change on main chain is allowed => treated as a change
out_change = messages.TxOutputType(
address_n=parse_path("44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
address_n=parse_path("m/44h/1h/0h/0/0"), # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
amount=900_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -1139,7 +1140,7 @@ def test_change_on_main_chain_allowed(client):
)
def test_not_enough_vouts(client):
def test_not_enough_vouts(client: Client):
# input tx: ac4ca0e7827a1228f44449cb57b4b9a809a667ca044dc43bb124627fed4bc10a
prev_tx = TX_CACHE_MAINNET[TXHASH_ac4ca0]
@ -1149,20 +1150,20 @@ def test_not_enough_vouts(client):
# vout[0] and vout[1] exist
inp0 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/55"), # 14nw9rFTWGUncHZjSqpPSJQaptWW7iRRB8
address_n=parse_path("m/44h/0h/0h/0/55"), # 14nw9rFTWGUncHZjSqpPSJQaptWW7iRRB8
amount=10_000,
prev_hash=TXHASH_ac4ca0,
prev_index=1,
)
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/1/7"), # 16hgR6bjr99X6NhrsWuDR6NLpCLEacUNk
address_n=parse_path("m/44h/0h/0h/1/7"), # 16hgR6bjr99X6NhrsWuDR6NLpCLEacUNk
amount=83_130,
prev_hash=TXHASH_ac4ca0,
prev_index=0,
)
# vout[2] does not exist
inp2 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/1/0"), # 1DyHzbQUoQEsLxJn6M7fMD8Xdt1XvNiwNE
address_n=parse_path("m/44h/0h/0h/1/0"), # 1DyHzbQUoQEsLxJn6M7fMD8Xdt1XvNiwNE
prev_hash=TXHASH_ac4ca0,
amount=100_000_000,
prev_index=2,
@ -1197,9 +1198,9 @@ def test_not_enough_vouts(client):
("branch_id", 13),
),
)
def test_prevtx_forbidden_fields(client, field, value):
def test_prevtx_forbidden_fields(client: Client, field, value):
inp0 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/0"), # 1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL
address_n=parse_path("m/44h/0h/0h/0/0"), # 1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL
prev_hash=TXHASH_157041,
amount=100_000_000,
prev_index=0,
@ -1223,9 +1224,9 @@ def test_prevtx_forbidden_fields(client, field, value):
"field, value",
(("expiry", 9), ("timestamp", 42), ("version_group_id", 69), ("branch_id", 13)),
)
def test_signtx_forbidden_fields(client, field, value):
def test_signtx_forbidden_fields(client: Client, field, value):
inp0 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/0"), # 1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL
address_n=parse_path("m/44h/0h/0h/0/0"), # 1JAd7XCBzGudGpJQSDSfpmJhiygtLQWaGL
prev_hash=TXHASH_157041,
amount=100_000_000,
prev_index=0,
@ -1248,8 +1249,8 @@ def test_signtx_forbidden_fields(client, field, value):
"script_type",
(messages.InputScriptType.SPENDADDRESS, messages.InputScriptType.EXTERNAL),
)
def test_incorrect_input_script_type(client, script_type):
address_n = parse_path("44h/1h/0h/0/0") # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
def test_incorrect_input_script_type(client: Client, script_type):
address_n = parse_path("m/44h/1h/0h/0/0") # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
attacker_multisig_public_key = bytes.fromhex(
"030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
)
@ -1302,8 +1303,8 @@ def test_incorrect_input_script_type(client, script_type):
messages.OutputScriptType.PAYTOSCRIPTHASH,
),
)
def test_incorrect_output_script_type(client, script_type):
address_n = parse_path("44h/1h/0h/0/0") # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
def test_incorrect_output_script_type(client: Client, script_type):
address_n = parse_path("m/44h/1h/0h/0/0") # mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
attacker_multisig_public_key = bytes.fromhex(
"030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
)
@ -1352,11 +1353,11 @@ def test_incorrect_output_script_type(client, script_type):
"lock_time, sequence",
((499_999_999, 0xFFFFFFFE), (500_000_000, 0xFFFFFFFE), (1, 0xFFFFFFFF)),
)
def test_lock_time(client, lock_time, sequence):
def test_lock_time(client: Client, lock_time, sequence):
# input tx: 0dac366fd8a67b2a89fbb0d31086e7acded7a5bbf9ef9daa935bc873229ef5b5
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/5h/0/9"), # 1H2CRJBrDMhkvCGZMW7T4oQwYbL8eVuh7p
address_n=parse_path("m/44h/0h/5h/0/9"), # 1H2CRJBrDMhkvCGZMW7T4oQwYbL8eVuh7p
amount=63_988,
prev_hash=TXHASH_0dac36,
prev_index=0,
@ -1400,11 +1401,11 @@ def test_lock_time(client, lock_time, sequence):
@pytest.mark.skip_t1(reason="Cannot test layouts on T1")
def test_lock_time_blockheight(client):
def test_lock_time_blockheight(client: Client):
# input tx: 0dac366fd8a67b2a89fbb0d31086e7acded7a5bbf9ef9daa935bc873229ef5b5
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/5h/0/9"), # 1H2CRJBrDMhkvCGZMW7T4oQwYbL8eVuh7p
address_n=parse_path("m/44h/0h/5h/0/9"), # 1H2CRJBrDMhkvCGZMW7T4oQwYbL8eVuh7p
amount=63_988,
prev_hash=TXHASH_0dac36,
prev_index=0,
@ -1449,11 +1450,11 @@ def test_lock_time_blockheight(client):
@pytest.mark.parametrize(
"lock_time_str", ("1985-11-05 00:53:20", "2048-08-16 22:14:00")
)
def test_lock_time_datetime(client, lock_time_str):
def test_lock_time_datetime(client: Client, lock_time_str):
# input tx: 0dac366fd8a67b2a89fbb0d31086e7acded7a5bbf9ef9daa935bc873229ef5b5
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/5h/0/9"), # 1H2CRJBrDMhkvCGZMW7T4oQwYbL8eVuh7p
address_n=parse_path("m/44h/0h/5h/0/9"), # 1H2CRJBrDMhkvCGZMW7T4oQwYbL8eVuh7p
amount=63_988,
prev_hash=TXHASH_0dac36,
prev_index=0,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...tx_cache import TxCache
@ -37,23 +38,23 @@ VECTORS = ( # amount_unit
@pytest.mark.parametrize("amount_unit", VECTORS)
def test_signtx(client, amount_unit):
def test_signtx(client: Client, amount_unit):
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=12_300_000,
prev_hash=TXHASH_091446,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
)
out1 = messages.TxOutputType(
address="2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp",
amount=5000000,
amount=5_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=12300000 - 11000 - 5000000,
amount=12_300_000 - 11_000 - 5_000_000,
)
with client:
_, serialized_tx = btc.sign_tx(

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
@ -67,13 +68,13 @@ TXHASH_4012d9 = bytes.fromhex(
@pytest.mark.skip_t1
def test_p2pkh_presigned(client):
def test_p2pkh_presigned(client: Client):
inp1 = messages.TxInputType(
# mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q
address_n=parse_path("m/44h/1h/0h/0/0"),
prev_hash=TXHASH_e5040e,
prev_index=0,
amount=31000000,
amount=31_000_000,
)
inp1ext = messages.TxInputType(
@ -81,7 +82,7 @@ def test_p2pkh_presigned(client):
# address_n=parse_path("m/44h/1h/0h/0/0"),
prev_hash=TXHASH_e5040e,
prev_index=0,
amount=31000000,
amount=31_000_000,
script_type=messages.InputScriptType.EXTERNAL,
script_pubkey=bytes.fromhex(
"76a914a579388225827d9f2fe9014add644487808c695d88ac"
@ -96,7 +97,7 @@ def test_p2pkh_presigned(client):
address_n=parse_path("m/44h/1h/0h/0/1"),
prev_hash=TXHASH_d830b8,
prev_index=1,
amount=600000000,
amount=600_000_000,
)
inp2ext = messages.TxInputType(
@ -104,7 +105,7 @@ def test_p2pkh_presigned(client):
# address_n=parse_path("m/44h/1h/0h/0/1"),
prev_hash=TXHASH_d830b8,
prev_index=1,
amount=600000000,
amount=600_000_000,
script_type=messages.InputScriptType.EXTERNAL,
script_pubkey=bytes.fromhex(
"76a9145b157a678a10021243307e4bb58f36375aa80e1088ac"
@ -116,13 +117,13 @@ def test_p2pkh_presigned(client):
out1 = messages.TxOutputType(
address="tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2",
amount=620000000,
amount=620_000_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("44h/1h/0h/1/0"),
amount=31000000 + 600000000 - 620000000 - 10000,
address_n=parse_path("m/44h/1h/0h/1/0"),
amount=31_000_000 + 600_000_000 - 620_000_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -164,10 +165,10 @@ def test_p2pkh_presigned(client):
@pytest.mark.skip_t1
def test_p2wpkh_in_p2sh_presigned(client):
def test_p2wpkh_in_p2sh_presigned(client: Client):
inp1 = messages.TxInputType(
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=111145789,
amount=111_145_789,
prev_hash=TXHASH_091446,
prev_index=1,
script_type=messages.InputScriptType.EXTERNAL,
@ -178,26 +179,26 @@ def test_p2wpkh_in_p2sh_presigned(client):
),
)
inp2 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=7_289_000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS,
)
out1 = messages.TxOutputType(
address="tb1q54un3q39sf7e7tlfq99d6ezys7qgc62a6rxllc",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
# address_n=parse_path("44'/1'/0'/0/0"),
address="2N6UeBoqYEEnybg4cReFYDammpsyDw8R2Mc",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=45600000,
amount=45_600_000,
)
out3 = messages.TxOutputType(
address="mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q",
amount=111145789 + 7289000 - 11000 - 12300000 - 45600000,
amount=111_145_789 + 7_289_000 - 11_000 - 12_300_000 - 45_600_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -280,13 +281,13 @@ def test_p2wpkh_in_p2sh_presigned(client):
@pytest.mark.skip_t1
def test_p2wpkh_presigned(client):
def test_p2wpkh_presigned(client: Client):
inp1 = messages.TxInputType(
# tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9
address_n=parse_path("m/84h/1h/0h/0/0"),
prev_hash=TXHASH_70f987,
prev_index=0,
amount=100000,
amount=100_000,
script_type=messages.InputScriptType.SPENDWITNESS,
)
@ -295,7 +296,7 @@ def test_p2wpkh_presigned(client):
# address_n=parse_path("m/84h/1h/0h/0/1"),
prev_hash=TXHASH_65b768,
prev_index=0,
amount=10000,
amount=10_000,
script_type=messages.InputScriptType.EXTERNAL,
script_pubkey=bytes.fromhex("0014fb7e49f4017dc951615dea221b66626189aa43b9"),
script_sig=bytes.fromhex(""),
@ -306,13 +307,13 @@ def test_p2wpkh_presigned(client):
out1 = messages.TxOutputType(
address="tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2",
amount=50000,
amount=50_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("84h/1h/0h/1/0"),
amount=100000 + 10000 - 50000 - 1000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=100_000 + 10_000 - 50_000 - 1_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
)
@ -344,10 +345,10 @@ def test_p2wpkh_presigned(client):
@pytest.mark.skip_t1
def test_p2wsh_external_presigned(client):
def test_p2wsh_external_presigned(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=12_300_000,
prev_hash=TXHASH_091446,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -372,7 +373,7 @@ def test_p2wsh_external_presigned(client):
out1 = messages.TxOutputType(
address="2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp",
amount=12300000 + 100 - 10000,
amount=12_300_000 + 100 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -441,11 +442,11 @@ def test_p2wsh_external_presigned(client):
@pytest.mark.skip_t1
def test_p2tr_external_presigned(client):
def test_p2tr_external_presigned(client: Client):
inp1 = messages.TxInputType(
# tb1pswrqtykue8r89t9u4rprjs0gt4qzkdfuursfnvqaa3f2yql07zmq8s8a5u
address_n=parse_path("86'/1'/0'/0/0"),
amount=6800,
address_n=parse_path("m/86h/1h/0h/0/0"),
amount=6_800,
prev_hash=TXHASH_df862e,
prev_index=0,
script_type=messages.InputScriptType.SPENDTAPROOT,
@ -453,7 +454,7 @@ def test_p2tr_external_presigned(client):
inp2 = messages.TxInputType(
# tb1p8tvmvsvhsee73rhym86wt435qrqm92psfsyhy6a3n5gw455znnpqm8wald
# m/86'/1'/0'/0/1 for "all all ... all" seed.
amount=13000,
amount=13_000,
prev_hash=TXHASH_3ac32e,
prev_index=1,
script_pubkey=bytes.fromhex(
@ -467,14 +468,14 @@ def test_p2tr_external_presigned(client):
out1 = messages.TxOutputType(
# 84'/1'/1'/0/0
address="tb1q7r9yvcdgcl6wmtta58yxf29a8kc96jkyxl7y88",
amount=15000,
amount=15_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
# tb1pn2d0yjeedavnkd8z8lhm566p0f2utm3lgvxrsdehnl94y34txmts5s7t4c
address_n=parse_path("86'/1'/0'/1/0"),
address_n=parse_path("m/86h/1h/0h/1/0"),
script_type=messages.OutputScriptType.PAYTOTAPROOT,
amount=6800 + 13000 - 200 - 15000,
amount=6_800 + 13_000 - 200 - 15_000,
)
with client:
client.set_expected_responses(
@ -531,24 +532,24 @@ def test_p2tr_external_presigned(client):
@pytest.mark.skip_t1
def test_p2pkh_with_proof(client):
def test_p2pkh_with_proof(client: Client):
# TODO
pass
@pytest.mark.skip_t1
def test_p2wpkh_in_p2sh_with_proof(client):
def test_p2wpkh_in_p2sh_with_proof(client: Client):
# TODO
pass
@pytest.mark.skip_t1
def test_p2wpkh_with_proof(client):
def test_p2wpkh_with_proof(client: Client):
inp1 = messages.TxInputType(
# seed "alcohol woman abuse must during monitor noble actual mixed trade anger aisle"
# 84'/1'/0'/0/0
# tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2
amount=100000,
amount=100_000,
prev_hash=TXHASH_e5b7e2,
prev_index=0,
script_type=messages.InputScriptType.EXTERNAL,
@ -558,20 +559,20 @@ def test_p2wpkh_with_proof(client):
),
)
inp2 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=7_289_000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS,
)
out1 = messages.TxOutputType(
address="tb1q54un3q39sf7e7tlfq99d6ezys7qgc62a6rxllc",
amount=1230000,
amount=1_230_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q",
amount=100000 + 7289000 - 11000 - 1230000,
amount=100_000 + 7_289_000 - 11_000 - 1_230_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -632,7 +633,7 @@ def test_p2wpkh_with_proof(client):
@pytest.mark.setup_client(
mnemonic="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
)
def test_p2tr_with_proof(client):
def test_p2tr_with_proof(client: Client):
# Resulting TXID 48ec6dc7bb772ff18cbce0135fedda7c0e85212c7b2f85a5d0cc7a917d77c48a
inp1 = messages.TxInputType(
@ -640,7 +641,7 @@ def test_p2tr_with_proof(client):
# 86'/1'/2'/0/0
# tb1pyu3e8expmey3n5mhra64c9lhz8865rftmaedwa7dddxrlktuv6us6snqxg
# afde2d41702948e922150825742cda3294d80d43b8e508865c1e2d648f6d4dae
amount=100892,
amount=100_892,
prev_hash=TXHASH_afde2d,
prev_index=2,
script_type=messages.InputScriptType.EXTERNAL,
@ -652,15 +653,15 @@ def test_p2tr_with_proof(client):
),
)
inp2 = messages.TxInputType(
address_n=parse_path("86'/1'/0'/0/0"),
amount=6456,
address_n=parse_path("m/86h/1h/0h/0/0"),
amount=6_456,
prev_hash=TXHASH_4012d9,
prev_index=0,
script_type=messages.InputScriptType.SPENDTAPROOT,
)
out1 = messages.TxOutputType(
address="tb1puyst6yj0x3w5z253k5xt0crk2zjy36g0fzhascd4wknxfwv9h9lszyhefk",
amount=100892 + 6456 - 300,
amount=100_892 + 6_456 - 300,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -696,13 +697,13 @@ def test_p2tr_with_proof(client):
@pytest.mark.skip_t1
def test_p2wpkh_with_false_proof(client):
def test_p2wpkh_with_false_proof(client: Client):
inp1 = messages.TxInputType(
# tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9
address_n=parse_path("m/84h/1h/0h/0/0"),
prev_hash=TXHASH_70f987,
prev_index=0,
amount=100000,
amount=100_000,
script_type=messages.InputScriptType.SPENDWITNESS,
)
@ -711,7 +712,7 @@ def test_p2wpkh_with_false_proof(client):
# address_n=parse_path("m/84h/1h/0h/0/1"),
prev_hash=TXHASH_65b768,
prev_index=0,
amount=10000,
amount=10_000,
script_type=messages.InputScriptType.EXTERNAL,
script_pubkey=bytes.fromhex("0014fb7e49f4017dc951615dea221b66626189aa43b9"),
ownership_proof=bytes.fromhex(
@ -721,7 +722,7 @@ def test_p2wpkh_with_false_proof(client):
out1 = messages.TxOutputType(
address="tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2",
amount=50000,
amount=50_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
)

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import H_, parse_path
@ -50,13 +51,13 @@ TXHASH_5dfd1b = bytes.fromhex(
# Litecoin does not have strong replay protection using SIGHASH_FORKID,
# spending from Bitcoin path should fail.
@pytest.mark.altcoin
def test_invalid_path_fail(client):
def test_invalid_path_fail(client: Client):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/0"),
amount=390000,
address_n=parse_path("m/44h/0h/0h/0/0"),
amount=390_000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
@ -64,7 +65,7 @@ def test_invalid_path_fail(client):
# address is converted from 1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1 by changing the version
out1 = messages.TxOutputType(
address="LfWz9wLHmqU9HoDkMg9NqbRosrHvEixeVZ",
amount=390000 - 10000,
amount=390_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -80,13 +81,13 @@ def test_invalid_path_fail(client):
# Litecoin does not have strong replay protection using SIGHASH_FORKID, but
# spending from Bitcoin path should pass with safety checks set to prompt.
@pytest.mark.altcoin
def test_invalid_path_prompt(client):
def test_invalid_path_prompt(client: Client):
# tx: d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882
# input 0: 0.0039 BTC
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/0"),
amount=390000,
address_n=parse_path("m/44h/0h/0h/0/0"),
amount=390_000,
prev_hash=TXHASH_d5f65e,
prev_index=0,
)
@ -94,7 +95,7 @@ def test_invalid_path_prompt(client):
# address is converted from 1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1 by changing the version
out1 = messages.TxOutputType(
address="LfWz9wLHmqU9HoDkMg9NqbRosrHvEixeVZ",
amount=390000 - 10000,
amount=390_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -110,13 +111,13 @@ def test_invalid_path_prompt(client):
# Bcash does have strong replay protection using SIGHASH_FORKID,
# spending from Bitcoin path should work.
@pytest.mark.altcoin
def test_invalid_path_pass_forkid(client):
def test_invalid_path_pass_forkid(client: Client):
# tx: 8cc1f4adf7224ce855cf535a5104594a0004cb3b640d6714fdb00b9128832dd5
# input 0: 0.0039 BTC
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/0"),
amount=390000,
address_n=parse_path("m/44h/0h/0h/0/0"),
amount=390_000,
prev_hash=TXHASH_8cc1f4,
prev_index=0,
)
@ -124,14 +125,14 @@ def test_invalid_path_pass_forkid(client):
# address is converted from 1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1 to cashaddr format
out1 = messages.TxOutputType(
address="bitcoincash:qr0fk25d5zygyn50u5w7h6jkvctas52n0qxff9ja6r",
amount=390000 - 10000,
amount=390_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
btc.sign_tx(client, "Bcash", [inp1], [out1], prev_txes=TX_CACHE_BCASH)
def test_attack_path_segwit(client):
def test_attack_path_segwit(client: Client):
# Scenario: The attacker falsely claims that the transaction uses Testnet paths to
# avoid the path warning dialog, but in step6_sign_segwit_inputs() uses Bitcoin paths
# to get a valid signature.
@ -142,8 +143,8 @@ def test_attack_path_segwit(client):
inp1 = messages.TxInputType(
# The actual input that the attcker wants to get signed.
address_n=parse_path("84'/0'/0'/0/0"),
amount=9426,
address_n=parse_path("m/84h/0h/0h/0/0"),
amount=9_426,
prev_hash=TXHASH_fa80a9,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -152,8 +153,8 @@ def test_attack_path_segwit(client):
# The actual input that the attcker wants to get signed.
# We need this one to be from a different account, so that the match checker
# allows the transaction to pass.
address_n=parse_path("84'/0'/1'/0/1"),
amount=7086,
address_n=parse_path("m/84h/0h/1h/0/1"),
amount=7_086,
prev_hash=TXHASH_5dfd1b,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -163,7 +164,7 @@ def test_attack_path_segwit(client):
# Attacker's Mainnet address encoded as Testnet.
address="tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=9426 + 7086 - 500,
amount=9_426 + 7_086 - 500,
)
attack_count = 6
@ -222,19 +223,19 @@ def test_attack_path_segwit(client):
@pytest.mark.skip_t1(reason="T1 only prevents using paths known to be altcoins")
def test_invalid_path_fail_asap(client):
def test_invalid_path_fail_asap(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("0"),
amount=4977040,
address_n=parse_path("m/0"),
amount=4_977_040,
prev_hash=TXHASH_a5cd2a,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
sequence=4294967293,
sequence=4_294_967_293,
)
out1 = messages.TxOutputType(
address_n=parse_path("84h/0h/0h/1/0"),
amount=4977040,
address_n=parse_path("m/84h/0h/0h/1/0"),
amount=4_977_040,
script_type=messages.OutputScriptType.PAYTOWITNESS,
)

View File

@ -15,6 +15,7 @@
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...tx_cache import TxCache
@ -35,25 +36,25 @@ TXHASH_31bc1c = bytes.fromhex(
)
def test_non_segwit_segwit_inputs(client):
def test_non_segwit_segwit_inputs(client: Client):
# First is non-segwit, second is segwit.
inp1 = messages.TxInputType(
address_n=parse_path("44'/1'/0'/0/0"),
amount=31000000,
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=31_000_000,
prev_hash=TXHASH_e5040e,
prev_index=0,
)
inp2 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=7_289_000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS,
)
out1 = messages.TxOutputType(
address="tb1q54un3q39sf7e7tlfq99d6ezys7qgc62a6rxllc",
amount=31000000 + 7289000 - 1000,
amount=31_000_000 + 7_289_000 - 1_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -77,25 +78,25 @@ def test_non_segwit_segwit_inputs(client):
)
def test_segwit_non_segwit_inputs(client):
def test_segwit_non_segwit_inputs(client: Client):
# First is segwit, second is non-segwit.
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=7_289_000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS,
)
inp2 = messages.TxInputType(
address_n=parse_path("44'/1'/0'/0/0"),
amount=31000000,
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=31_000_000,
prev_hash=TXHASH_e5040e,
prev_index=0,
)
out1 = messages.TxOutputType(
address="tb1q54un3q39sf7e7tlfq99d6ezys7qgc62a6rxllc",
amount=31000000 + 7289000 - 1000,
amount=31_000_000 + 7_289_000 - 1_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -119,32 +120,32 @@ def test_segwit_non_segwit_inputs(client):
)
def test_segwit_non_segwit_segwit_inputs(client):
def test_segwit_non_segwit_segwit_inputs(client: Client):
# First is segwit, second is non-segwit and third is segwit again.
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=7_289_000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS,
)
inp2 = messages.TxInputType(
address_n=parse_path("44'/1'/0'/0/0"),
amount=31000000,
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=31_000_000,
prev_hash=TXHASH_e5040e,
prev_index=0,
)
inp3 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
amount=1603000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=1_603_000,
prev_hash=TXHASH_31bc1c,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
)
out1 = messages.TxOutputType(
address="tb1q54un3q39sf7e7tlfq99d6ezys7qgc62a6rxllc",
amount=31000000 + 7289000 - 1000,
amount=31_000_000 + 7_289_000 - 1_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -172,31 +173,31 @@ def test_segwit_non_segwit_segwit_inputs(client):
)
def test_non_segwit_segwit_non_segwit_inputs(client):
def test_non_segwit_segwit_non_segwit_inputs(client: Client):
# First is non-segwit, second is segwit and third is non-segwit again.
inp1 = messages.TxInputType(
address_n=parse_path("44'/1'/0'/0/0"),
amount=31000000,
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=31_000_000,
prev_hash=TXHASH_e5040e,
prev_index=0,
)
inp2 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=7_289_000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS,
)
inp3 = messages.TxInputType(
address_n=parse_path("44'/1'/1'/0/0"),
amount=9226912,
address_n=parse_path("m/44h/1h/1h/0/0"),
amount=9_226_912,
prev_hash=TXHASH_2bac7a,
prev_index=0,
)
out1 = messages.TxOutputType(
address="tb1q54un3q39sf7e7tlfq99d6ezys7qgc62a6rxllc",
amount=31000000 + 7289000 - 1000,
amount=31_000_000 + 7_289_000 - 1_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)

View File

@ -19,6 +19,7 @@ from collections import namedtuple
import pytest
from trezorlib import btc, messages, misc
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
@ -45,8 +46,8 @@ def case(id, *args, altcoin=False):
inputs = [
messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=12_300_000,
prev_hash=TXHASH_091446,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -56,18 +57,18 @@ inputs = [
outputs = [
messages.TxOutputType(
address="2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp",
amount=5000000,
amount=5_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
),
messages.TxOutputType(
address="tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=2000000,
amount=2_000_000,
),
messages.TxOutputType(
# tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9
address_n=parse_path("84h/1h/0h/0/0"),
amount=12300000 - 5000000 - 2000000 - 11000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=12_300_000 - 5_000_000 - 2_000_000 - 11_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
),
]
@ -77,7 +78,7 @@ memos1 = [
amount="15.9636 DASH",
coin_name="Dash",
slip44=5,
address_n=parse_path("44'/5'/0'/1/0"),
address_n=parse_path("m/44h/5h/0h/1/0"),
),
]
@ -86,17 +87,17 @@ memos2 = [
amount="3.1896 DASH",
coin_name="Dash",
slip44=5,
address_n=parse_path("44'/5'/0'/1/0"),
address_n=parse_path("m/44h/5h/0h/1/0"),
),
CoinPurchaseMemo(
amount="831.570802 GRS",
coin_name="Groestlcoin",
slip44=17,
address_n=parse_path("44'/17'/0'/0/3"),
address_n=parse_path("m/44h/17h/0h/0/3"),
),
]
memos3 = [TextMemo("Invoice #87654321."), RefundMemo(parse_path("44'/1'/0'/0/1"))]
memos3 = [TextMemo("Invoice #87654321."), RefundMemo(parse_path("m/44h/1h/0h/0/1"))]
PaymentRequestParams = namedtuple(
"PaymentRequestParams", ["txo_indices", "memos", "get_nonce"]
@ -130,7 +131,7 @@ SERIALIZED_TX = "010000000001018a44999c07bba32df1cacdc50987944e68e3205b4429438fd
case("out12", (PaymentRequestParams([1, 2], [], get_nonce=True),)),
),
)
def test_payment_request(client, payment_request_params):
def test_payment_request(client: Client, payment_request_params):
for txo in outputs:
txo.payment_req_index = None
@ -175,7 +176,7 @@ def test_payment_request(client, payment_request_params):
)
def test_payment_request_details(client):
def test_payment_request_details(client: Client):
# Test that payment request details are shown when requested.
outputs[0].payment_req_index = 0
outputs[1].payment_req_index = 0
@ -225,7 +226,7 @@ def test_payment_request_details(client):
assert serialized_tx.hex() == SERIALIZED_TX
def test_payment_req_wrong_amount(client):
def test_payment_req_wrong_amount(client: Client):
# Test wrong total amount in payment request.
outputs[0].payment_req_index = 0
outputs[1].payment_req_index = 0
@ -251,9 +252,9 @@ def test_payment_req_wrong_amount(client):
)
def test_payment_req_wrong_mac_refund(client):
def test_payment_req_wrong_mac_refund(client: Client):
# Test wrong MAC in payment request memo.
memo = RefundMemo(parse_path("44'/1'/0'/1/0"))
memo = RefundMemo(parse_path("m/44h/1h/0h/1/0"))
outputs[0].payment_req_index = 0
outputs[1].payment_req_index = 0
outputs[2].payment_req_index = None
@ -282,13 +283,13 @@ def test_payment_req_wrong_mac_refund(client):
@pytest.mark.altcoin
def test_payment_req_wrong_mac_purchase(client):
def test_payment_req_wrong_mac_purchase(client: Client):
# Test wrong MAC in payment request memo.
memo = CoinPurchaseMemo(
amount="22.34904 DASH",
coin_name="Dash",
slip44=5,
address_n=parse_path("44'/5'/0'/1/0"),
address_n=parse_path("m/44h/5h/0h/1/0"),
)
outputs[0].payment_req_index = 0
outputs[1].payment_req_index = 0
@ -317,7 +318,7 @@ def test_payment_req_wrong_mac_purchase(client):
)
def test_payment_req_wrong_output(client):
def test_payment_req_wrong_output(client: Client):
# Test wrong output in payment request.
outputs[0].payment_req_index = 0
outputs[1].payment_req_index = 0

View File

@ -4,6 +4,7 @@ from io import BytesIO
import pytest
from trezorlib import btc, messages, tools
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from ...tx_cache import TxCache
@ -76,17 +77,17 @@ with_bad_prevhashes = pytest.mark.parametrize(
@with_bad_prevhashes
def test_invalid_prev_hash(client, prev_hash):
def test_invalid_prev_hash(client: Client, prev_hash):
inp1 = messages.TxInputType(
address_n=tools.parse_path("m/44h/0h/0h/0/0"),
amount=123456789,
amount=123_456_789,
prev_hash=prev_hash,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
out1 = messages.TxOutputType(
address="mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -96,18 +97,18 @@ def test_invalid_prev_hash(client, prev_hash):
@with_bad_prevhashes
def test_invalid_prev_hash_attack(client, prev_hash):
def test_invalid_prev_hash_attack(client: Client, prev_hash):
# prepare input with a valid prev-hash
inp1 = messages.TxInputType(
address_n=tools.parse_path("m/44h/0h/0h/0/0"),
amount=100000000,
amount=100_000_000,
prev_hash=TXHASH_157041,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
out1 = messages.TxOutputType(
address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1",
amount=100000000 - 10000,
amount=100_000_000 - 10_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -138,7 +139,7 @@ def test_invalid_prev_hash_attack(client, prev_hash):
@with_bad_prevhashes
def test_invalid_prev_hash_in_prevtx(client, prev_hash):
def test_invalid_prev_hash_in_prevtx(client: Client, prev_hash):
cache = TxCache("Bitcoin")
prev_tx = cache[TXHASH_157041]
@ -148,13 +149,13 @@ def test_invalid_prev_hash_in_prevtx(client, prev_hash):
inp0 = messages.TxInputType(
address_n=tools.parse_path("m/44h/0h/0h/0/0"),
amount=100000000,
amount=100_000_000,
prev_hash=tx_hash,
prev_index=0,
)
out1 = messages.TxOutputType(
address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1",
amount=99000000,
amount=99_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
btc.sign_tx(client, "Bitcoin", [inp0], [out1], prev_txes={tx_hash: prev_tx})

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
@ -88,10 +89,10 @@ TXHASH_8e4af7 = bytes.fromhex(
)
def test_p2pkh_fee_bump(client):
def test_p2pkh_fee_bump(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/4"),
amount=174998,
address_n=parse_path("m/44h/0h/0h/0/4"),
amount=174_998,
prev_hash=TXHASH_beafc7,
prev_index=0,
orig_hash=TXHASH_50f6f1,
@ -99,8 +100,8 @@ def test_p2pkh_fee_bump(client):
)
out1 = messages.TxOutputType(
address_n=parse_path("44h/0h/0h/1/2"),
amount=174998 - 50000 - 15000, # Originally fee was 11300, now 15000.
address_n=parse_path("m/44h/0h/0h/1/2"),
amount=174_998 - 50_000 - 15_000, # Originally fee was 11_300, now 15_000.
script_type=messages.OutputScriptType.PAYTOADDRESS,
orig_hash=TXHASH_50f6f1,
orig_index=0,
@ -108,7 +109,7 @@ def test_p2pkh_fee_bump(client):
out2 = messages.TxOutputType(
address="1GA9u9TfCG7SWmKCveBumdA1TZpfom6ZdJ",
amount=50000,
amount=50_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
orig_hash=TXHASH_50f6f1,
orig_index=1,
@ -157,17 +158,17 @@ def test_p2pkh_fee_bump(client):
)
def test_p2wpkh_op_return_fee_bump(client):
def test_p2wpkh_op_return_fee_bump(client: Client):
# Original input.
inp1 = messages.TxInputType(
address_n=parse_path("m/84h/1h/1h/0/14"),
amount=1000000,
amount=1_000_000,
script_type=messages.InputScriptType.SPENDWITNESS,
prev_hash=TXHASH_408397,
prev_index=1,
orig_hash=TXHASH_ba917a,
orig_index=0,
sequence=4294967293,
sequence=4_294_967_293,
)
# Original OP_RETURN output.
@ -182,7 +183,7 @@ def test_p2wpkh_op_return_fee_bump(client):
# Change-output. We bump the fee from 150 to 300.
out2 = messages.TxOutputType(
address_n=parse_path("m/84h/1h/1h/1/10"),
amount=999850 - 150,
amount=999_850 - 150,
script_type=messages.OutputScriptType.PAYTOWITNESS,
orig_hash=TXHASH_ba917a,
orig_index=1,
@ -204,11 +205,11 @@ def test_p2wpkh_op_return_fee_bump(client):
# txid 48bc29fc42a64b43d043b0b7b99b21aa39654234754608f791c60bcbd91a8e92
def test_p2tr_fee_bump(client):
def test_p2tr_fee_bump(client: Client):
inp1 = messages.TxInputType(
# tb1p8tvmvsvhsee73rhym86wt435qrqm92psfsyhy6a3n5gw455znnpqm8wald
address_n=parse_path("86'/1'/0'/0/1"),
amount=13000,
address_n=parse_path("m/86h/1h/0h/0/1"),
amount=13_000,
orig_hash=TXHASH_8e4af7,
orig_index=0,
prev_hash=TXHASH_a4e274,
@ -217,8 +218,8 @@ def test_p2tr_fee_bump(client):
)
inp2 = messages.TxInputType(
# tb1pswrqtykue8r89t9u4rprjs0gt4qzkdfuursfnvqaa3f2yql07zmq8s8a5u
address_n=parse_path("86'/1'/0'/0/0"),
amount=6800,
address_n=parse_path("m/86h/1h/0h/0/0"),
amount=6_800,
orig_hash=TXHASH_8e4af7,
orig_index=1,
prev_hash=TXHASH_ccd7ea,
@ -227,15 +228,15 @@ def test_p2tr_fee_bump(client):
)
out1 = messages.TxOutputType(
address="tb1qq0rurzt04d76hk7pjxhqggk7ad4zj7c9u369kt",
amount=15000,
amount=15_000,
orig_hash=TXHASH_8e4af7,
orig_index=0,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
# tb1pn2d0yjeedavnkd8z8lhm566p0f2utm3lgvxrsdehnl94y34txmts5s7t4c
address_n=parse_path("86'/1'/0'/1/0"),
amount=4600 - 250, # bump the fee by 250
address_n=parse_path("m/86h/1h/0h/1/0"),
amount=4_600 - 250, # bump the fee by 250
orig_hash=TXHASH_8e4af7,
orig_index=1,
script_type=messages.OutputScriptType.PAYTOTAPROOT,
@ -273,23 +274,23 @@ def test_p2tr_fee_bump(client):
)
def test_p2wpkh_finalize(client):
def test_p2wpkh_finalize(client: Client):
# Original input with disabled RBF opt-in, i.e. we finalize the transaction.
inp1 = messages.TxInputType(
address_n=parse_path("84h/1h/0h/0/2"),
amount=20000000,
address_n=parse_path("m/84h/1h/0h/0/2"),
amount=20_000_000,
script_type=messages.InputScriptType.SPENDWITNESS,
prev_hash=TXHASH_43d273,
prev_index=1,
orig_hash=TXHASH_70f987,
orig_index=0,
sequence=4294967294,
sequence=4_294_967_294,
)
# Original external output (actually 84h/1h/0h/0/0).
out1 = messages.TxOutputType(
address="tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9",
amount=100000,
amount=100_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
orig_hash=TXHASH_70f987,
orig_index=0,
@ -297,8 +298,8 @@ def test_p2wpkh_finalize(client):
# Change output. We bump the fee from 141 to 200.
out2 = messages.TxOutputType(
address_n=parse_path("84h/1h/0h/1/1"),
amount=20000000 - 100000 - 200,
address_n=parse_path("m/84h/1h/0h/1/1"),
amount=20_000_000 - 100_000 - 200,
script_type=messages.OutputScriptType.PAYTOWITNESS,
orig_hash=TXHASH_70f987,
orig_index=1,
@ -334,7 +335,7 @@ def test_p2wpkh_finalize(client):
"Testnet",
[inp1],
[out1, out2],
lock_time=1348713,
lock_time=1_348_713,
prev_txes=TX_CACHE_TESTNET,
)
@ -395,19 +396,19 @@ def test_p2wpkh_payjoin(
):
# Original input.
inp1 = messages.TxInputType(
address_n=parse_path("84h/1h/0h/0/0"),
amount=100000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=100_000,
script_type=messages.InputScriptType.SPENDWITNESS,
prev_hash=TXHASH_e4b5b2,
prev_index=0,
orig_hash=TXHASH_65b768,
orig_index=0,
sequence=1516634,
sequence=1_516_634,
)
# New presigned external input. (Actually 84h/1h/0h/1/1, making it easier to generate witnesses.)
inp2 = messages.TxInputType(
amount=19899859,
amount=19_899_859,
script_type=messages.InputScriptType.EXTERNAL,
prev_hash=TXHASH_70f987,
prev_index=1,
@ -427,7 +428,7 @@ def test_p2wpkh_payjoin(
# Original change.
out2 = messages.TxOutputType(
address_n=parse_path("84h/1h/0h/1/2"),
address_n=parse_path("m/84h/1h/0h/1/2"),
amount=out2_amount,
script_type=messages.OutputScriptType.PAYTOWITNESS,
orig_hash=TXHASH_65b768,
@ -471,19 +472,19 @@ def test_p2wpkh_payjoin(
"Testnet",
[inp1, inp2],
[out1, out2],
lock_time=1516634,
lock_time=1_516_634,
prev_txes=TX_CACHE_TESTNET,
)
assert serialized_tx.hex() == expected_tx
def test_p2wpkh_in_p2sh_remove_change(client):
def test_p2wpkh_in_p2sh_remove_change(client: Client):
# Test fee bump with change-output removal. Originally fee was 3780, now 98060.
inp1 = messages.TxInputType(
address_n=parse_path("49h/1h/0h/0/4"),
amount=100000,
address_n=parse_path("m/49h/1h/0h/0/4"),
amount=100_000,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
prev_hash=TXHASH_5e7667,
prev_index=1,
@ -492,8 +493,8 @@ def test_p2wpkh_in_p2sh_remove_change(client):
)
inp2 = messages.TxInputType(
address_n=parse_path("49h/1h/0h/0/3"),
amount=998060,
address_n=parse_path("m/49h/1h/0h/0/3"),
amount=998_060,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
prev_hash=TXHASH_efaa41,
prev_index=0,
@ -504,7 +505,7 @@ def test_p2wpkh_in_p2sh_remove_change(client):
out1 = messages.TxOutputType(
# Actually m/49'/1'/0'/0/5.
address="2MvUUSiQZDSqyeSdofKX9KrSCio1nANPDTe",
amount=1000000,
amount=1_000_000,
orig_hash=TXHASH_334cd7,
orig_index=0,
)
@ -553,13 +554,13 @@ def test_p2wpkh_in_p2sh_remove_change(client):
)
def test_p2wpkh_in_p2sh_fee_bump_from_external(client):
def test_p2wpkh_in_p2sh_fee_bump_from_external(client: Client):
# Use the change output and an external output to bump the fee.
# Originally fee was 3780, now 108060 (94280 from change and 10000 from external).
inp1 = messages.TxInputType(
address_n=parse_path("49h/1h/0h/0/4"),
amount=100000,
address_n=parse_path("m/49h/1h/0h/0/4"),
amount=100_000,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
prev_hash=TXHASH_5e7667,
prev_index=1,
@ -568,8 +569,8 @@ def test_p2wpkh_in_p2sh_fee_bump_from_external(client):
)
inp2 = messages.TxInputType(
address_n=parse_path("49h/1h/0h/0/3"),
amount=998060,
address_n=parse_path("m/49h/1h/0h/0/3"),
amount=998_060,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
prev_hash=TXHASH_efaa41,
prev_index=0,
@ -580,7 +581,7 @@ def test_p2wpkh_in_p2sh_fee_bump_from_external(client):
out1 = messages.TxOutputType(
# Actually m/49'/1'/0'/0/5.
address="2MvUUSiQZDSqyeSdofKX9KrSCio1nANPDTe",
amount=990000,
amount=990_000,
orig_hash=TXHASH_334cd7,
orig_index=0,
)
@ -633,12 +634,12 @@ def test_p2wpkh_in_p2sh_fee_bump_from_external(client):
@pytest.mark.skip_t1
def test_tx_meld(client):
def test_tx_meld(client: Client):
# Meld two original transactions into one, joining the change-outputs into a different one.
inp1 = messages.TxInputType(
address_n=parse_path("49h/1h/0h/0/4"),
amount=100000,
address_n=parse_path("m/49h/1h/0h/0/4"),
amount=100_000,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
prev_hash=TXHASH_5e7667,
prev_index=1,
@ -647,8 +648,8 @@ def test_tx_meld(client):
)
inp2 = messages.TxInputType(
address_n=parse_path("49h/1h/0h/0/8"),
amount=4973340,
address_n=parse_path("m/49h/1h/0h/0/8"),
amount=4_973_340,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
prev_hash=TXHASH_6673b7,
prev_index=0,
@ -657,8 +658,8 @@ def test_tx_meld(client):
)
inp3 = messages.TxInputType(
address_n=parse_path("49h/1h/0h/0/3"),
amount=998060,
address_n=parse_path("m/49h/1h/0h/0/3"),
amount=998_060,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
prev_hash=TXHASH_efaa41,
prev_index=0,
@ -667,8 +668,8 @@ def test_tx_meld(client):
)
inp4 = messages.TxInputType(
address_n=parse_path("49h/1h/0h/0/9"),
amount=839318869,
address_n=parse_path("m/49h/1h/0h/0/9"),
amount=839_318_869,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
prev_hash=TXHASH_927784,
prev_index=0,
@ -678,7 +679,7 @@ def test_tx_meld(client):
out1 = messages.TxOutputType(
address="moE1dVYvebvtaMuNdXQKvu4UxUftLmS1Gt",
amount=100000000,
amount=100_000_000,
orig_hash=TXHASH_ed89ac,
orig_index=1,
)
@ -686,15 +687,21 @@ def test_tx_meld(client):
out2 = messages.TxOutputType(
# Actually m/49'/1'/0'/0/5.
address="2MvUUSiQZDSqyeSdofKX9KrSCio1nANPDTe",
amount=1000000,
amount=1_000_000,
orig_hash=TXHASH_334cd7,
orig_index=0,
)
# Change-output. Original fees were 3780 + 90720 = 94500.
out3 = messages.TxOutputType(
address_n=parse_path("49h/1h/0h/1/0"),
amount=100000 + 4973340 + 998060 + 839318869 - 100000000 - 1000000 - 94500,
address_n=parse_path("m/49h/1h/0h/1/0"),
amount=100_000
+ 4_973_340
+ 998_060
+ 839_318_869
- 100_000_000
- 1_000_000
- 94_500,
script_type=messages.OutputScriptType.PAYTOP2SHWITNESS,
)
@ -772,26 +779,26 @@ def test_tx_meld(client):
)
def test_attack_steal_change(client):
def test_attack_steal_change(client: Client):
# Attempt to steal amount equivalent to the change in the original transaction by
# hiding the fact that an output in the original transaction is a change-output.
# Original input.
inp1 = messages.TxInputType(
address_n=parse_path("84h/1h/0h/0/0"),
amount=100000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=100_000,
script_type=messages.InputScriptType.SPENDWITNESS,
prev_hash=TXHASH_e4b5b2,
prev_index=0,
orig_hash=TXHASH_65b768,
orig_index=0,
sequence=1516634,
sequence=1_516_634,
)
# New input for the attacker to steal from.
inp2 = messages.TxInputType(
address_n=parse_path("84h/1h/0h/1/1"),
amount=19899859,
address_n=parse_path("m/84h/1h/0h/1/1"),
amount=19_899_859,
script_type=messages.InputScriptType.SPENDWITNESS,
prev_hash=TXHASH_70f987,
prev_index=1,
@ -800,7 +807,7 @@ def test_attack_steal_change(client):
# Original output.
out1 = messages.TxOutputType(
address="tb1qldlynaqp0hy4zc2aag3pkenzvxy65saesxw3wd",
amount=10000,
amount=10_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
orig_hash=TXHASH_65b768,
orig_index=0,
@ -809,8 +816,8 @@ def test_attack_steal_change(client):
# Original change was 89859. We bump the fee from 141 to 200 and
# attacker gives back what he can't steal.
out2 = messages.TxOutputType(
address_n=parse_path("84h/1h/0h/1/2"),
amount=100000 - 10000 - 200 + (19899859 - 89859),
address_n=parse_path("m/84h/1h/0h/1/2"),
amount=100_000 - 10_000 - 200 + (19_899_859 - 89_859),
script_type=messages.OutputScriptType.PAYTOWITNESS,
orig_hash=TXHASH_65b768,
orig_index=1,
@ -819,7 +826,7 @@ def test_attack_steal_change(client):
# Attacker's new output.
out3 = messages.TxOutputType(
address="tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu",
amount=89859,
amount=89_859,
)
# Attacker hides the fact that second output of 65b768 is a change-output.
@ -837,21 +844,21 @@ def test_attack_steal_change(client):
"Testnet",
[inp1, inp2],
[out1, out2, out3],
lock_time=1516634,
lock_time=1_516_634,
prev_txes=prev_txes,
)
@pytest.mark.skip_t1
def test_attack_false_internal(client):
def test_attack_false_internal(client: Client):
# Falsely claim that an external input is internal in the original transaction.
# If this were possible, it would allow an attacker to make it look like the
# user was spending more in the original than they actually were, making it
# possible for the attacker to steal the difference.
inp1 = messages.TxInputType(
address_n=parse_path("49h/1h/0h/0/4"),
amount=100000,
address_n=parse_path("m/49h/1h/0h/0/4"),
amount=100_000,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
prev_hash=TXHASH_5e7667,
prev_index=1,
@ -862,7 +869,7 @@ def test_attack_false_internal(client):
inp2 = messages.TxInputType(
# Actually 49h/1h/0h/0/3, but we will make it look like it's external,
# while in the original it will show up as intenal.
amount=998060,
amount=998_060,
script_type=messages.InputScriptType.EXTERNAL,
prev_hash=TXHASH_efaa41,
prev_index=0,
@ -878,7 +885,7 @@ def test_attack_false_internal(client):
out1 = messages.TxOutputType(
# Actually m/49'/1'/0'/0/5.
address="2MvUUSiQZDSqyeSdofKX9KrSCio1nANPDTe",
amount=1000000 + 94280,
amount=1_000_000 + 94_280,
orig_hash=TXHASH_334cd7,
orig_index=0,
)
@ -895,15 +902,15 @@ def test_attack_false_internal(client):
)
def test_attack_fake_int_input_amount(client):
def test_attack_fake_int_input_amount(client: Client):
# Give a fake input amount for an original internal input while giving the correct
# amount for the replacement input. If an attacker could increase the amount of an
# internal input in the original transaction, then they could bump the fee of the
# transaction without the user noticing.
inp1 = messages.TxInputType(
address_n=parse_path("44h/0h/0h/0/4"),
amount=174998,
address_n=parse_path("m/44h/0h/0h/0/4"),
amount=174_998,
prev_hash=TXHASH_beafc7,
prev_index=0,
orig_hash=TXHASH_50f6f1,
@ -911,8 +918,8 @@ def test_attack_fake_int_input_amount(client):
)
out1 = messages.TxOutputType(
address_n=parse_path("44h/0h/0h/1/2"),
amount=174998
address_n=parse_path("m/44h/0h/0h/1/2"),
amount=174_998
- 50000
- 111300, # Original fee was 11300, attacker increases it by 100000.
script_type=messages.OutputScriptType.PAYTOADDRESS,
@ -922,7 +929,7 @@ def test_attack_fake_int_input_amount(client):
out2 = messages.TxOutputType(
address="1GA9u9TfCG7SWmKCveBumdA1TZpfom6ZdJ",
amount=50000,
amount=50_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
orig_hash=TXHASH_50f6f1,
orig_index=1,
@ -950,15 +957,15 @@ def test_attack_fake_int_input_amount(client):
@pytest.mark.skip_t1
def test_attack_fake_ext_input_amount(client):
def test_attack_fake_ext_input_amount(client: Client):
# Give a fake input amount for an original external input while giving the correct
# amount for the replacement input. If an attacker could decrease the amount of an
# external input in the original transaction, then they could steal the fee from
# the transaction without the user noticing.
inp1 = messages.TxInputType(
address_n=parse_path("49h/1h/0h/0/8"),
amount=4973340,
address_n=parse_path("m/49h/1h/0h/0/8"),
amount=4_973_340,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
prev_hash=TXHASH_6673b7,
prev_index=0,
@ -969,7 +976,7 @@ def test_attack_fake_ext_input_amount(client):
inp2 = messages.TxInputType(
# Actually 49h/1h/0h/0/9, but we will make it look like it's external,
# so that we can try out this scenario, i.e. not a part of the attack.
amount=839318869,
amount=839_318_869,
script_type=messages.InputScriptType.EXTERNAL,
prev_hash=TXHASH_927784,
prev_index=0,
@ -985,15 +992,15 @@ def test_attack_fake_ext_input_amount(client):
# Attacker adds 30000, but it could even go to a new output.
out1 = messages.TxOutputType(
address="moE1dVYvebvtaMuNdXQKvu4UxUftLmS1Gt",
amount=100000000 + 30000,
amount=100_000_000 + 30_000,
orig_hash=TXHASH_ed89ac,
orig_index=1,
)
# Change-output. Original fee was 90720, attacker steals 30000.
out2 = messages.TxOutputType(
address_n=parse_path("49h/1h/0h/1/6"),
amount=4973340 + 839318869 - (100000000 + 30000) - 60720,
address_n=parse_path("m/49h/1h/0h/1/6"),
amount=4_973_340 + 839_318_869 - (100_000_000 + 30_000) - 60_720,
script_type=messages.OutputScriptType.PAYTOP2SHWITNESS,
)
@ -1025,25 +1032,25 @@ def test_attack_fake_ext_input_amount(client):
)
def test_p2wpkh_invalid_signature(client):
def test_p2wpkh_invalid_signature(client: Client):
# Ensure that transaction replacement fails when the original signature is invalid.
# Original input with disabled RBF opt-in, i.e. we finalize the transaction.
inp1 = messages.TxInputType(
address_n=parse_path("84h/1h/0h/0/2"),
amount=20000000,
address_n=parse_path("m/84h/1h/0h/0/2"),
amount=20_000_000,
script_type=messages.InputScriptType.SPENDWITNESS,
prev_hash=TXHASH_43d273,
prev_index=1,
orig_hash=TXHASH_70f987,
orig_index=0,
sequence=4294967294,
sequence=4_294_967_294,
)
# Original external output (actually 84h/1h/0h/0/0).
out1 = messages.TxOutputType(
address="tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9",
amount=100000,
amount=100_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
orig_hash=TXHASH_70f987,
orig_index=0,
@ -1051,8 +1058,8 @@ def test_p2wpkh_invalid_signature(client):
# Change output. We bump the fee from 141 to 200.
out2 = messages.TxOutputType(
address_n=parse_path("84h/1h/0h/1/1"),
amount=20000000 - 100000 - 200,
address_n=parse_path("m/84h/1h/0h/1/1"),
amount=20_000_000 - 100_000 - 200,
script_type=messages.OutputScriptType.PAYTOWITNESS,
orig_hash=TXHASH_70f987,
orig_index=1,
@ -1073,18 +1080,18 @@ def test_p2wpkh_invalid_signature(client):
"Testnet",
[inp1],
[out1, out2],
lock_time=1348713,
lock_time=1_348_713,
prev_txes=prev_txes,
)
def test_p2tr_invalid_signature(client):
def test_p2tr_invalid_signature(client: Client):
# Ensure that transaction replacement fails when the original signature is invalid.
inp1 = messages.TxInputType(
# tb1p8tvmvsvhsee73rhym86wt435qrqm92psfsyhy6a3n5gw455znnpqm8wald
address_n=parse_path("86'/1'/0'/0/1"),
amount=13000,
address_n=parse_path("m/86h/1h/0h/0/1"),
amount=13_000,
orig_hash=TXHASH_8e4af7,
orig_index=0,
prev_hash=TXHASH_a4e274,
@ -1093,8 +1100,8 @@ def test_p2tr_invalid_signature(client):
)
inp2 = messages.TxInputType(
# tb1pswrqtykue8r89t9u4rprjs0gt4qzkdfuursfnvqaa3f2yql07zmq8s8a5u
address_n=parse_path("86'/1'/0'/0/0"),
amount=6800,
address_n=parse_path("m/86h/1h/0h/0/0"),
amount=6_800,
orig_hash=TXHASH_8e4af7,
orig_index=1,
prev_hash=TXHASH_ccd7ea,
@ -1103,15 +1110,15 @@ def test_p2tr_invalid_signature(client):
)
out1 = messages.TxOutputType(
address="tb1qq0rurzt04d76hk7pjxhqggk7ad4zj7c9u369kt",
amount=15000,
amount=15_000,
orig_hash=TXHASH_8e4af7,
orig_index=0,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
# tb1pn2d0yjeedavnkd8z8lhm566p0f2utm3lgvxrsdehnl94y34txmts5s7t4c
address_n=parse_path("86'/1'/0'/1/0"),
amount=4600 - 250, # bump the fee by 250
address_n=parse_path("m/86h/1h/0h/1/0"),
amount=4_600 - 250, # bump the fee by 250
orig_hash=TXHASH_8e4af7,
orig_index=1,
script_type=messages.OutputScriptType.PAYTOTAPROOT,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import H_, parse_path
@ -40,24 +41,24 @@ TXHASH_e5040e = bytes.fromhex(
)
def test_send_p2sh(client):
def test_send_p2sh(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"),
address_n=parse_path("m/49h/1h/0h/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=123456789,
amount=123_456_789,
prev_hash=TXHASH_20912f,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
out1 = messages.TxOutputType(
address="mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=123456789 - 11000 - 12300000,
amount=123_456_789 - 11_000 - 12_300_000,
)
with client:
client.set_expected_responses(
@ -90,24 +91,24 @@ def test_send_p2sh(client):
)
def test_send_p2sh_change(client):
def test_send_p2sh_change(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"),
address_n=parse_path("m/49h/1h/0h/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=123456789,
amount=123_456_789,
prev_hash=TXHASH_20912f,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
out1 = messages.TxOutputType(
address="mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("49'/1'/0'/1/0"),
address_n=parse_path("m/49h/1h/0h/1/0"),
script_type=messages.OutputScriptType.PAYTOP2SHWITNESS,
amount=123456789 - 11000 - 12300000,
amount=123_456_789 - 11_000 - 12_300_000,
)
with client:
client.set_expected_responses(
@ -139,18 +140,18 @@ def test_send_p2sh_change(client):
)
def test_testnet_segwit_big_amount(client):
def test_testnet_segwit_big_amount(client: Client):
# This test is testing transaction with amount bigger than fits to uint32
inp1 = messages.TxInputType(
address_n=parse_path("m/49'/1'/0'/0/0"),
address_n=parse_path("m/49h/1h/0h/0/0"),
amount=2 ** 32 + 1,
prev_hash=TXHASH_dee13c,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
out1 = messages.TxOutputType(
address="2Mt7P2BAfE922zmfXrdcYTLyR7GUvbwSEns", # seed allallall, bip32: m/49'/1'/0'/0/1, script type:p2shsegwit
address="2Mt7P2BAfE922zmfXrdcYTLyR7GUvbwSEns", # seed allallall, bip32: m/49h/1h/0h/0/1, script type:p2shsegwit
amount=2 ** 32 + 1,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -180,10 +181,10 @@ def test_testnet_segwit_big_amount(client):
@pytest.mark.multisig
def test_send_multisig_1(client):
def test_send_multisig_1(client: Client):
nodes = [
btc.get_public_node(
client, parse_path(f"49'/1'/{i}'"), coin_name="Testnet"
client, parse_path(f"m/49h/1h/{i}h"), coin_name="Testnet"
).node
for i in range(1, 4)
]
@ -193,17 +194,17 @@ def test_send_multisig_1(client):
)
inp1 = messages.TxInputType(
address_n=parse_path("49'/1'/1'/1/0"),
address_n=parse_path("m/49h/1h/1h/1/0"),
prev_hash=TXHASH_9c3192,
prev_index=1,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
multisig=multisig,
amount=1610436,
amount=1_610_436,
)
out1 = messages.TxOutputType(
address="mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC",
amount=1605000,
amount=1_605_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -257,24 +258,24 @@ def test_send_multisig_1(client):
)
def test_attack_change_input_address(client):
def test_attack_change_input_address(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"),
address_n=parse_path("m/49h/1h/0h/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=123456789,
amount=123_456_789,
prev_hash=TXHASH_20912f,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
out1 = messages.TxOutputType(
address="mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("49'/1'/12'/1/0"),
address_n=parse_path("m/49h/1h/12h/1/0"),
script_type=messages.OutputScriptType.PAYTOP2SHWITNESS,
amount=123456789 - 11000 - 12300000,
amount=123_456_789 - 11_000 - 12_300_000,
)
# Test if the transaction can be signed normally
@ -344,20 +345,20 @@ def test_attack_change_input_address(client):
assert exc.value.message.endswith("Transaction has changed during signing")
def test_attack_mixed_inputs(client):
def test_attack_mixed_inputs(client: Client):
TRUE_AMOUNT = 123456789
FAKE_AMOUNT = 120000000
inp1 = messages.TxInputType(
address_n=parse_path("44'/1'/0'/0/0"),
amount=31000000,
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=31_000_000,
prev_hash=TXHASH_e5040e,
prev_index=0,
script_type=messages.InputScriptType.SPENDADDRESS,
sequence=0xFFFFFFFD,
)
inp2 = messages.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"),
address_n=parse_path("m/49h/1h/0h/1/0"),
amount=TRUE_AMOUNT,
prev_hash=TXHASH_20912f,
prev_index=0,
@ -366,7 +367,7 @@ def test_attack_mixed_inputs(client):
)
out1 = messages.TxOutputType(
address="mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC",
amount=31000000 + TRUE_AMOUNT - 3456789,
amount=31_000_000 + TRUE_AMOUNT - 3_456_789,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import H_, parse_path
from ...bip32 import deserialize
@ -58,24 +59,24 @@ TXHASH_ec16dc = bytes.fromhex(
)
def test_send_p2sh(client):
def test_send_p2sh(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"),
address_n=parse_path("m/49h/1h/0h/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=123456789,
amount=123_456_789,
prev_hash=TXHASH_20912f,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
out1 = messages.TxOutputType(
address="tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=123456789 - 11000 - 12300000,
amount=123_456_789 - 11_000 - 12_300_000,
)
with client:
client.set_expected_responses(
@ -108,24 +109,24 @@ def test_send_p2sh(client):
)
def test_send_p2sh_change(client):
def test_send_p2sh_change(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"),
address_n=parse_path("m/49h/1h/0h/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=123456789,
amount=123_456_789,
prev_hash=TXHASH_20912f,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
out1 = messages.TxOutputType(
address="tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("49'/1'/0'/1/0"),
address_n=parse_path("m/49h/1h/0h/1/0"),
script_type=messages.OutputScriptType.PAYTOP2SHWITNESS,
amount=123456789 - 11000 - 12300000,
amount=123_456_789 - 11_000 - 12_300_000,
)
with client:
client.set_expected_responses(
@ -157,23 +158,23 @@ def test_send_p2sh_change(client):
)
def test_send_native(client):
def test_send_native(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=12_300_000,
prev_hash=TXHASH_091446,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
)
out1 = messages.TxOutputType(
address="2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp",
amount=5000000,
amount=5_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=12300000 - 11000 - 5000000,
amount=12_300_000 - 11_000 - 5_000_000,
)
with client:
client.set_expected_responses(
@ -206,23 +207,23 @@ def test_send_native(client):
)
def test_send_to_taproot(client):
def test_send_to_taproot(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
amount=10000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=10_000,
prev_hash=TXHASH_ec16dc,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
)
out1 = messages.TxOutputType(
address="tb1pdvdljpj774356dpk32c2ks0yqv7q7c4f98px2d9e76s73vpudpxs7tl6vp",
amount=7000,
amount=7_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address="tb1qcc4ext5rsa8pzqa2m030jk670wmn5f649pu7sr",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=10000 - 7000 - 200,
amount=10_000 - 7_000 - 200,
)
with client:
_, serialized_tx = btc.sign_tx(
@ -235,23 +236,23 @@ def test_send_to_taproot(client):
)
def test_send_native_change(client):
def test_send_native_change(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=12_300_000,
prev_hash=TXHASH_091446,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
)
out1 = messages.TxOutputType(
address="2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp",
amount=5000000,
amount=5_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("84'/1'/0'/1/0"),
address_n=parse_path("m/84h/1h/0h/1/0"),
script_type=messages.OutputScriptType.PAYTOWITNESS,
amount=12300000 - 11000 - 5000000,
amount=12_300_000 - 11_000 - 5_000_000,
)
with client:
client.set_expected_responses(
@ -283,25 +284,25 @@ def test_send_native_change(client):
)
def test_send_both(client):
def test_send_both(client: Client):
inp1 = messages.TxInputType(
address_n=parse_path("49'/1'/0'/1/0"),
address_n=parse_path("m/49h/1h/0h/1/0"),
# 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
amount=111145789,
amount=111_145_789,
prev_hash=TXHASH_091446,
prev_index=1,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
inp2 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=7_289_000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS,
)
out1 = messages.TxOutputType(
address="tb1q54un3q39sf7e7tlfq99d6ezys7qgc62a6rxllc",
amount=12300000,
amount=12_300_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
@ -309,11 +310,11 @@ def test_send_both(client):
# script_type=messages.OutputScriptType.PAYTOP2SHWITNESS,
address="2N6UeBoqYEEnybg4cReFYDammpsyDw8R2Mc",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=45600000,
amount=45_600_000,
)
out3 = messages.TxOutputType(
address="mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q",
amount=111145789 + 7289000 - 11000 - 12300000 - 45600000,
amount=111_145_789 + 7_289_000 - 11_000 - 12_300_000 - 45_600_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -360,9 +361,11 @@ def test_send_both(client):
@pytest.mark.multisig
def test_send_multisig_1(client):
def test_send_multisig_1(client: Client):
nodes = [
btc.get_public_node(client, parse_path(f"49'/1'/{index}'"), coin_name="Testnet")
btc.get_public_node(
client, parse_path(f"m/49h/1h/{index}h"), coin_name="Testnet"
)
for index in range(1, 4)
]
multisig = messages.MultisigRedeemScriptType(
@ -373,17 +376,17 @@ def test_send_multisig_1(client):
)
inp1 = messages.TxInputType(
address_n=parse_path("49'/1'/1'/0/0"),
address_n=parse_path("m/49h/1h/1h/0/0"),
prev_hash=TXHASH_9c3192,
prev_index=1,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
multisig=multisig,
amount=1610436,
amount=1_610_436,
)
out1 = messages.TxOutputType(
address="tb1qch62pf820spe9mlq49ns5uexfnl6jzcezp7d328fw58lj0rhlhasge9hzy",
amount=1605000,
amount=1_605_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -438,9 +441,11 @@ def test_send_multisig_1(client):
@pytest.mark.multisig
def test_send_multisig_2(client):
def test_send_multisig_2(client: Client):
nodes = [
btc.get_public_node(client, parse_path(f"84'/1'/{index}'"), coin_name="Testnet")
btc.get_public_node(
client, parse_path(f"m/84h/1h/{index}h"), coin_name="Testnet"
)
for index in range(1, 4)
]
multisig = messages.MultisigRedeemScriptType(
@ -451,17 +456,17 @@ def test_send_multisig_2(client):
)
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/2'/0/1"),
address_n=parse_path("m/84h/1h/2h/0/1"),
prev_hash=TXHASH_f41cbe,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
multisig=multisig,
amount=1605000,
amount=1_605_000,
)
out1 = messages.TxOutputType(
address="tb1qr6xa5v60zyt3ry9nmfew2fk5g9y3gerkjeu6xxdz7qga5kknz2ssld9z2z",
amount=1604000,
amount=1_604_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -514,9 +519,11 @@ def test_send_multisig_2(client):
@pytest.mark.multisig
def test_send_multisig_3_change(client):
def test_send_multisig_3_change(client: Client):
nodes = [
btc.get_public_node(client, parse_path(f"84'/1'/{index}'"), coin_name="Testnet")
btc.get_public_node(
client, parse_path(f"m/84h/1h/{index}h"), coin_name="Testnet"
)
for index in range(1, 4)
]
multisig = messages.MultisigRedeemScriptType(
@ -533,17 +540,17 @@ def test_send_multisig_3_change(client):
)
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/1'/1/0"),
address_n=parse_path("m/84h/1h/1h/1/0"),
prev_hash=TXHASH_c93480,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
multisig=multisig,
amount=1604000,
amount=1_604_000,
)
out1 = messages.TxOutputType(
address_n=parse_path("84'/1'/1'/1/1"),
amount=1603000,
address_n=parse_path("m/84h/1h/1h/1/1"),
amount=1_603_000,
multisig=multisig2,
script_type=messages.OutputScriptType.PAYTOP2SHWITNESS,
)
@ -596,9 +603,11 @@ def test_send_multisig_3_change(client):
@pytest.mark.multisig
def test_send_multisig_4_change(client):
def test_send_multisig_4_change(client: Client):
nodes = [
btc.get_public_node(client, parse_path(f"49'/1'/{index}'"), coin_name="Testnet")
btc.get_public_node(
client, parse_path(f"m/49h/1h/{index}h"), coin_name="Testnet"
)
for index in range(1, 4)
]
multisig = messages.MultisigRedeemScriptType(
@ -615,17 +624,17 @@ def test_send_multisig_4_change(client):
)
inp1 = messages.TxInputType(
address_n=parse_path("49'/1'/1'/1/1"),
address_n=parse_path("m/49h/1h/1h/1/1"),
prev_hash=TXHASH_31bc1c,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
multisig=multisig,
amount=1603000,
amount=1_603_000,
)
out1 = messages.TxOutputType(
address_n=parse_path("49'/1'/1'/1/2"),
amount=1602000,
address_n=parse_path("m/49h/1h/1h/1/2"),
amount=1_602_000,
multisig=multisig2,
script_type=messages.OutputScriptType.PAYTOWITNESS,
)
@ -679,7 +688,7 @@ def test_send_multisig_4_change(client):
# Ensure that if there is a non-multisig input, then a multisig output
# will not be identified as a change output.
def test_multisig_mismatch_inputs_single(client):
def test_multisig_mismatch_inputs_single(client: Client):
# m/84'/1'/0' for "alcohol woman abuse ..." seed.
node_int = deserialize(
"Vpub5kFDCYhiYuAzjk7TBQPNFffbexHF7iAd8AVVgHQKUany7e6NQvthgk86d7DfH57DY2dwBK4PyVTDDaS1r2gjkdyJyUYGoV9qNujGSrW9Dpe"
@ -700,15 +709,15 @@ def test_multisig_mismatch_inputs_single(client):
)
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
amount=12300000,
address_n=parse_path("m/84h/1h/0h/0/0"),
amount=12_300_000,
prev_hash=TXHASH_091446,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
)
inp2 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/0/0"),
address_n=parse_path("m/84h/1h/0h/0/0"),
prev_hash=TXHASH_a345b8,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -718,15 +727,15 @@ def test_multisig_mismatch_inputs_single(client):
out1 = messages.TxOutputType(
address="2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp",
amount=5000000,
amount=5_000_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
address_n=parse_path("84'/1'/0'/1/0"),
address_n=parse_path("m/84h/1h/0h/1/0"),
script_type=messages.OutputScriptType.PAYTOWITNESS,
multisig=multisig_out,
amount=12300000 + 100 - 5000000 - 10000,
amount=12_300_000 + 100 - 5_000_000 - 10_000,
)
with client:

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import H_, parse_path
@ -49,11 +50,11 @@ TXHASH_65b811 = bytes.fromhex(
)
def test_send_p2tr(client):
def test_send_p2tr(client: Client):
inp1 = messages.TxInputType(
# tb1pn2d0yjeedavnkd8z8lhm566p0f2utm3lgvxrsdehnl94y34txmts5s7t4c
address_n=parse_path("86'/1'/0'/1/0"),
amount=4600,
address_n=parse_path("m/86h/1h/0h/1/0"),
amount=4_600,
prev_hash=TXHASH_7956f1,
prev_index=1,
script_type=messages.InputScriptType.SPENDTAPROOT,
@ -61,7 +62,7 @@ def test_send_p2tr(client):
out1 = messages.TxOutputType(
# 86'/1'/1'/0/0
address="tb1paxhjl357yzctuf3fe58fcdx6nul026hhh6kyldpfsf3tckj9a3wslqd7zd",
amount=4450,
amount=4_450,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
with client:
@ -87,19 +88,19 @@ def test_send_p2tr(client):
)
def test_send_two_with_change(client):
def test_send_two_with_change(client: Client):
inp1 = messages.TxInputType(
# tb1pswrqtykue8r89t9u4rprjs0gt4qzkdfuursfnvqaa3f2yql07zmq8s8a5u
address_n=parse_path("86'/1'/0'/0/0"),
amount=6800,
address_n=parse_path("m/86h/1h/0h/0/0"),
amount=6_800,
prev_hash=TXHASH_df862e,
prev_index=0,
script_type=messages.InputScriptType.SPENDTAPROOT,
)
inp2 = messages.TxInputType(
# tb1p8tvmvsvhsee73rhym86wt435qrqm92psfsyhy6a3n5gw455znnpqm8wald
address_n=parse_path("86'/1'/0'/0/1"),
amount=13000,
address_n=parse_path("m/86h/1h/0h/0/1"),
amount=13_000,
prev_hash=TXHASH_3ac32e,
prev_index=1,
script_type=messages.InputScriptType.SPENDTAPROOT,
@ -107,14 +108,14 @@ def test_send_two_with_change(client):
out1 = messages.TxOutputType(
# 84'/1'/1'/0/0
address="tb1q7r9yvcdgcl6wmtta58yxf29a8kc96jkyxl7y88",
amount=15000,
amount=15_000,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
out2 = messages.TxOutputType(
# tb1pn2d0yjeedavnkd8z8lhm566p0f2utm3lgvxrsdehnl94y34txmts5s7t4c
address_n=parse_path("86'/1'/0'/1/0"),
address_n=parse_path("m/86h/1h/0h/1/0"),
script_type=messages.OutputScriptType.PAYTOTAPROOT,
amount=6800 + 13000 - 200 - 15000,
amount=6_800 + 13_000 - 200 - 15_000,
)
with client:
client.set_expected_responses(
@ -144,52 +145,52 @@ def test_send_two_with_change(client):
)
def test_send_mixed(client):
def test_send_mixed(client: Client):
inp1 = messages.TxInputType(
# 2MutHjgAXkqo3jxX2DZWorLAckAnwTxSM9V
address_n=parse_path("49'/1'/1'/0/0"),
amount=20000,
address_n=parse_path("m/49h/1h/1h/0/0"),
amount=20_000,
prev_hash=TXHASH_8c3ea7,
prev_index=0,
script_type=messages.InputScriptType.SPENDP2SHWITNESS,
)
inp2 = messages.TxInputType(
# tb1q7r9yvcdgcl6wmtta58yxf29a8kc96jkyxl7y88
address_n=parse_path("84'/1'/1'/0/0"),
amount=15000,
address_n=parse_path("m/84h/1h/1h/0/0"),
amount=15_000,
prev_hash=TXHASH_7956f1,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
)
inp3 = messages.TxInputType(
# tb1paxhjl357yzctuf3fe58fcdx6nul026hhh6kyldpfsf3tckj9a3wslqd7zd
address_n=parse_path("86'/1'/1'/0/0"),
amount=4450,
address_n=parse_path("m/86h/1h/1h/0/0"),
amount=4_450,
prev_hash=TXHASH_901593,
prev_index=0,
script_type=messages.InputScriptType.SPENDTAPROOT,
)
inp4 = messages.TxInputType(
# msUqRgCWS7ryuFcF34EaKTrsTe3xHra128
address_n=parse_path("44'/1'/1'/0/0"),
amount=10000,
address_n=parse_path("m/44h/1h/1h/0/0"),
amount=10_000,
prev_hash=TXHASH_3ac32e,
prev_index=2,
script_type=messages.InputScriptType.SPENDADDRESS,
)
out1 = messages.TxOutputType(
address="tb1q6xnnna3g7lk22h5tn8nlx2ezmndlvuk556w4w3",
amount=25000,
amount=25_000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
)
out2 = messages.TxOutputType(
address="mfnMbVFC1rH4p9GNbjkMfrAjyKRLycFAzA",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=7000,
amount=7_000,
)
out3 = messages.TxOutputType(
address="2MvAG8m2xSf83FgeR4ZpUtaubpLNjAMMoka",
amount=6900,
amount=6_900,
script_type=messages.OutputScriptType.PAYTOP2SHWITNESS,
)
out4 = messages.TxOutputType(
@ -199,7 +200,7 @@ def test_send_mixed(client):
)
out5 = messages.TxOutputType(
address="tb1ptgp9w0mm89ms43flw0gkrhyx75gyc6qjhtpf0jmt5sv0dufpnsrsyv9nsz",
amount=10000,
amount=10_000,
script_type=messages.OutputScriptType.PAYTOTAPROOT,
)
@ -287,7 +288,7 @@ def test_send_mixed(client):
)
def test_attack_script_type(client):
def test_attack_script_type(client: Client):
# Scenario: The attacker falsely claims that the transaction is Taproot-only to
# avoid prev tx streaming and gives a lower amount for one of the inputs. The
# correct input types and amounts are revelaled only in step6_sign_segwit_inputs()
@ -295,15 +296,15 @@ def test_attack_script_type(client):
# larger than what the user confirmed.
inp1 = messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000,
address_n=parse_path("m/84h/1h/0h/1/0"),
amount=7_289_000,
prev_hash=TXHASH_65b811,
prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS,
)
inp2 = messages.TxInputType(
address_n=parse_path("84'/1'/1'/0/0"),
amount=12300000,
address_n=parse_path("m/84h/1h/1h/0/0"),
amount=12_300_000,
prev_hash=TXHASH_091446,
prev_index=0,
script_type=messages.InputScriptType.SPENDWITNESS,
@ -312,7 +313,7 @@ def test_attack_script_type(client):
out1 = messages.TxOutputType(
address="tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu",
script_type=messages.OutputScriptType.PAYTOADDRESS,
amount=7289000 + 10000 - 1000,
amount=7_289_000 + 10_000 - 1_000,
)
attack_count = 5

View File

@ -19,9 +19,10 @@ import base64
import pytest
from trezorlib import btc
from trezorlib.debuglink import TrezorClientDebugLink as Client
def test_message_long(client):
def test_message_long(client: Client):
ret = btc.verify_message(
client,
"Bitcoin",
@ -34,7 +35,7 @@ def test_message_long(client):
assert ret is True
def test_message_testnet(client):
def test_message_testnet(client: Client):
ret = btc.verify_message(
client,
"Testnet",
@ -48,7 +49,7 @@ def test_message_testnet(client):
@pytest.mark.altcoin
def test_message_grs(client):
def test_message_grs(client: Client):
ret = btc.verify_message(
client,
"Groestlcoin",
@ -61,7 +62,7 @@ def test_message_grs(client):
assert ret is True
def test_message_verify(client):
def test_message_verify(client: Client):
res = btc.verify_message(
client,
"Bitcoin",
@ -171,7 +172,7 @@ def test_message_verify(client):
@pytest.mark.altcoin
def test_message_verify_bcash(client):
def test_message_verify_bcash(client: Client):
res = btc.verify_message(
client,
"Bcash",
@ -184,7 +185,7 @@ def test_message_verify_bcash(client):
assert res is True
def test_verify_bitcoind(client):
def test_verify_bitcoind(client: Client):
res = btc.verify_message(
client,
"Bitcoin",
@ -198,7 +199,7 @@ def test_verify_bitcoind(client):
assert res is True
def test_verify_utf(client):
def test_verify_utf(client: Client):
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"

View File

@ -15,9 +15,10 @@
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from trezorlib import btc
from trezorlib.debuglink import TrezorClientDebugLink as Client
def test_message_long(client):
def test_message_long(client: Client):
ret = btc.verify_message(
client,
"Bitcoin",
@ -30,7 +31,7 @@ def test_message_long(client):
assert ret is True
def test_message_testnet(client):
def test_message_testnet(client: Client):
ret = btc.verify_message(
client,
"Testnet",
@ -43,7 +44,7 @@ def test_message_testnet(client):
assert ret is True
def test_message_verify(client):
def test_message_verify(client: Client):
res = btc.verify_message(
client,
"Bitcoin",
@ -80,7 +81,7 @@ def test_message_verify(client):
assert res is False
def test_verify_utf(client):
def test_verify_utf(client: Client):
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"

View File

@ -15,9 +15,10 @@
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from trezorlib import btc
from trezorlib.debuglink import TrezorClientDebugLink as Client
def test_message_long(client):
def test_message_long(client: Client):
ret = btc.verify_message(
client,
"Bitcoin",
@ -30,7 +31,7 @@ def test_message_long(client):
assert ret is True
def test_message_testnet(client):
def test_message_testnet(client: Client):
ret = btc.verify_message(
client,
"Testnet",
@ -43,7 +44,7 @@ def test_message_testnet(client):
assert ret is True
def test_message_verify(client):
def test_message_verify(client: Client):
res = btc.verify_message(
client,
"Bitcoin",
@ -80,7 +81,7 @@ def test_message_verify(client):
assert res is False
def test_verify_utf(client):
def test_verify_utf(client: Client):
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
@ -55,21 +56,21 @@ TXHASH_v4 = bytes.fromhex(
pytestmark = [pytest.mark.altcoin, pytest.mark.zcash]
def test_v3_not_supported(client):
def test_v3_not_supported(client: Client):
# prevout: aaf51e4606c264e47e5c42c958fe4cf1539c5172684721e38e69f4ef634d75dc:1
# input 1: 3.0 TAZ
inp1 = messages.TxInputType(
# tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=300000000,
amount=300_000_000,
prev_hash=TXHASH_aaf51e,
prev_index=1,
)
out1 = messages.TxOutputType(
address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z",
amount=300000000 - 1940,
amount=300_000_000 - 1_940,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -86,21 +87,21 @@ def test_v3_not_supported(client):
)
def test_one_one_fee_sapling(client):
def test_one_one_fee_sapling(client: Client):
# prevout: e3820602226974b1dd87b7113cc8aea8c63e5ae29293991e7bfa80c126930368:0
# input 1: 3.0 TAZ
inp1 = messages.TxInputType(
# tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=300000000,
amount=300_000_000,
prev_hash=TXHASH_e38206,
prev_index=0,
)
out1 = messages.TxOutputType(
address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z",
amount=300000000 - 1940,
amount=300_000_000 - 1_940,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -142,17 +143,17 @@ def test_one_one_fee_sapling(client):
)
def test_version_group_id_missing(client):
def test_version_group_id_missing(client: Client):
inp1 = messages.TxInputType(
# tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=300000000,
amount=300_000_000,
prev_hash=TXHASH_e38206,
prev_index=0,
)
out1 = messages.TxOutputType(
address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z",
amount=300000000 - 1940,
amount=300_000_000 - 1_940,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)
@ -167,29 +168,29 @@ def test_version_group_id_missing(client):
)
def test_spend_old_versions(client):
def test_spend_old_versions(client: Client):
# inputs are NOT OWNED by this seed
input_v1 = messages.TxInputType(
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=123000000,
amount=123_000_000,
prev_hash=TXHASH_v1,
prev_index=0,
)
input_v2 = messages.TxInputType(
address_n=parse_path("m/44h/1h/0h/0/1"),
amount=49990000,
amount=49_990_000,
prev_hash=TXHASH_v2,
prev_index=0,
)
input_v3 = messages.TxInputType(
address_n=parse_path("m/44h/1h/0h/0/2"),
amount=300000000,
amount=300_000_000,
prev_hash=TXHASH_v3,
prev_index=1,
)
input_v4 = messages.TxInputType(
address_n=parse_path("m/44h/1h/0h/0/3"),
amount=100000,
amount=100_000,
prev_hash=TXHASH_v4,
prev_index=0,
)
@ -225,11 +226,11 @@ def test_spend_old_versions(client):
@pytest.mark.skip_t1
def test_external_presigned(client):
def test_external_presigned(client: Client):
inp1 = messages.TxInputType(
# tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
address_n=parse_path("m/44h/1h/0h/0/0"),
amount=300000000,
amount=300_000_000,
prev_hash=TXHASH_e38206,
prev_index=0,
)
@ -237,7 +238,7 @@ def test_external_presigned(client):
inp2 = messages.TxInputType(
# tmQoJ3PTXgQLaRRZZYT6xk8XtjRbr2kCqwu
# address_n=parse_path("m/44h/1h/0h/0/0"),
amount=300000000,
amount=300_000_000,
prev_hash=TXHASH_aaf51e,
prev_index=1,
script_type=messages.InputScriptType.EXTERNAL,
@ -251,7 +252,7 @@ def test_external_presigned(client):
out1 = messages.TxOutputType(
address="tmJ1xYxP8XNTtCoDgvdmQPSrxh5qZJgy65Z",
amount=300000000 + 300000000 - 1940,
amount=300_000_000 + 300_000_000 - 1_940,
script_type=messages.OutputScriptType.PAYTOADDRESS,
)

View File

@ -22,6 +22,7 @@ from trezorlib.cardano import (
get_public_key,
parse_optional_bytes,
)
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.messages import CardanoAddressType, CardanoDerivationType
from trezorlib.tools import parse_path
@ -45,7 +46,7 @@ pytestmark = [
"cardano/get_reward_address.json",
"cardano/get_base_address.derivations.json",
)
def test_cardano_get_address(client, parameters, result):
def test_cardano_get_address(client: Client, parameters, result):
client.init_device(new_session=True, derive_cardano=True)
derivation_type = CardanoDerivationType.__members__[
@ -88,7 +89,7 @@ def test_cardano_get_address(client, parameters, result):
"cardano/get_public_key.slip39.json",
"cardano/get_public_key.derivations.json",
)
def test_cardano_get_public_key(client, parameters, result):
def test_cardano_get_public_key(client: Client, parameters, result):
client.init_device(new_session=True, derive_cardano=True)
derivation_type = CardanoDerivationType.__members__[

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib.cardano import get_public_key
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.messages import CardanoDerivationType as D
from trezorlib.tools import parse_path
@ -29,10 +30,10 @@ pytestmark = [
pytest.mark.skip_t1,
]
ADDRESS_N = parse_path("m/1852'/1815'/0'")
ADDRESS_N = parse_path("m/1852h/1815h/0h")
def test_bad_session(client):
def test_bad_session(client: Client):
client.init_device(new_session=True)
with pytest.raises(TrezorFailure, match="not enabled"):
get_public_key(client, ADDRESS_N, derivation_type=D.ICARUS)
@ -42,7 +43,7 @@ def test_bad_session(client):
get_public_key(client, ADDRESS_N, derivation_type=D.ICARUS)
def test_ledger_available_always(client):
def test_ledger_available_always(client: Client):
client.init_device(new_session=True, derive_cardano=False)
get_public_key(client, ADDRESS_N, derivation_type=D.LEDGER)
@ -52,7 +53,7 @@ def test_ledger_available_always(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6)
@pytest.mark.parametrize("derivation_type", D) # try ALL derivation types
def test_derivation_irrelevant_on_slip39(client, derivation_type):
def test_derivation_irrelevant_on_slip39(client: Client, derivation_type):
client.init_device(new_session=True, derive_cardano=False)
pubkey = get_public_key(client, ADDRESS_N, derivation_type=D.ICARUS)
test_pubkey = get_public_key(client, ADDRESS_N, derivation_type=derivation_type)

View File

@ -18,6 +18,7 @@ import pytest
from trezorlib import messages
from trezorlib.cardano import get_native_script_hash, parse_native_script
from trezorlib.debuglink import TrezorClientDebugLink as Client
from ...common import parametrize_using_common_fixtures
@ -31,7 +32,7 @@ pytestmark = [
@parametrize_using_common_fixtures(
"cardano/get_native_script_hash.json",
)
def test_cardano_get_native_script_hash(client, parameters, result):
def test_cardano_get_native_script_hash(client: Client, parameters, result):
client.init_device(new_session=True, derive_cardano=True)
native_script_hash = get_native_script_hash(

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import cardano, device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from ...common import parametrize_using_common_fixtures
@ -34,7 +35,7 @@ pytestmark = [
"cardano/sign_tx.multisig.json",
"cardano/sign_tx.slip39.json",
)
def test_cardano_sign_tx(client, parameters, result):
def test_cardano_sign_tx(client: Client, parameters, result):
client.init_device(new_session=True, derive_cardano=True)
signing_mode = messages.CardanoTxSigningMode.__members__[parameters["signing_mode"]]
@ -81,7 +82,7 @@ def test_cardano_sign_tx(client, parameters, result):
"cardano/sign_tx.multisig.failed.json",
"cardano/sign_tx_stake_pool_registration.failed.json",
)
def test_cardano_sign_tx_failed(client, parameters, result):
def test_cardano_sign_tx_failed(client: Client, parameters, result):
client.init_device(new_session=True, derive_cardano=True)
signing_mode = messages.CardanoTxSigningMode.__members__[parameters["signing_mode"]]

View File

@ -16,6 +16,7 @@
import pytest
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.eos import get_public_key
from trezorlib.tools import parse_path
@ -26,9 +27,9 @@ from ...common import MNEMONIC12
@pytest.mark.eos
@pytest.mark.skip_t1
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_eos_get_public_key(client):
def test_eos_get_public_key(client: Client):
public_key = get_public_key(
client, parse_path("m/44'/194'/0'/0/0"), show_display=True
client, parse_path("m/44h/194h/0h/0/0"), show_display=True
)
assert (
public_key.wif_public_key
@ -38,7 +39,7 @@ def test_eos_get_public_key(client):
public_key.raw_public_key.hex()
== "02015fabe197c955036bab25f4e7c16558f9f672f9f625314ab1ec8f64f7b1198e"
)
public_key = get_public_key(client, parse_path("m/44'/194'/0'/0/1"))
public_key = get_public_key(client, parse_path("m/44h/194h/0h/0/1"))
assert (
public_key.wif_public_key
== "EOS5d1VP15RKxT4dSakWu2TFuEgnmaGC2ckfSvQwND7pZC1tXkfLP"
@ -47,7 +48,7 @@ def test_eos_get_public_key(client):
public_key.raw_public_key.hex()
== "02608bc2c431521dee0b9d5f2fe34053e15fc3b20d2895e0abda857b9ed8e77a78"
)
public_key = get_public_key(client, parse_path("m/44'/194'/1'/0/0"))
public_key = get_public_key(client, parse_path("m/44h/194h/1h/0/0"))
assert (
public_key.wif_public_key
== "EOS7UuNeTf13nfcG85rDB7AHGugZi4C4wJ4ft12QRotqNfxdV2NvP"

View File

@ -17,13 +17,14 @@
import pytest
from trezorlib import eos
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.messages import EosSignedTx
from trezorlib.tools import parse_path
from ...common import MNEMONIC12
CHAIN_ID = "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f"
ADDRESS_N = parse_path("m/44'/194'/0'/0/0")
ADDRESS_N = parse_path("m/44h/194h/0h/0/0")
pytestmark = [
pytest.mark.altcoin,
@ -33,7 +34,7 @@ pytestmark = [
]
def test_eos_signtx_transfer_token(client):
def test_eos_signtx_transfer_token(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -67,7 +68,7 @@ def test_eos_signtx_transfer_token(client):
)
def test_eos_signtx_buyram(client):
def test_eos_signtx_buyram(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -100,7 +101,7 @@ def test_eos_signtx_buyram(client):
)
def test_eos_signtx_buyrambytes(client):
def test_eos_signtx_buyrambytes(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -133,7 +134,7 @@ def test_eos_signtx_buyrambytes(client):
)
def test_eos_signtx_sellram(client):
def test_eos_signtx_sellram(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -162,7 +163,7 @@ def test_eos_signtx_sellram(client):
)
def test_eos_signtx_delegate(client):
def test_eos_signtx_delegate(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -197,7 +198,7 @@ def test_eos_signtx_delegate(client):
)
def test_eos_signtx_undelegate(client):
def test_eos_signtx_undelegate(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -231,7 +232,7 @@ def test_eos_signtx_undelegate(client):
)
def test_eos_signtx_refund(client):
def test_eos_signtx_refund(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -260,7 +261,7 @@ def test_eos_signtx_refund(client):
)
def test_eos_signtx_linkauth(client):
def test_eos_signtx_linkauth(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -294,7 +295,7 @@ def test_eos_signtx_linkauth(client):
)
def test_eos_signtx_unlinkauth(client):
def test_eos_signtx_unlinkauth(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -327,7 +328,7 @@ def test_eos_signtx_unlinkauth(client):
)
def test_eos_signtx_updateauth(client):
def test_eos_signtx_updateauth(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -383,7 +384,7 @@ def test_eos_signtx_updateauth(client):
)
def test_eos_signtx_deleteauth(client):
def test_eos_signtx_deleteauth(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -412,7 +413,7 @@ def test_eos_signtx_deleteauth(client):
)
def test_eos_signtx_vote(client):
def test_eos_signtx_vote(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -475,7 +476,7 @@ def test_eos_signtx_vote(client):
)
def test_eos_signtx_vote_proxy(client):
def test_eos_signtx_vote_proxy(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -504,7 +505,7 @@ def test_eos_signtx_vote_proxy(client):
)
def test_eos_signtx_unknown(client):
def test_eos_signtx_unknown(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -533,7 +534,7 @@ def test_eos_signtx_unknown(client):
)
def test_eos_signtx_newaccount(client):
def test_eos_signtx_newaccount(client: Client):
transaction = {
"expiration": "2018-07-14T10:43:28",
"ref_block_num": 6439,
@ -609,7 +610,7 @@ def test_eos_signtx_newaccount(client):
)
def test_eos_signtx_setcontract(client):
def test_eos_signtx_setcontract(client: Client):
transaction = {
"expiration": "2018-06-19T13:29:53",
"ref_block_num": 30587,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import ethereum
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import parametrize_using_common_fixtures
@ -25,6 +26,6 @@ pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
@parametrize_using_common_fixtures("ethereum/getaddress.json")
def test_getaddress(client, parameters, result):
def test_getaddress(client: Client, parameters, result):
address_n = parse_path(parameters["path"])
assert ethereum.get_address(client, address_n) == result["address"]

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import ethereum
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import parametrize_using_common_fixtures
@ -25,7 +26,7 @@ pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
@parametrize_using_common_fixtures("ethereum/getpublickey.json")
def test_ethereum_getpublickey(client, parameters, result):
def test_ethereum_getpublickey(client: Client, parameters, result):
path = parse_path(parameters["path"])
res = ethereum.get_public_node(client, path)
assert res.node.depth == len(path)

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import ethereum, exceptions
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import parametrize_using_common_fixtures
@ -28,7 +29,7 @@ pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
@pytest.mark.skip_t1
@parametrize_using_common_fixtures("ethereum/sign_typed_data.json")
def test_ethereum_sign_typed_data(client, parameters, result):
def test_ethereum_sign_typed_data(client: Client, parameters, result):
with client:
address_n = parse_path(parameters["path"])
ret = ethereum.sign_typed_data(
@ -43,7 +44,7 @@ def test_ethereum_sign_typed_data(client, parameters, result):
@pytest.mark.skip_t2
@parametrize_using_common_fixtures("ethereum/sign_typed_data.json")
def test_ethereum_sign_typed_data_blind(client, parameters, result):
def test_ethereum_sign_typed_data_blind(client: Client, parameters, result):
with client:
address_n = parse_path(parameters["path"])
ret = ethereum.sign_typed_data_hash(
@ -93,7 +94,7 @@ DATA = {
}
def input_flow_show_more(client):
def input_flow_show_more(client: Client):
"""Clicks show_more button wherever possible"""
yield # confirm domain
client.debug.wait_layout()
@ -133,33 +134,33 @@ def input_flow_show_more(client):
client.debug.press_yes()
def input_flow_cancel(client):
def input_flow_cancel(client: Client):
"""Clicks cancelling button"""
yield # confirm domain
client.debug.press_no()
@pytest.mark.skip_t1
def test_ethereum_sign_typed_data_show_more_button(client):
def test_ethereum_sign_typed_data_show_more_button(client: Client):
with client:
client.watch_layout()
client.set_input_flow(input_flow_show_more(client))
ethereum.sign_typed_data(
client,
parse_path("m/44'/60'/0'/0/0"),
parse_path("m/44h/60h/0h/0/0"),
DATA,
metamask_v4_compat=True,
)
@pytest.mark.skip_t1
def test_ethereum_sign_typed_data_cancel(client):
def test_ethereum_sign_typed_data_cancel(client: Client):
with client, pytest.raises(exceptions.Cancelled):
client.watch_layout()
client.set_input_flow(input_flow_cancel(client))
ethereum.sign_typed_data(
client,
parse_path("m/44'/60'/0'/0/0"),
parse_path("m/44h/60h/0h/0/0"),
DATA,
metamask_v4_compat=True,
)

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import ethereum
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import parametrize_using_common_fixtures
@ -25,7 +26,7 @@ pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
@parametrize_using_common_fixtures("ethereum/signmessage.json")
def test_signmessage(client, parameters, result):
def test_signmessage(client: Client, parameters, result):
res = ethereum.sign_message(
client, parse_path(parameters["path"]), parameters["msg"]
)
@ -34,7 +35,7 @@ def test_signmessage(client, parameters, result):
@parametrize_using_common_fixtures("ethereum/verifymessage.json")
def test_verify(client, parameters, result):
def test_verify(client: Client, parameters, result):
res = ethereum.verify_message(
client,
parameters["address"],
@ -44,7 +45,7 @@ def test_verify(client, parameters, result):
assert res is True
def test_verify_invalid(client):
def test_verify_invalid(client: Client):
# First vector from the verifymessage JSON fixture
msg = "This is an example of a signed message."
address = "0xEa53AF85525B1779eE99ece1a5560C0b78537C3b"

View File

@ -17,7 +17,7 @@
import pytest
from trezorlib import ethereum, exceptions, messages
from trezorlib.debuglink import message_filters
from trezorlib.debuglink import TrezorClientDebugLink as Client, message_filters
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
@ -34,7 +34,7 @@ pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
"ethereum/sign_tx.json",
"ethereum/sign_tx_eip155.json",
)
def test_signtx(client, parameters, result):
def test_signtx(client: Client, parameters, result):
with client:
sig_v, sig_r, sig_s = ethereum.sign_tx(
client,
@ -57,7 +57,7 @@ def test_signtx(client, parameters, result):
@parametrize_using_common_fixtures("ethereum/sign_tx_eip1559.json")
def test_signtx_eip1559(client, parameters, result):
def test_signtx_eip1559(client: Client, parameters, result):
with client:
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
client,
@ -77,7 +77,7 @@ def test_signtx_eip1559(client, parameters, result):
assert sig_v == result["sig_v"]
def test_sanity_checks(client):
def test_sanity_checks(client: Client):
"""Is not vectorized because these are internal-only tests that do not
need to be exposed to the public.
"""
@ -85,12 +85,12 @@ def test_sanity_checks(client):
with pytest.raises(TrezorFailure, match=r"DataError"):
ethereum.sign_tx(
client,
n=parse_path("44'/60'/0'/0/0"),
nonce=123456,
gas_price=20000,
gas_limit=20000,
n=parse_path("m/44h/60h/0h/0/0"),
nonce=123_456,
gas_price=20_000,
gas_limit=20_000,
to="",
value=12345678901234567890,
value=12_345_678_901_234_567_890,
chain_id=1,
)
@ -98,12 +98,12 @@ def test_sanity_checks(client):
with pytest.raises(TrezorFailure, match=r"DataError"):
ethereum.sign_tx(
client,
n=parse_path("44'/60'/0'/0/0"),
nonce=123456,
n=parse_path("m/44h/60h/0h/0/0"),
nonce=123_456,
gas_price=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
gas_limit=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
to=TO_ADDR,
value=12345678901234567890,
value=12_345_678_901_234_567_890,
chain_id=1,
)
@ -111,17 +111,17 @@ def test_sanity_checks(client):
with pytest.raises(TrezorFailure, match=r"Chain ID out of bounds"):
ethereum.sign_tx(
client,
n=parse_path("44'/60'/0'/0/0"),
nonce=123456,
gas_price=20000,
gas_limit=20000,
n=parse_path("m/44h/60h/0h/0/0"),
nonce=123_456,
gas_price=20_000,
gas_limit=20_000,
to=TO_ADDR,
value=12345678901234567890,
value=12_345_678_901_234_567_890,
chain_id=0,
)
def test_data_streaming(client):
def test_data_streaming(client: Client):
"""Only verifying the expected responses, the signatures are
checked in vectorized function above.
"""
@ -132,19 +132,19 @@ def test_data_streaming(client):
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
messages.ButtonRequest(code=messages.ButtonRequestType.SignTx),
message_filters.EthereumTxRequest(
data_length=1024,
data_length=1_024,
signature_r=None,
signature_s=None,
signature_v=None,
),
message_filters.EthereumTxRequest(
data_length=1024,
data_length=1_024,
signature_r=None,
signature_s=None,
signature_v=None,
),
message_filters.EthereumTxRequest(
data_length=1024,
data_length=1_024,
signature_r=None,
signature_s=None,
signature_v=None,
@ -161,10 +161,10 @@ def test_data_streaming(client):
ethereum.sign_tx(
client,
n=parse_path("44'/60'/0'/0/0"),
n=parse_path("m/44h/60h/0h/0/0"),
nonce=0,
gas_price=20000,
gas_limit=20000,
gas_price=20_000,
gas_limit=20_000,
to=TO_ADDR,
value=0,
data=b"ABCDEFGHIJKLMNOP" * 256 + b"!!!",
@ -172,12 +172,12 @@ def test_data_streaming(client):
)
def test_signtx_eip1559_access_list(client):
def test_signtx_eip1559_access_list(client: Client):
with client:
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
client,
n=parse_path("44'/60'/0'/0/100"),
n=parse_path("m/44h/60h/0h/0/100"),
nonce=0,
gas_limit=20,
to="0x1d1c328764a41bda0492b66baa30c4a339ff85ef",
@ -211,12 +211,12 @@ def test_signtx_eip1559_access_list(client):
)
def test_signtx_eip1559_access_list_larger(client):
def test_signtx_eip1559_access_list_larger(client: Client):
with client:
sig_v, sig_r, sig_s = ethereum.sign_tx_eip1559(
client,
n=parse_path("44'/60'/0'/0/100"),
n=parse_path("m/44h/60h/0h/0/100"),
nonce=0,
gas_limit=20,
to="0x1d1c328764a41bda0492b66baa30c4a339ff85ef",
@ -264,7 +264,7 @@ def test_signtx_eip1559_access_list_larger(client):
)
def test_sanity_checks_eip1559(client):
def test_sanity_checks_eip1559(client: Client):
"""Is not vectorized because these are internal-only tests that do not
need to be exposed to the public.
"""
@ -272,7 +272,7 @@ def test_sanity_checks_eip1559(client):
with pytest.raises(TrezorFailure, match=r"DataError"):
ethereum.sign_tx_eip1559(
client,
n=parse_path("44'/60'/0'/0/100"),
n=parse_path("m/44h/60h/0h/0/100"),
nonce=0,
gas_limit=20,
to="",
@ -286,7 +286,7 @@ def test_sanity_checks_eip1559(client):
with pytest.raises(TrezorFailure, match=r"DataError"):
ethereum.sign_tx_eip1559(
client,
n=parse_path("44'/60'/0'/0/100"),
n=parse_path("m/44h/60h/0h/0/100"),
nonce=0,
gas_limit=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
to=TO_ADDR,
@ -300,7 +300,7 @@ def test_sanity_checks_eip1559(client):
with pytest.raises(TrezorFailure, match=r"DataError"):
ethereum.sign_tx_eip1559(
client,
n=parse_path("44'/60'/0'/0/100"),
n=parse_path("m/44h/60h/0h/0/100"),
nonce=0,
gas_limit=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
to=TO_ADDR,
@ -314,7 +314,7 @@ def test_sanity_checks_eip1559(client):
with pytest.raises(TrezorFailure, match=r"Chain ID out of bounds"):
ethereum.sign_tx_eip1559(
client,
n=parse_path("44'/60'/0'/0/100"),
n=parse_path("m/44h/60h/0h/0/100"),
nonce=0,
gas_limit=20,
to=TO_ADDR,
@ -325,7 +325,7 @@ def test_sanity_checks_eip1559(client):
)
def input_flow_skip(client, cancel=False):
def input_flow_skip(client: Client, cancel=False):
yield # confirm sending
client.debug.press_yes()
@ -338,7 +338,7 @@ def input_flow_skip(client, cancel=False):
client.debug.press_yes()
def input_flow_scroll_down(client, cancel=False):
def input_flow_scroll_down(client: Client, cancel=False):
yield # confirm sending
client.debug.wait_layout()
client.debug.press_yes()
@ -363,7 +363,7 @@ def input_flow_scroll_down(client, cancel=False):
client.debug.press_yes()
def input_flow_go_back(client, cancel=False):
def input_flow_go_back(client: Client, cancel=False):
br = yield # confirm sending
client.debug.wait_layout()
client.debug.press_yes()
@ -399,13 +399,13 @@ HEXDATA = "0123456789abcd000023456789abcd010003456789abcd020000456789abcd0300000
"flow", (input_flow_skip, input_flow_scroll_down, input_flow_go_back)
)
@pytest.mark.skip_t1
def test_signtx_data_pagination(client, flow):
def test_signtx_data_pagination(client: Client, flow):
with client:
client.watch_layout()
client.set_input_flow(flow(client))
ethereum.sign_tx(
client,
n=parse_path("m/44'/60'/0'/0/0"),
n=parse_path("m/44h/60h/0h/0/0"),
nonce=0x0,
gas_price=0x14,
gas_limit=0x14,
@ -421,7 +421,7 @@ def test_signtx_data_pagination(client, flow):
client.set_input_flow(flow(client, cancel=True))
ethereum.sign_tx(
client,
n=parse_path("m/44'/60'/0'/0/0"),
n=parse_path("m/44h/60h/0h/0/0"),
nonce=0x0,
gas_price=0x14,
gas_limit=0x14,

View File

@ -19,17 +19,18 @@ from hashlib import sha256
import pytest
from trezorlib import cosi
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
pytestmark = pytest.mark.skip_t2
def test_cosi_commit(client):
def test_cosi_commit(client: Client):
digest = sha256(b"this is a message").digest()
c0 = cosi.commit(client, parse_path("10018'/0'"), digest)
c1 = cosi.commit(client, parse_path("10018'/1'"), digest)
c2 = cosi.commit(client, parse_path("10018'/2'"), digest)
c0 = cosi.commit(client, parse_path("m/10018h/0h"), digest)
c1 = cosi.commit(client, parse_path("m/10018h/1h"), digest)
c2 = cosi.commit(client, parse_path("m/10018h/2h"), digest)
assert c0.pubkey != c1.pubkey
assert c0.pubkey != c2.pubkey
@ -41,9 +42,9 @@ def test_cosi_commit(client):
digestb = sha256(b"this is a different message").digest()
c0b = cosi.commit(client, parse_path("10018'/0'"), digestb)
c1b = cosi.commit(client, parse_path("10018'/1'"), digestb)
c2b = cosi.commit(client, parse_path("10018'/2'"), digestb)
c0b = cosi.commit(client, parse_path("m/10018h/0h"), digestb)
c1b = cosi.commit(client, parse_path("m/10018h/1h"), digestb)
c2b = cosi.commit(client, parse_path("m/10018h/2h"), digestb)
assert c0.pubkey == c0b.pubkey
assert c1.pubkey == c1b.pubkey
@ -54,20 +55,20 @@ def test_cosi_commit(client):
assert c2.commitment != c2b.commitment
def test_cosi_sign(client):
def test_cosi_sign(client: Client):
digest = sha256(b"this is a message").digest()
c0 = cosi.commit(client, parse_path("10018'/0'"), digest)
c1 = cosi.commit(client, parse_path("10018'/1'"), digest)
c2 = cosi.commit(client, parse_path("10018'/2'"), digest)
c0 = cosi.commit(client, parse_path("m/10018h/0h"), digest)
c1 = cosi.commit(client, parse_path("m/10018h/1h"), digest)
c2 = cosi.commit(client, parse_path("m/10018h/2h"), digest)
global_pk = cosi.combine_keys([c0.pubkey, c1.pubkey, c2.pubkey])
global_R = cosi.combine_keys([c0.commitment, c1.commitment, c2.commitment])
# fmt: off
sig0 = cosi.sign(client, parse_path("10018'/0'"), digest, global_R, global_pk)
sig1 = cosi.sign(client, parse_path("10018'/1'"), digest, global_R, global_pk)
sig2 = cosi.sign(client, parse_path("10018'/2'"), digest, global_R, global_pk)
sig0 = cosi.sign(client, parse_path("m/10018h/0h"), digest, global_R, global_pk)
sig1 = cosi.sign(client, parse_path("m/10018h/1h"), digest, global_R, global_pk)
sig2 = cosi.sign(client, parse_path("m/10018h/2h"), digest, global_R, global_pk)
# fmt: on
sig = cosi.combine_sig(global_R, [sig0.signature, sig1.signature, sig2.signature])
@ -75,9 +76,9 @@ def test_cosi_sign(client):
cosi.verify_combined(sig, digest, global_pk)
def test_cosi_compat(client):
def test_cosi_compat(client: Client):
digest = sha256(b"this is not a pipe").digest()
remote_commit = cosi.commit(client, parse_path("10018'/0'"), digest)
remote_commit = cosi.commit(client, parse_path("m/10018h/0h"), digest)
local_privkey = sha256(b"private key").digest()[:32]
local_pubkey = cosi.pubkey_from_privkey(local_privkey)
@ -86,7 +87,9 @@ def test_cosi_compat(client):
global_pk = cosi.combine_keys([remote_commit.pubkey, local_pubkey])
global_R = cosi.combine_keys([remote_commit.commitment, local_commitment])
remote_sig = cosi.sign(client, parse_path("10018'/0'"), digest, global_R, global_pk)
remote_sig = cosi.sign(
client, parse_path("m/10018h/0h"), digest, global_R, global_pk
)
local_sig = cosi.sign_with_privkey(
digest, local_privkey, global_pk, local_nonce, global_R
)

View File

@ -17,12 +17,13 @@
import pytest
from trezorlib import misc
from trezorlib.debuglink import TrezorClientDebugLink as Client
from ...common import MNEMONIC12
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_encrypt(client):
def test_encrypt(client: Client):
res = misc.encrypt_keyvalue(
client,
[0, 1, 2],
@ -100,7 +101,7 @@ def test_encrypt(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_decrypt(client):
def test_decrypt(client: Client):
res = misc.decrypt_keyvalue(
client,
[0, 1, 2],
@ -177,11 +178,11 @@ def test_decrypt(client):
assert res == b"testing message!"
def test_encrypt_badlen(client):
def test_encrypt_badlen(client: Client):
with pytest.raises(Exception):
misc.encrypt_keyvalue(client, [0, 1, 2], "test", b"testing")
def test_decrypt_badlen(client):
def test_decrypt_badlen(client: Client):
with pytest.raises(Exception):
misc.decrypt_keyvalue(client, [0, 1, 2], "test", b"testing")

View File

@ -17,12 +17,13 @@
import pytest
from trezorlib import messages, misc
from trezorlib.debuglink import TrezorClientDebugLink as Client
from ...common import MNEMONIC12
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_ecdh(client):
def test_ecdh(client: Client):
identity = messages.IdentityType(
proto="gpg",
user="",

View File

@ -19,6 +19,7 @@ import math
import pytest
from trezorlib import messages as m, misc
from trezorlib.debuglink import TrezorClientDebugLink as Client
ENTROPY_LENGTHS_POW2 = [2 ** l for l in range(10)]
ENTROPY_LENGTHS_POW2_1 = [2 ** l + 1 for l in range(10)]
@ -38,7 +39,7 @@ def entropy(data):
@pytest.mark.parametrize("entropy_length", ENTROPY_LENGTHS)
def test_entropy(client, entropy_length):
def test_entropy(client: Client, entropy_length):
with client:
client.set_expected_responses(
[m.ButtonRequest(code=m.ButtonRequestType.ProtectCall), m.Entropy]

View File

@ -17,12 +17,13 @@
import pytest
from trezorlib import messages, misc
from trezorlib.debuglink import TrezorClientDebugLink as Client
from ...common import MNEMONIC12
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_sign(client):
def test_sign(client: Client):
hidden = bytes.fromhex(
"cd8552569d6e4509266ef137584d1e62c7579b5b8ed69bbafa4b864c6521e7c2"
)

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import monero
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import MNEMONIC12
@ -26,7 +27,7 @@ from ...common import MNEMONIC12
@pytest.mark.monero
@pytest.mark.skip_t1
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_monero_getaddress(client):
def test_monero_getaddress(client: Client):
assert (
monero.get_address(client, parse_path("m/44h/128h/0h"), show_display=True)
== b"4Ahp23WfMrMFK3wYL2hLWQFGt87ZTeRkufS6JoQZu6MEFDokAQeGWmu9MA3GFq1yVLSJQbKJqVAn9F9DLYGpRzRAEXqAXKM"

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import monero
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import MNEMONIC12
@ -26,7 +27,7 @@ from ...common import MNEMONIC12
@pytest.mark.monero
@pytest.mark.skip_t1
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_monero_getwatchkey(client):
def test_monero_getwatchkey(client: Client):
res = monero.get_watch_key(client, parse_path("m/44h/128h/0h"))
assert (
res.address

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import nem
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import MNEMONIC12
@ -25,16 +26,16 @@ from ...common import MNEMONIC12
@pytest.mark.altcoin
@pytest.mark.nem
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_nem_getaddress(client):
def test_nem_getaddress(client: Client):
assert (
nem.get_address(
client, parse_path("m/44'/1'/0'/0'/0'"), 0x68, show_display=True
client, parse_path("m/44h/1h/0h/0h/0h"), 0x68, show_display=True
)
== "NB3JCHVARQNGDS3UVGAJPTFE22UQFGMCQGHUBWQN"
)
assert (
nem.get_address(
client, parse_path("m/44'/1'/0'/0'/0'"), 0x98, show_display=True
client, parse_path("m/44h/1h/0h/0h/0h"), 0x98, show_display=True
)
== "TB3JCHVARQNGDS3UVGAJPTFE22UQFGMCQHSBNBMF"
)

View File

@ -17,11 +17,12 @@
import pytest
from trezorlib import nem
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import MNEMONIC12
ADDRESS_N = parse_path("m/44'/1'/0'/0'/0'")
ADDRESS_N = parse_path("m/44h/1h/0h/0h/0h")
pytestmark = [
pytest.mark.altcoin,
@ -30,7 +31,7 @@ pytestmark = [
]
def test_nem_signtx_mosaic_supply_change(client):
def test_nem_signtx_mosaic_supply_change(client: Client):
tx = nem.sign_tx(
client,
ADDRESS_N,
@ -59,7 +60,7 @@ def test_nem_signtx_mosaic_supply_change(client):
)
def test_nem_signtx_mosaic_creation(client):
def test_nem_signtx_mosaic_creation(client: Client):
tx = nem.sign_tx(
client,
ADDRESS_N,
@ -91,7 +92,7 @@ def test_nem_signtx_mosaic_creation(client):
)
def test_nem_signtx_mosaic_creation_properties(client):
def test_nem_signtx_mosaic_creation_properties(client: Client):
tx = nem.sign_tx(
client,
ADDRESS_N,
@ -128,7 +129,7 @@ def test_nem_signtx_mosaic_creation_properties(client):
)
def test_nem_signtx_mosaic_creation_levy(client):
def test_nem_signtx_mosaic_creation_levy(client: Client):
tx = nem.sign_tx(
client,
ADDRESS_N,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import nem
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import MNEMONIC12
@ -29,10 +30,10 @@ pytestmark = [
# assertion data from T1
def test_nem_signtx_aggregate_modification(client):
def test_nem_signtx_aggregate_modification(client: Client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 74649215,
"fee": 2000000,
@ -59,10 +60,10 @@ def test_nem_signtx_aggregate_modification(client):
)
def test_nem_signtx_multisig(client):
def test_nem_signtx_multisig(client: Client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 1,
"fee": 10000,
@ -97,7 +98,7 @@ def test_nem_signtx_multisig(client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 74649215,
"fee": 150,
@ -130,10 +131,10 @@ def test_nem_signtx_multisig(client):
)
def test_nem_signtx_multisig_signer(client):
def test_nem_signtx_multisig_signer(client: Client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 333,
"fee": 200,
@ -168,7 +169,7 @@ def test_nem_signtx_multisig_signer(client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 900000,
"fee": 200000,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import nem
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import MNEMONIC12
@ -29,11 +30,11 @@ pytestmark = [
# assertion data from T1
def test_nem_signtx_importance_transfer(client):
def test_nem_signtx_importance_transfer(client: Client):
with client:
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 12349215,
"fee": 9900,
@ -58,10 +59,10 @@ def test_nem_signtx_importance_transfer(client):
)
def test_nem_signtx_provision_namespace(client):
def test_nem_signtx_provision_namespace(client: Client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 74649215,
"fee": 2000000,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import messages, nem
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import MNEMONIC12
@ -29,7 +30,7 @@ pytestmark = [
# assertion data from T1
def test_nem_signtx_simple(client):
def test_nem_signtx_simple(client: Client):
with client:
client.set_expected_responses(
[
@ -45,7 +46,7 @@ def test_nem_signtx_simple(client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 74649215,
"amount": 2000000,
@ -72,7 +73,7 @@ def test_nem_signtx_simple(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_nem_signtx_encrypted_payload(client):
def test_nem_signtx_encrypted_payload(client: Client):
with client:
client.set_expected_responses(
[
@ -88,7 +89,7 @@ def test_nem_signtx_encrypted_payload(client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 74649215,
"amount": 2000000,
@ -118,10 +119,10 @@ def test_nem_signtx_encrypted_payload(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_nem_signtx_xem_as_mosaic(client):
def test_nem_signtx_xem_as_mosaic(client: Client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 76809215,
"amount": 5000000,
@ -152,10 +153,10 @@ def test_nem_signtx_xem_as_mosaic(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_nem_signtx_unknown_mosaic(client):
def test_nem_signtx_unknown_mosaic(client: Client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 76809215,
"amount": 2000000,
@ -186,10 +187,10 @@ def test_nem_signtx_unknown_mosaic(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_nem_signtx_known_mosaic(client):
def test_nem_signtx_known_mosaic(client: Client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 76809215,
"amount": 3000000,
@ -220,10 +221,10 @@ def test_nem_signtx_known_mosaic(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_nem_signtx_known_mosaic_with_levy(client):
def test_nem_signtx_known_mosaic_with_levy(client: Client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 76809215,
"amount": 2000000,
@ -254,10 +255,10 @@ def test_nem_signtx_known_mosaic_with_levy(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_nem_signtx_multiple_mosaics(client):
def test_nem_signtx_multiple_mosaics(client: Client):
tx = nem.sign_tx(
client,
parse_path("m/44'/1'/0'/0'/0'"),
parse_path("m/44h/1h/0h/0h/0h"),
{
"timeStamp": 76809215,
"amount": 2000000,

View File

@ -17,12 +17,13 @@
import pytest
from trezorlib import device, exceptions, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from ... import buttons
from ...common import MNEMONIC12
def do_recover_legacy(client, mnemonic, **kwargs):
def do_recover_legacy(client: Client, mnemonic, **kwargs):
def input_callback(_):
word, pos = client.debug.read_recovery_word()
if pos != 0:
@ -45,7 +46,7 @@ def do_recover_legacy(client, mnemonic, **kwargs):
return ret
def do_recover_core(client, mnemonic, **kwargs):
def do_recover_core(client: Client, mnemonic, **kwargs):
def input_flow():
yield
layout = client.debug.wait_layout()
@ -86,7 +87,7 @@ def do_recover_core(client, mnemonic, **kwargs):
return device.recover(client, dry_run=True, **kwargs)
def do_recover(client, mnemonic):
def do_recover(client: Client, mnemonic):
if client.features.model == "1":
return do_recover_legacy(client, mnemonic)
else:
@ -94,13 +95,13 @@ def do_recover(client, mnemonic):
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_dry_run(client):
def test_dry_run(client: Client):
ret = do_recover(client, MNEMONIC12.split(" "))
assert isinstance(ret, messages.Success)
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_seed_mismatch(client):
def test_seed_mismatch(client: Client):
with pytest.raises(
exceptions.TrezorFailure, match="does not match the one in the device"
):
@ -108,13 +109,13 @@ def test_seed_mismatch(client):
@pytest.mark.skip_t2
def test_invalid_seed_t1(client):
def test_invalid_seed_t1(client: Client):
with pytest.raises(exceptions.TrezorFailure, match="Invalid seed"):
do_recover(client, ["stick"] * 12)
@pytest.mark.skip_t1
def test_invalid_seed_core(client):
def test_invalid_seed_core(client: Client):
def input_flow():
yield
layout = client.debug.wait_layout()
@ -168,7 +169,7 @@ def test_invalid_seed_core(client):
@pytest.mark.setup_client(uninitialized=True)
def test_uninitialized(client):
def test_uninitialized(client: Client):
with pytest.raises(exceptions.TrezorFailure, match="not initialized"):
do_recover(client, ["all"] * 12)
@ -197,7 +198,7 @@ def _make_bad_params():
@pytest.mark.parametrize("field_name, field_value", _make_bad_params())
def test_bad_parameters(client, field_name, field_value):
def test_bad_parameters(client: Client, field_name, field_value):
msg = messages.RecoveryDevice(
dry_run=True,
word_count=12,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from ...common import MNEMONIC12
@ -27,7 +28,7 @@ pytestmark = pytest.mark.skip_t2
@pytest.mark.setup_client(uninitialized=True)
def test_pin_passphrase(client):
def test_pin_passphrase(client: Client):
mnemonic = MNEMONIC12.split(" ")
ret = client.call_raw(
messages.RecoveryDevice(
@ -89,7 +90,7 @@ def test_pin_passphrase(client):
@pytest.mark.setup_client(uninitialized=True)
def test_nopin_nopassphrase(client):
def test_nopin_nopassphrase(client: Client):
mnemonic = MNEMONIC12.split(" ")
ret = client.call_raw(
messages.RecoveryDevice(
@ -139,7 +140,7 @@ def test_nopin_nopassphrase(client):
@pytest.mark.setup_client(uninitialized=True)
def test_word_fail(client):
def test_word_fail(client: Client):
ret = client.call_raw(
messages.RecoveryDevice(
word_count=12,
@ -168,7 +169,7 @@ def test_word_fail(client):
@pytest.mark.setup_client(uninitialized=True)
def test_pin_fail(client):
def test_pin_fail(client: Client):
ret = client.call_raw(
messages.RecoveryDevice(
word_count=12,
@ -200,7 +201,7 @@ def test_pin_fail(client):
assert isinstance(ret, messages.Failure)
def test_already_initialized(client):
def test_already_initialized(client: Client):
with pytest.raises(RuntimeError):
device.recover(
client, 12, False, False, "label", "en-US", client.mnemonic_callback

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import device, exceptions, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from ...common import MNEMONIC12
@ -24,7 +25,7 @@ pytestmark = pytest.mark.skip_t1
@pytest.mark.setup_client(uninitialized=True)
def test_tt_pin_passphrase(client):
def test_tt_pin_passphrase(client: Client):
layout = client.debug.wait_layout
mnemonic = MNEMONIC12.split(" ")
@ -78,7 +79,7 @@ def test_tt_pin_passphrase(client):
@pytest.mark.setup_client(uninitialized=True)
def test_tt_nopin_nopassphrase(client):
def test_tt_nopin_nopassphrase(client: Client):
layout = client.debug.wait_layout
mnemonic = MNEMONIC12.split(" ")
@ -122,7 +123,7 @@ def test_tt_nopin_nopassphrase(client):
assert client.features.label == "hello"
def test_already_initialized(client):
def test_already_initialized(client: Client):
with pytest.raises(RuntimeError):
device.recover(client)

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import device, exceptions, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from ...common import (
MNEMONIC_SLIP39_ADVANCED_20,
@ -41,7 +42,7 @@ VECTORS = (
# To allow reusing functionality for multiple tests
def _test_secret(client, shares, secret, click_info=False):
def _test_secret(client: Client, shares, secret, click_info=False):
debug = client.debug
def input_flow():
@ -69,18 +70,18 @@ def _test_secret(client, shares, secret, click_info=False):
@pytest.mark.parametrize("shares, secret", VECTORS)
@pytest.mark.setup_client(uninitialized=True)
def test_secret(client, shares, secret):
def test_secret(client: Client, shares, secret):
_test_secret(client, shares, secret)
@pytest.mark.parametrize("shares, secret", VECTORS)
@pytest.mark.setup_client(uninitialized=True)
def test_secret_click_info_button(client, shares, secret):
def test_secret_click_info_button(client: Client, shares, secret):
_test_secret(client, shares, secret, click_info=True)
@pytest.mark.setup_client(uninitialized=True)
def test_extra_share_entered(client):
def test_extra_share_entered(client: Client):
_test_secret(
client,
shares=EXTRA_GROUP_SHARE + MNEMONIC_SLIP39_ADVANCED_20,
@ -89,7 +90,7 @@ def test_extra_share_entered(client):
@pytest.mark.setup_client(uninitialized=True)
def test_abort(client):
def test_abort(client: Client):
debug = client.debug
def input_flow():
@ -109,7 +110,7 @@ def test_abort(client):
@pytest.mark.setup_client(uninitialized=True)
def test_noabort(client):
def test_noabort(client: Client):
debug = client.debug
def input_flow():
@ -131,7 +132,7 @@ def test_noabort(client):
@pytest.mark.setup_client(uninitialized=True)
def test_same_share(client):
def test_same_share(client: Client):
debug = client.debug
# we choose the second share from the fixture because
# the 1st is 1of1 and group threshold condition is reached first
@ -172,7 +173,7 @@ def test_same_share(client):
@pytest.mark.setup_client(uninitialized=True)
def test_group_threshold_reached(client):
def test_group_threshold_reached(client: Client):
debug = client.debug
# first share in the fixture is 1of1 so we choose that
first_share = MNEMONIC_SLIP39_ADVANCED_20[0].split(" ")

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from ...common import MNEMONIC_SLIP39_ADVANCED_20, recovery_enter_shares
@ -37,7 +38,7 @@ EXTRA_GROUP_SHARE = [
@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_ADVANCED_20, passphrase=False)
def test_2of3_dryrun(client):
def test_2of3_dryrun(client: Client):
debug = client.debug
def input_flow():
@ -66,7 +67,7 @@ def test_2of3_dryrun(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_ADVANCED_20)
def test_2of3_invalid_seed_dryrun(client):
def test_2of3_invalid_seed_dryrun(client: Client):
debug = client.debug
def input_flow():

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import device, exceptions, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from ...common import (
MNEMONIC_SLIP39_BASIC_20_3of6,
@ -47,7 +48,7 @@ VECTORS = (
@pytest.mark.setup_client(uninitialized=True)
@pytest.mark.parametrize("shares, secret", VECTORS)
def test_secret(client, shares, secret):
def test_secret(client: Client, shares, secret):
debug = client.debug
def input_flow():
@ -71,7 +72,7 @@ def test_secret(client, shares, secret):
@pytest.mark.setup_client(uninitialized=True)
def test_recover_with_pin_passphrase(client):
def test_recover_with_pin_passphrase(client: Client):
debug = client.debug
def input_flow():
@ -98,7 +99,7 @@ def test_recover_with_pin_passphrase(client):
@pytest.mark.setup_client(uninitialized=True)
def test_abort(client):
def test_abort(client: Client):
debug = client.debug
def input_flow():
@ -118,7 +119,7 @@ def test_abort(client):
@pytest.mark.setup_client(uninitialized=True)
def test_noabort(client):
def test_noabort(client: Client):
debug = client.debug
def input_flow():
@ -138,7 +139,7 @@ def test_noabort(client):
@pytest.mark.setup_client(uninitialized=True)
def test_ask_word_number(client):
def test_ask_word_number(client: Client):
debug = client.debug
def input_flow_retry_first():
@ -230,7 +231,7 @@ def test_ask_word_number(client):
@pytest.mark.setup_client(uninitialized=True)
@pytest.mark.parametrize("nth_word", range(3))
def test_wrong_nth_word(client, nth_word):
def test_wrong_nth_word(client: Client, nth_word):
debug = client.debug
share = MNEMONIC_SLIP39_BASIC_20_3of6[0].split(" ")
@ -269,7 +270,7 @@ def test_wrong_nth_word(client, nth_word):
@pytest.mark.setup_client(uninitialized=True)
def test_same_share(client):
def test_same_share(client: Client):
debug = client.debug
first_share = MNEMONIC_SLIP39_BASIC_20_3of6[0].split(" ")
# second share is first 4 words of first
@ -306,7 +307,7 @@ def test_same_share(client):
@pytest.mark.setup_client(uninitialized=True)
def test_1of1(client):
def test_1of1(client: Client):
debug = client.debug
def input_flow():

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from ...common import recovery_enter_shares
@ -36,7 +37,7 @@ INVALID_SHARES_20_2of3 = [
@pytest.mark.setup_client(mnemonic=SHARES_20_2of3[0:2])
def test_2of3_dryrun(client):
def test_2of3_dryrun(client: Client):
debug = client.debug
def input_flow():
@ -63,7 +64,7 @@ def test_2of3_dryrun(client):
@pytest.mark.setup_client(mnemonic=SHARES_20_2of3[0:2])
def test_2of3_invalid_seed_dryrun(client):
def test_2of3_invalid_seed_dryrun(client: Client):
debug = client.debug
def input_flow():

View File

@ -21,12 +21,13 @@ import pytest
from shamir_mnemonic import shamir
from trezorlib import device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.messages import BackupType, ButtonRequestType as B
from ...common import EXTERNAL_ENTROPY, click_through, read_and_confirm_mnemonic
def backup_flow_bip39(client):
def backup_flow_bip39(client: Client):
mnemonic = None
def input_flow():
@ -65,7 +66,7 @@ def backup_flow_bip39(client):
return mnemonic.encode()
def backup_flow_slip39_basic(client):
def backup_flow_slip39_basic(client: Client):
mnemonics = []
def input_flow():
@ -111,7 +112,7 @@ def backup_flow_slip39_basic(client):
return ems.ciphertext
def backup_flow_slip39_advanced(client):
def backup_flow_slip39_advanced(client: Client):
mnemonics = []
def input_flow():
@ -181,7 +182,7 @@ VECTORS = [
@pytest.mark.skip_t1
@pytest.mark.parametrize("backup_type, backup_flow", VECTORS)
@pytest.mark.setup_client(uninitialized=True)
def test_skip_backup_msg(client, backup_type, backup_flow):
def test_skip_backup_msg(client: Client, backup_type, backup_flow):
os_urandom = mock.Mock(return_value=EXTERNAL_ENTROPY)
with mock.patch("os.urandom", os_urandom), client:
@ -216,7 +217,7 @@ def test_skip_backup_msg(client, backup_type, backup_flow):
@pytest.mark.skip_t1
@pytest.mark.parametrize("backup_type, backup_flow", VECTORS)
@pytest.mark.setup_client(uninitialized=True)
def test_skip_backup_manual(client, backup_type, backup_flow):
def test_skip_backup_manual(client: Client, backup_type, backup_flow):
def reset_skip_input_flow():
yield # Confirm Recovery
client.debug.press_yes()

View File

@ -18,6 +18,7 @@ import pytest
from mnemonic import Mnemonic
from trezorlib import messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from ...common import generate_entropy
@ -28,7 +29,7 @@ STRENGTH = 128
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_skip_backup(client):
def test_reset_device_skip_backup(client: Client):
ret = client.call_raw(
messages.ResetDevice(
display_random=False,
@ -97,7 +98,7 @@ def test_reset_device_skip_backup(client):
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_skip_backup_break(client):
def test_reset_device_skip_backup_break(client: Client):
ret = client.call_raw(
messages.ResetDevice(
display_random=False,
@ -150,13 +151,13 @@ def test_reset_device_skip_backup_break(client):
assert ret.no_backup is False
def test_initialized_device_backup_fail(client):
def test_initialized_device_backup_fail(client: Client):
ret = client.call_raw(messages.BackupDevice())
assert isinstance(ret, messages.Failure)
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_skip_backup_show_entropy_fail(client):
def test_reset_device_skip_backup_show_entropy_fail(client: Client):
ret = client.call_raw(
messages.ResetDevice(
display_random=True,

View File

@ -18,13 +18,14 @@ import pytest
from mnemonic import Mnemonic
from trezorlib import device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from ...common import generate_entropy
pytestmark = pytest.mark.skip_t2
def reset_device(client, strength):
def reset_device(client: Client, strength):
# No PIN, no passphrase
external_entropy = b"zlutoucky kun upel divoke ody" * 2
@ -91,17 +92,17 @@ def reset_device(client, strength):
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_128(client):
def test_reset_device_128(client: Client):
reset_device(client, 128)
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_192(client):
def test_reset_device_192(client: Client):
reset_device(client, 192)
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_256_pin(client):
def test_reset_device_256_pin(client: Client):
external_entropy = b"zlutoucky kun upel divoke ody" * 2
strength = 256
@ -191,7 +192,7 @@ def test_reset_device_256_pin(client):
@pytest.mark.setup_client(uninitialized=True)
def test_failed_pin(client):
def test_failed_pin(client: Client):
# external_entropy = b'zlutoucky kun upel divoke ody' * 2
strength = 128
@ -235,6 +236,6 @@ def test_failed_pin(client):
assert isinstance(ret, messages.Failure)
def test_already_initialized(client):
def test_already_initialized(client: Client):
with pytest.raises(Exception):
device.reset(client, False, 128, True, True, "label", "en-US")

View File

@ -20,6 +20,7 @@ import pytest
from mnemonic import Mnemonic
from trezorlib import device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.messages import ButtonRequestType as B
@ -35,7 +36,7 @@ pytestmark = [pytest.mark.skip_t1]
EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2
def reset_device(client, strength):
def reset_device(client: Client, strength):
mnemonic = None
def input_flow():
@ -108,17 +109,17 @@ def reset_device(client, strength):
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device(client):
def test_reset_device(client: Client):
reset_device(client, 128) # 12 words
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_192(client):
def test_reset_device_192(client: Client):
reset_device(client, 192) # 18 words
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_pin(client):
def test_reset_device_pin(client: Client):
mnemonic = None
strength = 256 # 24 words
@ -214,7 +215,7 @@ def test_reset_device_pin(client):
@pytest.mark.setup_client(uninitialized=True)
def test_reset_failed_check(client):
def test_reset_failed_check(client: Client):
mnemonic = None
strength = 256 # 24 words
@ -294,7 +295,7 @@ def test_reset_failed_check(client):
@pytest.mark.setup_client(uninitialized=True)
def test_failed_pin(client):
def test_failed_pin(client: Client):
# external_entropy = b'zlutoucky kun upel divoke ody' * 2
strength = 128
ret = client.call_raw(
@ -320,6 +321,6 @@ def test_failed_pin(client):
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_already_initialized(client):
def test_already_initialized(client: Client):
with pytest.raises(Exception):
device.reset(client, False, 128, True, True, "label", "en-US")

View File

@ -20,6 +20,7 @@ from unittest import mock
import pytest
from trezorlib import btc, device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.messages import BackupType, ButtonRequestType as B
from trezorlib.tools import parse_path
@ -28,17 +29,17 @@ from ...common import EXTERNAL_ENTROPY, click_through, read_and_confirm_mnemonic
@pytest.mark.skip_t1
@pytest.mark.setup_client(uninitialized=True)
def test_reset_recovery(client):
def test_reset_recovery(client: Client):
mnemonic = reset(client)
address_before = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))
address_before = btc.get_address(client, "Bitcoin", parse_path("m/44h/0h/0h/0/0"))
device.wipe(client)
recover(client, mnemonic)
address_after = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))
address_after = btc.get_address(client, "Bitcoin", parse_path("m/44h/0h/0h/0/0"))
assert address_before == address_after
def reset(client, strength=128, skip_backup=False):
def reset(client: Client, strength=128, skip_backup=False):
mnemonic = None
def input_flow():
@ -100,7 +101,7 @@ def reset(client, strength=128, skip_backup=False):
return mnemonic
def recover(client, mnemonic):
def recover(client: Client, mnemonic):
debug = client.debug
words = mnemonic.split(" ")

View File

@ -19,6 +19,7 @@ from unittest import mock
import pytest
from trezorlib import btc, device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.messages import BackupType, ButtonRequestType as B
from trezorlib.tools import parse_path
@ -32,9 +33,9 @@ from ...common import (
@pytest.mark.skip_t1
@pytest.mark.setup_client(uninitialized=True)
def test_reset_recovery(client):
def test_reset_recovery(client: Client):
mnemonics = reset(client)
address_before = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))
address_before = btc.get_address(client, "Bitcoin", parse_path("m/44h/0h/0h/0/0"))
# we're generating 3of5 groups 3of5 shares each
test_combinations = [
mnemonics[0:3] # shares 1-3 from groups 1-3
@ -53,11 +54,13 @@ def test_reset_recovery(client):
for combination in test_combinations:
device.wipe(client)
recover(client, combination)
address_after = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))
address_after = btc.get_address(
client, "Bitcoin", parse_path("m/44h/0h/0h/0/0")
)
assert address_before == address_after
def reset(client, strength=128):
def reset(client: Client, strength=128):
all_mnemonics = []
def input_flow():
@ -150,7 +153,7 @@ def reset(client, strength=128):
return all_mnemonics
def recover(client, shares):
def recover(client: Client, shares):
debug = client.debug
def input_flow():

View File

@ -20,6 +20,7 @@ from unittest import mock
import pytest
from trezorlib import btc, device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.messages import BackupType, ButtonRequestType as B
from trezorlib.tools import parse_path
@ -32,19 +33,21 @@ MOCK_OS_URANDOM = mock.Mock(return_value=EXTERNAL_ENTROPY)
@pytest.mark.skip_t1
@pytest.mark.setup_client(uninitialized=True)
@mock.patch("os.urandom", MOCK_OS_URANDOM)
def test_reset_recovery(client):
def test_reset_recovery(client: Client):
mnemonics = reset(client)
address_before = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))
address_before = btc.get_address(client, "Bitcoin", parse_path("m/44h/0h/0h/0/0"))
for share_subset in itertools.combinations(mnemonics, 3):
device.wipe(client)
selected_mnemonics = share_subset
recover(client, selected_mnemonics)
address_after = btc.get_address(client, "Bitcoin", parse_path("44'/0'/0'/0/0"))
address_after = btc.get_address(
client, "Bitcoin", parse_path("m/44h/0h/0h/0/0")
)
assert address_before == address_after
def reset(client, strength=128):
def reset(client: Client, strength=128):
all_mnemonics = []
def input_flow():
@ -122,7 +125,7 @@ def reset(client, strength=128):
return all_mnemonics
def recover(client, shares):
def recover(client: Client, shares):
debug = client.debug
def input_flow():

View File

@ -20,6 +20,7 @@ import pytest
from shamir_mnemonic import shamir
from trezorlib import device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.messages import BackupType, ButtonRequestType as B
@ -32,7 +33,7 @@ EXTERNAL_ENTROPY = b"zlutoucky kun upel divoke ody" * 2
# TODO: test with different options
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_slip39_advanced(client):
def test_reset_device_slip39_advanced(client: Client):
strength = 128
member_threshold = 3
all_mnemonics = []

View File

@ -21,6 +21,7 @@ import pytest
from shamir_mnemonic import MnemonicError, shamir
from trezorlib import device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.messages import BackupType, ButtonRequestType as B
@ -34,7 +35,7 @@ from ...common import (
pytestmark = [pytest.mark.skip_t1]
def reset_device(client, strength):
def reset_device(client: Client, strength):
member_threshold = 3
all_mnemonics = []
@ -125,12 +126,12 @@ def reset_device(client, strength):
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_slip39_basic(client):
def test_reset_device_slip39_basic(client: Client):
reset_device(client, 128)
@pytest.mark.setup_client(uninitialized=True)
def test_reset_device_slip39_basic_256(client):
def test_reset_device_slip39_basic_256(client: Client):
reset_device(client, 256)

View File

@ -16,6 +16,7 @@
import pytest
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.ripple import get_address
from trezorlib.tools import parse_path
@ -32,20 +33,20 @@ pytestmark = [
]
def test_ripple_get_address(client):
def test_ripple_get_address(client: Client):
# data from https://iancoleman.io/bip39/
address = get_address(client, parse_path("m/44'/144'/0'/0/0"))
address = get_address(client, parse_path("m/44h/144h/0h/0/0"))
assert address == "rNaqKtKrMSwpwZSzRckPf7S96DkimjkF4H"
address = get_address(client, parse_path("m/44'/144'/0'/0/1"))
address = get_address(client, parse_path("m/44h/144h/0h/0/1"))
assert address == "rBKz5MC2iXdoS3XgnNSYmF69K1Yo4NS3Ws"
address = get_address(client, parse_path("m/44'/144'/1'/0/0"))
address = get_address(client, parse_path("m/44h/144h/1h/0/0"))
assert address == "rJX2KwzaLJDyFhhtXKi3htaLfaUH2tptEX"
@pytest.mark.setup_client(mnemonic=CUSTOM_MNEMONIC)
def test_ripple_get_address_other(client):
def test_ripple_get_address_other(client: Client):
# data from https://github.com/you21979/node-ripple-bip32/blob/master/test/test.js
address = get_address(client, parse_path("m/44'/144'/0'/0/0"))
address = get_address(client, parse_path("m/44h/144h/0h/0/0"))
assert address == "r4ocGE47gm4G4LkA9mriVHQqzpMLBTgnTY"
address = get_address(client, parse_path("m/44'/144'/0'/0/1"))
address = get_address(client, parse_path("m/44h/144h/0h/0/1"))
assert address == "rUt9ULSrUvfCmke8HTFU1szbmFpWzVbBXW"

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import ripple
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
@ -27,7 +28,7 @@ pytestmark = [
]
def test_ripple_sign_simple_tx(client):
def test_ripple_sign_simple_tx(client: Client):
msg = ripple.create_sign_tx_msg(
{
"TransactionType": "Payment",
@ -40,7 +41,7 @@ def test_ripple_sign_simple_tx(client):
"Sequence": 25,
}
)
resp = ripple.sign_tx(client, parse_path("m/44'/144'/0'/0/0"), msg)
resp = ripple.sign_tx(client, parse_path("m/44h/144h/0h/0/0"), msg)
assert (
resp.signature.hex()
== "3045022100e243ef623675eeeb95965c35c3e06d63a9fc68bb37e17dc87af9c0af83ec057e02206ca8aa5eaab8396397aef6d38d25710441faf7c79d292ee1d627df15ad9346c0"
@ -61,7 +62,7 @@ def test_ripple_sign_simple_tx(client):
"Sequence": 1,
}
)
resp = ripple.sign_tx(client, parse_path("m/44'/144'/0'/0/2"), msg)
resp = ripple.sign_tx(client, parse_path("m/44h/144h/0h/0/2"), msg)
assert (
resp.signature.hex()
== "3044022069900e6e578997fad5189981b74b16badc7ba8b9f1052694033fa2779113ddc002206c8006ada310edf099fb22c0c12073550c8fc73247b236a974c5f1144831dd5f"
@ -85,7 +86,7 @@ def test_ripple_sign_simple_tx(client):
"LastLedgerSequence": 333111,
}
)
resp = ripple.sign_tx(client, parse_path("m/44'/144'/0'/0/2"), msg)
resp = ripple.sign_tx(client, parse_path("m/44h/144h/0h/0/2"), msg)
assert (
resp.signature.hex()
== "30450221008770743a472bb2d1c746a53ef131cc17cc118d538ec910ca928d221db4494cf702201e4ef242d6c3bff110c3cc3897a471fed0f5ac10987ea57da63f98dfa01e94df"
@ -96,7 +97,7 @@ def test_ripple_sign_simple_tx(client):
)
def test_ripple_sign_invalid_fee(client):
def test_ripple_sign_invalid_fee(client: Client):
msg = ripple.create_sign_tx_msg(
{
"TransactionType": "Payment",
@ -113,4 +114,4 @@ def test_ripple_sign_invalid_fee(client):
TrezorFailure,
match="ProcessError: Fee must be in the range of 10 to 10,000 drops",
):
ripple.sign_tx(client, parse_path("m/44'/144'/0'/0/2"), msg)
ripple.sign_tx(client, parse_path("m/44h/144h/0h/0/2"), msg)

View File

@ -55,6 +55,7 @@ from base64 import b64encode
import pytest
from trezorlib import messages, protobuf, stellar
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
from ...common import parametrize_using_common_fixtures
@ -82,7 +83,7 @@ def parameters_to_proto(parameters):
@pytest.mark.altcoin
@pytest.mark.stellar
@parametrize_using_common_fixtures("stellar/sign_tx.json")
def test_sign_tx(client, parameters, result):
def test_sign_tx(client: Client, parameters, result):
tx, operations = parameters_to_proto(parameters)
response = stellar.sign_tx(
client, tx, operations, tx.address_n, tx.network_passphrase
@ -112,7 +113,7 @@ def test_xdr(parameters, result):
@pytest.mark.altcoin
@pytest.mark.stellar
@parametrize_using_common_fixtures("stellar/get_address.json")
def test_get_address(client, parameters, result):
def test_get_address(client: Client, parameters, result):
address_n = parse_path(parameters["path"])
address = stellar.get_address(client, address_n, show_display=True)
assert address == result["address"]

View File

@ -19,6 +19,7 @@ import time
import pytest
from trezorlib import device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from ..common import TEST_ADDRESS_N, get_test_address
@ -28,7 +29,7 @@ PIN4 = "1234"
pytestmark = pytest.mark.setup_client(pin=PIN4)
def pin_request(client):
def pin_request(client: Client):
return (
messages.PinMatrixRequest
if client.features.model == "1"
@ -36,7 +37,7 @@ def pin_request(client):
)
def set_autolock_delay(client, delay):
def set_autolock_delay(client: Client, delay):
with client:
client.use_pin_sequence([PIN4])
client.set_expected_responses(
@ -50,7 +51,7 @@ def set_autolock_delay(client, delay):
device.apply_settings(client, auto_lock_delay_ms=delay)
def test_apply_auto_lock_delay(client):
def test_apply_auto_lock_delay(client: Client):
set_autolock_delay(client, 10 * 1000)
time.sleep(0.1) # sleep less than auto-lock delay
@ -77,12 +78,12 @@ def test_apply_auto_lock_delay(client):
536870, # 149 hours, maximum
],
)
def test_apply_auto_lock_delay_valid(client, seconds):
def test_apply_auto_lock_delay_valid(client: Client, seconds):
set_autolock_delay(client, seconds * 1000)
assert client.features.auto_lock_delay_ms == seconds * 1000
def test_autolock_default_value(client):
def test_autolock_default_value(client: Client):
assert client.features.auto_lock_delay_ms is None
with client:
client.use_pin_sequence([PIN4])
@ -95,7 +96,7 @@ def test_autolock_default_value(client):
"seconds",
[0, 1, 9, 536871, 2 ** 22],
)
def test_apply_auto_lock_delay_out_of_range(client, seconds):
def test_apply_auto_lock_delay_out_of_range(client: Client, seconds):
with client:
client.use_pin_sequence([PIN4])
client.set_expected_responses(
@ -111,7 +112,7 @@ def test_apply_auto_lock_delay_out_of_range(client, seconds):
@pytest.mark.skip_t1
def test_autolock_cancels_ui(client):
def test_autolock_cancels_ui(client: Client):
set_autolock_delay(client, 10 * 1000)
resp = client.call_raw(

View File

@ -15,9 +15,10 @@
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from trezorlib import device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
def test_features(client):
def test_features(client: Client):
f0 = client.features
# client erases session_id from its features
f0.session_id = client.session_id
@ -25,12 +26,12 @@ def test_features(client):
assert f0 == f1
def test_ping(client):
def test_ping(client: Client):
ping = client.call(messages.Ping(message="ahoj!"))
assert ping == messages.Success(message="ahoj!")
def test_device_id_same(client):
def test_device_id_same(client: Client):
id1 = client.get_device_id()
client.init_device()
id2 = client.get_device_id()
@ -42,7 +43,7 @@ def test_device_id_same(client):
assert id1 == id2
def test_device_id_different(client):
def test_device_id_different(client: Client):
id1 = client.get_device_id()
device.wipe(client)
id2 = client.get_device_id()

View File

@ -19,6 +19,7 @@ import time
import pytest
from trezorlib import btc
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import H_
pytestmark = [
@ -27,7 +28,7 @@ pytestmark = [
]
def test_public_ckd(client):
def test_public_ckd(client: Client):
btc.get_address(client, "Bitcoin", []) # to compute root node via BIP39
for depth in range(8):
@ -39,7 +40,7 @@ def test_public_ckd(client):
assert delay <= expected
def test_private_ckd(client):
def test_private_ckd(client: Client):
btc.get_address(client, "Bitcoin", []) # to compute root node via BIP39
for depth in range(8):
@ -52,7 +53,7 @@ def test_private_ckd(client):
assert delay <= expected
def test_cache(client):
def test_cache(client: Client):
start = time.time()
for x in range(10):
btc.get_address(client, "Bitcoin", [x, 2, 3, 4, 5, 6, 7, 8])

View File

@ -17,6 +17,7 @@
import pytest
import trezorlib.messages as m
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import Cancelled
from ..common import TEST_ADDRESS_N
@ -34,7 +35,7 @@ from ..common import TEST_ADDRESS_N
),
],
)
def test_cancel_message_via_cancel(client, message):
def test_cancel_message_via_cancel(client: Client, message):
def input_flow():
yield
client.cancel()
@ -57,7 +58,7 @@ def test_cancel_message_via_cancel(client, message):
),
],
)
def test_cancel_message_via_initialize(client, message):
def test_cancel_message_via_initialize(client: Client, message):
resp = client.call_raw(message)
assert isinstance(resp, m.ButtonRequest)
@ -70,7 +71,7 @@ def test_cancel_message_via_initialize(client, message):
@pytest.mark.skip_t1
def test_cancel_on_paginated(client):
def test_cancel_on_paginated(client: Client):
"""Check that device is responsive on paginated screen. See #1708."""
# In #1708, the device would ignore USB (or UDP) events while waiting for the user
# to page through the screen. This means that this testcase, instead of failing,

View File

@ -17,20 +17,21 @@
import pytest
from trezorlib import debuglink, device, messages, misc
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.transport import udp
from ..common import MNEMONIC12
@pytest.mark.skip_t2
def test_layout(client):
def test_layout(client: Client):
layout = client.debug.state().layout
assert len(layout) == 1024
@pytest.mark.skip_t2
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_mnemonic(client):
def test_mnemonic(client: Client):
client.ensure_unlocked()
mnemonic = client.debug.state().mnemonic_secret
assert mnemonic == MNEMONIC12.encode()
@ -38,7 +39,7 @@ def test_mnemonic(client):
@pytest.mark.skip_t2
@pytest.mark.setup_client(mnemonic=MNEMONIC12, pin="1234", passphrase="")
def test_pin(client):
def test_pin(client: Client):
resp = client.call_raw(messages.GetAddress())
assert isinstance(resp, messages.PinMatrixRequest)
@ -55,7 +56,7 @@ def test_pin(client):
@pytest.mark.skip_t1
def test_softlock_instability(client):
def test_softlock_instability(client: Client):
def load_device():
debuglink.load_device(
client,

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import btc, device, exceptions, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.tools import parse_path
EXPECTED_RESPONSES_NOPIN = [
@ -32,7 +33,7 @@ PIN4 = "1234"
pytestmark = pytest.mark.setup_client(pin=PIN4)
def _set_expected_responses(client):
def _set_expected_responses(client: Client):
client.use_pin_sequence([PIN4])
if client.features.model == "1":
client.set_expected_responses(EXPECTED_RESPONSES_PIN_T1)
@ -40,7 +41,7 @@ def _set_expected_responses(client):
client.set_expected_responses(EXPECTED_RESPONSES_PIN_TT)
def test_apply_settings(client):
def test_apply_settings(client: Client):
assert client.features.label == "test"
with client:
@ -51,7 +52,7 @@ def test_apply_settings(client):
@pytest.mark.skip_t1
def test_apply_settings_rotation(client):
def test_apply_settings_rotation(client: Client):
assert client.features.display_rotation is None
with client:
@ -62,7 +63,7 @@ def test_apply_settings_rotation(client):
@pytest.mark.skip_t2
def test_invalid_language(client):
def test_invalid_language(client: Client):
assert client.features.language == "en-US"
with client:
@ -73,7 +74,7 @@ def test_invalid_language(client):
@pytest.mark.setup_client(pin=PIN4, passphrase=False)
def test_apply_settings_passphrase(client):
def test_apply_settings_passphrase(client: Client):
with client:
_set_expected_responses(client)
device.apply_settings(client, use_passphrase=True)
@ -95,7 +96,7 @@ def test_apply_settings_passphrase(client):
@pytest.mark.setup_client(passphrase=False)
@pytest.mark.skip_t1
def test_apply_settings_passphrase_on_device(client):
def test_apply_settings_passphrase_on_device(client: Client):
# enable passphrase
with client:
client.set_expected_responses(EXPECTED_RESPONSES_NOPIN)
@ -129,7 +130,7 @@ def test_apply_settings_passphrase_on_device(client):
@pytest.mark.skip_t1
def test_apply_homescreen_toif(client):
def test_apply_homescreen_toif(client: Client):
img = b"TOIf\x90\x00\x90\x00~\x00\x00\x00\xed\xd2\xcb\r\x83@\x10D\xc1^.\xde#!\xac31\x99\x10\x8aC%\x14~\x16\x92Y9\x02WI3\x01<\xf5cI2d\x1es(\xe1[\xdbn\xba\xca\xe8s7\xa4\xd5\xd4\xb3\x13\xbdw\xf6:\xf3\xd1\xe7%\xc7]\xdd_\xb3\x9e\x9f\x9e\x9fN\xed\xaaE\xef\xdc\xcf$D\xa7\xa4X\r\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0OV"
with client:
@ -156,14 +157,14 @@ def test_apply_homescreen_toif(client):
],
)
@pytest.mark.skip_t1
def test_apply_homescreen_toif_fail(client, toif_data):
def test_apply_homescreen_toif_fail(client: Client, toif_data):
with pytest.raises(exceptions.TrezorFailure), client:
client.use_pin_sequence([PIN4])
device.apply_settings(client, homescreen=toif_data)
@pytest.mark.skip_t2
def test_apply_homescreen(client):
def test_apply_homescreen(client: Client):
img = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\x04\x80\x00\x00\x00\x00\x00\x00\x00\x00\x04\x88\x02\x00\x00\x00\x02\x91\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x90@\x00\x11@\x00\x00\x00\x00\x00\x00\x08\x00\x10\x92\x12\x04\x00\x00\x05\x12D\x00\x00\x00\x00\x00 \x00\x00\x08\x00Q\x00\x00\x02\xc0\x00\x00\x00\x00\x00\x00\x00\x10\x02 \x01\x04J\x00)$\x00\x00\x00\x00\x80\x00\x00\x00\x00\x08\x10\xa1\x00\x00\x02\x81 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\tP\x00\x00\x00\x00\x00\x00 \x00\x00\xa0\x00\xa0R \x12\x84\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x08\x00\tP\x00\x00\x00\x00 \x00\x04 \x00\x80\x02\x00@\x02T\xc2 \x00\x00\x00\x00\x00\x00\x00\x10@\x00)\t@\n\xa0\x80\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x80@\x14\xa9H\x04\x00\x00\x88@\x00\x00\x00\x00\x00\x02\x02$\x00\x15B@\x00\nP\x00\x00\x00\x00\x00\x80\x00\x00\x91\x01UP\x00\x00 \x02\x00\x00\x00\x00\x00\x00\x02\x08@ Z\xa5 \x00\x00\x80\x00\x00\x00\x00\x00\x00\x08\xa1%\x14*\xa0\x00\x00\x02\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00@\xaa\x91 \x00\x05E\x80\x00\x00\x00\x00\x00\x02*T\x05-D\x00\x00\x05 @\x00\x00\x00\x00\x00%@\x80\x11V\xa0\x88\x00\x05@\xb0\x00\x00\x00\x00\x00\x818$\x04\xabD \x00\x06\xa1T\x00\x00\x00\x00\x02\x03\xb8\x01R\xd5\x01\x00\x00\x05AP\x00\x00\x00\x00\x08\xadT\x00\x05j\xa4@\x00\x87ah\x00\x00\x00\x00\x02\x8d\xb8\x08\x00.\x01\x00\x00\x02\xa5\xa8\x10\x00\x00\x00*\xc1\xec \n\xaa\x88 \x02@\xf6\xd0\x02\x00\x00\x00\x0bB\xb6\x14@U"\x80\x00\x01{`\x00\x00\x00\x00M\xa3\xf8 \x15*\x00\x00\x00\x10n\xc0\x04\x00\x00\x02\x06\xc2\xa8)\x00\x96\x84\x80\x00\x00\x1b\x00\x00\x80@\x10\x87\xa7\xf0\x84\x10\xaa\x10\x00\x00D\x00\x00\x02 \x00\x8a\x06\xfa\xe0P\n-\x02@\x00\x12\x00\x00\x00\x00\x10@\x83\xdf\xa0\x00\x08\xaa@\x00\x00\x01H\x00\x05H\x04\x12\x01\xf7\x81P\x02T\t\x00\x00\x00 \x00\x00\x84\x10\x00\x00z\x00@)* \x00\x00\x01\n\xa0\x02 \x05\n\x00\x00\x05\x10\x84\xa8\x84\x80\x00\x00@\x14\x00\x92\x10\x80\x00\x04\x11@\tT\x00\x00\x00\x00\n@\x00\x08\x84@$\x00H\x00\x12Q\x02\x00\x00\x00\x00\x90\x02A\x12\xa8\n\xaa\x92\x10\x04\xa8\x10@\x00\x00\x04\x04\x00\x04I\x00\x04\x14H\x80"R\x01\x00\x00\x00!@\x00\x00$\xa0EB\x80\x08\x95hH\x00\x00\x00\x84\x10 \x05Z\x00\x00(\x00\x02\x00\xa1\x01\x00\x00\x04\x00@\x82\x00\xadH*\x92P\x00\xaaP\x00\x00\x00\x00\x11\x02\x01*\xad\x01\x00\x01\x01"\x11D\x08\x00\x00\x10\x80 \x00\x81W\x80J\x94\x04\x08\xa5 !\x00\x00\x00\x02\x00B*\xae\xa1\x00\x80\x10\x01\x08\xa4\x00\x00\x00\x00\x00\x84\x00\t[@"HA\x04E\x00\x84\x00\x00\x00\x10\x00\x01J\xd5\x82\x90\x02\x00!\x02\xa2\x00\x00\x00\x00\x00\x00\x00\x05~\xa0\x00 \x10\n)\x00\x11\x00\x00\x00\x00\x00\x00!U\x80\xa8\x88\x82\x80\x01\x00\x00\x00\x00\x00\x00H@\x11\xaa\xc0\x82\x00 *\n\x00\x00\x00\x00\x00\x00\x00\x00\n\xabb@ \x04\x00! \x84\x00\x00\x00\x00\x02@\xa5\x15A$\x04\x81(\n\x00\x00\x00\x00\x00\x00 \x01\x10\x02\xe0\x91\x02\x00\x00\x04\x00\x00\x00\x00\x00\x00\x01 \xa9\tQH@\x91 P\x00\x00\x00\x00\x00\x00\x08\x00\x00\xa0T\xa5\x00@\x80\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\xa2\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00 T\xa0\t\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00@\x02\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00*\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x10\x00\x00\x10\x02\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00@\x04\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x08@\x10\x00\x00\x00\x00'
with client:
@ -172,9 +173,9 @@ def test_apply_homescreen(client):
@pytest.mark.setup_client(pin=None)
def test_safety_checks(client):
def test_safety_checks(client: Client):
def get_bad_address():
btc.get_address(client, "Bitcoin", parse_path("m/44'"), show_display=True)
btc.get_address(client, "Bitcoin", parse_path("m/44h"), show_display=True)
assert client.features.safety_checks == messages.SafetyCheckLevel.Strict
@ -223,14 +224,14 @@ def test_safety_checks(client):
@pytest.mark.skip_t1
def test_experimental_features(client):
def test_experimental_features(client: Client):
def experimental_call():
btc.authorize_coinjoin(
client,
coordinator="www.example.com",
max_total_fee=10010,
fee_per_anonymity=5000000, # 0.005 %
n=parse_path("m/84'/1'/0'"),
max_total_fee=10_010,
fee_per_anonymity=5_000_000, # 0.005 %
n=parse_path("m/84h/1h/0h"),
coin_name="Testnet",
script_type=messages.InputScriptType.SPENDWITNESS,
)
@ -277,7 +278,7 @@ def test_experimental_features(client):
@pytest.mark.setup_client(pin=None)
def test_label_too_long(client):
def test_label_too_long(client: Client):
with pytest.raises(exceptions.TrezorFailure), client:
client.set_expected_responses([messages.Failure])
device.apply_settings(client, label="A" * 33)

View File

@ -19,6 +19,7 @@ import pytest
import shamir_mnemonic as shamir
from trezorlib import device, messages
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from trezorlib.messages import ButtonRequestType as B
@ -39,7 +40,7 @@ def click_info_button(debug):
@pytest.mark.skip_t1 # TODO we want this for t1 too
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC12)
def test_backup_bip39(client):
def test_backup_bip39(client: Client):
assert client.features.needs_backup is True
mnemonic = None
@ -82,7 +83,7 @@ def test_backup_bip39(client):
@pytest.mark.parametrize(
"click_info", [True, False], ids=["click_info", "no_click_info"]
)
def test_backup_slip39_basic(client, click_info: bool):
def test_backup_slip39_basic(client: Client, click_info: bool):
assert client.features.needs_backup is True
mnemonics = []
@ -150,7 +151,7 @@ def test_backup_slip39_basic(client, click_info: bool):
@pytest.mark.parametrize(
"click_info", [True, False], ids=["click_info", "no_click_info"]
)
def test_backup_slip39_advanced(client, click_info: bool):
def test_backup_slip39_advanced(client: Client, click_info: bool):
assert client.features.needs_backup is True
mnemonics = []
@ -234,7 +235,7 @@ def test_backup_slip39_advanced(client, click_info: bool):
# we only test this with bip39 because the code path is always the same
@pytest.mark.setup_client(no_backup=True)
def test_no_backup_fails(client):
def test_no_backup_fails(client: Client):
client.ensure_unlocked()
assert client.features.initialized is True
assert client.features.no_backup is True
@ -247,7 +248,7 @@ def test_no_backup_fails(client):
# we only test this with bip39 because the code path is always the same
@pytest.mark.setup_client(needs_backup=True)
def test_interrupt_backup_fails(client):
def test_interrupt_backup_fails(client: Client):
client.ensure_unlocked()
assert client.features.initialized is True
assert client.features.needs_backup is True
@ -273,7 +274,7 @@ def test_interrupt_backup_fails(client):
# we only test this with bip39 because the code path is always the same
@pytest.mark.setup_client(uninitialized=True)
def test_no_backup_show_entropy_fails(client):
def test_no_backup_show_entropy_fails(client: Client):
with pytest.raises(
TrezorFailure, match=r".*Can't show internal entropy when backup is skipped"
):

View File

@ -18,6 +18,7 @@ import pytest
from trezorlib import device, exceptions, messages
from trezorlib.client import MAX_PIN_LENGTH
from trezorlib.debuglink import TrezorClientDebugLink as Client
PinType = messages.PinMatrixRequestType
@ -30,7 +31,7 @@ WIPE_CODE_TOO_LONG = WIPE_CODE_MAX + "1"
pytestmark = pytest.mark.skip_t2
def _set_wipe_code(client, pin, wipe_code):
def _set_wipe_code(client: Client, pin, wipe_code):
# Set/change wipe code.
with client:
if client.features.pin_protection:
@ -56,7 +57,7 @@ def _set_wipe_code(client, pin, wipe_code):
device.change_wipe_code(client)
def _change_pin(client, old_pin, new_pin):
def _change_pin(client: Client, old_pin, new_pin):
assert client.features.pin_protection is True
with client:
client.use_pin_sequence([old_pin, new_pin, new_pin])
@ -66,14 +67,14 @@ def _change_pin(client, old_pin, new_pin):
return f.failure
def _check_wipe_code(client, pin, wipe_code):
def _check_wipe_code(client: Client, pin, wipe_code):
"""Check that wipe code is set by changing the PIN to it."""
f = _change_pin(client, pin, wipe_code)
assert isinstance(f, messages.Failure)
@pytest.mark.setup_client(pin=PIN4)
def test_set_remove_wipe_code(client):
def test_set_remove_wipe_code(client: Client):
# Check that wipe code protection status is not revealed in locked state.
assert client.features.wipe_code_protection is None
@ -107,7 +108,7 @@ def test_set_remove_wipe_code(client):
assert client.features.wipe_code_protection is False
def test_set_wipe_code_mismatch(client):
def test_set_wipe_code_mismatch(client: Client):
# Check that there is no wipe code protection.
client.ensure_unlocked()
assert client.features.wipe_code_protection is False
@ -132,7 +133,7 @@ def test_set_wipe_code_mismatch(client):
@pytest.mark.setup_client(pin=PIN4)
def test_set_wipe_code_to_pin(client):
def test_set_wipe_code_to_pin(client: Client):
# Check that wipe code protection status is not revealed in locked state.
assert client.features.wipe_code_protection is None
@ -155,7 +156,7 @@ def test_set_wipe_code_to_pin(client):
assert client.features.wipe_code_protection is False
def test_set_pin_to_wipe_code(client):
def test_set_pin_to_wipe_code(client: Client):
# Set wipe code.
_set_wipe_code(client, None, WIPE_CODE4)
@ -181,7 +182,7 @@ def test_set_pin_to_wipe_code(client):
@pytest.mark.parametrize("invalid_wipe_code", ("1204", "", WIPE_CODE_TOO_LONG))
def test_set_wipe_code_invalid(client, invalid_wipe_code):
def test_set_wipe_code_invalid(client: Client, invalid_wipe_code):
# Let's set the wipe code
ret = client.call_raw(messages.ChangeWipeCode())
assert isinstance(ret, messages.ButtonRequest)

View File

@ -18,6 +18,7 @@ import pytest
from trezorlib import btc, device, messages
from trezorlib.client import MAX_PIN_LENGTH, PASSPHRASE_TEST_PATH
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import Cancelled, TrezorFailure
PIN4 = "1234"
@ -28,7 +29,7 @@ WIPE_CODE_MAX = "".join(chr((i % 10) + ord("0")) for i in range(MAX_PIN_LENGTH))
pytestmark = pytest.mark.skip_t1
def _check_wipe_code(client, pin, wipe_code):
def _check_wipe_code(client: Client, pin, wipe_code):
client.init_device()
assert client.features.wipe_code_protection is True
@ -42,7 +43,7 @@ def _check_wipe_code(client, pin, wipe_code):
device.change_pin(client)
def _ensure_unlocked(client, pin):
def _ensure_unlocked(client: Client, pin):
with client:
client.use_pin_sequence([pin])
btc.get_address(client, "Testnet", PASSPHRASE_TEST_PATH)
@ -51,7 +52,7 @@ def _ensure_unlocked(client, pin):
@pytest.mark.setup_client(pin=PIN4)
def test_set_remove_wipe_code(client):
def test_set_remove_wipe_code(client: Client):
# Test set wipe code.
assert client.features.wipe_code_protection is None
@ -93,7 +94,7 @@ def test_set_remove_wipe_code(client):
assert client.features.wipe_code_protection is False
def test_set_wipe_code_mismatch(client):
def test_set_wipe_code_mismatch(client: Client):
# Let's set a wipe code.
def input_flow():
yield # do you want to set the wipe code?
@ -121,7 +122,7 @@ def test_set_wipe_code_mismatch(client):
@pytest.mark.setup_client(pin=PIN4)
def test_set_wipe_code_to_pin(client):
def test_set_wipe_code_to_pin(client: Client):
_ensure_unlocked(client, PIN4)
with client:
@ -136,7 +137,7 @@ def test_set_wipe_code_to_pin(client):
_check_wipe_code(client, PIN4, WIPE_CODE4)
def test_set_pin_to_wipe_code(client):
def test_set_pin_to_wipe_code(client: Client):
# Set wipe code.
with client:
client.set_expected_responses(

View File

@ -18,6 +18,7 @@ import pytest
from trezorlib import device, messages
from trezorlib.client import MAX_PIN_LENGTH
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
from ..common import get_test_address
@ -30,7 +31,7 @@ PIN_TOO_LONG = PIN_MAX + "1"
pytestmark = pytest.mark.skip_t2
def _check_pin(client, pin):
def _check_pin(client: Client, pin):
client.lock()
with client:
client.use_pin_sequence([pin])
@ -38,14 +39,14 @@ def _check_pin(client, pin):
get_test_address(client)
def _check_no_pin(client):
def _check_no_pin(client: Client):
client.lock()
with client:
client.set_expected_responses([messages.Address])
get_test_address(client)
def test_set_pin(client):
def test_set_pin(client: Client):
assert client.features.pin_protection is False
# Check that there's no PIN protection
@ -72,7 +73,7 @@ def test_set_pin(client):
@pytest.mark.setup_client(pin=PIN4)
def test_change_pin(client):
def test_change_pin(client: Client):
assert client.features.pin_protection is True
# Check that there's PIN protection
_check_pin(client, PIN4)
@ -99,7 +100,7 @@ def test_change_pin(client):
@pytest.mark.setup_client(pin=PIN4)
def test_remove_pin(client):
def test_remove_pin(client: Client):
assert client.features.pin_protection is True
# Check that there's PIN protection
_check_pin(client, PIN4)
@ -122,7 +123,7 @@ def test_remove_pin(client):
_check_no_pin(client)
def test_set_mismatch(client):
def test_set_mismatch(client: Client):
assert client.features.pin_protection is False
# Check that there's no PIN protection
_check_no_pin(client)
@ -148,7 +149,7 @@ def test_set_mismatch(client):
@pytest.mark.setup_client(pin=PIN4)
def test_change_mismatch(client):
def test_change_mismatch(client: Client):
assert client.features.pin_protection is True
# Let's set new PIN
@ -172,7 +173,7 @@ def test_change_mismatch(client):
@pytest.mark.parametrize("invalid_pin", ("1204", "", PIN_TOO_LONG))
def test_set_invalid(client, invalid_pin):
def test_set_invalid(client: Client, invalid_pin):
assert client.features.pin_protection is False
# Let's set an invalid PIN
@ -198,7 +199,7 @@ def test_set_invalid(client, invalid_pin):
@pytest.mark.parametrize("invalid_pin", ("1204", "", PIN_TOO_LONG))
@pytest.mark.setup_client(pin=PIN4)
def test_enter_invalid(client, invalid_pin):
def test_enter_invalid(client: Client, invalid_pin):
assert client.features.pin_protection is True
# use an invalid PIN

View File

@ -18,6 +18,7 @@ import pytest
from trezorlib import btc, device, messages
from trezorlib.client import MAX_PIN_LENGTH, PASSPHRASE_TEST_PATH
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import Cancelled, TrezorFailure
PIN4 = "1234"
@ -27,7 +28,7 @@ PIN_MAX = "".join(chr((i % 10) + ord("0")) for i in range(MAX_PIN_LENGTH))
pytestmark = pytest.mark.skip_t1
def _check_pin(client, pin):
def _check_pin(client: Client, pin):
client.lock()
assert client.features.pin_protection is True
assert client.features.unlocked is False
@ -38,7 +39,7 @@ def _check_pin(client, pin):
btc.get_address(client, "Testnet", PASSPHRASE_TEST_PATH)
def _check_no_pin(client):
def _check_no_pin(client: Client):
client.lock()
assert client.features.pin_protection is False
@ -47,7 +48,7 @@ def _check_no_pin(client):
btc.get_address(client, "Testnet", PASSPHRASE_TEST_PATH)
def test_set_pin(client):
def test_set_pin(client: Client):
assert client.features.pin_protection is False
# Check that there's no PIN protection
@ -67,7 +68,7 @@ def test_set_pin(client):
@pytest.mark.setup_client(pin=PIN4)
def test_change_pin(client):
def test_change_pin(client: Client):
assert client.features.pin_protection is True
# Check current PIN value
@ -89,7 +90,7 @@ def test_change_pin(client):
@pytest.mark.setup_client(pin=PIN4)
def test_remove_pin(client):
def test_remove_pin(client: Client):
assert client.features.pin_protection is True
# Check current PIN value
@ -109,7 +110,7 @@ def test_remove_pin(client):
_check_no_pin(client)
def test_set_failed(client):
def test_set_failed(client: Client):
assert client.features.pin_protection is False
# Check that there's no PIN protection
@ -141,7 +142,7 @@ def test_set_failed(client):
@pytest.mark.setup_client(pin=PIN4)
def test_change_failed(client):
def test_change_failed(client: Client):
assert client.features.pin_protection is True
# Check current PIN value
@ -175,7 +176,7 @@ def test_change_failed(client):
@pytest.mark.setup_client(pin=PIN4)
def test_change_invalid_current(client):
def test_change_invalid_current(client: Client):
assert client.features.pin_protection is True
# Check current PIN value

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import debuglink, device
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.messages import BackupType
from ..common import (
@ -29,7 +30,7 @@ from ..common import (
pytestmark = pytest.mark.setup_client(uninitialized=True)
def test_load_device_1(client):
def test_load_device_1(client: Client):
debuglink.load_device(
client,
mnemonic=MNEMONIC12,
@ -46,7 +47,7 @@ def test_load_device_1(client):
assert address == "mkqRFzxmkCGX9jxgpqqFHcxRUmLJcLDBer"
def test_load_device_2(client):
def test_load_device_2(client: Client):
debuglink.load_device(
client,
mnemonic=MNEMONIC12,
@ -68,7 +69,7 @@ def test_load_device_2(client):
@pytest.mark.skip_t1
def test_load_device_slip39_basic(client):
def test_load_device_slip39_basic(client: Client):
debuglink.load_device(
client,
mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6,
@ -80,7 +81,7 @@ def test_load_device_slip39_basic(client):
@pytest.mark.skip_t1
def test_load_device_slip39_advanced(client):
def test_load_device_slip39_advanced(client: Client):
debuglink.load_device(
client,
mnemonic=MNEMONIC_SLIP39_ADVANCED_20,
@ -91,7 +92,7 @@ def test_load_device_slip39_advanced(client):
assert client.features.backup_type == BackupType.Slip39_Advanced
def test_load_device_utf(client):
def test_load_device_utf(client: Client):
words_nfkd = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
words_nfc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
words_nfkc = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"

Some files were not shown because too many files have changed in this diff Show More