From 8c5eb7d03d4b8a60bd376a36f0345664ef99b2f0 Mon Sep 17 00:00:00 2001 From: Carlos Medeiros Date: Fri, 4 Oct 2024 15:37:35 +0100 Subject: [PATCH] add support for blindsign tests --- src/Zemu.ts | 22 ++++++++++++++++++++-- src/zondax.ts | 12 ++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Zemu.ts b/src/Zemu.ts index 79b5dc1..1afa6da 100644 --- a/src/Zemu.ts +++ b/src/Zemu.ts @@ -66,7 +66,12 @@ import { type ISwipeCoordinates, type TModel, } from "./types"; -import { isTouchDevice, zondaxToggleExpertMode, zondaxTouchEnableSpecialMode } from "./zondax"; +import { + isTouchDevice, + zondaxToggleBlindSigning, + zondaxToggleExpertMode, + zondaxTouchEnableSpecialMode, +} from "./zondax"; export default class Zemu { public startOptions!: IStartOptions; @@ -445,6 +450,11 @@ export default class Zemu { return await this.navigate(".", testcaseName, nav.schedule, true, takeSnapshots, startImgIndex); } + async toggleBlindSigning(testcaseName = "", takeSnapshots = false, startImgIndex = 0): Promise { + const nav = zondaxToggleBlindSigning(this.startOptions.model); + return await this.navigate(".", testcaseName, nav.schedule, true, takeSnapshots, startImgIndex); + } + async enableSpecialMode( nanoModeText: string, nanoIsSecretMode: boolean = false, @@ -582,6 +592,7 @@ export default class Zemu { waitForScreenUpdate = true, startImgIndex = 0, timeout = DEFAULT_METHOD_TIMEOUT, + isBlindSigning = false, ): Promise { const approveKeyword = this.startOptions.approveKeyword; const takeSnapshots = true; @@ -593,6 +604,9 @@ export default class Zemu { takeSnapshots, startImgIndex, timeout, + true, + true, + isBlindSigning, ); if (isTouchDevice(this.startOptions.model)) { // Avoid taking a snapshot of the final animation @@ -664,6 +678,7 @@ export default class Zemu { timeout = DEFAULT_METHOD_TIMEOUT, runLastAction = true, waitForInitialEventsChange = true, + isBlindSigning = false, ): Promise { const snapshotPrefixGolden = resolve(`${path}/snapshots/${testcaseName}`); const snapshotPrefixTmp = resolve(`${path}/snapshots-tmp/${testcaseName}`); @@ -701,7 +716,10 @@ export default class Zemu { const nav: INavElement = { type: touchDevice ? ActionKind.Touch : ActionKind.RightClick, - button: getTouchElement(this.startOptions.model, ButtonKind.SwipeContinueButton), // For clicks, this will be ignored + button: + imageIndex === 1 && isBlindSigning + ? getTouchElement(this.startOptions.model, ButtonKind.RejectButton) + : getTouchElement(this.startOptions.model, ButtonKind.SwipeContinueButton), // Change button based on imageIndex }; await this.runAction(nav, filename, waitForScreenUpdate, true); start = new Date(); diff --git a/src/zondax.ts b/src/zondax.ts index f916acd..7036b4d 100644 --- a/src/zondax.ts +++ b/src/zondax.ts @@ -47,6 +47,18 @@ export function zondaxToggleExpertMode(model: TModel, clickArray?: number[]): Cl return new ClickNavigation(clickArray ?? DEFAULT_EXPERT_MODE_CLICKS); } +export function zondaxToggleBlindSigning(model: TModel, clickArray?: number[]): ClickNavigation | TouchNavigation { + if (isTouchDevice(model)) { + return new TouchNavigation(model, [ + ButtonKind.InfoButton, + ButtonKind.ToggleSettingButton2, + ButtonKind.SettingsQuitButton, + ]); + } + const DEFAULT_BLIND_SIGNING_MODE_CLICKS = [2, 0, -2]; + return new ClickNavigation(clickArray ?? DEFAULT_BLIND_SIGNING_MODE_CLICKS); +} + export function zondaxTouchEnableSpecialMode(model: TModel, toggleSettingButton?: ButtonKind): TouchNavigation { return new TouchNavigation(model, [ ButtonKind.InfoButton,