From d081f185b1e9fd29aca391631412ea3edece4831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Vejpustek?= Date: Fri, 15 Nov 2024 14:17:38 +0100 Subject: [PATCH] style(core/tests): fix warnings --- core/tests/test_apps.bitcoin.signtx_decred.py | 7 +++++-- core/tests/test_apps.cardano.address.py | 2 +- core/tests/test_apps.common.coins.py | 4 +++- core/tests/test_apps.ethereum.definitions.py | 8 ++++---- core/tests/test_apps.ethereum.sign_typed_data.py | 1 + .../test_apps.management.recovery_device.py | 16 ++++++++-------- core/tests/test_apps.monero.bulletproof.py | 2 +- core/tests/test_apps.monero.clsag.py | 2 +- core/tests/test_apps.thp.credential_manager.py | 2 +- core/tests/test_apps.zcash.zip244.py | 2 +- core/tests/test_storage.cache.py | 2 +- core/tests/test_trezor.crypto.base32.py | 14 ++++++-------- core/tests/test_trezor.crypto.bech32.py | 7 +++---- core/tests/test_trezor.crypto.cashaddr.py | 7 +++---- core/tests/test_trezor.crypto.curve.ed25519.py | 2 +- .../test_trezor.crypto.hashlib.groestl512.py | 10 ++++------ .../test_trezor.crypto.hashlib.ripemd160.py | 2 +- core/tests/test_trezor.crypto.hashlib.sha1.py | 12 +++++------- core/tests/test_trezor.crypto.hashlib.sha256.py | 12 +++++------- .../tests/test_trezor.crypto.hashlib.sha3_256.py | 12 +++++------- .../tests/test_trezor.crypto.hashlib.sha3_512.py | 12 +++++------- core/tests/test_trezor.crypto.hashlib.sha512.py | 12 +++++------- core/tests/test_trezor.crypto.hmac.py | 8 ++++---- core/tests/test_trezor.crypto.pbkdf2.py | 8 ++++---- core/tests/test_trezor.crypto.slip39.py | 4 ++-- core/tests/test_trezor.utils.py | 5 ++++- core/tests/unittest.py | 3 ++- 27 files changed, 86 insertions(+), 92 deletions(-) diff --git a/core/tests/test_apps.bitcoin.signtx_decred.py b/core/tests/test_apps.bitcoin.signtx_decred.py index c0131fd5c1..8d55c1d63d 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", ): +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 @@ -406,5 +406,8 @@ class TestSignTxDecred(unittest.TestCase): if __name__ == "__main__": - if utils.INTERNAL_MODEL in ("T2T1",): + if utils.INTERNAL_MODEL in ( # pylint: disable=internal-model-tuple-comparison + "T2T1", + ): + unittest.main() diff --git a/core/tests/test_apps.cardano.address.py b/core/tests/test_apps.cardano.address.py index c1fb264661..c5575a6fbf 100644 --- a/core/tests/test_apps.cardano.address.py +++ b/core/tests/test_apps.cardano.address.py @@ -628,7 +628,7 @@ class TestCardanoAddress(unittest.TestCase): for ( network_id, - address_type, + _, address_parameters, expected_address, ) in test_vectors: diff --git a/core/tests/test_apps.common.coins.py b/core/tests/test_apps.common.coins.py index f36b8ede7b..901a0b3782 100644 --- a/core/tests/test_apps.common.coins.py +++ b/core/tests/test_apps.common.coins.py @@ -23,7 +23,9 @@ class TestCoins(unittest.TestCase): ("ZEC", "Zcash", 7352), ("TAZ", "Zcash Testnet", 7461), ] - if utils.INTERNAL_MODEL in ("T2T1",): + if utils.INTERNAL_MODEL in ( # pylint: disable=internal-model-tuple-comparison + "T2T1", + ): ref.extend( [ ("NMC", "Namecoin", 52), diff --git a/core/tests/test_apps.ethereum.definitions.py b/core/tests/test_apps.ethereum.definitions.py index e72567c873..894b1a6fb2 100644 --- a/core/tests/test_apps.ethereum.definitions.py +++ b/core/tests/test_apps.ethereum.definitions.py @@ -58,7 +58,7 @@ class TestDecodeDefinition(unittest.TestCase): def test_missing_signature(self): payload = make_payload() - proof, signature = sign_payload(payload, []) + proof, _ = sign_payload(payload, []) self.assertFailed(payload + proof) def test_mangled_payload(self): @@ -69,7 +69,7 @@ class TestDecodeDefinition(unittest.TestCase): def test_proof_length_mismatch(self): payload = make_payload() - proof, signature = sign_payload(payload, []) + _, signature = sign_payload(payload, []) bad_proof = b"\x01" self.assertFailed(payload + bad_proof + signature) @@ -133,13 +133,13 @@ class TestEthereumDefinitions(unittest.TestCase): return if what is tokens.UNKNOWN_TOKEN: return - self.fail("Expected UNKNOWN_*, got %r" % what) + self.fail(f"Expected UNKNOWN_*, got {what}") def assertKnown(self, what: t.Any) -> None: if not EthereumNetworkInfo.is_type_of( what ) and not EthereumTokenInfo.is_type_of(what): - self.fail("Expected network / token info, got %r" % what) + self.fail(f"Expected network / token info, got {what}") if what is networks.UNKNOWN_NETWORK: self.fail("Expected known network, got UNKNOWN_NETWORK") if what is tokens.UNKNOWN_TOKEN: diff --git a/core/tests/test_apps.ethereum.sign_typed_data.py b/core/tests/test_apps.ethereum.sign_typed_data.py index 6dba7da7ab..136170ad31 100644 --- a/core/tests/test_apps.ethereum.sign_typed_data.py +++ b/core/tests/test_apps.ethereum.sign_typed_data.py @@ -135,6 +135,7 @@ def parse_type_n(type_name: str) -> int: buf += char else: return int("".join(reversed(buf))) + raise ValueError(f"Invalid type name: {type_name}") def parse_array_n(type_name: str) -> Union[int, str]: diff --git a/core/tests/test_apps.management.recovery_device.py b/core/tests/test_apps.management.recovery_device.py index adabe9e3af..e3fec11a89 100644 --- a/core/tests/test_apps.management.recovery_device.py +++ b/core/tests/test_apps.management.recovery_device.py @@ -175,19 +175,19 @@ class TestSlip39(unittest.TestCase): storage.recovery.set_in_progress(True) words = MNEMONIC_SLIP39_BASIC_20_3of6[0] - secret, share = process_slip39(words) + secret, _ = process_slip39(words) self.assertIsNone(secret) # same mnemonic words = MNEMONIC_SLIP39_BASIC_20_3of6[0] with self.assertRaises(RuntimeError): - secret, share = process_slip39(words) + secret, _ = process_slip39(words) self.assertIsNone(secret) # identifier mismatch words = MNEMONIC_SLIP39_ADVANCED_20[0] with self.assertRaises(RuntimeError): - secret, share = process_slip39(words) + secret, _ = process_slip39(words) self.assertIsNone(secret) # same identifier but different group settings @@ -200,7 +200,7 @@ class TestSlip39(unittest.TestCase): w[19] = "merchant" words = " ".join(w) with self.assertRaises(RuntimeError): - secret, share = process_slip39(words) + secret, _ = process_slip39(words) self.assertIsNone(secret) @mock_storage @@ -218,11 +218,11 @@ class TestSlip39(unittest.TestCase): check(BackupType.Bip39, ["ocean"]) # let's store two shares in the storage - secret, share = process_slip39( + secret, _ = process_slip39( "trash smug adjust ambition criminal prisoner security math cover pecan response pharmacy center criminal salary elbow bracelet lunar briefing dragon" ) self.assertIsNone(secret) - secret, share = process_slip39( + secret, _ = process_slip39( "trash smug adjust aide benefit temple round clogs devote prevent type cards clogs plastic aspect paper behavior lunar custody intimate" ) self.assertIsNone(secret) @@ -244,11 +244,11 @@ class TestSlip39(unittest.TestCase): check(BackupType.Slip39_Advanced, ["trash", "smug", "adjust", "ambition"]) # Let's store two more. The group is 4/6 so this group is now complete. - secret, share = process_slip39( + secret, _ = process_slip39( "trash smug adjust arena beard quick language program true hush amount round geology should training practice language diet order ruin" ) self.assertIsNone(secret) - secret, share = process_slip39( + secret, _ = process_slip39( "trash smug adjust beam brave sack magazine radar toxic emission domestic cradle vocal petition mule toxic acid hobo welcome downtown" ) self.assertIsNone(secret) diff --git a/core/tests/test_apps.monero.bulletproof.py b/core/tests/test_apps.monero.bulletproof.py index 1518e30a96..d94cbbde7e 100644 --- a/core/tests/test_apps.monero.bulletproof.py +++ b/core/tests/test_apps.monero.bulletproof.py @@ -14,7 +14,7 @@ class TestMoneroBulletproof(unittest.TestCase): ss = crypto.random_scalar() s1 = crypto.sc_copy(None, ss) s2 = crypto.sc_copy(None, ss) - for i in range(1, x): + for _ in range(1, x): crypto.sc_mul_into(s1, s1, ss) bp._sc_square_mult(s2, ss, x) diff --git a/core/tests/test_apps.monero.clsag.py b/core/tests/test_apps.monero.clsag.py index 7fcf9fe809..c697fe4933 100644 --- a/core/tests/test_apps.monero.clsag.py +++ b/core/tests/test_apps.monero.clsag.py @@ -108,7 +108,7 @@ class TestMoneroClsag(unittest.TestCase): Cp = crypto.add_keys2_into(None, alpha, amnt, crypto.xmr_H()) ring = [] - for i in range(ring_size - 1): + for _ in range(ring_size - 1): tk = TmpKey( crypto_helpers.encodepoint( crypto.scalarmult_base_into(None, crypto.random_scalar()) diff --git a/core/tests/test_apps.thp.credential_manager.py b/core/tests/test_apps.thp.credential_manager.py index c66b99985d..f62aa3bb9d 100644 --- a/core/tests/test_apps.thp.credential_manager.py +++ b/core/tests/test_apps.thp.credential_manager.py @@ -1,5 +1,5 @@ # flake8: noqa: F403,F405 -from common import * +from common import * # isort: skip from trezor import config, utils from trezor import log diff --git a/core/tests/test_apps.zcash.zip244.py b/core/tests/test_apps.zcash.zip244.py index 3ead9b9727..b4947a14dd 100644 --- a/core/tests/test_apps.zcash.zip244.py +++ b/core/tests/test_apps.zcash.zip244.py @@ -139,7 +139,7 @@ class TestZcashSigHasher(unittest.TestCase): self.assertEqual(computed_txid, expected_txid) # test ZcashSigHasher.signature_digest - for txi, expected_sighash, pk in zip(inputs, expected_sighashes, pubkeys): + for txi, expected_sighash, _ in zip(inputs, expected_sighashes, pubkeys): computed_sighash = hasher.signature_digest(txi, txi.script_pubkey) self.assertEqual(computed_sighash, expected_sighash) diff --git a/core/tests/test_storage.cache.py b/core/tests/test_storage.cache.py index f523403dbe..a3c7d509b6 100644 --- a/core/tests/test_storage.cache.py +++ b/core/tests/test_storage.cache.py @@ -64,7 +64,7 @@ class TestStorageCache(unittest.TestCase): session_id = cache.start_session() self.assertEqual(cache.start_session(session_id), session_id) cache.set(KEY, b"A") - for i in range(cache._MAX_SESSIONS_COUNT): + for _ in range(cache._MAX_SESSIONS_COUNT): cache.start_session() self.assertNotEqual(cache.start_session(session_id), session_id) self.assertIsNone(cache.get(KEY)) diff --git a/core/tests/test_trezor.crypto.base32.py b/core/tests/test_trezor.crypto.base32.py index f93c0c5ecd..69db5706df 100644 --- a/core/tests/test_trezor.crypto.base32.py +++ b/core/tests/test_trezor.crypto.base32.py @@ -26,15 +26,13 @@ class TestCryptoBase32(unittest.TestCase): b"zlutoucky kun upel dabelske ody", "PJWHK5DPOVRWW6JANN2W4IDVOBSWYIDEMFRGK3DTNNSSA33EPE======", ), - # fmt: off - (b"中文", "4S4K3ZUWQ4======"), # noqa: E999 - (b"中文1", "4S4K3ZUWQ4YQ===="), # noqa: E999 - (b"中文12", "4S4K3ZUWQ4YTE==="), # noqa: E999 - (b"aécio", "MHB2SY3JN4======"), # noqa: E999 - (b"𠜎", "6CQJZDQ="), # noqa: E999 - (b"Base64是一種基於64個可列印字元來表示二進制資料的表示方法", # noqa: E999 + ("中文".encode(), "4S4K3ZUWQ4======"), + ("中文1".encode(), "4S4K3ZUWQ4YQ===="), + ("中文12".encode(), "4S4K3ZUWQ4YTE==="), + ("aécio".encode(), "MHB2SY3JN4======"), + ("𠜎".encode(), "6CQJZDQ="), + ("Base64是一種基於64個可列印字元來表示二進制資料的表示方法".encode(), "IJQXGZJWGTTJRL7EXCAOPKFO4WP3VZUWXQ3DJZMARPSY7L7FRCL6LDNQ4WWZPZMFQPSL5BXIUGUOPJF24S5IZ2MAWLSYRNXIWOD6NFUZ46NIJ2FBVDT2JOXGS246NM4V"), - # fmt: on ] def test_encode(self): diff --git a/core/tests/test_trezor.crypto.bech32.py b/core/tests/test_trezor.crypto.bech32.py index a48f1807cc..ca8c195e20 100644 --- a/core/tests/test_trezor.crypto.bech32.py +++ b/core/tests/test_trezor.crypto.bech32.py @@ -1,6 +1,3 @@ -# flake8: noqa: F403,F405 -from common import * # isort:skip - # Copyright (c) 2017, 2020 Pieter Wuille # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -21,9 +18,11 @@ from common import * # isort:skip # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. - """Reference tests for segwit adresses""" +# flake8: noqa: F403,F405 +from common import * # isort:skip + from trezor.crypto import bech32 diff --git a/core/tests/test_trezor.crypto.cashaddr.py b/core/tests/test_trezor.crypto.cashaddr.py index 42fda52c57..0f004abb27 100644 --- a/core/tests/test_trezor.crypto.cashaddr.py +++ b/core/tests/test_trezor.crypto.cashaddr.py @@ -1,6 +1,3 @@ -# flake8: noqa: F403,F405 -from common import * # isort:skip - # Copyright (c) 2017 Pieter Wuille # Copyright (c) 2018 Pavol Rusnak # @@ -22,9 +19,11 @@ from common import * # isort:skip # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. - """Reference tests for cashaddr adresses""" +# flake8: noqa: F403,F405 +from common import * # isort:skip + from trezor.crypto import base58, cashaddr VALID_CHECKSUM = [ diff --git a/core/tests/test_trezor.crypto.curve.ed25519.py b/core/tests/test_trezor.crypto.curve.ed25519.py index 22f85abeac..db19c2747c 100644 --- a/core/tests/test_trezor.crypto.curve.ed25519.py +++ b/core/tests/test_trezor.crypto.curve.ed25519.py @@ -63,7 +63,7 @@ class TestCryptoEd25519(unittest.TestCase): self.assertEqual(sig2, unhexlify(sig)) def test_verify(self): - for sk, pk, sig in self.vectors: + for _, pk, sig in self.vectors: # msg = pk self.assertTrue( ed25519.verify(unhexlify(pk), unhexlify(sig), unhexlify(pk)) diff --git a/core/tests/test_trezor.crypto.hashlib.groestl512.py b/core/tests/test_trezor.crypto.hashlib.groestl512.py index c07c045884..caad11c45e 100644 --- a/core/tests/test_trezor.crypto.hashlib.groestl512.py +++ b/core/tests/test_trezor.crypto.hashlib.groestl512.py @@ -63,12 +63,10 @@ class TestCryptoGroestl512(unittest.TestCase): self.assertEqual(x.digest(), unhexlify(d)) # Test from ExtremelyLongMsgKAT_512.txt, disabled by default because it resource-expensive - """ - x = hashlib.groestl512() - for i in range(16777216): - x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - self.assertEqual(x.digest(), unhexlify('787C88460E5D09ABD7A98C050F3422BBFDBD36A74B05DE04B57A13FA3F36A570B8561580AB9DA4096CCD5111B5DE948F769D9D61833A6CE2B2F223061E688994')) - """ + # x = hashlib.groestl512() + # for i in range(16777216): + # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') + # self.assertEqual(x.digest(), unhexlify('787C88460E5D09ABD7A98C050F3422BBFDBD36A74B05DE04B57A13FA3F36A570B8561580AB9DA4096CCD5111B5DE948F769D9D61833A6CE2B2F223061E688994')) def test_digest_multi(self): x = hashlib.groestl512() diff --git a/core/tests/test_trezor.crypto.hashlib.ripemd160.py b/core/tests/test_trezor.crypto.hashlib.ripemd160.py index 19a13699e1..6ab0131eaf 100644 --- a/core/tests/test_trezor.crypto.hashlib.ripemd160.py +++ b/core/tests/test_trezor.crypto.hashlib.ripemd160.py @@ -38,7 +38,7 @@ class TestCryptoRipemd160(unittest.TestCase): self.assertEqual(x.digest(), unhexlify(d)) x = hashlib.ripemd160() - for i in range(8): + for _ in range(8): x.update(b"1234567890") self.assertEqual( x.digest(), unhexlify("9b752e45573d4b39f4dbd3323cab82bf63326bfb") diff --git a/core/tests/test_trezor.crypto.hashlib.sha1.py b/core/tests/test_trezor.crypto.hashlib.sha1.py index 21d76287a0..04871c2e61 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha1.py +++ b/core/tests/test_trezor.crypto.hashlib.sha1.py @@ -31,18 +31,16 @@ class TestCryptoSha1(unittest.TestCase): self.assertEqual(x.digest(), unhexlify(d)) x = hashlib.sha1() - for i in range(1000000): + for _ in range(1000000): x.update(b"a") self.assertEqual( x.digest(), unhexlify("34aa973cd4c4daa4f61eeb2bdbad27316534016f") ) - """ - x = hashlib.sha1() - for i in range(16777216): - x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - self.assertEqual(x.digest(), unhexlify('7789f0c9ef7bfc40d93311143dfbe69e2017f592')) - """ + # x = hashlib.sha1() + # for i in range(16777216): + # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') + # self.assertEqual(x.digest(), unhexlify('7789f0c9ef7bfc40d93311143dfbe69e2017f592')) def test_digest_multi(self): x = hashlib.sha1() diff --git a/core/tests/test_trezor.crypto.hashlib.sha256.py b/core/tests/test_trezor.crypto.hashlib.sha256.py index 48ee0d02bd..928949a04d 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha256.py +++ b/core/tests/test_trezor.crypto.hashlib.sha256.py @@ -31,7 +31,7 @@ class TestCryptoSha256(unittest.TestCase): self.assertEqual(x.digest(), unhexlify(d)) x = hashlib.sha256() - for i in range(1000000): + for _ in range(1000000): x.update(b"a") self.assertEqual( x.digest(), @@ -40,12 +40,10 @@ class TestCryptoSha256(unittest.TestCase): ), ) - """ - x = hashlib.sha256() - for i in range(16777216): - x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - self.assertEqual(x.digest(), unhexlify('50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e')) - """ + # x = hashlib.sha256() + # for i in range(16777216): + # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') + # self.assertEqual(x.digest(), unhexlify('50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e')) def test_digest_multi(self): x = hashlib.sha256() diff --git a/core/tests/test_trezor.crypto.hashlib.sha3_256.py b/core/tests/test_trezor.crypto.hashlib.sha3_256.py index 7e8645bf13..4b7f990c0d 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha3_256.py +++ b/core/tests/test_trezor.crypto.hashlib.sha3_256.py @@ -48,7 +48,7 @@ class TestCryptoSha3_256(unittest.TestCase): self.assertEqual(x.digest(), unhexlify(d)) x = hashlib.sha3_256() - for i in range(1000000): + for _ in range(1000000): x.update(b"a") self.assertEqual( x.digest(), @@ -57,12 +57,10 @@ class TestCryptoSha3_256(unittest.TestCase): ), ) - """ - x = hashlib.sha3_256() - for i in range(16777216): - x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - self.assertEqual(x.digest(), unhexlify('ecbbc42cbf296603acb2c6bc0410ef4378bafb24b710357f12df607758b33e2b')) - """ + # x = hashlib.sha3_256() + # for i in range(16777216): + # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') + # self.assertEqual(x.digest(), unhexlify('ecbbc42cbf296603acb2c6bc0410ef4378bafb24b710357f12df607758b33e2b')) def test_update_keccak(self): for b, d in self.vectors_keccak: diff --git a/core/tests/test_trezor.crypto.hashlib.sha3_512.py b/core/tests/test_trezor.crypto.hashlib.sha3_512.py index ae90fdd7bd..3c55ac7058 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha3_512.py +++ b/core/tests/test_trezor.crypto.hashlib.sha3_512.py @@ -60,7 +60,7 @@ class TestCryptoSha3_512(unittest.TestCase): self.assertEqual(x.digest(), unhexlify(d)) x = hashlib.sha3_512() - for i in range(1000000): + for _ in range(1000000): x.update(b"a") self.assertEqual( x.digest(), @@ -69,12 +69,10 @@ class TestCryptoSha3_512(unittest.TestCase): ), ) - """ - x = hashlib.sha3_512() - for i in range(16777216): - x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - self.assertEqual(x.digest(), unhexlify('235ffd53504ef836a1342b488f483b396eabbfe642cf78ee0d31feec788b23d0d18d5c339550dd5958a500d4b95363da1b5fa18affc1bab2292dc63b7d85097c')) - """ + # x = hashlib.sha3_512() + # for i in range(16777216): + # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') + # self.assertEqual(x.digest(), unhexlify('235ffd53504ef836a1342b488f483b396eabbfe642cf78ee0d31feec788b23d0d18d5c339550dd5958a500d4b95363da1b5fa18affc1bab2292dc63b7d85097c')) def test_update_keccak(self): for b, d in self.vectors_keccak: diff --git a/core/tests/test_trezor.crypto.hashlib.sha512.py b/core/tests/test_trezor.crypto.hashlib.sha512.py index 0b835e6ee8..4a5c420942 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha512.py +++ b/core/tests/test_trezor.crypto.hashlib.sha512.py @@ -37,7 +37,7 @@ class TestCryptoSha512(unittest.TestCase): self.assertEqual(x.digest(), unhexlify(d)) x = hashlib.sha512() - for i in range(1000000): + for _ in range(1000000): x.update(b"a") self.assertEqual( x.digest(), @@ -46,12 +46,10 @@ class TestCryptoSha512(unittest.TestCase): ), ) - """ - x = hashlib.sha512() - for i in range(16777216): - x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') - self.assertEqual(x.digest(), unhexlify('b47c933421ea2db149ad6e10fce6c7f93d0752380180ffd7f4629a712134831d77be6091b819ed352c2967a2e2d4fa5050723c9630691f1a05a7281dbe6c1086')) - """ + # x = hashlib.sha512() + # for i in range(16777216): + # x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') + # self.assertEqual(x.digest(), unhexlify('b47c933421ea2db149ad6e10fce6c7f93d0752380180ffd7f4629a712134831d77be6091b819ed352c2967a2e2d4fa5050723c9630691f1a05a7281dbe6c1086')) def test_digest_multi(self): x = hashlib.sha512() diff --git a/core/tests/test_trezor.crypto.hmac.py b/core/tests/test_trezor.crypto.hmac.py index 40aa78b8b1..4e27567df1 100644 --- a/core/tests/test_trezor.crypto.hmac.py +++ b/core/tests/test_trezor.crypto.hmac.py @@ -111,7 +111,7 @@ class TestCryptoHmac(unittest.TestCase): # case 3 key = b"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" x = hmac(hmac.SHA256, key) - for i in range(50): + for _ in range(50): x.update(b"\xdd") self.assertEqual( x.digest(), @@ -120,7 +120,7 @@ class TestCryptoHmac(unittest.TestCase): ), ) x = hmac(hmac.SHA512, key) - for i in range(50): + for _ in range(50): x.update(b"\xdd") self.assertEqual( x.digest(), @@ -132,7 +132,7 @@ class TestCryptoHmac(unittest.TestCase): # case 4 key = b"\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" x = hmac(hmac.SHA256, key) - for i in range(50): + for _ in range(50): x.update(b"\xcd") self.assertEqual( x.digest(), @@ -141,7 +141,7 @@ class TestCryptoHmac(unittest.TestCase): ), ) x = hmac(hmac.SHA512, key) - for i in range(50): + for _ in range(50): x.update(b"\xcd") self.assertEqual( x.digest(), diff --git a/core/tests/test_trezor.crypto.pbkdf2.py b/core/tests/test_trezor.crypto.pbkdf2.py index 69542ee811..fe7a349dc9 100644 --- a/core/tests/test_trezor.crypto.pbkdf2.py +++ b/core/tests/test_trezor.crypto.pbkdf2.py @@ -65,7 +65,7 @@ class TestCryptoPbkdf2(unittest.TestCase): ), ) p = pbkdf2(pbkdf2.HMAC_SHA256, P, S) - for i in range(32): + for _ in range(32): p.update(128) dk = p.key() self.assertEqual( @@ -77,7 +77,7 @@ class TestCryptoPbkdf2(unittest.TestCase): P = b"passwordPASSWORDpassword" S = b"saltSALTsaltSALTsaltSALTsaltSALTsalt" p = pbkdf2(pbkdf2.HMAC_SHA256, P, S) - for i in range(64): + for _ in range(64): p.update(64) dk = p.key() self.assertEqual( @@ -146,7 +146,7 @@ class TestCryptoPbkdf2(unittest.TestCase): ), ) p = pbkdf2(pbkdf2.HMAC_SHA512, P, S) - for i in range(32): + for _ in range(32): p.update(128) dk = p.key() self.assertEqual( @@ -158,7 +158,7 @@ class TestCryptoPbkdf2(unittest.TestCase): P = b"passwordPASSWORDpassword" S = b"saltSALTsaltSALTsaltSALTsaltSALTsalt" p = pbkdf2(pbkdf2.HMAC_SHA512, P, S) - for i in range(64): + for _ in range(64): p.update(64) dk = p.key() self.assertEqual( diff --git a/core/tests/test_trezor.crypto.slip39.py b/core/tests/test_trezor.crypto.slip39.py index 4fa298e74c..8e5a9421e2 100644 --- a/core/tests/test_trezor.crypto.slip39.py +++ b/core/tests/test_trezor.crypto.slip39.py @@ -65,13 +65,13 @@ class TestCryptoSlip39(unittest.TestCase): identifier = slip39.generate_random_identifier() mnemonics = slip39.split_ems(1, [(3, 5)], identifier, extendable, 1, self.EMS) mnemonics = mnemonics[0] - identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics[1:4]) + 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 = mnemonics[0] - identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics[1:4]) + identifier, extendable, _, ems = slip39.recover_ems(mnemonics[1:4]) self.assertEqual(ems, self.EMS) def test_group_sharing(self): diff --git a/core/tests/test_trezor.utils.py b/core/tests/test_trezor.utils.py index 015bf7a3be..67150d2a9b 100644 --- a/core/tests/test_trezor.utils.py +++ b/core/tests/test_trezor.utils.py @@ -54,7 +54,10 @@ class TestUtils(unittest.TestCase): ) # b'\xe1\x88\xb4\xe5\x99\xb8 def test_firmware_hash(self): - if utils.INTERNAL_MODEL in ('DISC2', 'T3W1'): + if utils.INTERNAL_MODEL in ( # pylint: disable=internal-model-tuple-comparison + "DISC2", + "T3W1", + ): self.assertEqual( utils.firmware_hash(), b"\xde\xce\xc5\xf6\xa4vgl5\x13l2\xa5\xf8F\xd8\xba\n$\x0b!x\x1fVM\x1e\xf3}@\xd9\xa8\xe9", diff --git a/core/tests/unittest.py b/core/tests/unittest.py index 00e398cc27..1127d0257d 100644 --- a/core/tests/unittest.py +++ b/core/tests/unittest.py @@ -140,10 +140,11 @@ class TestCase: func(*args, **kwargs) except Exception as e: if isinstance(e, exc): - return + return None raise else: ensure(False, f"{repr(exc)} not raised") + return None def assertListEqual(self, x, y, msg=""): if len(x) != len(y):