1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-08-02 11:58:32 +00:00

WIP - fix unittests that fail to write to storage

This commit is contained in:
grdddj 2022-03-22 18:14:40 +01:00
parent 5c39e775f6
commit 00fe4cd38a
2 changed files with 10 additions and 10 deletions

View File

@ -1,9 +1,6 @@
from common import * from common import *
from mock_storage import mock_storage
from storage import cache from storage import cache
from apps.common import safety_checks
from apps.common.paths import PATTERN_SEP5, PathSchema from apps.common.paths import PATTERN_SEP5, PathSchema
from apps.common.keychain import LRUCache, Keychain, with_slip44_keychain, get_keychain from apps.common.keychain import LRUCache, Keychain, with_slip44_keychain, get_keychain
from trezor import wire from trezor import wire
@ -18,7 +15,6 @@ class TestKeychain(unittest.TestCase):
def tearDown(self): def tearDown(self):
cache.clear_all() cache.clear_all()
@mock_storage
def test_verify_path(self): def test_verify_path(self):
schemas = ( schemas = (
PathSchema.parse("m/44'/coin_type'", slip44_id=134), PathSchema.parse("m/44'/coin_type'", slip44_id=134),
@ -43,7 +39,12 @@ class TestKeychain(unittest.TestCase):
keychain.verify_path(f) keychain.verify_path(f)
# turn off restrictions # turn off restrictions
safety_checks.apply_setting(SafetyCheckLevel.PromptTemporarily) # Call to safety_checks.apply_setting() does not work here because
# storage is not ready to be written to
cache.set(
cache.APP_COMMON_SAFETY_CHECKS_TEMPORARY,
SafetyCheckLevel.PromptTemporarily.to_bytes(1, "big"),
)
for path in correct + fails: for path in correct + fails:
keychain.verify_path(path) keychain.verify_path(path)
@ -74,9 +75,7 @@ class TestKeychain(unittest.TestCase):
cache.set(cache.APP_COMMON_SEED, seed) cache.set(cache.APP_COMMON_SEED, seed)
schema = PathSchema.parse("m/44'/1'", 0) schema = PathSchema.parse("m/44'/1'", 0)
keychain = await_result( keychain = await_result(get_keychain(wire.DUMMY_CONTEXT, "secp256k1", [schema]))
get_keychain(wire.DUMMY_CONTEXT, "secp256k1", [schema])
)
# valid path: # valid path:
self.assertIsNotNone(keychain.derive([H_(44), H_(1)])) self.assertIsNotNone(keychain.derive([H_(44), H_(1)]))

View File

@ -1,7 +1,7 @@
from common import * from common import *
from mock_storage import mock_storage
from storage import cache from storage import cache
from trezor import config
from trezor.messages import Initialize from trezor.messages import Initialize
from trezor.messages import EndSession from trezor.messages import EndSession
from trezor.wire import DUMMY_CONTEXT from trezor.wire import DUMMY_CONTEXT
@ -163,8 +163,9 @@ class TestStorageCache(unittest.TestCase):
# function is not called for a second time # function is not called for a second time
self.assertEqual(run_count, 1) self.assertEqual(run_count, 1)
@mock_storage
def test_Initialize(self): def test_Initialize(self):
config.init()
def call_Initialize(**kwargs): def call_Initialize(**kwargs):
msg = Initialize(**kwargs) msg = Initialize(**kwargs)
return await_result(handle_Initialize(DUMMY_CONTEXT, msg)) return await_result(handle_Initialize(DUMMY_CONTEXT, msg))