diff --git a/core/tests/common.py b/core/tests/common.py index 6cf9585290..03e69bc003 100644 --- a/core/tests/common.py +++ b/core/tests/common.py @@ -18,13 +18,6 @@ def H_(x: int) -> int: return x | HARDENED -def UH_(x: int) -> int: - """ - Shortcut function that "un-hardens" a number in a BIP44 path. - """ - return x & ~(HARDENED) - - def await_result(task: Awaitable) -> Any: value = None while True: diff --git a/core/tests/mock.py b/core/tests/mock.py index f5bd260083..f5dcb7d484 100644 --- a/core/tests/mock.py +++ b/core/tests/mock.py @@ -1,4 +1,4 @@ -if False: +if False: # noqa from typing import Any diff --git a/core/tests/mock_storage.py b/core/tests/mock_storage.py index 2aa0576050..f6839eb3b3 100644 --- a/core/tests/mock_storage.py +++ b/core/tests/mock_storage.py @@ -26,13 +26,13 @@ class MockStorage: self.namespace[app].pop(key, None) def __enter__(self): - for patch in self.patches: - patch.__enter__() + for self_patch in self.patches: + self_patch.__enter__() return self def __exit__(self, exc_type, exc_value, tb): - for patch in self.patches: - patch.__exit__(exc_type, exc_value, tb) + for self_patch in self.patches: + self_patch.__exit__(exc_type, exc_value, tb) def mock_storage(func): diff --git a/core/tests/test_apps.binance.address.py b/core/tests/test_apps.binance.address.py index ea6da68305..a5bc2ddb8a 100644 --- a/core/tests/test_apps.binance.address.py +++ b/core/tests/test_apps.binance.address.py @@ -1,5 +1,4 @@ from common import * -from apps.common.paths import HARDENED from trezor.crypto.curve import secp256k1 diff --git a/core/tests/test_apps.bitcoin.keychain.py b/core/tests/test_apps.bitcoin.keychain.py index fe103a99c5..4fa04dfe55 100644 --- a/core/tests/test_apps.bitcoin.keychain.py +++ b/core/tests/test_apps.bitcoin.keychain.py @@ -3,7 +3,6 @@ from common import * from storage import cache from trezor import wire from trezor.crypto import bip39 -from apps.common.paths import HARDENED from apps.bitcoin.keychain import _get_coin_by_name, _get_keychain_for_coin diff --git a/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py b/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py index a2844c96be..a9d8f76c12 100644 --- a/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py +++ b/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py @@ -87,11 +87,6 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase): ) def test_outputs(self): - - seed = bip39.seed( - "alcohol woman abuse must during monitor noble actual mixed trade anger aisle", - "", - ) coin = coins.by_name(self.tx.coin_name) sig_hasher = BitcoinSigHasher() diff --git a/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py b/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py index 293244741a..8927a2833d 100644 --- a/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py +++ b/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py @@ -73,10 +73,6 @@ class TestSegwitBip143(unittest.TestCase): ) def test_bip143_outputs(self): - seed = bip39.seed( - "alcohol woman abuse must during monitor noble actual mixed trade anger aisle", - "", - ) coin = coins.by_name(self.tx.coin_name) sig_hasher = BitcoinSigHasher() 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 18d64ed59f..cc8f1a1efd 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py @@ -456,26 +456,6 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): sequence=0xFFFFFFFF, multisig=None, ) - ptx1 = PrevTx( - version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 - ) - pinp1 = PrevInput( - script_sig=unhexlify("160014d16b8c0680c61fc6ed2e407455715055e41052f5"), - prev_hash=unhexlify( - "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" - ), - prev_index=0, - sequence=4294967295, - ) - pout1 = PrevOutput( - script_pubkey=unhexlify("00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c"), - amount=12300000, - ) - pout2 = PrevOutput( - script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), - amount=111145789, - ) - out1 = TxOutput( address="TB1Q694CCP5QCC0UDMFWGP692U2S2HJPQ5H407URTU", # Error: should be lower case script_type=OutputScriptType.PAYTOADDRESS, diff --git a/core/tests/test_apps.bitcoin.signtx.fee_threshold.py b/core/tests/test_apps.bitcoin.signtx.fee_threshold.py index aad6803240..6ebf6a3759 100644 --- a/core/tests/test_apps.bitcoin.signtx.fee_threshold.py +++ b/core/tests/test_apps.bitcoin.signtx.fee_threshold.py @@ -1,6 +1,6 @@ from common import * -from trezor.crypto import bip32, bip39 +from trezor.crypto import bip39 from trezor.enums import AmountUnit, OutputScriptType from trezor.enums.RequestType import TXINPUT, TXMETA, TXOUTPUT from trezor.messages import ( diff --git a/core/tests/test_apps.cardano.address.py b/core/tests/test_apps.cardano.address.py index bc05130159..a6736c9909 100644 --- a/core/tests/test_apps.cardano.address.py +++ b/core/tests/test_apps.cardano.address.py @@ -366,13 +366,6 @@ class TestCardanoAddress(unittest.TestCase): "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff" ), ), - "BASE_OWN_STAKING_KEY_HASH": CardanoAddressParametersType( - address_type=CardanoAddressType.BASE, - address_n=[1852 | HARDENED, 1815 | HARDENED, 4 | HARDENED, 0, 0], - staking_key_hash=unhexlify( - "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff" - ), - ), # staking key hash not owned - derived with "all all..." mnenomnic "BASE_FOREIGN_STAKING_KEY_HASH_ACCOUNT_4": CardanoAddressParametersType( address_type=CardanoAddressType.BASE, diff --git a/core/tests/test_apps.ethereum.definitions.py b/core/tests/test_apps.ethereum.definitions.py index b9fae418c8..a45d3c0ddc 100644 --- a/core/tests/test_apps.ethereum.definitions.py +++ b/core/tests/test_apps.ethereum.definitions.py @@ -2,7 +2,6 @@ from common import * import typing as t import unittest -from ubinascii import hexlify # noqa: F401 from trezor import utils, wire @@ -12,15 +11,10 @@ if not utils.BITCOIN_ONLY: from apps.ethereum import networks, tokens from apps.ethereum.definitions import decode_definition, Definitions from ethereum_common import * - from trezor import protobuf from trezor.enums import EthereumDefinitionType from trezor.messages import ( - EthereumDefinitions, EthereumNetworkInfo, EthereumTokenInfo, - EthereumSignTx, - EthereumSignTxEIP1559, - EthereumSignTypedData, ) TETHER_ADDRESS = b"\xda\xc1\x7f\x95\x8d\x2e\xe5\x23\xa2\x20\x62\x06\x99\x45\x97\xc1\x3d\x83\x1e\xc7" diff --git a/core/tests/test_apps.ethereum.helpers.py b/core/tests/test_apps.ethereum.helpers.py index 2b051222e8..cd09dab59e 100644 --- a/core/tests/test_apps.ethereum.helpers.py +++ b/core/tests/test_apps.ethereum.helpers.py @@ -1,7 +1,5 @@ from common import * -from apps.common.paths import HARDENED - if not utils.BITCOIN_ONLY: from apps.ethereum.helpers import address_from_bytes from ethereum_common import make_network diff --git a/core/tests/test_apps.ethereum.sign_typed_data.py b/core/tests/test_apps.ethereum.sign_typed_data.py index 0ab5c73d49..addbd9ba9f 100644 --- a/core/tests/test_apps.ethereum.sign_typed_data.py +++ b/core/tests/test_apps.ethereum.sign_typed_data.py @@ -540,16 +540,13 @@ class TestEthereumSignTypedData(unittest.TestCase): ) for field, value, expected in VECTORS: - # metamask_v4_compat should not have any effect on the - # result for items outside of arrays - for metamask_v4_compat in [True, False]: - w = bytearray() - encode_field( - w=w, - field=field, - value=value, - ) - self.assertEqual(w, expected) + w = bytearray() + encode_field( + w=w, + field=field, + value=value, + ) + self.assertEqual(w, expected) def test_validate_value(self): VECTORS_VALID_INVALID = ( # field, valid_values, invalid_values diff --git a/core/tests/test_apps.management.recovery_device.py b/core/tests/test_apps.management.recovery_device.py index f8dceb73c8..7810c8af71 100644 --- a/core/tests/test_apps.management.recovery_device.py +++ b/core/tests/test_apps.management.recovery_device.py @@ -25,11 +25,6 @@ MNEMONIC_SLIP39_ADVANCED_20 = [ "eraser senior ceramic shaft dynamic become junior wrist silver peasant force math alto coal amazing segment yelp velvet image paces", "eraser senior ceramic round column hawk trust auction smug shame alive greatest sheriff living perfect corner chest sled fumes adequate", ] -# Shamir shares (256 bits, 2 groups from 1 of 1, 1 of 1, 3 of 5, 2 of 6): -MNEMONIC_SLIP39_ADVANCED_33 = [ - "wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium", - "wildlife deal acrobat romp anxiety axis starting require metric flexible geology game drove editor edge screw helpful have huge holy making pitch unknown carve holiday numb glasses survive already tenant adapt goat fangs", -] class TestSlip39(unittest.TestCase): diff --git a/core/tests/test_apps.monero.bulletproof.py b/core/tests/test_apps.monero.bulletproof.py index 0bfe59ec11..71ac42712d 100644 --- a/core/tests/test_apps.monero.bulletproof.py +++ b/core/tests/test_apps.monero.bulletproof.py @@ -287,45 +287,6 @@ class TestMoneroBulletproof(unittest.TestCase): proof = bpi.prove_batch(sv, gamma) bpi.verify_batch([proof]) - def ctest_multiexp(self): - scalars = [0, 1, 2, 3, 4, 99] - point_base = [0, 2, 4, 7, 12, 18] - scalar_sc = [crypto.Scalar(x) for x in scalars] - points = [ - crypto.scalarmult_base_into(None, crypto.Scalar(x)) for x in point_base - ] - - muex = bp.MultiExp( - scalars=[crypto.encodeint(x) for x in scalar_sc], - point_fnc=lambda i, d: crypto.encodepoint(points[i]), - ) - - self.assertEqual(len(muex), len(scalars)) - res = bp.multiexp(None, muex) - res2 = bp.vector_exponent_custom( - A=bp.KeyVEval( - 3, - lambda i, d: crypto.encodepoint_into( - crypto.scalarmult_base_into(None, crypto.Scalar(point_base[i])), d - ), - ), - B=bp.KeyVEval( - 3, - lambda i, d: crypto.encodepoint_into( - crypto.scalarmult_base_into(None, crypto.Scalar(point_base[3 + i])), - d, - ), - ), - a=bp.KeyVEval( - 3, - lambda i, d: crypto.encodeint_into(crypto.Scalar(scalars[i]), d), - ), - b=bp.KeyVEval( - 3, lambda i, d: crypto.encodeint_into(crypto.Scalar(scalars[i + 3]), d) - ), - ) - self.assertEqual(res, res2) - if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.monero.clsag.py b/core/tests/test_apps.monero.clsag.py index 66458998eb..9e1bf9ff6d 100644 --- a/core/tests/test_apps.monero.clsag.py +++ b/core/tests/test_apps.monero.clsag.py @@ -335,7 +335,7 @@ class TestMoneroClsag(unittest.TestCase): sD = crypto.scalarmult_base_into(None, crypto.random_scalar()) self.verify_clsag(msg, scalars, sc1, sI, sD, ring2, Cp) - def test_clsag_invalid_P(self): + def test_clsag_invalid_P_dest(self): res = self.gen_clsag_sig(ring_size=11, index=5) msg, scalars, sc1, sI, sD, ring2, Cp = res with self.assertRaises(ValueError): @@ -344,7 +344,7 @@ class TestMoneroClsag(unittest.TestCase): ) self.verify_clsag(msg, scalars, sc1, sI, sD, ring2, Cp) - def test_clsag_invalid_P(self): + def test_clsag_invalid_P_commitment(self): res = self.gen_clsag_sig(ring_size=11, index=5) msg, scalars, sc1, sI, sD, ring2, Cp = res with self.assertRaises(ValueError): diff --git a/core/tests/test_apps.tezos.address.py b/core/tests/test_apps.tezos.address.py index b5298c8b82..74121fab47 100644 --- a/core/tests/test_apps.tezos.address.py +++ b/core/tests/test_apps.tezos.address.py @@ -1,7 +1,5 @@ from common import * -from apps.common.paths import HARDENED - if not utils.BITCOIN_ONLY: from apps.tezos.sign_tx import _get_address_from_contract from trezor.enums import TezosContractType diff --git a/core/tests/test_apps.zcash.zip244.py b/core/tests/test_apps.zcash.zip244.py index 21053d593e..b935595b8a 100644 --- a/core/tests/test_apps.zcash.zip244.py +++ b/core/tests/test_apps.zcash.zip244.py @@ -5,10 +5,6 @@ from trezor.messages import PrevOutput, SignTx, TxInput from trezor.utils import HashWriter from apps.zcash.hasher import ZcashHasher, blake2b, write_hash -from apps.common.coininfo import by_name - - -ZCASH_COININFO = by_name("Zcash") # NOTE: moved into tests not to occupy flash space diff --git a/core/tests/test_storage.cache.py b/core/tests/test_storage.cache.py index e3e030e034..9f80027504 100644 --- a/core/tests/test_storage.cache.py +++ b/core/tests/test_storage.cache.py @@ -113,7 +113,7 @@ class TestStorageCache(unittest.TestCase): self.assertIsNone(cache.get(KEY)) cache.set(KEY, b"hello") - session_id2 = cache.start_session() + cache.start_session() self.assertIsNone(cache.get(KEY)) cache.set(KEY, b"hello") self.assertEqual(cache.get(KEY), b"hello") @@ -219,7 +219,7 @@ class TestStorageCache(unittest.TestCase): def test_EndSession(self): self.assertRaises(cache.InvalidSessionError, cache.get, KEY) - session_id = cache.start_session() + cache.start_session() self.assertTrue(is_session_started()) self.assertIsNone(cache.get(KEY)) await_result(handle_EndSession(EndSession())) diff --git a/core/tests/test_trezor.crypto.bip32.py b/core/tests/test_trezor.crypto.bip32.py index 4f007f07fe..2340dd1336 100644 --- a/core/tests/test_trezor.crypto.bip32.py +++ b/core/tests/test_trezor.crypto.bip32.py @@ -6,7 +6,6 @@ from trezor.crypto import bip32 SECP256K1_NAME = "secp256k1" HARDENED = 0x80000000 VERSION_PUBLIC = 0x0488B21E -VERSION_PRIVATE = 0x0488ADE4 class TestCryptoBip32(unittest.TestCase): diff --git a/core/tests/test_trezor.wire.codec_v1.py b/core/tests/test_trezor.wire.codec_v1.py index febd9b1d48..c84a62c708 100644 --- a/core/tests/test_trezor.wire.codec_v1.py +++ b/core/tests/test_trezor.wire.codec_v1.py @@ -1,7 +1,6 @@ from common import * import ustruct -from ubinascii import unhexlify from trezor import io from trezor.loop import wait