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 7354a846b1..fd63f0a34b 100644 --- a/core/tests/test_apps.bitcoin.approver.py +++ b/core/tests/test_apps.bitcoin.approver.py @@ -39,9 +39,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, @@ -146,7 +144,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.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.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()