Skip to content

Commit

Permalink
add support for blindsign tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Oct 4, 2024
1 parent 6a1c9c0 commit 8c5eb7d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Zemu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<number> {
const nav = zondaxToggleBlindSigning(this.startOptions.model);
return await this.navigate(".", testcaseName, nav.schedule, true, takeSnapshots, startImgIndex);
}

async enableSpecialMode(
nanoModeText: string,
nanoIsSecretMode: boolean = false,
Expand Down Expand Up @@ -582,6 +592,7 @@ export default class Zemu {
waitForScreenUpdate = true,
startImgIndex = 0,
timeout = DEFAULT_METHOD_TIMEOUT,
isBlindSigning = false,
): Promise<boolean> {
const approveKeyword = this.startOptions.approveKeyword;
const takeSnapshots = true;
Expand All @@ -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
Expand Down Expand Up @@ -664,6 +678,7 @@ export default class Zemu {
timeout = DEFAULT_METHOD_TIMEOUT,
runLastAction = true,
waitForInitialEventsChange = true,
isBlindSigning = false,
): Promise<number> {
const snapshotPrefixGolden = resolve(`${path}/snapshots/${testcaseName}`);
const snapshotPrefixTmp = resolve(`${path}/snapshots-tmp/${testcaseName}`);
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions src/zondax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8c5eb7d

Please sign in to comment.