1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-29 02:48:18 +00:00

fixup: fix unit tests

This commit is contained in:
M1nd3r 2024-11-19 14:57:11 +01:00
parent 385f52a726
commit bcd68aecd9
6 changed files with 71 additions and 54 deletions

View File

@ -29,8 +29,15 @@ else:
class TestApprover(unittest.TestCase):
if utils.USE_THP:
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
def setUpClass(self):
if __debug__:
thp_common.suppres_debug_log()
thp_common.prepare_context()
else:
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
def tearDownClass(self):
context.CURRENT_CONTEXT = None

View File

@ -18,12 +18,20 @@ else:
class TestAuthorization(unittest.TestCase):
if utils.USE_THP:
coin = coins.by_name("Bitcoin")
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
if utils.USE_THP:
def setUpClass(self):
if __debug__:
thp_common.suppres_debug_log()
thp_common.prepare_context()
else:
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
def tearDownClass(self):
context.CURRENT_CONTEXT = None

View File

@ -15,13 +15,13 @@ else:
class TestBitcoinKeychain(unittest.TestCase):
if utils.USE_THP:
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def setUpClass(self):
if __debug__:
thp_common.suppres_debug_log()
thp_common.prepare_context()
def setUp(self):
seed = bip39.seed(" ".join(["all"] * 12), "")
@ -29,15 +29,17 @@ class TestBitcoinKeychain(unittest.TestCase):
else:
def __init__(self):
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
super().__init__()
def setUp(self):
cache_codec.start_session()
seed = bip39.seed(" ".join(["all"] * 12), "")
cache_codec.get_active_session().set(cache_common.APP_COMMON_SEED, seed)
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def test_bitcoin(self):
coin = _get_coin_by_name("Bitcoin")
keychain = await_result(_get_keychain_for_coin(coin))
@ -113,19 +115,30 @@ class TestBitcoinKeychain(unittest.TestCase):
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestAltcoinKeychains(unittest.TestCase):
if not utils.USE_THP:
if utils.USE_THP:
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
def setUpClass(self):
if __debug__:
thp_common.suppres_debug_log()
thp_common.prepare_context()
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def setUp(self):
seed = bip39.seed(" ".join(["all"] * 12), "")
context.cache_set(cache_common.APP_COMMON_SEED, seed)
else:
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
def setUp(self):
cache_codec.start_session()
seed = bip39.seed(" ".join(["all"] * 12), "")
cache_codec.get_active_session().set(cache_common.APP_COMMON_SEED, seed)
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def test_bcash(self):
coin = _get_coin_by_name("Bcash")
keychain = await_result(_get_keychain_for_coin(coin))

View File

@ -2,7 +2,7 @@ from common import * # isort:skip
from mock_storage import mock_storage
from storage import cache, cache_common
from trezor import utils, wire
from trezor import wire
from trezor.crypto import bip39
from trezor.enums import SafetyCheckLevel
from trezor.wire import context
@ -20,27 +20,24 @@ if not utils.USE_THP:
class TestKeychain(unittest.TestCase):
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
if utils.USE_THP:
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def __init__(self):
def setUpClass(self):
if __debug__:
thp_common.suppres_debug_log()
thp_common.prepare_context()
super().__init__()
else:
def __init__(self):
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
super().__init__()
def setUp(self):
cache_codec.start_session()
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def tearDown(self):
cache.clear_all()

View File

@ -79,17 +79,12 @@ class TestEthereumKeychain(unittest.TestCase):
addr,
)
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
if utils.USE_THP:
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def __init__(self):
def setUpClass(self):
if __debug__:
thp_common.suppres_debug_log()
thp_common.prepare_context()
super().__init__()
def setUp(self):
seed = bip39.seed(" ".join(["all"] * 12), "")
@ -97,15 +92,17 @@ class TestEthereumKeychain(unittest.TestCase):
else:
def __init__(self):
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
super().__init__()
def setUp(self):
cache_codec.start_session()
seed = bip39.seed(" ".join(["all"] * 12), "")
cache_codec.get_active_session().set(cache_common.APP_COMMON_SEED, seed)
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def from_address_n(self, address_n):
slip44 = _slip44_from_address_n(address_n)
network = make_network(slip44=slip44)

View File

@ -29,21 +29,11 @@ else:
class TestStorageCache(unittest.TestCase):
def setUpClass(self):
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
def tearDownClass(self):
context.CURRENT_CONTEXT = None
def setUp(self):
cache.clear_all()
if utils.USE_THP:
def __init__(self):
thp_common.suppres_debug_log()
# xthp_common.prepare_context()
# config.init()
def setUpClass(self):
if __debug__:
thp_common.suppres_debug_log()
super().__init__()
def setUp(self):
@ -316,14 +306,19 @@ class TestStorageCache(unittest.TestCase):
else:
def __init__(self):
# Context is needed to test decorators and handleInitialize
# It allows access to codec cache from different parts of the code
from trezor.wire import context
def setUpClass(self):
from trezor.wire.codec.codec_context import CodecContext
from trezor.wire import context
context.CURRENT_CONTEXT = CodecContext(None, bytearray(64))
super().__init__()
def tearDownClass(self):
from trezor.wire import context
context.CURRENT_CONTEXT = None
def setUp(self):
cache.clear_all()
def test_start_session(self):
session_id_a = cache_codec.start_session()