Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for blindsign tests #507

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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