Skip to content

Commit

Permalink
test(connect): enable T1B1 in nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
mroz22 committed Jan 15, 2025
1 parent 64d08a4 commit ed201cf
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 33 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test-connect.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
otherDevicesMatrix: ${{ steps.set-matrix-other-devices.outputs.otherDevicesMatrix }}
allFwsMatrix: ${{ steps.set-matrix-all-firmwares.outputs.allFwsMatrix }}
allTransportsMatrix: ${{ steps.set-matrix-all-transports.outputs.allTransportsMatrix }}
modelOneMatrix: ${{ steps.set-matrix-model-one.outputs.modelOneMatrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -93,6 +94,10 @@ jobs:
id: set-matrix-all-transports
run: echo "allTransportsMatrix=$(node ./scripts/ci/connect-test-matrix-generator.js --model=T2T1 --firmware=2-latest --env=node --groups=api --cache_tx=true --transport=all)" >> $GITHUB_OUTPUT

- name: Set trezor model one matrix
id: set-matrix-model-one
run: echo "modelOneMatrix=$(node ./scripts/ci/connect-test-matrix-generator.js --model=T1B1 --firmware=1-latest --env=node --groups=api --cache_tx=true --transport=2.0.33)" >> $GITHUB_OUTPUT

PR-check:
needs: [build, set-matrix]
name: PR-check ${{ matrix.key }}
Expand Down Expand Up @@ -183,3 +188,21 @@ jobs:
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.set-matrix.outputs.allTransportsMatrix) }}

model-one-api:
needs: [build, set-matrix]
name: model-one-api ${{ matrix.key }}
if: (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && github.repository == 'trezor/trezor-suite'
uses: ./.github/workflows/template-connect-test-params.yml
with:
testPattern: ${{ matrix.groups.pattern }}
includeFilter: ${{ matrix.groups.includeFilter }}
testsFirmware: ${{ matrix.firmware }}
testDescription: ${{ matrix.model }}-${{ matrix.firmware }}
cache_tx: ${{ matrix.cache_tx }}
transport: ${{ matrix.transport }}
testEnv: ${{ matrix.env }}
testFirmwareModel: ${{ matrix.model }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.set-matrix.outputs.modelOneMatrix) }}
8 changes: 8 additions & 0 deletions packages/connect/e2e/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ const getEmulatorOptions = (availableFirmwares: Firmwares) => {
};
}

if (
'version' in emulatorStartOpts &&
emulatorStartOpts.version?.startsWith('1') &&
emulatorStartOpts.model !== 'T1B1'
) {
throw new Error('firmware version 1.x is only supported for T1B1 model');
}

return emulatorStartOpts;
};

Expand Down
81 changes: 48 additions & 33 deletions packages/connect/e2e/tests/device/cancel.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { StartEmu, SetupEmu } from '@trezor/trezor-user-env-link';

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

const getAddress = (showOnTrezor: boolean, coin: string = 'regtest') =>
Expand Down Expand Up @@ -36,26 +34,13 @@ const assertGetAddressWorks = async () => {
const getAddressResponse = await getAddress(false, 'testnet');
expect(getAddressResponse).toMatchObject({
success: true,
payload: { address: 'tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2' },
payload: { address: 'tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9' },
});
};

describe('TrezorConnect.cancel', () => {
const controller = getController();

const setupTest = async ({ setupParams }: { setupParams: SetupEmu & StartEmu }) => {
await controller.stopBridge();
await controller.stopEmu();
await controller.startEmu({ wipe: true, ...setupParams });
await controller.setupEmu(setupParams);
await controller.startBridge(
// @ts-expect-error
process.env.TESTS_TRANSPORT,
);

await initTrezorConnect(controller, { debug: true });
};

beforeAll(async () => {
await controller.connect();
});
Expand All @@ -65,6 +50,10 @@ describe('TrezorConnect.cancel', () => {
controller.dispose();
});

beforeEach(() => {
TrezorConnect.dispose();
});

afterEach(async () => {
TrezorConnect.dispose();
await controller.stopEmu();
Expand All @@ -73,9 +62,11 @@ describe('TrezorConnect.cancel', () => {

// the goal is to run this test couple of times to uncover possible race conditions/flakiness
it(`GetAddress - ButtonRequest_Address - Cancel `, async () => {
await setupTest({
setupParams: {},
await setup(controller, {
mnemonic: 'mnemonic_all',
passphrase_protection: false,
});
await initTrezorConnect(controller);

TrezorConnect.removeAllListeners();
const getAddressCall = getAddress(true);
Expand Down Expand Up @@ -111,15 +102,18 @@ describe('TrezorConnect.cancel', () => {
});

it('Synchronous Cancel', async () => {
await setupTest({
setupParams: {},
await setup(controller, {
mnemonic: 'mnemonic_all',
passphrase_protection: false,
});

await initTrezorConnect(controller);
TrezorConnect.removeAllListeners();
const getAddressCall = getAddress(true);

// almost synchronous, TODO: core methodSynchronize race-condition in nodejs (works in web)
await new Promise(resolve => setTimeout(resolve, 1));
// TODO: model T is happy with 1ms, model one needs more (1000 worked)
await new Promise(resolve => setTimeout(resolve, 1000));

TrezorConnect.cancel('Cancel reason');

Expand All @@ -139,11 +133,11 @@ describe('TrezorConnect.cancel', () => {
});

it('Passphrase request - Cancel', async () => {
await setupTest({
setupParams: {
passphrase_protection: true,
},
await setup(controller, {
mnemonic: 'mnemonic_all',
passphrase_protection: true,
});
await initTrezorConnect(controller);

const getAddressCall = getAddress(true);
await new Promise<void>(resolve => {
Expand All @@ -159,17 +153,32 @@ describe('TrezorConnect.cancel', () => {
});

conditionalTest(['2'], 'Pin request - Cancel', async () => {
await setupTest({
setupParams: {
version: '1-latest',
model: 'T1B1',
pin: '1234',
},
await controller.stopBridge();
await controller.stopEmu();
await controller.startEmu({
wipe: true,
version: '1-latest',
model: 'T1B1',
});
await controller.setupEmu({
pin: '1234',
});
await controller.startBridge(
// @ts-expect-error
process.env.TESTS_TRANSPORT,
);

// T1 needs to be restarted for settings to be applied (pin)
await controller.stopEmu();
await controller.startEmu({ version: '1-latest', model: 'T1B1' });

await initTrezorConnect(controller);

// TODO: race condition. On my machine it doesn't work without this delay
// reproducible by commenting out this line and
// ./docker/docker-connect-test.sh node -p cancel.test -f 1-main -d -m T1B1
await new Promise(resolve => setTimeout(resolve, 1000));

const pinPromise = new Promise<void>(resolve => {
TrezorConnect.on('ui-request_pin', () => {
resolve();
Expand All @@ -189,7 +198,13 @@ describe('TrezorConnect.cancel', () => {
});

conditionalTest(['2'], 'Word request - Cancel', async () => {
await controller.startEmu({ version: '1-latest', model: 'T1B1', wipe: true });
await controller.stopBridge();
await controller.stopEmu();
await controller.startEmu({
wipe: true,
version: '1-latest',
model: 'T1B1',
});
await controller.startBridge(
// @ts-expect-error
process.env.TESTS_TRANSPORT,
Expand Down

0 comments on commit ed201cf

Please sign in to comment.