From 16c7284e98b27870b2751525dfd6fabf8987ea68 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 8 May 2017 22:31:21 +0200 Subject: [PATCH] apps.common: introduce cache module instead of caching in global variables --- src/apps/common/cache.py | 6 ++++++ src/apps/common/seed.py | 10 ++++------ src/apps/common/storage.py | 2 ++ tests/run_tests_python_trezor.sh | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 src/apps/common/cache.py diff --git a/src/apps/common/cache.py b/src/apps/common/cache.py new file mode 100644 index 0000000000..04272187ac --- /dev/null +++ b/src/apps/common/cache.py @@ -0,0 +1,6 @@ +seed = None + + +def clear(): + global seed + seed = None diff --git a/src/apps/common/seed.py b/src/apps/common/seed.py index 8c3fa223fe..069d6beb1a 100644 --- a/src/apps/common/seed.py +++ b/src/apps/common/seed.py @@ -4,8 +4,6 @@ from trezor.crypto import bip39 _DEFAULT_CURVE = 'secp256k1' -_cached_seed = None - async def get_root(session_id: int, curve_name=_DEFAULT_CURVE): seed = await get_seed(session_id) @@ -14,10 +12,10 @@ async def get_root(session_id: int, curve_name=_DEFAULT_CURVE): async def get_seed(session_id: int) -> bytes: - global _cached_seed - if _cached_seed is None: - _cached_seed = await compute_seed(session_id) - return _cached_seed + from . import cache + if cache.seed is None: + cache.seed = await compute_seed(session_id) + return cache.seed async def compute_seed(session_id: int) -> bytes: diff --git a/src/apps/common/storage.py b/src/apps/common/storage.py index 004c6d190c..00909be2ff 100644 --- a/src/apps/common/storage.py +++ b/src/apps/common/storage.py @@ -144,8 +144,10 @@ def load_settings(language: str=None, def wipe(): + from . import cache lock() config.wipe() + cache.clear() def new_device_id() -> str: diff --git a/tests/run_tests_python_trezor.sh b/tests/run_tests_python_trezor.sh index 774c125977..89565578a2 100755 --- a/tests/run_tests_python_trezor.sh +++ b/tests/run_tests_python_trezor.sh @@ -31,7 +31,7 @@ not passing: test_msg_changepin.py \ test_msg_ethereum_signtx.py test_msg_getaddress_show.py - test_msg_loaddevice.py + test_msg_loaddevice_xprv.py test_msg_ping.py test_msg_resetdevice.py test_msg_recoverydevice.py @@ -51,6 +51,7 @@ for i in \ test_msg_getaddress.py \ test_msg_getentropy.py test_msg_getpublickey.py \ + test_msg_loaddevice.py test_msg_signidentity.py \ test_msg_signmessage.py \ test_msg_signtx.py \