Skip to content

Commit dcfbbd2

Browse files
authored
Merge pull request #1941 from mintlayer/run_trezor_tests_on_ci
Run trezor_signer tests on CI
2 parents f51e8c9 + b066cf0 commit dcfbbd2

7 files changed

Lines changed: 208 additions & 63 deletions

File tree

.github/workflows/build.yml

Lines changed: 130 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Install python toml package
2626
run: python3 -m pip install toml
2727
- name: Install rust
28-
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py)
28+
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/cargo-info-extractor/extract.py --rust-version)
2929
- name: Build
3030
run: cargo build --release --locked --features trezor
3131
- name: Run tests
@@ -58,12 +58,10 @@ jobs:
5858
submodules: recursive
5959
- name: Update local dependency repositories
6060
run: sudo apt-get update
61-
- name: Install dependencies
62-
run: sudo apt-get install -yqq --no-install-recommends build-essential python3 python3-toml podman build-essential pkg-config libssl-dev
63-
- name: Install rust deps
64-
run: sudo apt-get install -yqq build-essential pkg-config libssl-dev
61+
- name: Install build dependencies
62+
run: sudo apt-get install -yqq --no-install-recommends build-essential python3 python3-toml podman pkg-config libssl-dev
6563
- name: Install rust
66-
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py)
64+
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/cargo-info-extractor/extract.py --rust-version)
6765
- name: Build
6866
run: cargo build --release --locked --features trezor
6967
- name: Run tests
@@ -95,7 +93,7 @@ jobs:
9593
- name: Install python toml package
9694
run: python3 -m pip install toml --break-system-packages --user
9795
- name: Install rust
98-
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py)
96+
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/cargo-info-extractor/extract.py --rust-version)
9997
- name: Build
10098
run: cargo build --release --locked --features trezor
10199
- name: Run tests
@@ -115,3 +113,128 @@ jobs:
115113
with:
116114
name: macos-functional-test-artifacts
117115
path: target/tmp
116+
117+
# Build Trezor-specific tests and archive them using cargo-nextest's "archive" feature.
118+
run_tests_on_trezor_preparation:
119+
runs-on: ubuntu-latest
120+
steps:
121+
# Note: we need to mimic the directory structure of the run_tests_on_trezor job, otherwise nextest
122+
# will fail to execute archived tests. So we checkout the source code to "./mintlayer-core".
123+
# (Also note that because of this the resulting path of the source dir will be "/.../mintlayer-core/mintlayer-core/mintlayer-core")
124+
- name: Checkout the core repository
125+
uses: actions/checkout@v4
126+
with:
127+
submodules: recursive
128+
path: ./mintlayer-core
129+
130+
- name: Update local dependency repositories
131+
run: sudo apt-get update
132+
133+
- name: Install build dependencies
134+
run: sudo apt-get install -yqq --no-install-recommends build-essential python3 python3-toml pkg-config libssl-dev
135+
136+
- name: Extract required info from Cargo.toml
137+
id: extract_cargo_info
138+
run: echo "RUST_VERSION=$(python3 ./build-tools/cargo-info-extractor/extract.py --rust-version)" >> $GITHUB_OUTPUT
139+
working-directory: ./mintlayer-core
140+
141+
- name: Install rust
142+
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain ${{ steps.extract_cargo_info.outputs.RUST_VERSION }}
143+
144+
- name: Install cargo-nextest
145+
uses: taiki-e/install-action@nextest
146+
147+
- name: Build and archive the tests
148+
run: cargo nextest archive --release --locked -p wallet --features enable-trezor-device-tests --archive-file tests.tar.zst
149+
working-directory: ./mintlayer-core
150+
151+
- name: Upload archived tests
152+
uses: actions/upload-artifact@v4
153+
with:
154+
name: archived-trezor-tests
155+
path: ./mintlayer-core/tests.tar.zst
156+
retention-days: 1
157+
158+
run_tests_on_trezor:
159+
needs: run_tests_on_trezor_preparation
160+
runs-on: ubuntu-latest
161+
strategy:
162+
matrix:
163+
model: [T2T1, T3B1, T3T1, T3W1]
164+
env:
165+
TREZOR_MODEL: ${{ matrix.model }}
166+
# Note: these are the default values, but it's better to specify them explicitly.
167+
TREZOR_TESTS_USE_REAL_DEVICE: false
168+
TREZOR_TESTS_AUTO_CONFIRM: true
169+
steps:
170+
# Note: cargo-nextest requires the source code to be present when running archived test binaries.
171+
- name: Checkout the core repository
172+
uses: actions/checkout@v4
173+
with:
174+
submodules: recursive
175+
path: ./mintlayer-core
176+
177+
- name: Download archived tests
178+
uses: actions/download-artifact@v4
179+
with:
180+
name: archived-trezor-tests
181+
path: ./mintlayer-core
182+
183+
- name: Install cargo-nextest
184+
uses: taiki-e/install-action@nextest
185+
186+
- name: Update local dependency repositories
187+
run: sudo apt-get update
188+
189+
- name: Install other necessary tools
190+
run: sudo apt-get install -yqq --no-install-recommends python3 python3-toml
191+
192+
- name: Extract required info from Cargo.toml
193+
id: extract_cargo_info
194+
run: |
195+
echo "TREZOR_REPO_REV=$(python3 ./build-tools/cargo-info-extractor/extract.py --trezor-repo-rev)" >> $GITHUB_OUTPUT
196+
working-directory: ./mintlayer-core
197+
198+
- name: Checkout mintlayer-trezor-firmware repository
199+
uses: actions/checkout@v4
200+
with:
201+
repository: mintlayer/mintlayer-trezor-firmware
202+
ref: ${{ steps.extract_cargo_info.outputs.TREZOR_REPO_REV }}
203+
submodules: recursive
204+
path: ./mintlayer-trezor-firmware
205+
206+
# Note: this is basically a copy of ".github/actions/environment" from the trezor repo, with
207+
# the "full-deps" parameter equal to false (which is the default).
208+
# Also note that the original "environment" action could technically be called from here
209+
# via "uses", so in theory the duplication could be avoided. Unfortunately, the "nix-shell"
210+
# calls require the current directory to be the one where the trezor repo has been checked out
211+
# and there is no way of overriding the working dir for another action (unless the action itself
212+
# supports it).
213+
- name: Install nix
214+
uses: cachix/install-nix-action@v23
215+
with:
216+
nix_path: nixpkgs=channel:nixos-unstable
217+
- name: Setup trezor repo build dependencies, part 1
218+
run: nix-shell --arg fullDeps false --run "true"
219+
working-directory: ./mintlayer-trezor-firmware
220+
- name: Setup trezor repo build dependencies, part 2
221+
run: nix-shell --arg fullDeps false --run "poetry install"
222+
working-directory: ./mintlayer-trezor-firmware
223+
224+
- name: Build the firmware
225+
run: nix-shell --run "poetry run make -C core build_unix"
226+
working-directory: ./mintlayer-trezor-firmware
227+
228+
# Note: since we haven't installed Cargo in this job, we have to execute "cargo-nextest nextest"
229+
# instead of "cargo nextest".
230+
- name: Run tests in the emulator
231+
run:
232+
nix-shell --run "
233+
poetry run core/emu.py
234+
--headless --quiet --temporary-profile
235+
--mnemonic \"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about\"
236+
--command env --chdir ../mintlayer-core
237+
cargo-nextest nextest run --archive-file tests.tar.zst -j1 trezor_signer
238+
"
239+
working-directory: ./mintlayer-trezor-firmware
240+
timeout-minutes: 10

.github/workflows/code_checks.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
run: sudo apt-get install -yqq --no-install-recommends build-essential python3 python3-toml
2929

3030
- name: Install rust
31-
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py)
31+
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/cargo-info-extractor/extract.py --rust-version)
3232
- name: Install rust clippy
3333
run: rustup component add clippy
3434
- name: Install cargo-deny
@@ -53,7 +53,7 @@ jobs:
5353
- name: Install python toml package
5454
run: python3 -m pip install toml
5555
- name: Install rust
56-
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py)
56+
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/cargo-info-extractor/extract.py --rust-version)
5757
- name: Install rust clippy
5858
run: rustup component add clippy
5959
- name: Install cargo-deny
@@ -73,7 +73,7 @@ jobs:
7373
- name: Install python toml package
7474
run: python3 -m pip install toml --break-system-packages --user
7575
- name: Install rust
76-
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py)
76+
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/cargo-info-extractor/extract.py --rust-version)
7777
- name: Install rust clippy
7878
run: rustup component add clippy
7979
- name: Install cargo-deny

.github/workflows/loom.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: sudo apt-get install -yqq build-essential pkg-config libssl-dev
2727
- uses: actions/checkout@v2
2828
- name: Install rust
29-
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py)
29+
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/cargo-info-extractor/extract.py --rust-version)
3030
- name: Checkout repository and submodules
3131
uses: actions/checkout@v2
3232
with:

.github/workflows/wasm.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
run: sudo apt-get install -yqq build-essential pkg-config libssl-dev
3131
- uses: actions/checkout@v3
3232
- name: Install rust
33-
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py)
33+
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/cargo-info-extractor/extract.py --rust-version)
3434
- name: Use Node.js ${{ matrix.node-version }}
3535
uses: actions/setup-node@v3
3636
with:
@@ -63,7 +63,7 @@ jobs:
6363
run: sudo apt-get install -yqq build-essential pkg-config libssl-dev
6464
- uses: actions/checkout@v3
6565
- name: Install rust
66-
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/rust-version-extractor/rust-version-extractor.py)
66+
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $(python3 ./build-tools/cargo-info-extractor/extract.py --rust-version)
6767
- name: Install wasm-pack
6868
run: cargo install wasm-pack
6969

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
'''
3+
A simple program that extracts certain info from Cargo.toml and prints it to stdout.
4+
To be used in CI.
5+
'''
6+
7+
import argparse
8+
import pathlib
9+
import toml
10+
11+
12+
ROOT_DIR = pathlib.Path(__file__).resolve().parent.parent.parent
13+
ROOT_CARGO_TOML = ROOT_DIR.joinpath("Cargo.toml")
14+
15+
16+
def get_rust_version(workspace_settings):
17+
version = workspace_settings["package"]["rust-version"]
18+
19+
# Unfortunately, rust-init doesn't support completing the version on its own, so we just pad with whatever works
20+
if len(version.split('.')) == 2:
21+
version = version + '.0'
22+
23+
return version
24+
25+
26+
def get_trezor_repo_rev(workspace_settings):
27+
return workspace_settings["dependencies"]["trezor-client"]["rev"]
28+
29+
30+
def main():
31+
parser = argparse.ArgumentParser()
32+
mutex_group = parser.add_mutually_exclusive_group(required=True)
33+
mutex_group.add_argument('--rust-version', action='store_true', help='extract Rust version')
34+
mutex_group.add_argument('--trezor-repo-rev', action='store_true', help='extract Trezor repo revision')
35+
args = parser.parse_args()
36+
37+
cargo_toml_root = toml.load(ROOT_CARGO_TOML)
38+
workspace_settings = cargo_toml_root["workspace"]
39+
40+
if args.rust_version:
41+
result = get_rust_version(workspace_settings)
42+
print(result)
43+
elif args.trezor_repo_rev:
44+
result = get_trezor_repo_rev(workspace_settings)
45+
print(result)
46+
47+
48+
if __name__ == "__main__":
49+
main()

build-tools/rust-version-extractor/rust-version-extractor.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

wallet/src/signer/trezor_signer/test_utils/mod.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
mod auto_confirmer;
1717

1818
use itertools::Itertools as _;
19-
use trezor_client::{find_devices, AvailableDevice, Model, Trezor, TrezorMessage};
19+
use trezor_client::{
20+
transport::{udp::UdpTransport, webusb::WebUsbTransport},
21+
AvailableDevice, Model, Trezor, TrezorMessage,
22+
};
2023

2124
use logging::log;
2225
use utils::env_utils::bool_from_env;
@@ -41,25 +44,32 @@ pub fn find_test_device_and_connect(debug: bool) -> Trezor {
4144
}
4245

4346
pub fn find_test_device(debug: bool) -> AvailableDevice {
44-
let use_real_device = should_use_real_device();
45-
46-
let devices = find_devices(debug)
47-
.into_iter()
48-
.filter(|device| {
49-
if use_real_device {
47+
// Note: calling `WebUsbTransport::find_devices` on CI will panic with the message
48+
// "Can't init Global usb context, error Other" (due to `unwrap()` on `rusb::devices()`).
49+
// Which means that we can't use `trezor_client::find_devices` here because it calls
50+
// `WebUsbTransport::find_devices` unconditionally.
51+
let devices = if should_use_real_device() {
52+
WebUsbTransport::find_devices(debug)
53+
.unwrap()
54+
.into_iter()
55+
.filter(|device| {
5056
// Note: we don't support `Model::TrezorLegacy` AKA Trezor Model One.
5157
device.model == Model::Trezor
52-
} else {
53-
device.model == Model::TrezorEmulator
54-
}
55-
})
56-
.collect_vec();
58+
})
59+
.collect_vec()
60+
} else {
61+
let devices = UdpTransport::find_devices(debug, None).unwrap();
62+
assert!(devices.iter().all(|device| device.model == Model::TrezorEmulator));
63+
devices
64+
};
5765

5866
if devices.len() > 1 {
5967
log::warn!("More than one device found, using the first one in the list");
6068
}
6169

62-
devices.into_iter().next().unwrap()
70+
let device = devices.into_iter().next().unwrap();
71+
log::debug!("Using device {device:?}");
72+
device
6373
}
6474

6575
// Note: `trezor_client::Trezor` only exposes `call_raw`, in which `write_message` is always followed

0 commit comments

Comments
 (0)