Skip to content

Commit 59917a6

Browse files
authored
Merge pull request #184 from synonymdev/test/trezor-foundations
Test/trezor foundations e2e tests
2 parents ab38a23 + 7faae13 commit 59917a6

20 files changed

Lines changed: 1276 additions & 22 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_modules
55
docker/lnd
66
docker/lnurl-server-data
77
docker/lnurl-server/data
8+
docker/.trezor-user-env
89
artifacts
910
WARP.md
1011
.ai

README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,137 @@ BACKEND=local ./scripts/build-ios-sim.sh
8383
BACKEND=regtest ./scripts/build-ios-sim.sh
8484
```
8585

86+
Optional Trezor Bridge support is disabled by default and can be enabled per build:
87+
88+
```bash
89+
# Android emulator, local backend
90+
TREZOR_BRIDGE=true ./scripts/build-android-apk.sh
91+
92+
# Android physical device, local backend
93+
TREZOR_BRIDGE=true TREZOR_BRIDGE_URL=http://127.0.0.1:21325 ./scripts/build-android-apk.sh
94+
95+
# Android emulator, staging regtest backend
96+
BACKEND=regtest TREZOR_BRIDGE=true ./scripts/build-android-apk.sh
97+
98+
# iOS simulator, local backend
99+
TREZOR_BRIDGE=true TREZOR_ELECTRUM_URL=tcp://127.0.0.1:60001 ./scripts/build-ios-sim.sh
100+
101+
# iOS simulator, staging regtest backend
102+
BACKEND=regtest TREZOR_BRIDGE=true ./scripts/build-ios-sim.sh
103+
```
104+
86105
---
87106

107+
### 🔐 Manual Trezor Emulator Setup
108+
109+
The local docker setup includes an opt-in Trezor User Env fixture for manual hardware-wallet checks. It starts the official Trezor emulator and Bridge, but it is not part of the default `docker compose up -d` stack.
110+
111+
Default emulator state:
112+
113+
- Model: `T2T1`
114+
- Firmware: `2-main`
115+
- Bridge: `node-bridge`
116+
- Mnemonic: random 12-word BIP39 phrase generated on each `start`
117+
- PIN: empty
118+
- Passphrase protection: off
119+
- Label: `Bitkit Test Trezor`
120+
121+
Start the emulator:
122+
123+
```bash
124+
./scripts/trezor-emulator start
125+
./scripts/trezor-emulator status
126+
```
127+
128+
`start` prints the generated mnemonic and the first native regtest receive address (`m/84h/1h/0h/0/0`) so it can be funded during manual checks.
129+
`start` refuses to wipe/reseed an already-running emulator. Use `stop` before starting a new one.
130+
131+
For CI or scripts, use JSON output:
132+
133+
```bash
134+
./scripts/trezor-emulator start --json > artifacts/trezor-emulator.json
135+
./scripts/trezor-emulator status --json
136+
```
137+
138+
`status --json` returns the current receive address metadata, but not the mnemonic.
139+
140+
Use the deterministic seed when you want to reuse known history/funds:
141+
142+
```bash
143+
TREZOR_RANDOM_MNEMONIC=false ./scripts/trezor-emulator start
144+
```
145+
146+
Or provide an explicit seed:
147+
148+
```bash
149+
TREZOR_MNEMONIC="all all all all all all all all all all all all" ./scripts/trezor-emulator start
150+
```
151+
152+
Override the printed address coin/path when needed:
153+
154+
```bash
155+
TREZOR_ADDRESS_COIN=Testnet TREZOR_ADDRESS_PATH="m/84h/1h/0h/0/0" ./scripts/trezor-emulator start
156+
```
157+
158+
Useful URLs:
159+
160+
- User Env dashboard: `http://localhost:9002`
161+
- Trezor Bridge: `http://localhost:21325`
162+
163+
The Trezor User Env image is pinned in `docker/docker-compose.yml` so the emulator Bridge keeps the raw message format expected by current Bitkit builds.
164+
165+
#### Android Emulator
166+
167+
```bash
168+
# Local backend
169+
cd docker
170+
docker compose up -d
171+
cd ..
172+
./scripts/trezor-emulator start
173+
TREZOR_BRIDGE=true ./scripts/build-android-apk.sh
174+
npm run e2e:android
175+
176+
# Staging regtest backend
177+
./scripts/trezor-emulator start
178+
BACKEND=regtest TREZOR_BRIDGE=true ./scripts/build-android-apk.sh
179+
BACKEND=regtest npm run e2e:android
180+
```
181+
182+
For manual checks, open Bitkit and use the app's developer Trezor screen to scan and connect to `Bitkit Test Trezor`.
183+
184+
#### Android Physical Device
185+
186+
```bash
187+
./scripts/trezor-emulator start
188+
./scripts/trezor-emulator adb
189+
TREZOR_BRIDGE=true TREZOR_BRIDGE_URL=http://127.0.0.1:21325 ./scripts/build-android-apk.sh
190+
```
191+
192+
#### iOS Simulator
193+
194+
```bash
195+
# Local backend
196+
cd docker
197+
docker compose up -d
198+
cd ..
199+
./scripts/trezor-emulator start
200+
TREZOR_BRIDGE=true TREZOR_ELECTRUM_URL=tcp://127.0.0.1:60001 ./scripts/build-ios-sim.sh
201+
npm run e2e:ios
202+
203+
# Staging regtest backend
204+
./scripts/trezor-emulator start
205+
BACKEND=regtest TREZOR_BRIDGE=true ./scripts/build-ios-sim.sh
206+
BACKEND=regtest npm run e2e:ios
207+
```
208+
209+
Stop the emulator when finished:
210+
211+
```bash
212+
./scripts/trezor-emulator stop
213+
```
214+
215+
Backend and Trezor are independent. `BACKEND=local` uses local Bitcoin/Electrum, while `BACKEND=regtest` uses remote staging regtest services. The Trezor emulator always provides only the device and Bridge. Fund or mine against the same backend the app was built for.
216+
88217
### 🧪 Running tests
89218

90219
**Important:** The `BACKEND` environment variable controls which infrastructure the tests use for blockchain operations (deposits, mining blocks):

ci_run_android.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ if [[ "${BACKEND:-local}" != "mainnet" ]]; then
5656
adb reverse tcp:30001 tcp:30001
5757
# homegate port
5858
adb reverse tcp:6288 tcp:6288
59+
# trezor bridge port
60+
adb reverse tcp:21325 tcp:21325
5961
fi
6062
# show touches
6163
adb shell settings put system show_touches 1

docker/docker-compose.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
x-trezor-user-env-image: &trezor_user_env_image ghcr.io/trezor/trezor-user-env@sha256:15871ebb234bf7c0197cfcd31ddc2edbe90173cd6386fc0283fafe05bf888c06
2+
13
services:
24
bitcoind:
35
container_name: bitcoin
@@ -199,6 +201,27 @@ services:
199201
ports:
200202
- '6288:8080'
201203

204+
trezor-user-env:
205+
image: *trezor_user_env_image
206+
profiles:
207+
- trezor
208+
ports:
209+
- '9001:9001' # User Env controller websocket
210+
- '9002:9002' # User Env dashboard
211+
- '21325:21325' # Trezor Bridge legacy port used by Bitkit
212+
- '21328:21328' # Trezor Bridge current port
213+
- '15900:5900' # VNC port, offset to avoid local VNC conflicts
214+
- '6080:6080' # noVNC web viewer
215+
- '9003:9003' # MCP server SSE transport
216+
environment:
217+
- MACOS=1
218+
- REGTEST_RPC_URL=http://host.docker.internal:43782
219+
volumes:
220+
- './.trezor-user-env/trezor-suite:/trezor-user-env/trezor-suite'
221+
- './.trezor-user-env/logs/screens:/trezor-user-env/logs/screens'
222+
- './.trezor-user-env/logs/mcp-screenshots:/trezor-user-env/logs/mcp-screenshots'
223+
- './.trezor-user-env/firmware/user_downloaded:/trezor-user-env/src/binaries/firmware/bin/user_downloaded'
224+
202225
volumes:
203226
bitcoin_home:
204227

scripts/adb-reverse.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ for d in $(adb devices | awk 'NR>1 && $2=="device" {print $1}'); do
77
adb -s "$d" reverse tcp:9735 tcp:9735
88
adb -s "$d" reverse tcp:30001 tcp:30001
99
adb -s "$d" reverse tcp:6288 tcp:6288
10+
adb -s "$d" reverse tcp:21325 tcp:21325
11+
1012
done
1113

1214
echo "Done."

scripts/build-android-apk.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
# ./scripts/build-android-apk.sh
1717
# BACKEND=regtest ./scripts/build-android-apk.sh
1818
# BACKEND=mainnet ./scripts/build-android-apk.sh
19+
# TREZOR_BRIDGE=true ./scripts/build-android-apk.sh
20+
# TREZOR_BRIDGE=true TREZOR_BRIDGE_URL=http://127.0.0.1:21325 ./scripts/build-android-apk.sh
1921
set -euo pipefail
2022

2123
E2E_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
2224
ANDROID_ROOT="$(cd "$E2E_ROOT/../bitkit-android" && pwd)"
2325

2426
BACKEND="${BACKEND:-local}"
27+
TREZOR_BRIDGE="${TREZOR_BRIDGE:-false}"
28+
TREZOR_BRIDGE_URL="${TREZOR_BRIDGE_URL:-http://10.0.2.2:21325}"
2529
E2E_BACKEND="local"
2630
GRADLE_TASK="assembleDevDebug"
2731
APK_FLAVOR_DIR="dev/debug"
@@ -40,10 +44,14 @@ else
4044
echo "ERROR: Unsupported BACKEND value: $BACKEND" >&2
4145
exit 1
4246
fi
43-
echo "Building Android APK (BACKEND=$BACKEND, E2E_BACKEND=$E2E_BACKEND, GRADLE_TASK=$GRADLE_TASK)..."
47+
echo "Building Android APK (BACKEND=$BACKEND, E2E_BACKEND=$E2E_BACKEND, TREZOR_BRIDGE=$TREZOR_BRIDGE, TREZOR_BRIDGE_URL=$TREZOR_BRIDGE_URL, GRADLE_TASK=$GRADLE_TASK)..."
4448

4549
pushd "$ANDROID_ROOT" >/dev/null
46-
E2E=true E2E_BACKEND="$E2E_BACKEND" ./gradlew "$GRADLE_TASK" --no-daemon --stacktrace
50+
E2E=true \
51+
E2E_BACKEND="$E2E_BACKEND" \
52+
TREZOR_BRIDGE="$TREZOR_BRIDGE" \
53+
TREZOR_BRIDGE_URL="$TREZOR_BRIDGE_URL" \
54+
./gradlew "$GRADLE_TASK" --no-daemon --stacktrace
4755
popd >/dev/null
4856

4957
# Find the universal APK

scripts/build-ios-sim.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
# Usage:
1515
# ./scripts/build-ios-sim.sh
1616
# BACKEND=regtest ./scripts/build-ios-sim.sh
17+
# TREZOR_BRIDGE=true ./scripts/build-ios-sim.sh
18+
# TREZOR_BRIDGE=true BACKEND=regtest ./scripts/build-ios-sim.sh
1719
set -euo pipefail
1820
E2E_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
1921
IOS_ROOT="$(cd "$E2E_ROOT/../bitkit-ios" && pwd)"
2022

2123
BACKEND="${BACKEND:-local}"
24+
TREZOR_BRIDGE="${TREZOR_BRIDGE:-false}"
25+
TREZOR_BRIDGE_URL="${TREZOR_BRIDGE_URL:-http://127.0.0.1:21325}"
26+
TREZOR_ELECTRUM_URL="${TREZOR_ELECTRUM_URL:-}"
2227
E2E_BACKEND="local"
2328
E2E_NETWORK="regtest"
2429
XCODE_EXTRA_ARGS=()
@@ -35,9 +40,17 @@ fi
3540
XCODE_EXTRA_ARGS+=(
3641
"E2E_BACKEND=$E2E_BACKEND"
3742
"E2E_NETWORK=$E2E_NETWORK"
43+
"TREZOR_BRIDGE=$TREZOR_BRIDGE"
44+
"TREZOR_BRIDGE_URL=$TREZOR_BRIDGE_URL"
3845
"SWIFT_ACTIVE_COMPILATION_CONDITIONS=\$(inherited) E2E_BUILD"
3946
)
4047

48+
if [[ -n "$TREZOR_ELECTRUM_URL" ]]; then
49+
XCODE_EXTRA_ARGS+=("TREZOR_ELECTRUM_URL=$TREZOR_ELECTRUM_URL")
50+
fi
51+
52+
echo "Building iOS simulator app (BACKEND=$BACKEND, E2E_BACKEND=$E2E_BACKEND, TREZOR_BRIDGE=$TREZOR_BRIDGE, TREZOR_BRIDGE_URL=$TREZOR_BRIDGE_URL)..."
53+
4154
xcodebuild \
4255
-project "$IOS_ROOT/Bitkit.xcodeproj" \
4356
-scheme Bitkit \

0 commit comments

Comments
 (0)