Skip to content

Commit

Permalink
[test] add test for flex
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Jul 16, 2024
1 parent 3d896c7 commit 26f9e30
Show file tree
Hide file tree
Showing 133 changed files with 95 additions and 45 deletions.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ integration_tests_basic_stax: app_stax.tgz \
tests/integration/touch/*
$(RUN_TEST_DOCKER) stax tests/integration/touch

integration_tests_basic_flex: app_flex.tgz \
app_flex_dbg.tgz \
tests/integration/* \
tests/integration/touch/*
$(RUN_TEST_DOCKER) flex tests/integration/touch

integration_tests_basic_%: app_%.tgz \
app_%_dbg.tgz \
tests/integration/* \
Expand All @@ -124,7 +130,8 @@ integration_tests_basic_%: app_%.tgz \
integration_tests_basic: integration_tests_basic_nanos \
integration_tests_basic_nanosp \
integration_tests_basic_nanox \
integration_tests_basic_stax
integration_tests_basic_stax \
integration_tests_basic_flex

integration_tests_%: integration_tests_basic_% \
test/samples/operations/nano/samples.hex\
Expand All @@ -138,7 +145,8 @@ integration_tests: tests/integration/*.sh \
integration_tests_nanos \
integration_tests_nanosp \
integration_tests_nanox \
integration_tests_basic_stax
integration_tests_basic_stax \
integration_tests_basic_flex

test/samples/micheline/%/samples.hex: tests/generate/*.ml* \
tests/generate/dune \
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ run_a_test() {
. $CMD
;;
*.py)
if [ "$TARGET" == "stax" ]; then
if [ "$TARGET" == "stax" ] || [ "$TARGET" == "flex" ]; then
start_speculos "$seed"
PORT=$PORT\
COMMIT_BYTES=$COMMIT_BYTES\
Expand Down Expand Up @@ -586,8 +586,8 @@ main() {

[ $# -lt 1 ] && usage "At least one test must be provided"

if ! echo $TARGET | grep -qE '^(stax)|(nano(s|sp|x))$'; then
usage "Target \"$TARGET\" must be nanos, nanosp, nanox or stax."
if ! echo $TARGET | grep -qE '^(stax)|(flex)|(nano(s|sp|x))$'; then
usage "Target \"$TARGET\" must be nanos, nanosp, nanox, stax or flex."
fi

if [ -z "$TGZ" ]; then
Expand Down
Binary file added tests/integration/touch/snapshots/flex/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/integration/touch/snapshots/flex/info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions tests/integration/touch/test_blindsign_valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from utils import (
tezos_app,
send_initialize_msg,
send_payload
send_payload,
index_screen
)

if __name__ == "__main__":
Expand All @@ -41,17 +42,18 @@
send_initialize_msg(app,"800f000011048000002c800006c18000000080000000")
send_payload(app,"800f81005e0300000000000000000000000000000000000000000000000000000000000000006c016e8874874d31c3fbd636e924d5a036a43ec8faa7d0860308362d80d30e01000000000000000000000000000000000000000000ff02000000020316")

app.review.next()
app.assert_screen("tst_review_001")
screen = "tst_review"
nb_screen = 2

app.review.next()
app.assert_screen("tst_review_002")
for index in range(1, nb_screen+1):
app.review.next()
app.assert_screen(index_screen(screen, index))

app.review.next()
app.expert_mode_splash()

app.review.next()
app.assert_screen("tst_review_003")
app.assert_screen(index_screen(screen, index+1))

app.review.next()
app.assert_screen("operation_sign")
Expand Down
14 changes: 9 additions & 5 deletions tests/integration/touch/test_expert_mode_rejections.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
tezos_app,
send_initialize_msg,
send_payload,
verify_reject_response
verify_reject_response,
index_screen
)

# full input: 0300000000000000000000000000000000000000000000000000000000000000006c016e8874874d31c3fbd636e924d5a036a43ec8faa7d0860308362d80d30e01000000000000000000000000000000000000000000ff02000000020316
Expand All @@ -30,10 +31,13 @@ def sign_transfer_initialize(app):
app.assert_home()
send_initialize_msg(app,"800f000011048000002c800006c18000000080000000")
send_payload(app,"800f81005e0300000000000000000000000000000000000000000000000000000000000000006c016e8874874d31c3fbd636e924d5a036a43ec8faa7d0860308362d80d30e01000000000000000000000000000000000000000000ff02000000020316")
app.review.next()
app.assert_screen("tst_review_001")
app.review.next()
app.assert_screen("tst_review_002")

screen = "tst_review"
nb_screen = 2

for index in range(1, nb_screen+1):
app.review.next()
app.assert_screen(index_screen(screen, index))


if __name__ == "__main__":
Expand Down
27 changes: 16 additions & 11 deletions tests/integration/touch/test_sign_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from utils import (
tezos_app,
send_initialize_msg,
send_payload
send_payload,
index_screen
)

# full input: 0300000000000000000000000000000000000000000000000000000000000000006c016e8874874d31c3fbd636e924d5a036a43ec8faa7d0860308362d80d30e01000000000000000000000000000000000000000000ff02000000020316
Expand All @@ -31,17 +32,19 @@

send_initialize_msg(app, "800f000011048000002c800006c18000000080000000")
send_payload(app, "800f81005e0300000000000000000000000000000000000000000000000000000000000000006c016e8874874d31c3fbd636e924d5a036a43ec8faa7d0860308362d80d30e01000000000000000000000000000000000000000000ff02000000020316")
app.review.next()
app.assert_screen("tst_review_001")

app.review.next()
app.assert_screen("tst_review_002")
screen = "tst_review"
nb_screen = 2

for index in range(1, nb_screen+1):
app.review.next()
app.assert_screen(index_screen(screen, index))

app.review.next()
app.expert_mode_splash()

app.review.next()
app.assert_screen("tst_review_003")
app.assert_screen(index_screen(screen, index+1))

app.review.next()
app.assert_screen("operation_sign")
Expand All @@ -54,17 +57,19 @@
# Now with expert enabled
send_initialize_msg(app, "800f000011048000002c800006c18000000080000000")
send_payload(app, "800f81005e0300000000000000000000000000000000000000000000000000000000000000006c016e8874874d31c3fbd636e924d5a036a43ec8faa7d0860308362d80d30e01000000000000000000000000000000000000000000ff02000000020316")
app.review.next()
app.assert_screen("tst_review_001")

app.review.next()
app.assert_screen("tst_review_002")
screen = "tst_review"
nb_screen = 2

for index in range(1, nb_screen+1):
app.review.next()
app.assert_screen(index_screen(screen, index))

app.review.next()
app.assert_screen("expert_mode_splash")

app.review.next()
app.assert_screen("tst_review_003")
app.assert_screen(index_screen(screen, index+1))

app.review.next()
app.assert_screen("operation_sign")
Expand Down
15 changes: 9 additions & 6 deletions tests/integration/touch/test_sign_transfer_without_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from utils import (
tezos_app,
send_initialize_msg,
send_payload
send_payload,
index_screen
)

# full input: 0300000000000000000000000000000000000000000000000000000000000000006c016e8874874d31c3fbd636e924d5a036a43ec8faa7d0860308362d80d30e01000000000000000000000000000000000000000000ff02000000020316
Expand All @@ -31,17 +32,19 @@

send_initialize_msg(app, "8004000011048000002c800006c18000000080000000")
send_payload(app, "800481005e0300000000000000000000000000000000000000000000000000000000000000006c016e8874874d31c3fbd636e924d5a036a43ec8faa7d0860308362d80d30e01000000000000000000000000000000000000000000ff02000000020316")
app.review.next()
app.assert_screen("review_0")

app.review.next()
app.assert_screen("review_1")
screen = "review"
nb_screen = 2

for index in range(1, nb_screen+1):
app.review.next()
app.assert_screen(index_screen(screen, index))

app.review.next()
app.expert_mode_splash()

app.review.next()
app.assert_screen("review_2")
app.assert_screen(index_screen(screen, index+1))

app.review.next()
app.assert_screen("operation_sign")
Expand Down
52 changes: 40 additions & 12 deletions tests/integration/touch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
STAX_BUTTON_LOWER_LEFT,
STAX_BUTTON_ABOVE_LOWER_MIDDLE,
STAX_BUTTON_LOWER_RIGHT,
STAX_BUTTON_LOWER_MIDDLE
STAX_BUTTON_LOWER_MIDDLE,
FLEX_BUTTON_LOWER_LEFT,
FLEX_BUTTON_ABOVE_LOWER_MIDDLE
)

MAX_ATTEMPTS = 50
Expand All @@ -62,7 +64,10 @@ class UseCaseChoice(OriginalUseCaseChoice):
# Fixed in Ragger v1.21.0
def reject(self) -> None:
"""Tap on reject button."""
self.client.finger_touch(*STAX_BUTTON_LOWER_LEFT)
if self.firmware == Firmware.STAX:
self.client.finger_touch(*STAX_BUTTON_LOWER_LEFT)
if self.firmware == Firmware.FLEX:
super().reject()

class UseCaseReview(OriginalUseCaseReview):
"""Extension of UseCaseReview for our app."""
Expand All @@ -87,24 +92,36 @@ def next(self) -> None:
# Fixed in Ragger v1.21.0
def tap(self) -> None:
"""Tap on screen."""
self.client.finger_touch(*STAX_BUTTON_LOWER_RIGHT)
if self.firmware == Firmware.STAX:
self.client.finger_touch(*STAX_BUTTON_LOWER_RIGHT)
if self.firmware == Firmware.FLEX:
super().tap()

# Fixed in Ragger v1.21.0
def previous(self) -> None:
"""Tap on screen."""
self.client.finger_touch(*STAX_BUTTON_LOWER_MIDDLE)
if self.firmware == Firmware.STAX:
self.client.finger_touch(*STAX_BUTTON_LOWER_MIDDLE)
if self.firmware == Firmware.FLEX:
super().previous()

# Fixed in Ragger v1.21.0
def reject(self) -> None:
"""Tap on reject button."""
self.client.finger_touch(*STAX_BUTTON_LOWER_LEFT)
if self.firmware == Firmware.STAX:
self.client.finger_touch(*STAX_BUTTON_LOWER_LEFT)
if self.firmware == Firmware.FLEX:
super().reject()

class UseCaseAddressConfirmation(OriginalUseCaseAddressConfirmation):
"""Extension of UseCaseAddressConfirmation for our app."""

_center: Center

QR_POSITION = Position(STAX_BUTTON_LOWER_LEFT.x, STAX_BUTTON_ABOVE_LOWER_MIDDLE.y)
QR_POSITIONS = {
Firmware.STAX: Position(STAX_BUTTON_LOWER_LEFT.x, STAX_BUTTON_ABOVE_LOWER_MIDDLE.y),
Firmware.FLEX: Position(FLEX_BUTTON_LOWER_LEFT.x, FLEX_BUTTON_ABOVE_LOWER_MIDDLE.y)
}

def __init__(self, client: BackendInterface, firmware: Firmware):
super().__init__(client, firmware)
Expand All @@ -117,7 +134,7 @@ def next(self) -> None:
@property
def qr_position(self) -> Position:
"""Position of the qr code."""
return UseCaseAddressConfirmation.QR_POSITION
return UseCaseAddressConfirmation.QR_POSITIONS[self.firmware]

def show_qr(self) -> None:
"""Tap to show qr code."""
Expand All @@ -126,7 +143,10 @@ def show_qr(self) -> None:
# Fixed in Ragger v1.21.0
def cancel(self) -> None:
"""Tap on cancel button."""
self.client.finger_touch(*STAX_BUTTON_LOWER_LEFT)
if self.firmware == Firmware.STAX:
self.client.finger_touch(*STAX_BUTTON_LOWER_LEFT)
if self.firmware == Firmware.FLEX:
super().cancel()

class UseCaseSettings(OriginalUseCaseSettings):
"""Extension of UseCaseSettings for our app."""
Expand All @@ -153,7 +173,10 @@ def exit(self) -> None:
STAX_BUTTON_LOWER_MIDDLE_RIGHT = Position(266, 615)
def previous(self) -> None:
"""Tap on cancel button."""
self.client.finger_touch(*UseCaseSettings.STAX_BUTTON_LOWER_MIDDLE_RIGHT)
if self.firmware == Firmware.STAX:
self.client.finger_touch(*UseCaseSettings.STAX_BUTTON_LOWER_MIDDLE_RIGHT)
if self.firmware == Firmware.FLEX:
super().previous()

class TezosAppScreen(metaclass=MetaScreen):
use_case_welcome = UseCaseHomeExt
Expand All @@ -166,8 +189,9 @@ class TezosAppScreen(metaclass=MetaScreen):
provide_pk: UseCaseAddressConfirmation
review: UseCaseReview

commit: str
version: str
firmware: Firmware
commit: str
version: str

__backend: BackendInterface
__golden: bool
Expand All @@ -188,6 +212,7 @@ def __init__(self,
f"{os.path.dirname(realpath)}/snapshots/{firmware.name}"
self.__prefixed_snapshots_path = \
f"{self.__snapshots_path}/{Path(snapshot_prefix).stem}"
self.firmware = firmware
self.commit = commit
self.version = version
self.__golden = golden
Expand Down Expand Up @@ -322,7 +347,7 @@ def tezos_app(prefix) -> TezosAppScreen:
version = os.environ["VERSION_BYTES"]
golden = os.getenv("GOLDEN") != None
target = os.getenv("TARGET")
firmware = Firmware.STAX if target == "stax" else Firmware.STAX
firmware = Firmware.STAX if target == "stax" else Firmware.FLEX
backend = SpeculosBackend("__unused__", firmware, args=["--api-port", port])
return TezosAppScreen(backend, firmware, commit, version, prefix, golden)

Expand Down Expand Up @@ -352,3 +377,6 @@ def verify_reject_response_common(app, tag, err_code):
with app.fading_screen("rejected"):
app.review.reject_tx.confirm()
assert_home_with_code(app, err_code)

def index_screen(screen: str, index: int) -> str:
return screen + "_" + str(index).zfill(2)

0 comments on commit 26f9e30

Please sign in to comment.