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

Fix flaky connect tests #16149

Merged
merged 5 commits into from
Jan 7, 2025
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
3 changes: 2 additions & 1 deletion packages/blockchain-link/src/workers/blockfrost/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ const pushTransaction = async (request: Request<MessageTypes.PushTransaction>) =

const getAccountInfo = async (request: Request<MessageTypes.GetAccountInfo>) => {
const api = await request.connect();
const info = await api.getAccountInfo(request.payload);
const { details = 'basic', ...rest } = request.payload;
const info = await api.getAccountInfo({ details, ...rest });

return {
type: RESPONSES.GET_ACCOUNT_INFO,
Expand Down
21 changes: 17 additions & 4 deletions packages/connect/e2e/common.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ export const setup = async (
);
};

type InitParams = Partial<Parameters<typeof TrezorConnect.init>[0]> & { autoConfirm?: boolean };

export const initTrezorConnect = async (
// eslint-disable-next-line @typescript-eslint/no-shadow
TrezorUserEnvLink: TrezorUserEnvLinkClass,
options?: Partial<Parameters<typeof TrezorConnect.init>[0]>,
{ autoConfirm = true, ...options }: InitParams = {},
) => {
TrezorConnect.removeAllListeners();

Expand Down Expand Up @@ -162,9 +164,12 @@ export const initTrezorConnect = async (
});
});

TrezorConnect.on(UI.REQUEST_BUTTON, () => {
setTimeout(() => TrezorUserEnvLink.send({ type: 'emulator-press-yes' }), 1);
});
if (autoConfirm) {
TrezorConnect.on(UI.REQUEST_BUTTON, e => {
if (e.code === 'ButtonRequest_PinEntry') return;
setTimeout(() => TrezorUserEnvLink.send({ type: 'emulator-press-yes' }), 1);
});
}

await TrezorConnect.init({
manifest: {
Expand Down Expand Up @@ -241,3 +246,11 @@ export const conditionalTest = (rules: string[], ...args: any) => {
// @ts-expect-error
return testMethod(...args);
};

export const conditionalDescribe = (rules: string[], ...args: any) => {
const skipMethod = typeof jest !== 'undefined' ? describe.skip : xdescribe;
const testMethod = skipTest(rules) ? skipMethod : describe;

// @ts-expect-error
return testMethod(...args);
};
12 changes: 10 additions & 2 deletions packages/connect/e2e/tests/device/authorizeCoinjoin.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import TrezorConnect from '../../../src';
import { getController, setup, conditionalTest, initTrezorConnect } from '../../common.setup';
import {
getController,
setup,
conditionalTest,
conditionalDescribe,
initTrezorConnect,
} from '../../common.setup';

const controller = getController();

describe('TrezorConnect.authorizeCoinjoin', () => {
// skip T3T1 until `emulator-apply-settings` with `auto_lock_delay_ms` is fixed on emu
// https://github.com/trezor/trezor-user-env/issues/280
conditionalDescribe(['!T3T1'], 'TrezorConnect.authorizeCoinjoin', () => {
beforeAll(async () => {
await setup(controller, {
mnemonic: 'mnemonic_all',
Expand Down
8 changes: 3 additions & 5 deletions packages/connect/e2e/tests/device/cancel.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StartEmu, SetupEmu } from '@trezor/trezor-user-env-link';

import { getController, initTrezorConnect } from '../../common.setup';
import { conditionalTest, getController, initTrezorConnect } from '../../common.setup';
import TrezorConnect from '../../../src';

const getAddress = (showOnTrezor: boolean, coin: string = 'regtest') => {
Expand Down Expand Up @@ -159,8 +159,7 @@ describe('TrezorConnect.cancel', () => {
await assertGetAddressWorks();
});

// todo: this should be conditionalTest(['2'])
it('Pin request - Cancel', async () => {
conditionalTest(['2'], 'Pin request - Cancel', async () => {
await setupTest({
setupParams: {
version: '1-latest',
Expand Down Expand Up @@ -190,8 +189,7 @@ describe('TrezorConnect.cancel', () => {
expect(feat.payload).toMatchObject({ initialized: true });
});

// todo: this should be conditionalTest(['2'])
it('Word request - Cancel', async () => {
conditionalTest(['2'], 'Word request - Cancel', async () => {
await controller.startEmu({ version: '1-latest', model: 'T1B1', wipe: true });
await controller.startBridge(
// @ts-expect-error
Expand Down
2 changes: 1 addition & 1 deletion packages/connect/e2e/tests/device/override.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('TrezorConnect override param', () => {
await setup(controller, {
mnemonic: 'mnemonic_all',
});
await initTrezorConnect(controller);
await initTrezorConnect(controller, { autoConfirm: false });
});

afterAll(() => {
Expand Down
12 changes: 10 additions & 2 deletions packages/connect/e2e/tests/device/setBusy.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import TrezorConnect from '../../../src';
import { getController, setup, conditionalTest, initTrezorConnect } from '../../common.setup';
import {
getController,
setup,
conditionalTest,
initTrezorConnect,
conditionalDescribe,
} from '../../common.setup';

const controller = getController();

describe('TrezorConnect.setBusy', () => {
// skip T3T1 until `emulator-apply-settings` with `auto_lock_delay_ms` is fixed on emu
// https://github.com/trezor/trezor-user-env/issues/280
conditionalDescribe(['!T3T1'], 'TrezorConnect.setBusy', () => {
beforeAll(async () => {
await setup(controller, {
mnemonic: 'mnemonic_all',
Expand Down
Loading