From ed201cffb10f03002e5fbe7eda0feb6d6b4ed739 Mon Sep 17 00:00:00 2001 From: Martin Varmuza Date: Mon, 25 Nov 2024 18:33:18 +0100 Subject: [PATCH] test(connect): enable T1B1 in nightly --- .github/workflows/test-connect.yml | 23 ++++++ packages/connect/e2e/run.ts | 8 ++ .../connect/e2e/tests/device/cancel.test.ts | 81 +++++++++++-------- 3 files changed, 79 insertions(+), 33 deletions(-) diff --git a/.github/workflows/test-connect.yml b/.github/workflows/test-connect.yml index 6f0c05f0851..1ccd27a28fc 100644 --- a/.github/workflows/test-connect.yml +++ b/.github/workflows/test-connect.yml @@ -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 @@ -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 }} @@ -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) }} diff --git a/packages/connect/e2e/run.ts b/packages/connect/e2e/run.ts index 2d69f08ce89..aa0fa1dae3c 100644 --- a/packages/connect/e2e/run.ts +++ b/packages/connect/e2e/run.ts @@ -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; }; diff --git a/packages/connect/e2e/tests/device/cancel.test.ts b/packages/connect/e2e/tests/device/cancel.test.ts index 42a24129959..43fa6c46951 100644 --- a/packages/connect/e2e/tests/device/cancel.test.ts +++ b/packages/connect/e2e/tests/device/cancel.test.ts @@ -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') => @@ -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(); }); @@ -65,6 +50,10 @@ describe('TrezorConnect.cancel', () => { controller.dispose(); }); + beforeEach(() => { + TrezorConnect.dispose(); + }); + afterEach(async () => { TrezorConnect.dispose(); await controller.stopEmu(); @@ -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); @@ -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'); @@ -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(resolve => { @@ -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(resolve => { TrezorConnect.on('ui-request_pin', () => { resolve(); @@ -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,