Skip to content

Commit

Permalink
test(trezor-user-env-link): add a basic test proving that all availab…
Browse files Browse the repository at this point in the history
…le emulators run
  • Loading branch information
mroz22 committed Feb 19, 2025
1 parent e1c840f commit e41b381
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 15 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/test-trezor-user-env-link-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "[Test] trezor-user-env-link e2e"

on:
pull_request:
branches:
- develop
paths:
- ".github/workflows/test-trezor-user-env-link-e2e.yml"
- "packages/trezor-user-env/**"
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
e2e-test-trezor-user-env-link:
if: github.repository == 'trezor/trezor-suite'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{github.event.after}}
fetch-depth: 2
- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: yarn
- name: Install dependencies
run: |
echo -e "\nenableScripts: false" >> .yarnrc.yml
echo -e "\nenableHardenedMode: false" >> .yarnrc.yml
yarn workspaces focus @trezor/trezor-user-env-link
- name: Run e2e tests
run: |
docker run ghcr.io/trezor/trezor-user-env:b23cde1860e03c8bdaebbbc8fcbcd2cc9d6375d3 -d
yarn workspace @trezor/trezor-user-env-link test:e2e
38 changes: 38 additions & 0 deletions packages/trezor-user-env-link/e2e/api.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { typedObjectKeys } from '@trezor/utils';

import { TrezorUserEnvLink } from '../src';

(async () => {
await TrezorUserEnvLink.connect();

if (!TrezorUserEnvLink.firmwares) {
throw new Error('firmwares not loaded');
}
for (const model of typedObjectKeys(TrezorUserEnvLink.firmwares)) {
console.log('testing firmwares for model', model);

Check failure on line 12 in packages/trezor-user-env-link/e2e/api.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error

for (const version of TrezorUserEnvLink.firmwares[model]) {
console.log('starting emulator', model, version);

Check failure on line 15 in packages/trezor-user-env-link/e2e/api.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
await TrezorUserEnvLink.startEmu({
model,
version,
wipe: true,
});

console.log('setting up emulator');

Check failure on line 22 in packages/trezor-user-env-link/e2e/api.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
await TrezorUserEnvLink.setupEmu();

// todo: run more complex commands, typically those that require interaction with multiple screens (dry run..)

console.log('wiping emulator');

Check failure on line 27 in packages/trezor-user-env-link/e2e/api.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
await TrezorUserEnvLink.wipeEmu();

console.log('stopping emulator');

Check failure on line 30 in packages/trezor-user-env-link/e2e/api.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
await TrezorUserEnvLink.stopEmu();
}
}

await TrezorUserEnvLink.disconnect();

console.log('ALL TESTS DONE');

Check failure on line 37 in packages/trezor-user-env-link/e2e/api.test.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement. Only these console methods are allowed: warn, error
})();
6 changes: 5 additions & 1 deletion packages/trezor-user-env-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
"main": "src/index",
"scripts": {
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build"
"type-check": "yarn g:tsc --build",
"test:e2e": "ts-node -T -O '{\"module\": \"commonjs\", \"esModuleInterop\": true}' ./e2e/api.test.ts"
},
"dependencies": {
"@trezor/utils": "workspace:*",
"@trezor/websocket-client": "workspace:*",
"cross-fetch": "^4.0.0"
},
"devDependencies": {
"ts-node": "^10.9.2"
}
}
Loading

0 comments on commit e41b381

Please sign in to comment.