From df6208c389da5bfd71c9ab82ec46b86fcd6f31d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Palmer?= Date: Thu, 5 Oct 2023 14:12:14 +0200 Subject: [PATCH 1/3] Tests: refactor the with_retry function to make it more generic --- tests/integration/check_section_text.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integration/check_section_text.py b/tests/integration/check_section_text.py index 94f557529..c4cf50e96 100755 --- a/tests/integration/check_section_text.py +++ b/tests/integration/check_section_text.py @@ -47,12 +47,11 @@ def strip(self, content: str) -> str: content = content.lstrip('\n') return content -def with_retry(url, f, timeout=TIMEOUT): +def with_retry(f, timeout=TIMEOUT): attempts = timeout / 0.5 while True: try: - on_screen = get_screen(url) - return f(on_screen) + return f() except AssertionError as e: print('- retrying:', e) if attempts <= 0: @@ -89,14 +88,15 @@ def press_left(url): def check_multi_screen(url, title, content, content_lines, device): """Assert that the screen contents across all screens with the given title match expected content.""" while True: - def check_screen(screen): + def check_screen(): + screen = get_screen(url) assert screen.title == title, f"expected section '{title}' but on '{screen.title}'" assert screen.matches(content, content_lines), \ f"{screen} did not match {content[:10]}...{content[-10:]}" return screen.strip(content) - content = with_retry(url, check_screen) + content = with_retry(check_screen) if content == "": break From 87c636d952a513bfc803266d28633f5b1935e664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Palmer?= Date: Thu, 5 Oct 2023 14:59:43 +0200 Subject: [PATCH 2/3] Tests: get screens contents with the 'events' service for nanox While the 'events?currentscreenonly=true' service does not work properly for nanox in the sha-6a34680 version of speculos --- tests/integration/check_section_text.py | 33 +++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/integration/check_section_text.py b/tests/integration/check_section_text.py index c4cf50e96..08dd234b0 100755 --- a/tests/integration/check_section_text.py +++ b/tests/integration/check_section_text.py @@ -71,6 +71,27 @@ def get_screen(url): print(f'- {screen} -') return screen +def find_last(lst, elm): + """Find the index of the last element in lst that matches elm""" + gen = (len(lst) - 1 - i for i, v in enumerate(reversed(lst)) if v == elm) + return next(gen, None) + +def get_titled_screen(url, title): + """Retrieve the screen until title""" + r = requests.get(f'{url}/events') + r.raise_for_status() + lines = [e["text"] for e in r.json()["events"]] + + assert len(lines) > 0, "Unexpected empty screen. Speculos killed?" + + assert title in lines, f"Title \"{title}\" no found" + + title_index = find_last(lines, title) + + screen = Screen(title=lines[title_index], text=lines[title_index+1:]) + print(f'- {screen} -') + return screen + def press_button(url, button): """Press a button on the ledger device.""" print("- press", button) @@ -89,8 +110,16 @@ def check_multi_screen(url, title, content, content_lines, device): """Assert that the screen contents across all screens with the given title match expected content.""" while True: def check_screen(): - screen = get_screen(url) - assert screen.title == title, f"expected section '{title}' but on '{screen.title}'" + if device in ["nanos", "nanosp"]: + screen = get_screen(url) + assert screen.title == title, f"expected section '{title}' but on '{screen.title}'" + # https://github.com/trilitech/ledger-app-tezos-wallet/issues/43 + # Get screens contents with the 'events' service for nanox + # while the 'events?currentscreenonly=true' service does not + # work properly for nanox in the sha-6a34680 version of + # speculos + if device == "nanox": + screen = get_titled_screen(url, title) assert screen.matches(content, content_lines), \ f"{screen} did not match {content[:10]}...{content[-10:]}" From 056fac0e98b44bdb1c4de1dcc874489e5ce654ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Palmer?= Date: Thu, 5 Oct 2023 15:23:35 +0200 Subject: [PATCH 3/3] CI: re-enable nanox generated tests --- .github/workflows/build.yml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 560f4808d..b147767a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -116,8 +116,8 @@ jobs: mkdir -p tests/samples/micheline/nanosp mkdir -p tests/samples/operations/nanosp -# mkdir -p tests/samples/micheline/nanox -# mkdir -p tests/samples/operations/nanox + mkdir -p tests/samples/micheline/nanox + mkdir -p tests/samples/operations/nanox - name: Generate run: | @@ -133,10 +133,10 @@ jobs: dune exec ./tests/generate/generate.exe operations 500 \ nanosp tests/samples/operations \ -# dune exec ./tests/generate/generate.exe micheline 500 \ -# nanox tests/samples/micheline -# dune exec ./tests/generate/generate.exe operations 500 \ -# nanox tests/samples/operations + dune exec ./tests/generate/generate.exe micheline 500 \ + nanox tests/samples/micheline + dune exec ./tests/generate/generate.exe operations 500 \ + nanox tests/samples/operations - name: Unit tests run: | @@ -167,17 +167,17 @@ jobs: name: nanosp_samples_operations path: tests/samples/operations/nanosp -# - name: Upload results (nanox, micheline) -# uses: actions/upload-artifact@v3 -# with: -# name: nanox_samples_micheline -# path: tests/samples/micheline/nanox -# -# - name: Upload results (nanox, operations) -# uses: actions/upload-artifact@v3 -# with: -# name: nanox_samples_operations -# path: tests/samples/operations/nanox + - name: Upload results (nanox, micheline) + uses: actions/upload-artifact@v3 + with: + name: nanox_samples_micheline + path: tests/samples/micheline/nanox + + - name: Upload results (nanox, operations) + uses: actions/upload-artifact@v3 + with: + name: nanox_samples_operations + path: tests/samples/operations/nanox integration_tests_samples: needs: [build_app, generate_samples_unit_tests, build_docker_integration_tests] @@ -185,7 +185,7 @@ jobs: strategy: fail-fast: false matrix: - device: [nanos, nanosp] + device: [nanos, nanosp, nanox] type: [micheline, operations] container: image: ${{ needs.build_docker_integration_tests.outputs.image }}