1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-03 03:50:58 +00:00

chore(tests): remove unused imports and variables

[no changelog]
This commit is contained in:
grdddj 2023-06-28 12:48:01 +02:00 committed by Vít Obrusník
parent 4bca28bac0
commit 171c615dfa
21 changed files with 17 additions and 125 deletions

View File

@ -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:

View File

@ -1,4 +1,4 @@
if False:
if False: # noqa
from typing import Any

View File

@ -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):

View File

@ -1,5 +1,4 @@
from common import *
from apps.common.paths import HARDENED
from trezor.crypto.curve import secp256k1

View File

@ -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

View File

@ -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()

View File

@ -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()

View File

@ -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,

View File

@ -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 (

View File

@ -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,

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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()

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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()))

View File

@ -6,7 +6,6 @@ from trezor.crypto import bip32
SECP256K1_NAME = "secp256k1"
HARDENED = 0x80000000
VERSION_PUBLIC = 0x0488B21E
VERSION_PRIVATE = 0x0488ADE4
class TestCryptoBip32(unittest.TestCase):

View File

@ -1,7 +1,6 @@
from common import *
import ustruct
from ubinascii import unhexlify
from trezor import io
from trezor.loop import wait