Skip to content

Latest commit

 

History

History
88 lines (51 loc) · 4.25 KB

README.md

File metadata and controls

88 lines (51 loc) · 4.25 KB

trezor-connect tests

Continuous Integration

Tests are powered by trezor-user-env which is daily built into a docker image providing all the necessary instrumentation required to run tests (bridge and emulators).

Tests are running in two environments:

SatoshiLabs GitLab CI NixOS runner

Test are running directly in trezor-user-env docker image. All required variables are declared in gitlab-ci.yml config file.

Github Actions CI Ubuntu runner

Test are using run.sh script to spin up trezor-user-env docker image and set all required variables.

Run it locally

Note: All paths below are relative to the root of trezor-connect repository.

Note: Running tests with custom firmware is not currently possible.

On Linux

Prerequisites

  • Docker
  • Podman using tests/run.sh -D podman (not officially supported)

On MacOS

Note: As of now M1 Macs aren't supported. See this issue for detailed information.

Note: Running all test at once using Docker for Mac v20 may end up with unexpected EOF error.

Note: Running test with graphical output from emulator may end up with device disconnected during action error.

Prerequisites

Steps

Note: Make sure that your default/local trezord is disabled and all physical Trezor devices are disconnected.

Note: Running all test at once may take a while. It is recommended to narrow the subset using -i methodName option.

Note: If you are running trezor-user-env docker image as standalone process in terminal use -d option.

  1. See available options tests/run.sh -h
  2. Limit tests to subset of methods use tests/run.sh -i getPublicKey,getAddress
  3. Run all tests tests/run.sh (may take some time)

How to add tests

  1. Create or modify file in tests/__fixtures__
  2. Make sure it is imported in tests/__fixtures__/index.js
  3. Make sure the method you are testing is listed in .github/workflows/*.yml and .gitlab-ci.yml

Transactions cache

Bitcoin-like coins signTransaction method require additional data about transactions referenced from used inputs.

Those data are automatically downloaded from backend defined in coins.json by default if refTxs param is not specified.

Note: Backends hosted on *.trezor.io are limiting requests per min. Too many requests from not whitelisted origins may be penalized with temporary ban. ("All backends are down" error)

Backend connection will be omitted in case of providing refTxs so even coins without officially supported backends (like zcash testnet) may sign a transaction in "offline mode". see docs

To reduce network traffic Github Actions CI is using cached (offline) mode and whitelisted GitLab CI is using default (online) mode.

Caching is enabled by default. To disable it use tests/run.sh -c option.

Cached transactions are stored in tests/__txcache__ directory in the same structure as in trezor-firmware repository.

Cached transactions are provided to test fixtures via TX_CACHE utility.

Missing tx json? use this tool to generate it.

Websocket cache

Similar to transaction cache. If process.env.TESTS_USE_WS_CACHE is set to true then @trezor/blockchain-link is conditionally connected to a local websocket server returning cached results from tests/__wscache__.

Server

WebSocketServer in Karma plugin

WsCacheServer in jest.setup

Karma production tests

Testing ./build directory in browser environment.

Run: ./tests/run.sh -s "yarn test:karma:production" -i getAddress