diff --git a/tests/device_tests/REGISTERED_MARKERS b/tests/REGISTERED_MARKERS similarity index 100% rename from tests/device_tests/REGISTERED_MARKERS rename to tests/REGISTERED_MARKERS diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/device_tests/common.py b/tests/common.py similarity index 100% rename from tests/device_tests/common.py rename to tests/common.py diff --git a/tests/device_tests/conftest.py b/tests/conftest.py similarity index 100% rename from tests/device_tests/conftest.py rename to tests/conftest.py diff --git a/tests/upgrade_tests/download_emulators.sh b/tests/download_emulators.sh similarity index 100% rename from tests/upgrade_tests/download_emulators.sh rename to tests/download_emulators.sh diff --git a/tests/upgrade_tests/emulator_wrapper.py b/tests/emulators.py similarity index 75% rename from tests/upgrade_tests/emulator_wrapper.py rename to tests/emulators.py index 76c833fdb..91ca16b6c 100644 --- a/tests/upgrade_tests/emulator_wrapper.py +++ b/tests/emulators.py @@ -14,6 +14,7 @@ # You should have received a copy of the License along with this library. # If not, see . +from collections import defaultdict import os import subprocess import tempfile @@ -25,6 +26,47 @@ from trezorlib.transport import TransportException, get_transport BINDIR = os.path.dirname(os.path.abspath(__file__)) + "/emulators" ENV = {"SDL_VIDEODRIVER": "dummy"} +ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../" +LOCAL_BUILDS = { + "core": ROOT + "core/build/unix/micropython", + "legacy": ROOT + "legacy/firmware/trezor.elf", +} +BIN_DIR = os.path.dirname(os.path.abspath(__file__)) + "/emulators" + + +def check_version(tag, ver_emu): + if tag.startswith("v") and len(tag.split(".")) == 3: + assert tag == "v" + ".".join(["%d" % i for i in ver_emu]) + + +def check_file(gen, tag): + if tag.startswith("/"): + filename = tag + else: + filename = "%s/trezor-emu-%s-%s" % (BIN_DIR, gen, tag) + if not os.path.exists(filename): + raise ValueError(filename + " not found. Do not forget to build firmware.") + + +def get_tags(): + files = os.listdir(BIN_DIR) + if not files: + raise ValueError( + "No files found. Use download_emulators.sh to download emulators." + ) + + result = defaultdict(list) + for f in sorted(files): + try: + _, _, gen, tag = f.split("-", maxsplit=3) + result[gen].append(tag) + except ValueError: + pass + return result + + +ALL_TAGS = get_tags() + class EmulatorWrapper: def __init__(self, gen, tag, storage=None): diff --git a/tests/upgrade_tests/emulators/.gitignore b/tests/emulators/.gitignore similarity index 100% rename from tests/upgrade_tests/emulators/.gitignore rename to tests/emulators/.gitignore diff --git a/tests/device_tests/tx_cache.py b/tests/tx_cache.py similarity index 96% rename from tests/device_tests/tx_cache.py rename to tests/tx_cache.py index 991a9edef..2133e55f4 100644 --- a/tests/device_tests/tx_cache.py +++ b/tests/tx_cache.py @@ -21,7 +21,7 @@ import os.path from trezorlib import coins from trezorlib.tx_api import json_to_tx -CACHE_PATH = os.path.join(os.path.dirname(__file__), "..", "txcache") +CACHE_PATH = os.path.join(os.path.dirname(__file__), "txcache") def tx_cache(coin_name, allow_fetch=True): diff --git a/tests/upgrade_tests/test_firmware_upgrades.py b/tests/upgrade_tests/test_firmware_upgrades.py index 533c91983..352003af7 100644 --- a/tests/upgrade_tests/test_firmware_upgrades.py +++ b/tests/upgrade_tests/test_firmware_upgrades.py @@ -25,10 +25,7 @@ from trezorlib.tools import H_ MINIMUM_FIRMWARE_VERSION["1"] = (1, 0, 0) MINIMUM_FIRMWARE_VERSION["T"] = (2, 0, 0) -try: - from .emulator_wrapper import EmulatorWrapper -except ImportError: - pass +from ..emulators import EmulatorWrapper, ALL_TAGS, LOCAL_BUILDS # **** COMMON DEFINITIONS **** @@ -39,47 +36,6 @@ LABEL = "test" LANGUAGE = "english" STRENGTH = 128 -ROOT = os.path.dirname(os.path.abspath(__file__)) + "/../../" -LOCAL_BUILDS = { - "core": ROOT + "core/build/unix/micropython", - "legacy": ROOT + "legacy/firmware/trezor.elf", -} -BIN_DIR = os.path.dirname(os.path.abspath(__file__)) + "/emulators" - - -def check_version(tag, ver_emu): - if tag.startswith("v") and len(tag.split(".")) == 3: - assert tag == "v" + ".".join(["%d" % i for i in ver_emu]) - - -def check_file(gen, tag): - if tag.startswith("/"): - filename = tag - else: - filename = "%s/trezor-emu-%s-%s" % (BIN_DIR, gen, tag) - if not os.path.exists(filename): - raise ValueError(filename + " not found. Do not forget to build firmware.") - - -def get_tags(): - files = os.listdir(BIN_DIR) - if not files: - raise ValueError( - "No files found. Use download_emulators.sh to download emulators." - ) - - result = defaultdict(list) - for f in sorted(files): - try: - _, _, gen, tag = f.split("-", maxsplit=3) - result[gen].append(tag) - except ValueError: - pass - return result - - -ALL_TAGS = get_tags() - def for_all(*args, minimum_version=(1, 0, 0)): if not args: