diff --git a/core/tests/ethereum_common.py b/core/tests/ethereum_common.py index a0ce8e83d1..2f480401e7 100644 --- a/core/tests/ethereum_common.py +++ b/core/tests/ethereum_common.py @@ -43,9 +43,9 @@ def make_payload( prefix: bytes = b"trzd1", data_type: EthereumDefinitionType = EthereumDefinitionType.NETWORK, timestamp: int = 0xFFFF_FFFF, - message: messages.EthereumNetworkInfo - | messages.EthereumTokenInfo - | bytes = make_network(), + message: ( + messages.EthereumNetworkInfo | messages.EthereumTokenInfo | bytes + ) = make_network(), ) -> bytes: payload = prefix payload += data_type.to_bytes(1, "little") diff --git a/core/tests/slip39_vectors.py b/core/tests/slip39_vectors.py index bd89c0c05c..8d5fe46e2b 100644 --- a/core/tests/slip39_vectors.py +++ b/core/tests/slip39_vectors.py @@ -283,7 +283,7 @@ vectors = [ [ "herald flea academic cage avoid space trend estate dryer hairy evoke eyebrow improve airline artwork garlic premium duration prevent oven", "herald flea academic client blue skunk class goat luxury deny presence impulse graduate clay join blanket bulge survive dish necklace", - "herald flea academic acne advance fused brother frozen broken game ranked ajar already believe check install theory angry exercise adult" + "herald flea academic acne advance fused brother frozen broken game ranked ajar already believe check install theory angry exercise adult", ], "ad6f2ad8b59bbbaa01369b9006208d9a", ], @@ -296,7 +296,7 @@ vectors = [ [ [ "enemy favorite academic acid cowboy phrase havoc level response walnut budget painting inside trash adjust froth kitchen learn tidy punish", - "enemy favorite academic always academic sniff script carpet romp kind promise scatter center unfair training emphasis evening belong fake enforce" + "enemy favorite academic always academic sniff script carpet romp kind promise scatter center unfair training emphasis evening belong fake enforce", ], "48b1a4b80b8c209ad42c33672bdaa428", ], @@ -309,7 +309,7 @@ vectors = [ [ [ "western apart academic always artist resident briefing sugar woman oven coding club ajar merit pecan answer prisoner artist fraction amount desktop mild false necklace muscle photo wealthy alpha category unwrap spew losing making", - "western apart academic acid answer ancient auction flip image penalty oasis beaver multiple thunder problem switch alive heat inherit superior teaspoon explain blanket pencil numb lend punish endless aunt garlic humidity kidney observe" + "western apart academic acid answer ancient auction flip image penalty oasis beaver multiple thunder problem switch alive heat inherit superior teaspoon explain blanket pencil numb lend punish endless aunt garlic humidity kidney observe", ], "8dc652d6d6cd370d8c963141f6d79ba440300f25c467302c1d966bff8f62300d", ], diff --git a/core/tests/test_apps.bitcoin.approver.py b/core/tests/test_apps.bitcoin.approver.py index 22888546f0..8086fd8e2d 100644 --- a/core/tests/test_apps.bitcoin.approver.py +++ b/core/tests/test_apps.bitcoin.approver.py @@ -48,9 +48,7 @@ class TestApprover(unittest.TestCase): self.msg_auth = AuthorizeCoinJoin( coordinator=self.coordinator_name, max_rounds=10, - max_coordinator_fee_rate=int( - self.fee_rate_percent * 10**FEE_RATE_DECIMALS - ), + max_coordinator_fee_rate=int(self.fee_rate_percent * 10**FEE_RATE_DECIMALS), max_fee_per_kvbyte=7000, address_n=[H_(10025), H_(0), H_(0), H_(1)], coin_name=self.coin.coin_name, @@ -155,7 +153,11 @@ class TestApprover(unittest.TestCase): if txo.address_n: await_result(approver.add_change_output(txo, script_pubkey=bytes(22))) else: - await_result(approver.add_external_output(txo, script_pubkey=bytes(22), tx_info=tx_info)) + await_result( + approver.add_external_output( + txo, script_pubkey=bytes(22), tx_info=tx_info + ) + ) await_result(approver.approve_tx(tx_info, [], None)) diff --git a/core/tests/test_apps.bitcoin.change_detector.py b/core/tests/test_apps.bitcoin.change_detector.py index 16e6ca2103..56629207da 100644 --- a/core/tests/test_apps.bitcoin.change_detector.py +++ b/core/tests/test_apps.bitcoin.change_detector.py @@ -1,14 +1,9 @@ from common import H_, unittest # isort:skip from ubinascii import unhexlify -from trezor.enums import InputScriptType, OutputScriptType, MultisigPubkeysOrder +from trezor.enums import InputScriptType, MultisigPubkeysOrder, OutputScriptType from trezor.enums.MultisigPubkeysOrder import LEXICOGRAPHIC, PRESERVED -from trezor.messages import ( - TxInput, - TxOutput, - HDNodeType, - MultisigRedeemScriptType, -) +from trezor.messages import HDNodeType, MultisigRedeemScriptType, TxInput, TxOutput from apps.bitcoin.sign_tx.change_detector import ChangeDetector @@ -17,8 +12,12 @@ xpub1 = HDNodeType( depth=2, fingerprint=50263508, child_num=0, - chain_code=unhexlify("8eb1f96a45dcb693dbad61f5184871d999127a37f1b0d4dae9964eaf3fb0e15b"), - public_key=unhexlify("03922315cd2d2d874e4c55add2e0ea41af9c2957f02c0abe0f55285d364a067b61"), + chain_code=unhexlify( + "8eb1f96a45dcb693dbad61f5184871d999127a37f1b0d4dae9964eaf3fb0e15b" + ), + public_key=unhexlify( + "03922315cd2d2d874e4c55add2e0ea41af9c2957f02c0abe0f55285d364a067b61" + ), ) # all all all all all all all all all all all all/45/1 @@ -26,8 +25,12 @@ xpub2 = HDNodeType( depth=2, fingerprint=50263508, child_num=1, - chain_code=unhexlify("acad50a7e52e44841d42bec6886df516974f8d366bc471a8515dfc69a6692700"), - public_key=unhexlify("02e6f3bf3093b45705e3d838490377e0d99eed911ca01990d1e94acd445dee59e8"), + chain_code=unhexlify( + "acad50a7e52e44841d42bec6886df516974f8d366bc471a8515dfc69a6692700" + ), + public_key=unhexlify( + "02e6f3bf3093b45705e3d838490377e0d99eed911ca01990d1e94acd445dee59e8" + ), ) # all all all all all all all all all all all all/45/2 @@ -35,12 +38,18 @@ xpub3 = HDNodeType( depth=2, fingerprint=50263508, child_num=2, - chain_code=unhexlify("5204b124a264b0bbf86360e365f0c9a0cb6e3ea57dda97196af015d64ccfa6b1"), - public_key=unhexlify("021cd5d138ba442c7f8ee9a2b8f4e254dc599a57d42c69b7194074135a0ba82926"), + chain_code=unhexlify( + "5204b124a264b0bbf86360e365f0c9a0cb6e3ea57dda97196af015d64ccfa6b1" + ), + public_key=unhexlify( + "021cd5d138ba442c7f8ee9a2b8f4e254dc599a57d42c69b7194074135a0ba82926" + ), ) -def get_multisig(path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder) -> MultisigRedeemScriptType: +def get_multisig( + path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder +) -> MultisigRedeemScriptType: return MultisigRedeemScriptType( nodes=xpubs, signatures=b"" * len(xpubs), @@ -60,7 +69,9 @@ def get_singlesig_input(path: list[int]) -> TxInput: ) -def get_multisig_input(path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder) -> TxInput: +def get_multisig_input( + path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder +) -> TxInput: return TxInput( address_n=path, amount=1_000_000, @@ -71,7 +82,9 @@ def get_multisig_input(path: list[int], xpubs: list[HDNodeType], pubkeys_order: ) -def get_internal_multisig_output(path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder) -> TxOutput: +def get_internal_multisig_output( + path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder +) -> TxOutput: return TxOutput( address_n=path, amount=1_000_000, @@ -108,17 +121,42 @@ class TestChangeDetector(unittest.TestCase): self.d.add_input(get_singlesig_input([H_(45), 0, 1, 1])) # Same outputs as inputs - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is True - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 1])) is True - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 1, 0])) is True - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 1, 1])) is True + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) + is True + ) + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 1])) + is True + ) + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 1, 0])) + is True + ) + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 1, 1])) + is True + ) # Different account index - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) is False + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) + is False + ) # Multisig instead of singlesig - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], PRESERVED)) is False - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], LEXICOGRAPHIC)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], PRESERVED) + ) + is False + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], LEXICOGRAPHIC) + ) + is False + ) # External output assert self.d.output_is_change(get_external_singlesig_output()) is False @@ -129,150 +167,432 @@ class TestChangeDetector(unittest.TestCase): self.d.add_input(get_singlesig_input([H_(45), 1, 0, 0])) # Same outputs as inputs - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) is False + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) + is False + ) + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) + is False + ) # Multisig instead of singlesig - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 1, 0, 0], [xpub1], PRESERVED)) is False - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 1, 0, 0], [xpub1], LEXICOGRAPHIC)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output([H_(45), 1, 0, 0], [xpub1], PRESERVED) + ) + is False + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output([H_(45), 1, 0, 0], [xpub1], LEXICOGRAPHIC) + ) + is False + ) # External output assert self.d.output_is_change(get_external_singlesig_output()) is False def test_unsorted_multisig(self): # Different change and account index - self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) - self.d.add_input(get_multisig_input([H_(45), 0, 0, 1], [xpub1, xpub2], PRESERVED)) - self.d.add_input(get_multisig_input([H_(45), 0, 1, 0], [xpub1, xpub2], PRESERVED)) - self.d.add_input(get_multisig_input([H_(45), 0, 1, 1], [xpub1, xpub2], PRESERVED)) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED) + ) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 1], [xpub1, xpub2], PRESERVED) + ) + self.d.add_input( + get_multisig_input([H_(45), 0, 1, 0], [xpub1, xpub2], PRESERVED) + ) + self.d.add_input( + get_multisig_input([H_(45), 0, 1, 1], [xpub1, xpub2], PRESERVED) + ) # Same outputs as inputs - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is True - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 1], [xpub1, xpub2], PRESERVED)) is True - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 1, 0], [xpub1, xpub2], PRESERVED)) is True - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 1, 1], [xpub1, xpub2], PRESERVED)) is True + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED + ) + ) + is True + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 1], [xpub1, xpub2], PRESERVED + ) + ) + is True + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 1, 0], [xpub1, xpub2], PRESERVED + ) + ) + is True + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 1, 1], [xpub1, xpub2], PRESERVED + ) + ) + is True + ) # Singlesig instead of multisig - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) + is False + ) # Different account index - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) is False + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) + is False + ) # Different order of xpubs - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED + ) + ) + is False + ) # Sorted instead of unsorted - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC + ) + ) + is False + ) # Different xpubs - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED + ) + ) + is False + ) # External output assert self.d.output_is_change(get_external_singlesig_output()) is False def test_sorted_multisig(self): # Different change and account index - self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) - self.d.add_input(get_multisig_input([H_(45), 0, 0, 1], [xpub1, xpub2], LEXICOGRAPHIC)) - self.d.add_input(get_multisig_input([H_(45), 0, 1, 0], [xpub1, xpub2], LEXICOGRAPHIC)) - self.d.add_input(get_multisig_input([H_(45), 0, 1, 1], [xpub1, xpub2], LEXICOGRAPHIC)) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC) + ) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 1], [xpub1, xpub2], LEXICOGRAPHIC) + ) + self.d.add_input( + get_multisig_input([H_(45), 0, 1, 0], [xpub1, xpub2], LEXICOGRAPHIC) + ) + self.d.add_input( + get_multisig_input([H_(45), 0, 1, 1], [xpub1, xpub2], LEXICOGRAPHIC) + ) # Same outputs as inputs - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is True - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 1], [xpub1, xpub2], LEXICOGRAPHIC)) is True - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 1, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is True - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 1, 1], [xpub1, xpub2], LEXICOGRAPHIC)) is True + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC + ) + ) + is True + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 1], [xpub1, xpub2], LEXICOGRAPHIC + ) + ) + is True + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 1, 0], [xpub1, xpub2], LEXICOGRAPHIC + ) + ) + is True + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 1, 1], [xpub1, xpub2], LEXICOGRAPHIC + ) + ) + is True + ) # Singlesig instead of multisig - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) + is False + ) # Different account index - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) is False + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) + is False + ) # Different order of xpubs - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC)) is True + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC + ) + ) + is True + ) # Unsorted instead of sorted - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED + ) + ) + is False + ) # Different xpubs - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC + ) + ) + is False + ) # External output assert self.d.output_is_change(get_external_singlesig_output()) is False def test_unsorted_multisig_different_xpubs_order(self): # Different order of xpubs - self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) - self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED)) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED) + ) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED) + ) # Same ouputs as inputs - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is False - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED + ) + ) + is False + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED + ) + ) + is False + ) # Sorted instead of unsorted - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is False - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC + ) + ) + is False + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC + ) + ) + is False + ) # Singlesig instead of multisig - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) + is False + ) # External output assert self.d.output_is_change(get_external_singlesig_output()) is False def test_sorted_multisig_different_xpubs_order(self): # Different order of xpubs - self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) - self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC)) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC) + ) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC) + ) # Same ouputs as inputs - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is True - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC)) is True + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC + ) + ) + is True + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC + ) + ) + is True + ) # Sorted instead of unsorted - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is False - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED + ) + ) + is False + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED + ) + ) + is False + ) # Singlesig instead of multisig - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) + is False + ) # External output assert self.d.output_is_change(get_external_singlesig_output()) is False def test_unsorted_multisig_different_xpubs(self): # Different xpubs - self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) - self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED)) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED) + ) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED) + ) # Same ouputs as inputs - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is False - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED + ) + ) + is False + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED + ) + ) + is False + ) # Sorted instead of unsorted - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is False - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC + ) + ) + is False + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC + ) + ) + is False + ) # Singlesig instead of multisig - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) + is False + ) # External output assert self.d.output_is_change(get_external_singlesig_output()) is False def test_sorted_multisig_different_xpubs(self): # Different xpubs - self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) - self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC)) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC) + ) + self.d.add_input( + get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC) + ) # Same ouputs as inputs - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is False - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC + ) + ) + is False + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC + ) + ) + is False + ) # Sorted instead of unsorted - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is False - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED + ) + ) + is False + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output( + [H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED + ) + ) + is False + ) # Singlesig instead of multisig - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) + is False + ) # External output assert self.d.output_is_change(get_external_singlesig_output()) is False @@ -282,11 +602,24 @@ class TestChangeDetector(unittest.TestCase): self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1], LEXICOGRAPHIC)) # Same ouputs as inputs - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], PRESERVED)) is False - assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], LEXICOGRAPHIC)) is False + assert ( + self.d.output_is_change( + get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], PRESERVED) + ) + is False + ) + assert ( + self.d.output_is_change( + get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], LEXICOGRAPHIC) + ) + is False + ) # Singlesig instead of multisig - assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False + assert ( + self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) + is False + ) # External output assert self.d.output_is_change(get_external_singlesig_output()) is False diff --git a/core/tests/test_apps.bitcoin.keychain.py b/core/tests/test_apps.bitcoin.keychain.py index 85727df560..232d2bf01d 100644 --- a/core/tests/test_apps.bitcoin.keychain.py +++ b/core/tests/test_apps.bitcoin.keychain.py @@ -1,14 +1,13 @@ # flake8: noqa: F403,F405 from common import * # isort:skip -from storage import cache_common +from storage import cache_codec, cache_common from trezor import wire from trezor.crypto import bip39 from trezor.wire import context +from trezor.wire.codec.codec_context import CodecContext from apps.bitcoin.keychain import _get_coin_by_name, _get_keychain_for_coin -from trezor.wire.codec.codec_context import CodecContext -from storage import cache_codec class TestBitcoinKeychain(unittest.TestCase): diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py index 49743b0516..1c1ebc8444 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py @@ -113,7 +113,9 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)] + ), True, TxRequest( request_type=TXOUTPUT, @@ -121,7 +123,9 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)] + ), True, helpers.UiConfirmTotal( 12300000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3] @@ -310,7 +314,9 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)] + ), True, TxRequest( request_type=TXOUTPUT, diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py index dac240f903..a1b1ef683a 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py @@ -124,7 +124,9 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(84), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out1, coin, AmountUnit.BITCOIN, 0, False, [H_(84), H_(1), H_(0)] + ), True, TxRequest( request_type=TXOUTPUT, @@ -132,7 +134,9 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False, [H_(84), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out2, coin, AmountUnit.BITCOIN, 1, False, [H_(84), H_(1), H_(0)] + ), True, helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False), True, @@ -333,7 +337,9 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(84), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out1, coin, AmountUnit.BITCOIN, 0, False, [H_(84), H_(1), H_(0)] + ), True, TxRequest( request_type=TXOUTPUT, diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py index 3187c65ec8..289e7f75e3 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py @@ -115,7 +115,9 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)] + ), True, TxRequest( request_type=TXOUTPUT, @@ -123,7 +125,9 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)] + ), True, helpers.UiConfirmTotal( 123445789 + 11000, @@ -318,7 +322,9 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)] + ), True, TxRequest( request_type=TXOUTPUT, @@ -532,7 +538,9 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)] + ), True, TxRequest( request_type=TXOUTPUT, diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py index 549fa2d04b..4130cd4e6c 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py @@ -124,7 +124,9 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)] + ), True, TxRequest( request_type=TXOUTPUT, @@ -132,7 +134,9 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)] + ), True, helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False), True, @@ -337,7 +341,9 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)] + ), True, TxRequest( request_type=TXOUTPUT, diff --git a/core/tests/test_apps.bitcoin.signtx.fee_threshold.py b/core/tests/test_apps.bitcoin.signtx.fee_threshold.py index 9352c63333..b0ef6e57e7 100644 --- a/core/tests/test_apps.bitcoin.signtx.fee_threshold.py +++ b/core/tests/test_apps.bitcoin.signtx.fee_threshold.py @@ -181,7 +181,9 @@ class TestSignTxFeeThreshold(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin_bitcoin, AmountUnit.BITCOIN, 0, False, None), + helpers.UiConfirmOutput( + out1, coin_bitcoin, AmountUnit.BITCOIN, 0, False, None + ), True, helpers.UiConfirmMultipleAccounts(), True, diff --git a/core/tests/test_apps.bitcoin.signtx.py b/core/tests/test_apps.bitcoin.signtx.py index a2dfe23ad4..ec3ee4286a 100644 --- a/core/tests/test_apps.bitcoin.signtx.py +++ b/core/tests/test_apps.bitcoin.signtx.py @@ -112,7 +112,9 @@ class TestSignTx(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin_bitcoin, AmountUnit.BITCOIN, 0, False, [H_(44), H_(0), H_(0)]), + helpers.UiConfirmOutput( + out1, coin_bitcoin, AmountUnit.BITCOIN, 0, False, [H_(44), H_(0), H_(0)] + ), True, helpers.UiConfirmTotal( 3_801_747, diff --git a/core/tests/test_apps.bitcoin.signtx_decred.py b/core/tests/test_apps.bitcoin.signtx_decred.py index 8d55c1d63d..58b52fa369 100644 --- a/core/tests/test_apps.bitcoin.signtx_decred.py +++ b/core/tests/test_apps.bitcoin.signtx_decred.py @@ -1,7 +1,7 @@ # flake8: noqa: F403,F405 from common import * # isort:skip -if utils.INTERNAL_MODEL in ("T2T1", ): # pylint: disable=internal-model-tuple-comparison +if utils.INTERNAL_MODEL in ("T2T1",): # pylint: disable=internal-model-tuple-comparison from trezor.crypto import bip39 from trezor.enums import AmountUnit, OutputScriptType from trezor.enums.RequestType import TXFINISHED, TXINPUT, TXMETA, TXOUTPUT @@ -113,7 +113,9 @@ class TestSignTxDecred(unittest.TestCase): ), ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin_decred, AmountUnit.BITCOIN, 0, False, [H_(44), H_(1), H_(0)]), + helpers.UiConfirmOutput( + out1, coin_decred, AmountUnit.BITCOIN, 0, False, [H_(44), H_(1), H_(0)] + ), True, helpers.UiConfirmTotal( 200_000_000, diff --git a/core/tests/test_apps.bitcoin.signtx_grs.py b/core/tests/test_apps.bitcoin.signtx_grs.py index 6320937533..15fe027f3d 100644 --- a/core/tests/test_apps.bitcoin.signtx_grs.py +++ b/core/tests/test_apps.bitcoin.signtx_grs.py @@ -113,7 +113,9 @@ class TestSignTx_GRS(unittest.TestCase): serialized=EMPTY_SERIALIZED, ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(44), H_(17), H_(0)]), + helpers.UiConfirmOutput( + out1, coin, AmountUnit.BITCOIN, 0, False, [H_(44), H_(17), H_(0)] + ), True, helpers.UiConfirmTotal( 210016, 192, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3] diff --git a/core/tests/test_apps.cardano.address.py b/core/tests/test_apps.cardano.address.py index c5575a6fbf..22ad3b37dc 100644 --- a/core/tests/test_apps.cardano.address.py +++ b/core/tests/test_apps.cardano.address.py @@ -192,7 +192,9 @@ class TestCardanoAddress(unittest.TestCase): ] passphrase = b"TREZOR" identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics) - master_secret = slip39.decrypt(ems, passphrase, exponent, identifier, extendable) + master_secret = slip39.decrypt( + ems, passphrase, exponent, identifier, extendable + ) node = cardano.from_seed_slip23(master_secret) @@ -266,7 +268,9 @@ class TestCardanoAddress(unittest.TestCase): ] passphrase = b"TREZOR" identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics) - master_secret = slip39.decrypt(ems, passphrase, exponent, identifier, extendable) + master_secret = slip39.decrypt( + ems, passphrase, exponent, identifier, extendable + ) node = cardano.from_seed_slip23(master_secret) diff --git a/core/tests/test_apps.cardano.get_public_key.py b/core/tests/test_apps.cardano.get_public_key.py index 61e46277c1..ae5850bd2d 100644 --- a/core/tests/test_apps.cardano.get_public_key.py +++ b/core/tests/test_apps.cardano.get_public_key.py @@ -146,7 +146,9 @@ class TestCardanoGetPublicKey(unittest.TestCase): ] passphrase = b"TREZOR" identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics) - master_secret = slip39.decrypt(ems, passphrase, exponent, identifier, extendable) + master_secret = slip39.decrypt( + ems, passphrase, exponent, identifier, extendable + ) node = cardano.from_seed_slip23(master_secret) @@ -195,7 +197,9 @@ class TestCardanoGetPublicKey(unittest.TestCase): ] passphrase = b"TREZOR" identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics) - master_secret = slip39.decrypt(ems, passphrase, exponent, identifier, extendable) + master_secret = slip39.decrypt( + ems, passphrase, exponent, identifier, extendable + ) node = cardano.from_seed_slip23(master_secret) diff --git a/core/tests/test_apps.common.cbor.py b/core/tests/test_apps.common.cbor.py index dd0f588c1a..ae62d8e180 100644 --- a/core/tests/test_apps.common.cbor.py +++ b/core/tests/test_apps.common.cbor.py @@ -34,19 +34,19 @@ class TestCardanoCbor(unittest.TestCase): def test_create_tagged_set_header(self): test_vectors = [ - (0, 'd9010280'), - (23, 'd9010297'), - ((2 ** 8) - 1, 'd9010298ff'), - ((2 ** 16) - 1, 'd9010299ffff'), - ((2 ** 32) - 1, 'd901029affffffff'), - ((2 ** 64) - 1, 'd901029bffffffffffffffff'), + (0, "d9010280"), + (23, "d9010297"), + ((2**8) - 1, "d9010298ff"), + ((2**16) - 1, "d9010299ffff"), + ((2**32) - 1, "d901029affffffff"), + ((2**64) - 1, "d901029bffffffffffffffff"), ] for val, header_hex in test_vectors: header = unhexlify(header_hex) self.assertEqual(create_tagged_set_header(val), header) with self.assertRaises(NotImplementedError): - create_tagged_set_header(2 ** 64) + create_tagged_set_header(2**64) def test_create_map_header(self): test_vectors = [ diff --git a/core/tests/test_apps.common.keychain.py b/core/tests/test_apps.common.keychain.py index 9175091081..f54f64d74f 100644 --- a/core/tests/test_apps.common.keychain.py +++ b/core/tests/test_apps.common.keychain.py @@ -2,17 +2,16 @@ from common import * # isort:skip from mock_storage import mock_storage -from storage import cache, cache_common +from storage import cache, cache_codec, cache_common from trezor import wire from trezor.crypto import bip39 from trezor.enums import SafetyCheckLevel from trezor.wire import context +from trezor.wire.codec.codec_context import CodecContext from apps.common import safety_checks from apps.common.keychain import Keychain, LRUCache, get_keychain, with_slip44_keychain from apps.common.paths import PATTERN_SEP5, PathSchema -from trezor.wire.codec.codec_context import CodecContext -from storage import cache_codec class TestKeychain(unittest.TestCase): diff --git a/core/tests/test_apps.ethereum.keychain.py b/core/tests/test_apps.ethereum.keychain.py index 3696e134f0..3215aba267 100644 --- a/core/tests/test_apps.ethereum.keychain.py +++ b/core/tests/test_apps.ethereum.keychain.py @@ -3,15 +3,14 @@ from common import * # isort:skip import unittest -from storage import cache_common +from storage import cache_codec, cache_common from trezor import wire from trezor.crypto import bip39 from trezor.wire import context +from trezor.wire.codec.codec_context import CodecContext from apps.common.keychain import get_keychain from apps.common.paths import HARDENED -from trezor.wire.codec.codec_context import CodecContext -from storage import cache_codec if not utils.BITCOIN_ONLY: from ethereum_common import encode_network, make_network diff --git a/core/tests/test_apps.ethereum.layout.py b/core/tests/test_apps.ethereum.layout.py index 61fdd7e0e4..b160ade4ed 100644 --- a/core/tests/test_apps.ethereum.layout.py +++ b/core/tests/test_apps.ethereum.layout.py @@ -10,6 +10,7 @@ if not utils.BITCOIN_ONLY: ETH = networks.by_chain_id(1) + @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestFormatEthereumAmount(unittest.TestCase): def test_denominations(self): diff --git a/core/tests/test_apps.thp.credential_manager.py b/core/tests/test_apps.thp.credential_manager.py index f62aa3bb9d..267707d374 100644 --- a/core/tests/test_apps.thp.credential_manager.py +++ b/core/tests/test_apps.thp.credential_manager.py @@ -1,12 +1,12 @@ # flake8: noqa: F403,F405 from common import * # isort: skip -from trezor import config, utils -from trezor import log +from trezor import config, log, utils if utils.USE_THP: - from apps.thp import credential_manager from trezor.messages import ThpCredentialMetadata + from apps.thp import credential_manager + def _issue_credential(host_name: str, host_static_pubkey: bytes) -> bytes: metadata = ThpCredentialMetadata(host_name=host_name) return credential_manager.issue_credential(host_static_pubkey, metadata) diff --git a/core/tests/test_storage.py b/core/tests/test_storage.py index 5e697c5cd6..348ff144d9 100644 --- a/core/tests/test_storage.py +++ b/core/tests/test_storage.py @@ -4,6 +4,7 @@ from common import * # isort:skip from storage import device from trezor import config, utils + class TestConfig(unittest.TestCase): def setUp(self): @@ -39,7 +40,7 @@ class TestConfig(unittest.TestCase): def test_cred_auth_key_counter_overflow(self): from storage import common - from storage.device import _NAMESPACE, _CRED_AUTH_KEY_COUNTER + from storage.device import _CRED_AUTH_KEY_COUNTER, _NAMESPACE common.set(_NAMESPACE, _CRED_AUTH_KEY_COUNTER, b"\xff\xff\xff\xfe") device.increment_cred_auth_key_counter() diff --git a/core/tests/test_trezor.crypto.aesgcm.py b/core/tests/test_trezor.crypto.aesgcm.py index 54cc3c0bd5..9f2bc8164e 100644 --- a/core/tests/test_trezor.crypto.aesgcm.py +++ b/core/tests/test_trezor.crypto.aesgcm.py @@ -116,7 +116,7 @@ class TestCryptoAes(unittest.TestCase): # Decrypt by chunks and add authenticated data by chunks. ctx = aesgcm(key, iv) - returned = ctx.decrypt_in_place(memoryview(buffer)[: chunk1_length]) + returned = ctx.decrypt_in_place(memoryview(buffer)[:chunk1_length]) self.assertEqual(returned, chunk1_length) ctx.auth(aad[:17]) returned = ctx.decrypt_in_place(memoryview(buffer)[chunk1_length:]) @@ -128,7 +128,7 @@ class TestCryptoAes(unittest.TestCase): # Encrypt by chunks and add authenticated data by chunks. ctx.reset(iv) ctx.auth(aad[:7]) - returned = ctx.encrypt_in_place(memoryview(buffer)[: chunk1_length]) + returned = ctx.encrypt_in_place(memoryview(buffer)[:chunk1_length]) self.assertEqual(returned, chunk1_length) ctx.auth(aad[7:]) returned = ctx.encrypt_in_place(memoryview(buffer)[chunk1_length:]) diff --git a/core/tests/test_trezor.crypto.base32.py b/core/tests/test_trezor.crypto.base32.py index 69db5706df..e06cd7f638 100644 --- a/core/tests/test_trezor.crypto.base32.py +++ b/core/tests/test_trezor.crypto.base32.py @@ -1,5 +1,5 @@ # flake8: noqa: F403,F405 -from common import * # isort:skip +from common import * # isort:skip from trezor.crypto import base32 @@ -31,8 +31,10 @@ class TestCryptoBase32(unittest.TestCase): ("中文12".encode(), "4S4K3ZUWQ4YTE==="), ("aécio".encode(), "MHB2SY3JN4======"), ("𠜎".encode(), "6CQJZDQ="), - ("Base64是一種基於64個可列印字元來表示二進制資料的表示方法".encode(), - "IJQXGZJWGTTJRL7EXCAOPKFO4WP3VZUWXQ3DJZMARPSY7L7FRCL6LDNQ4WWZPZMFQPSL5BXIUGUOPJF24S5IZ2MAWLSYRNXIWOD6NFUZ46NIJ2FBVDT2JOXGS246NM4V"), + ( + "Base64是一種基於64個可列印字元來表示二進制資料的表示方法".encode(), + "IJQXGZJWGTTJRL7EXCAOPKFO4WP3VZUWXQ3DJZMARPSY7L7FRCL6LDNQ4WWZPZMFQPSL5BXIUGUOPJF24S5IZ2MAWLSYRNXIWOD6NFUZ46NIJ2FBVDT2JOXGS246NM4V", + ), ] def test_encode(self): diff --git a/core/tests/test_trezor.crypto.bech32.py b/core/tests/test_trezor.crypto.bech32.py index ca8c195e20..e9d56bcad5 100644 --- a/core/tests/test_trezor.crypto.bech32.py +++ b/core/tests/test_trezor.crypto.bech32.py @@ -202,7 +202,7 @@ class TestCryptoBech32(unittest.TestCase): def test_valid_address(self): """Test whether valid addresses decode to the correct output.""" - for (address, hexscript) in VALID_ADDRESS: + for address, hexscript in VALID_ADDRESS: hrp = "tb" if address.startswith("tb1") else "bc" witver, witprog = bech32.decode(hrp, address) self.assertIsNotNone(witver) diff --git a/core/tests/test_trezor.crypto.elligator2.py b/core/tests/test_trezor.crypto.elligator2.py index f68352fe9d..11ecbf8615 100644 --- a/core/tests/test_trezor.crypto.elligator2.py +++ b/core/tests/test_trezor.crypto.elligator2.py @@ -11,30 +11,53 @@ class TestCryptoElligator2(unittest.TestCase): # https://elligator.org/vectors/curve25519_direct.vec vectors = [ - ("0000000000000000000000000000000000000000000000000000000000000000", - "0000000000000000000000000000000000000000000000000000000000000000"), - ("66665895c5bc6e44ba8d65fd9307092e3244bf2c18877832bd568cb3a2d38a12", - "04d44290d13100b2c25290c9343d70c12ed4813487a07ac1176daa5925e7975e"), - ("673a505e107189ee54ca93310ac42e4545e9e59050aaac6f8b5f64295c8ec02f", - "242ae39ef158ed60f20b89396d7d7eef5374aba15dc312a6aea6d1e57cacf85e"), - ("990b30e04e1c3620b4162b91a33429bddb9f1b70f1da6e5f76385ed3f98ab131", - "998e98021eb4ee653effaa992f3fae4b834de777a953271baaa1fa3fef6b776e"), - ("341a60725b482dd0de2e25a585b208433044bc0a1ba762442df3a0e888ca063c", - "683a71d7fca4fc6ad3d4690108be808c2e50a5af3174486741d0a83af52aeb01"), - ("922688fa428d42bc1fa8806998fbc5959ae801817e85a42a45e8ec25a0d7541a", - "696f341266c64bcfa7afa834f8c34b2730be11c932e08474d1a22f26ed82410b"), - ("0d3b0eb88b74ed13d5f6a130e03c4ad607817057dc227152827c0506a538bb3a", - "0b00df174d9fb0b6ee584d2cf05613130bad18875268c38b377e86dfefef177f"), - ("01a3ea5658f4e00622eeacf724e0bd82068992fae66ed2b04a8599be16662e35", - "7ae4c58bc647b5646c9f5ae4c2554ccbf7c6e428e7b242a574a5a9c293c21f7e"), - ("1d991dff82a84afe97874c0f03a60a56616a15212fbe10d6c099aa3afcfabe35", - "f81f235696f81df90ac2fc861ceee517bff611a394b5be5faaee45584642fb0a"), - ("185435d2b005a3b63f3187e64a1ef3582533e1958d30e4e4747b4d1d3376c728", - "f938b1b320abb0635930bd5d7ced45ae97fa8b5f71cc21d87b4c60905c125d34"), + ( + "0000000000000000000000000000000000000000000000000000000000000000", + "0000000000000000000000000000000000000000000000000000000000000000", + ), + ( + "66665895c5bc6e44ba8d65fd9307092e3244bf2c18877832bd568cb3a2d38a12", + "04d44290d13100b2c25290c9343d70c12ed4813487a07ac1176daa5925e7975e", + ), + ( + "673a505e107189ee54ca93310ac42e4545e9e59050aaac6f8b5f64295c8ec02f", + "242ae39ef158ed60f20b89396d7d7eef5374aba15dc312a6aea6d1e57cacf85e", + ), + ( + "990b30e04e1c3620b4162b91a33429bddb9f1b70f1da6e5f76385ed3f98ab131", + "998e98021eb4ee653effaa992f3fae4b834de777a953271baaa1fa3fef6b776e", + ), + ( + "341a60725b482dd0de2e25a585b208433044bc0a1ba762442df3a0e888ca063c", + "683a71d7fca4fc6ad3d4690108be808c2e50a5af3174486741d0a83af52aeb01", + ), + ( + "922688fa428d42bc1fa8806998fbc5959ae801817e85a42a45e8ec25a0d7541a", + "696f341266c64bcfa7afa834f8c34b2730be11c932e08474d1a22f26ed82410b", + ), + ( + "0d3b0eb88b74ed13d5f6a130e03c4ad607817057dc227152827c0506a538bb3a", + "0b00df174d9fb0b6ee584d2cf05613130bad18875268c38b377e86dfefef177f", + ), + ( + "01a3ea5658f4e00622eeacf724e0bd82068992fae66ed2b04a8599be16662e35", + "7ae4c58bc647b5646c9f5ae4c2554ccbf7c6e428e7b242a574a5a9c293c21f7e", + ), + ( + "1d991dff82a84afe97874c0f03a60a56616a15212fbe10d6c099aa3afcfabe35", + "f81f235696f81df90ac2fc861ceee517bff611a394b5be5faaee45584642fb0a", + ), + ( + "185435d2b005a3b63f3187e64a1ef3582533e1958d30e4e4747b4d1d3376c728", + "f938b1b320abb0635930bd5d7ced45ae97fa8b5f71cc21d87b4c60905c125d34", + ), ] for input, output in vectors: - self.assertEqual(hexlify(elligator2.map_to_curve25519(unhexlify(input))).decode('ascii'), output) + self.assertEqual( + hexlify(elligator2.map_to_curve25519(unhexlify(input))).decode("ascii"), + output, + ) if __name__ == "__main__": diff --git a/core/tests/test_trezor.crypto.slip39.py b/core/tests/test_trezor.crypto.slip39.py index 8e5a9421e2..ff0d840b86 100644 --- a/core/tests/test_trezor.crypto.slip39.py +++ b/core/tests/test_trezor.crypto.slip39.py @@ -41,17 +41,24 @@ class TestCryptoSlip39(unittest.TestCase): def test_basic_sharing_extend(self): identifier = slip39.generate_random_identifier() for extendable in (False, True): - mnemonics = slip39.split_ems(1, [(2, 3)], identifier, extendable, 1, self.EMS) + mnemonics = slip39.split_ems( + 1, [(2, 3)], identifier, extendable, 1, self.EMS + ) mnemonics = mnemonics[0] extended_mnemonics = slip39.extend_mnemonics(4, mnemonics[1:]) self.assertEqual(mnemonics, extended_mnemonics[:3]) for i in range(3): - self.assertEqual(slip39.recover_ems([extended_mnemonics[3], mnemonics[i]])[3], self.EMS) + self.assertEqual( + slip39.recover_ems([extended_mnemonics[3], mnemonics[i]])[3], + self.EMS, + ) def test_basic_sharing_fixed(self): for extendable in (False, True): generated_identifier = slip39.generate_random_identifier() - mnemonics = slip39.split_ems(1, [(3, 5)], generated_identifier, extendable, 1, self.EMS) + mnemonics = slip39.split_ems( + 1, [(3, 5)], generated_identifier, extendable, 1, self.EMS + ) mnemonics = mnemonics[0] identifier, _, _, ems = slip39.recover_ems(mnemonics[:3]) self.assertEqual(ems, self.EMS) @@ -63,13 +70,17 @@ class TestCryptoSlip39(unittest.TestCase): def test_iteration_exponent(self): for extendable in (False, True): identifier = slip39.generate_random_identifier() - mnemonics = slip39.split_ems(1, [(3, 5)], identifier, extendable, 1, self.EMS) + mnemonics = slip39.split_ems( + 1, [(3, 5)], identifier, extendable, 1, self.EMS + ) mnemonics = mnemonics[0] identifier, extendable, _, ems = slip39.recover_ems(mnemonics[1:4]) self.assertEqual(ems, self.EMS) identifier = slip39.generate_random_identifier() - mnemonics = slip39.split_ems(1, [(3, 5)], identifier, extendable, 2, self.EMS) + mnemonics = slip39.split_ems( + 1, [(3, 5)], identifier, extendable, 2, self.EMS + ) mnemonics = mnemonics[0] identifier, extendable, _, ems = slip39.recover_ems(mnemonics[1:4]) self.assertEqual(ems, self.EMS) @@ -90,7 +101,9 @@ class TestCryptoSlip39(unittest.TestCase): ) # Test all valid combinations of mnemonics. - for groups in combinations(zip(mnemonics, member_thresholds), group_threshold): + for groups in combinations( + zip(mnemonics, member_thresholds), group_threshold + ): for group1_subset in combinations(groups[0][0], groups[0][1]): for group2_subset in combinations(groups[1][0], groups[1][1]): mnemonic_subset = list(group1_subset + group2_subset) @@ -104,7 +117,9 @@ class TestCryptoSlip39(unittest.TestCase): ) self.assertEqual(ems, self.EMS) self.assertEqual( - slip39.recover_ems([mnemonics[2][3], mnemonics[3][0], mnemonics[2][4]])[3], + slip39.recover_ems([mnemonics[2][3], mnemonics[3][0], mnemonics[2][4]])[ + 3 + ], ems, ) @@ -160,23 +175,33 @@ class TestCryptoSlip39(unittest.TestCase): # Group threshold exceeds number of groups. with self.assertRaises(ValueError): - slip39.split_ems(3, [(3, 5), (2, 5)], identifier, extendable, 1, self.EMS) + slip39.split_ems( + 3, [(3, 5), (2, 5)], identifier, extendable, 1, self.EMS + ) # Invalid group threshold. with self.assertRaises(ValueError): - slip39.split_ems(0, [(3, 5), (2, 5)], identifier, extendable, 1, self.EMS) + slip39.split_ems( + 0, [(3, 5), (2, 5)], identifier, extendable, 1, self.EMS + ) # Member threshold exceeds number of members. with self.assertRaises(ValueError): - slip39.split_ems(2, [(3, 2), (2, 5)], identifier, extendable, 1, self.EMS) + slip39.split_ems( + 2, [(3, 2), (2, 5)], identifier, extendable, 1, self.EMS + ) # Invalid member threshold. with self.assertRaises(ValueError): - slip39.split_ems(2, [(0, 2), (2, 5)], identifier, extendable, 1, self.EMS) + slip39.split_ems( + 2, [(0, 2), (2, 5)], identifier, extendable, 1, self.EMS + ) # Group with multiple members and threshold 1. with self.assertRaises(ValueError): - slip39.split_ems(2, [(3, 5), (1, 3), (2, 5)], identifier, extendable, 1, self.EMS) + slip39.split_ems( + 2, [(3, 5), (1, 3), (2, 5)], identifier, extendable, 1, self.EMS + ) def test_vectors(self): for mnemonics, secret in vectors: diff --git a/core/tests/test_trezor.strings.py b/core/tests/test_trezor.strings.py index 3b48d9e679..721d491be1 100644 --- a/core/tests/test_trezor.strings.py +++ b/core/tests/test_trezor.strings.py @@ -44,14 +44,54 @@ class TestStrings(unittest.TestCase): def test_format_plural(self): VECTORS = [ - ("You are about to sign {count} {plural}", 0, "action|actions", "You are about to sign 0 actions"), - ("You are about to sign {count} {plural}", 1, "action|actions", "You are about to sign 1 action"), - ("You are about to sign {count} {plural}", 3, "action|actions", "You are about to sign 3 actions"), - ("You are about to sign {count} {plural}", 15, "action|actions", "You are about to sign 15 actions"), - ("Chystáte se podepsat {count} {plural}", 0, "akci|akce|akcí", "Chystáte se podepsat 0 akcí"), - ("Chystáte se podepsat {count} {plural}", 1, "akci|akce|akcí", "Chystáte se podepsat 1 akci"), - ("Chystáte se podepsat {count} {plural}", 3, "akci|akce|akcí", "Chystáte se podepsat 3 akce"), - ("Chystáte se podepsat {count} {plural}", 15, "akci|akce|akcí", "Chystáte se podepsat 15 akcí"), + ( + "You are about to sign {count} {plural}", + 0, + "action|actions", + "You are about to sign 0 actions", + ), + ( + "You are about to sign {count} {plural}", + 1, + "action|actions", + "You are about to sign 1 action", + ), + ( + "You are about to sign {count} {plural}", + 3, + "action|actions", + "You are about to sign 3 actions", + ), + ( + "You are about to sign {count} {plural}", + 15, + "action|actions", + "You are about to sign 15 actions", + ), + ( + "Chystáte se podepsat {count} {plural}", + 0, + "akci|akce|akcí", + "Chystáte se podepsat 0 akcí", + ), + ( + "Chystáte se podepsat {count} {plural}", + 1, + "akci|akce|akcí", + "Chystáte se podepsat 1 akci", + ), + ( + "Chystáte se podepsat {count} {plural}", + 3, + "akci|akce|akcí", + "Chystáte se podepsat 3 akce", + ), + ( + "Chystáte se podepsat {count} {plural}", + 15, + "akci|akce|akcí", + "Chystáte se podepsat 15 akcí", + ), ] for v in VECTORS: self.assertEqual(strings.format_plural(v[0], v[1], v[2]), v[3]) diff --git a/core/tests/test_trezor.utils.py b/core/tests/test_trezor.utils.py index 67150d2a9b..af39f4f683 100644 --- a/core/tests/test_trezor.utils.py +++ b/core/tests/test_trezor.utils.py @@ -77,6 +77,5 @@ class TestUtils(unittest.TestCase): ) - if __name__ == "__main__": unittest.main()