Skip to content

Commit

Permalink
test(suite-native): introduce passphrase testing scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
jbazant committed Jan 17, 2025
1 parent eb6f53b commit f243b15
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 0 deletions.
7 changes: 7 additions & 0 deletions suite-native/app/e2e/pageObjects/deviceManagerActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ class DeviceManagerActions {
await waitFor(deviceSettingsButton).toBeVisible().withTimeout(30000);
await deviceSettingsButton.tap();
}

async tapOpenPassphraseButton() {
const openPassphraseButton = element(by.id('@device-manager/passphrase/add'));

await waitFor(openPassphraseButton).toBeVisible().withTimeout(2e3);
await openPassphraseButton.tap();
}
}

export const onDeviceManager = new DeviceManagerActions();
59 changes: 59 additions & 0 deletions suite-native/app/e2e/pageObjects/passphraseModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link';

import { wait, waitForElementByTextToBeVisible } from '../utils';

class PassphraseModule {
public async expectEnterPassphraseScreen() {
await waitForElementByTextToBeVisible('Enter your passphrase');
}

public async enterPassphrase(passphrase: string) {
await element(by.id('@passphrase/passphraseInput')).tap();
// wait for animation to finish
await wait(200);
await element(by.id('@passphrase/passphraseInput')).replaceText(passphrase);
await element(by.text('Enter passphrase')).tap();
}

public async expectEnablePassphraseOnDeviceRequest() {
await waitForElementByTextToBeVisible('Enable passphrase on your Trezor.');
}

public async allowPassphraseOnEmu() {
await TrezorUserEnvLink.swipeEmu('up');
await TrezorUserEnvLink.swipeEmu('up');
await TrezorUserEnvLink.pressYes();
}

public async expectConfirmPassphraseOnDeviceRequest() {
await waitForElementByTextToBeVisible(
'Go to your device and confirm the passphrase you’ve entered.',
);
}

public async confirmPassphraseOnEmu() {
await TrezorUserEnvLink.swipeEmu('up');
await TrezorUserEnvLink.swipeEmu('up');
await TrezorUserEnvLink.pressYes();
}

public async expectCheckingPassphraseScreen() {
await waitForElementByTextToBeVisible('Checking your passphrase');
}

public async expectEmptyPassphraseWalletScreen() {
await waitForElementByTextToBeVisible('This passphrase wallet is empty');
}

public async openEmptyPassphraseWalletAndConfirmBestPractices() {
await element(by.text('Yes, open')).tap();
await waitForElementByTextToBeVisible('Passphrase best practices');
await element(by.text('Got it')).tap();
}

public async expectEmptyPassphraseWalletConfirmationScreen() {
await waitForElementByTextToBeVisible('Confirm empty passphrase');
}
}

export const onPassphrase = new PassphraseModule();
80 changes: 80 additions & 0 deletions suite-native/app/e2e/tests/passphraseFlow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { randomUUID } from 'node:crypto';

import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link';

import {
appIsFullyLoaded,
disconnectTrezorUserEnv,
openApp,
prepareTrezorEmulator,
restartApp,
} from '../utils';
import { onOnboarding } from '../pageObjects/onboardingActions';
import { onConnectingDevice } from '../pageObjects/connectingDevice';
import { onDeviceManager } from '../pageObjects/deviceManagerActions';
import { onCoinEnablingInit } from '../pageObjects/coinEnablingActions';
import { onAlertSheet } from '../pageObjects/alertSheetActions';
import { onPassphrase } from '../pageObjects/passphraseModule';

const INITIAL_ACCOUNT_BALANCE = 3.14;

describe('passphrase flow', () => {
beforeAll(async () => {
await prepareTrezorEmulator();
await openApp({ newInstance: true });
await onOnboarding.skipOnboarding();

await TrezorUserEnvLink.sendToAddressAndMineBlock({
address: 'bcrt1q34up3cga3fkmph47t22mpk5d0xxj3ppghph9da',
btc_amount: INITIAL_ACCOUNT_BALANCE,
});

await onCoinEnablingInit.waitForScreen();
await onCoinEnablingInit.enableNetwork('regtest');
await onCoinEnablingInit.clickOnConfirmButton();

await onAlertSheet.skipViewOnlyMode();
});

afterAll(async () => {
await disconnectTrezorUserEnv();
});

beforeEach(async () => {
await prepareTrezorEmulator();
await restartApp();
await appIsFullyLoaded();

await onConnectingDevice.waitForScreen();
});

it('Open empty passphrase wallet', async () => {
const passphrase = 'E2E:test passphrase ' + randomUUID();

await onDeviceManager.tapDeviceSwitch();
await onDeviceManager.tapOpenPassphraseButton();

await onPassphrase.expectEnablePassphraseOnDeviceRequest();
await onPassphrase.allowPassphraseOnEmu();

await onPassphrase.expectEnterPassphraseScreen();
await onPassphrase.enterPassphrase(passphrase);
await onPassphrase.expectConfirmPassphraseOnDeviceRequest();

await onPassphrase.confirmPassphraseOnEmu();
// TODO this does not happens, why?
await onPassphrase.expectCheckingPassphraseScreen();
await onPassphrase.expectEmptyPassphraseWalletScreen();
await onPassphrase.openEmptyPassphraseWalletAndConfirmBestPractices();

await onPassphrase.expectEmptyPassphraseWalletConfirmationScreen();
await onPassphrase.enterPassphrase(passphrase);

await onPassphrase.expectConfirmPassphraseOnDeviceRequest();
await onPassphrase.confirmPassphraseOnEmu();
});

it.todo('Open passphrase wallet with funds');

it.todo('non-happy scenarios');
});
5 changes: 5 additions & 0 deletions suite-native/app/e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,8 @@ export const disconnectTrezorUserEnv = async () => {
export const wait = async (ms: number) => {
await new Promise(resolve => setTimeout(resolve, ms));
};

export const waitForElementByTextToBeVisible = (text: string, timeout = 2e3) =>
waitFor(element(by.text(text)))
.toBeVisible()
.withTimeout(timeout);
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export const PassphraseForm = ({
onFocus={handleFocusInput}
onBlur={() => setIsInputFocused(false)}
secureTextEntry
testID="@passphrase/passphraseInput"
/>
{isDirty && (
<Animated.View entering={FadeIn} exiting={FadeOut}>
Expand Down

0 comments on commit f243b15

Please sign in to comment.