Skip to content

Commit

Permalink
Merge pull request #46 from trilitech/palmer@functori@43-nanox-re-ena…
Browse files Browse the repository at this point in the history
…ble-generated-tests

Re-enable nanox generated tests
  • Loading branch information
emturner authored Oct 9, 2023
2 parents c7a8272 + 056fac0 commit e694e3e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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: |
Expand Down Expand Up @@ -167,25 +167,25 @@ 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]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
device: [nanos, nanosp]
device: [nanos, nanosp, nanox]
type: [micheline, operations]
container:
image: ${{ needs.build_docker_integration_tests.outputs.image }}
Expand Down
41 changes: 35 additions & 6 deletions tests/integration/check_section_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -72,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)
Expand All @@ -89,14 +109,23 @@ 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):
assert screen.title == title, f"expected section '{title}' but on '{screen.title}'"
def check_screen():
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:]}"

return screen.strip(content)

content = with_retry(url, check_screen)
content = with_retry(check_screen)

if content == "":
break
Expand Down

0 comments on commit e694e3e

Please sign in to comment.