Skip to content

Commit

Permalink
chore: update trezor-user-env
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan authored and mroz22 committed Aug 25, 2024
1 parent 6173b7a commit 45db0d4
Show file tree
Hide file tree
Showing 28 changed files with 57 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/template-connect-test-params.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
required: false
default: "2-latest"
testFirmwareModel:
description: "Firmware model for the tests (example: R)"
description: "Firmware model for the tests (example: T3T1)"
type: "string"
required: false
nodeEnvironment:
Expand All @@ -30,7 +30,7 @@ on:
required: false
default: true
testDescription:
description: "A description to make test title more descriptive (example: 2-latest-R)"
description: "A description to make test title more descriptive (example: T3T1-latest)"
type: "string"
required: false
default: ""
Expand Down
18 changes: 8 additions & 10 deletions docker/docker-connect-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ set -euo pipefail

ENVIRONMENT=$1

if [[ "$ENVIRONMENT" != "web" && "$ENVIRONMENT" != "node" ]];
then
echo "either 'web' or 'node' must be specified as the first argument"
exit 1
if [[ "$ENVIRONMENT" != "web" && "$ENVIRONMENT" != "node" ]]; then
echo "either 'web' or 'node' must be specified as the first argument"
exit 1
fi

show_usage() {
Expand All @@ -35,7 +34,7 @@ show_usage() {
echo " -D PATH Set path to docker executable. Can be replaced with \`podman\`. default: docker"
echo " -e All methods except excluded, example: applySettings,signTransaction"
echo " -p Test pattern"
echo " -f Use specific firmware version, example: 2.1.4, 1.8.0 default: 2-main"
echo " -f Use specific firmware version, example: 2.1.4, 1.8.0 default: -main"
echo " -i Included methods only, example: applySettings,signTransaction"
echo " -s actual test script. default: 'yarn test:integration'"
echo " -u Firmware url"
Expand Down Expand Up @@ -106,11 +105,10 @@ shift $((OPTIND - 1))

export DOCKER_PATH

if [[ $ENVIRONMENT == "node" ]];
then
SCRIPT="yarn workspace @trezor/connect test:e2e:node"
else
SCRIPT="yarn workspace @trezor/connect test:e2e:web"
if [[ $ENVIRONMENT == "node" ]]; then
SCRIPT="yarn workspace @trezor/connect test:e2e:node"
else
SCRIPT="yarn workspace @trezor/connect test:e2e:web"
fi

# export essential process.env variables
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-popup/e2e/tests/passphrase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../support/helpers';

const url = process.env.URL || 'http://localhost:8088/';
const bridgeVersion = '2.0.31';
const bridgeVersion = '2.0.33';

const isWebExtension = process.env.IS_WEBEXTENSION === 'true';
const isCoreInPopup = process.env.CORE_IN_POPUP === 'true';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link';
import { createDeferred, Deferred } from '@trezor/utils';
import { log } from '../support/helpers';

const BRIDGE_VERSION = '2.0.31';
const BRIDGE_VERSION = '2.0.33';
const WAIT_AFTER_TEST = 3000; // how long test should wait for more potential trezord requests
const CONNECT_LEGACY_VERSION = '9.0.10';

Expand Down
2 changes: 1 addition & 1 deletion packages/connect-popup/e2e/tests/popup-pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import fs from 'fs';

const url = process.env.URL || 'http://localhost:8088/';

const bridgeVersion = '2.0.31';
const bridgeVersion = '2.0.33';
// popup window reference
let popup: Page;
let persistentContext: BrowserContext | undefined;
Expand Down
33 changes: 11 additions & 22 deletions packages/connect/e2e/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { runCLI, getVersion as getJestVersion } from 'jest';
import webpack from 'webpack';
import karma from 'karma';

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

import argv from './jest.config';

Expand All @@ -19,10 +19,13 @@ const getEmulatorOptions = (availableFirmwares: Firmwares) => {
const getLatestFirmware = (model: keyof Firmwares) =>
availableFirmwares[model].find(fw => !fw.replace('-arm', '').includes('-'));

const latest2 = getLatestFirmware('2');
const latest1 = getLatestFirmware('1');
const model =
firmwareModel && Object.keys(availableFirmwares).includes(firmwareModel)
? (firmwareModel as Model)
: 'T2T1';
const latest = getLatestFirmware(model);

if (!latest2 || !latest1) {
if (!latest) {
// should never happen
throw new Error('could not translate n-latest into specific firmware version');
}
Expand All @@ -31,17 +34,15 @@ const getEmulatorOptions = (availableFirmwares: Firmwares) => {
type: 'emulator-start',
wipe: true,
version: firmwareArg,
model,
};

if (firmwareArg === '2-latest') {
Object.assign(emulatorStartOpts, { version: latest2 });
}
if (firmwareArg === '1-latest') {
Object.assign(emulatorStartOpts, { version: latest1 });
if (firmwareArg?.endsWith('-latest')) {
Object.assign(emulatorStartOpts, { version: latest });
}
// no firmwareArg and not loading from url at the same time - provide fallback
if (!firmwareArg && !firmwareUrl) {
Object.assign(emulatorStartOpts, { version: latest2 });
Object.assign(emulatorStartOpts, { version: latest });
}
if (firmwareUrl) {
Object.assign(emulatorStartOpts, {
Expand All @@ -50,18 +51,6 @@ const getEmulatorOptions = (availableFirmwares: Firmwares) => {
});
}

if (firmwareModel) {
Object.assign(emulatorStartOpts, { model: firmwareModel });

// temporary, it seems that model "R" does not have any built versions
// and only master build is available
if (firmwareModel === 'R') {
[emulatorStartOpts.version] = availableFirmwares.R;
} else if (firmwareModel === 'T3T1') {
[emulatorStartOpts.version] = availableFirmwares.T3T1;
}
}

return emulatorStartOpts;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/suite-web/e2e/tests/analytics/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Analytics Events', () => {
cy.getTestElement('@analytics/toggle-switch').click({ force: true });
cy.getTestElement('@settings/menu/close').click();

cy.task('startEmu', { wipe: true, version: '2.6.0' });
cy.task('startEmu', { wipe: true, model: 'T2T1', version: '2.6.0' });
cy.task('setupEmu', {
needs_backup: false,
mnemonic: 'all all all all all all all all all all all all',
Expand Down
2 changes: 1 addition & 1 deletion packages/suite-web/e2e/tests/backup/t2t1-fail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let requests: Requests;

describe('Backup fail', () => {
beforeEach(() => {
cy.task('startEmu', { wipe: true });
cy.task('startEmu', { wipe: true, model: 'T2T1' });
cy.task('setupEmu', { needs_backup: true });
cy.task('startBridge');
cy.viewport(1440, 2560).resetDb();
Expand Down
2 changes: 1 addition & 1 deletion packages/suite-web/e2e/tests/backup/t2t1-misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

describe('Backup misc', () => {
beforeEach(() => {
cy.task('startEmu', { wipe: true });
cy.task('startEmu', { wipe: true, model: 'T2T1' });
cy.task('setupEmu', { needs_backup: true });
cy.task('startBridge');

Expand Down
2 changes: 1 addition & 1 deletion packages/suite-web/e2e/tests/firmware/firmware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Firmware', () => {
});

it(`Firmware 2.5.2 outdated notification banner should open firmware update modal`, () => {
cy.task('startEmu', { wipe: true, version: '2.5.2' });
cy.task('startEmu', { wipe: true, model: 'T2T1', version: '2.5.2' });
cy.task('setupEmu');
cy.task('startBridge');
cy.prefixedVisit('/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Metadata - cancel metadata on device', () => {

it('user cancels metadata on device, choice is respected on subsequent runs but only for the cancelled wallet', () => {
// prepare test
cy.task('startEmu', { wipe: true, version: '2.7.0' });
cy.task('startEmu', { wipe: true, model: 'T2T1', version: '2.7.0' });
cy.task('setupEmu', {
mnemonic,
passphrase_protection: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Onboarding - create wallet', () => {
// todo: skipping for it is too flaky..
// after calling "resetDevice" we almost always receive "device disconnected during action" which is error sent by bridge.
it.skip('Success (basic)', () => {
cy.task('startEmu', { version: '1-latest', wipe: true });
cy.task('startEmu', { model: 'T1B1', version: '1-latest', wipe: true });
cy.getTestElement('@analytics/continue-button').click();
cy.getTestElement('@analytics/continue-button').click();
cy.getTestElement('@firmware/continue-button').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

describe('Onboarding - recover wallet T1B1', () => {
beforeEach(() => {
cy.task('startEmu', { version: '1-latest', wipe: true });
cy.task('startEmu', { model: 'T1B1', version: '1-latest', wipe: true });
cy.task('startBridge');

cy.viewport(1440, 2560).resetDb();
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('Onboarding - recover wallet T1B1', () => {
cy.wait(501);
cy.task('stopEmu');
cy.getTestElement('@connect-device-prompt', { timeout: 20000 });
cy.task('startEmu', { version: '1-latest' });
cy.task('startEmu', { model: 'T1B1', version: '1-latest' });

cy.getTestElement('@onboarding/recovery/retry-button').click();
cy.getTestElement('@recover/select-count/12').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// todo: this started to fail mysteriously after merging new base image. Skipping it for now and will investigate.
describe.skip('Onboarding - recover wallet T1B1', () => {
before(() => {
cy.task('startEmu', { version: '1-latest', wipe: true });
cy.task('startEmu', { model: 'T1B1', version: '1-latest', wipe: true });
cy.task('startBridge');

cy.viewport(1440, 2560).resetDb();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Onboarding - create wallet', () => {
// note: this is an example of test that can not be parametrized to be both integration (isolated) test and e2e test.
// the problem is that it always needs to run the newest possible emulator. If this was pinned to use emulator which is currently
// in production, and we locally bumped emulator version, we would get into a screen saying "update your firmware" and the test would fail.
cy.task('startEmu', { wipe: true, version: '2-master' });
cy.task('startEmu', { wipe: true, model: 'T2T1', version: '2-main' });
cy.getTestElement('@analytics/continue-button').click();
cy.getTestElement('@analytics/continue-button').click();
cy.getTestElement('@firmware/continue-button').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ describe('Onboarding - recover wallet T2T1', () => {
// note: this is an example of test that can not be parametrized to be both integration (isolated) test and e2e test.
// the problem is that it always needs to run the newest possible emulator. If this was pinned to use emulator which is currently
// in production, and we locally bumped emulator version, we would get into a screen saying "update your firmware" and the test would fail.
cy.task('startEmu', { wipe: true, version: '2-master' });
cy.task('startEmu', { wipe: true, model: 'T2T1', version: '2-main' });

// Disable revision check. On emulator '2-master' it wont pass as it is unreleased version
// Disable revision check. On emulator '2-main' it wont pass as it is unreleased version
cy.getTestElement('@device-compromised').should('be.visible');
cy.getTestElement('@suite/menu/settings').click();
cy.getTestElement('@settings/menu/device').click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const shareTwoOfThree = [
describe('Onboarding - T2T1 in recovery mode', () => {
beforeEach(() => {
cy.task('startBridge');
cy.task('startEmu', { wipe: true, version: '2.4.3' });
cy.task('startEmu', { wipe: true, model: 'T2T1', version: '2.5.3' });
cy.resetDb();
cy.viewport(1440, 2560);
cy.prefixedVisit('/');
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Onboarding - T2T1 in recovery mode', () => {
cy.safeReload();

// now suite has reloaded. database is wiped.
cy.task('startEmu', { wipe: false, version: '2.4.3' });
cy.task('startEmu', { wipe: false, model: 'T2T1', version: '2.5.3' });
// analytics opt-out again
cy.getTestElement('@analytics/continue-button').click();
cy.getTestElement('@analytics/continue-button').click();
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('Onboarding - T2T1 in recovery mode', () => {
cy.task('stopEmu');
cy.wait(501);
cy.getTestElement('@connect-device-prompt', { timeout: 30000 });
cy.task('startEmu', { wipe: false, version: '2.4.3' });
cy.task('startEmu', { wipe: false, model: 'T2T1', version: '2.5.3' });
cy.getTestElement('@onboarding/confirm-on-device');
cy.wait(501);
cy.task('pressYes');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Onboarding - recover wallet T2T1', () => {
cy.viewport(1440, 2560).resetDb();
cy.prefixedVisit('/');

cy.task('startEmu', { wipe: true, version: '2.5.3' });
cy.task('startEmu', { wipe: true, model: 'T2T1', version: '2.5.3' });
cy.getTestElement('@analytics/continue-button').click();
cy.getTestElement('@analytics/continue-button').click();

Expand Down
2 changes: 1 addition & 1 deletion packages/suite-web/e2e/tests/recovery/t1b1-dry-run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe.skip('Recovery - dry run', () => {
beforeEach(() => {
cy.task('startEmu', { version: '1-latest', wipe: true });
cy.task('startEmu', { model: 'T1B1', version: '1-latest', wipe: true });
cy.wait(2000);
cy.task('setupEmu', { needs_backup: false });
cy.task('startBridge');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// udp transport in suite and trying to enable this test again.
describe.skip('T1B1 - Device settings', () => {
beforeEach(() => {
cy.task('startEmu', { version: '1-latest', wipe: true });
cy.task('startEmu', { model: 'T1B1', version: '1-latest', wipe: true });
cy.task('setupEmu', { needs_backup: false });
cy.task('startBridge');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
describe('T2B1 - Device settings', () => {
const startEmuOpts = {
version: '2-main',
model: 'R', // TODO: T2B1 DeviceModelInternal
model: 'T2B1',
wipe: true,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('T2T1 - Device settings', () => {
});

it('unable to change homescreen in firmware < 2.5.4', () => {
cy.task('startEmu', { wipe: true, version: '2.5.3' });
cy.task('startEmu', { wipe: true, model: 'T2T1', version: '2.5.3' });
cy.task('setupEmu');

cy.prefixedVisit('/');
Expand All @@ -82,7 +82,7 @@ describe('T2T1 - Device settings', () => {
});

it('able to change homescreen in firmware >= 2.5.4', () => {
cy.task('startEmu', { wipe: true, version: '2-main' });
cy.task('startEmu', { wipe: true, model: 'T2T1', version: '2-main' });
cy.task('setupEmu');

cy.prefixedVisit('/');
Expand Down
9 changes: 5 additions & 4 deletions packages/suite-web/e2e/tests/suite/passphrase-cancel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// @retry=2

const testedVersions = [
'2-latest',
'1.11.2', // Todo: fix latest version to return proper revision hash (it reports possibly FAKE device now)
// Todo: fix latest version to return proper revision hash (it reports possibly FAKE device now)
{ version: '2-latest', model: 'T2T1' },
{ version: '1.11.2', model: 'T1B1' },
];

describe('Passphrase cancel', () => {
Expand All @@ -12,8 +13,8 @@ describe('Passphrase cancel', () => {
});

testedVersions.forEach(version => {
it(version, () => {
cy.task('startEmu', { wipe: true, version });
it(version.model + '_' + version.version, () => {
cy.task('startEmu', { wipe: true, ...version });
cy.task('setupEmu', {
mnemonic: 'all all all all all all all all all all all all',
passphrase_protection: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/transport-test/e2e/bridge/bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { pathLength, descriptor as expectedDescriptor } from './expect';
// todo: introduce global jest config for e2e
jest.setTimeout(60000);

const emulatorStartOpts = { version: '2-main', wipe: true };
const emulatorStartOpts = { model: 'T2T1', version: '2-main', wipe: true } as const;

describe('bridge', () => {
beforeAll(async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/transport-test/e2e/bridge/multi-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getDescriptor = (descriptor: any): Descriptor => ({
...descriptor,
});

const emulatorStartOpts = { version: '2-main', wipe: true };
const emulatorStartOpts = { model: 'T2T1', version: '2-main', wipe: true } as const;

describe('bridge', () => {
let bridge1: BridgeTransport;
Expand Down
4 changes: 3 additions & 1 deletion packages/trezor-user-env-link/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class TrezorUserEnvLinkClass extends TypedEmitter<WebsocketClientEvents>
private client: WebsocketClient;
public firmwares?: Firmwares;
private defaultFirmware?: string;
private defaultModel: Model = 'T2T1';

// todo: remove later, used in some of the tests
public send: WebsocketClient['send'];
Expand All @@ -69,7 +70,7 @@ export class TrezorUserEnvLinkClass extends TypedEmitter<WebsocketClientEvents>
// select the highest version from the list of available firmwares.
// this is the version that is likely to be the newest production.
this.defaultFirmware = semverRSort(
this.firmwares['2'].filter(fw => semverValid(fw)),
this.firmwares[this.defaultModel].filter(fw => semverValid(fw)),
)[0];
});

Expand Down Expand Up @@ -139,6 +140,7 @@ export class TrezorUserEnvLinkClass extends TypedEmitter<WebsocketClientEvents>
async startEmu(arg?: StartEmu) {
const params = {
type: 'emulator-start',
model: this.defaultModel,
version: this.defaultFirmware || '2-main',
...arg,
};
Expand Down
Loading

0 comments on commit 45db0d4

Please sign in to comment.