Skip to content

test: drive jade flows with an emulator - #2052

Merged
ovitrif merged 3 commits into
masterfrom
feat/jade-emulator
Nov 26, 2026
Merged

ovitrif merged 3 commits into
masterfrom
feat/jade-emulator

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #2049

Twin: synonymdev/bitkit-ios#1441
Dependency: synonymdev/bitkit-docker#45

This PR lets debug builds drive every Jade flow against the Blockstream Jade emulator from bitkit-docker, and adds a journey for each.

Description

  • Adds a TCP transport to the Blockstream Jade emulator in bitkit-docker, behind JADE_EMULATOR in debug builds, so the Jade flows run on an emulator without a device. The emulator shows up in scans as one more Jade.
  • Reports a closed emulator socket as the Jade disconnecting, as a dropped Bluetooth or USB link does, so the next request after an emulator restart reconnects instead of reusing a dead session.
  • Adds a journey for each Jade flow the app has: pairing, receive address check, signing on the device, each hardware__jade_* error the app can reach, logging out on the device and a passphrase wallet.
  • Fixes the wrong PIN message on the Found Jade step disappearing as soon as the next scan found the same Jade.

Out of Scope

Design

N/A — no design available.

Preview

The Found step's wrong PIN message stays on screen, and the app reconnects after the emulator restarts:

Wrong PIN on Found Emulator restart
android-wrong-pin2x.mp4
android-restart-reconnect2x.mp4

QA Notes

Setup

  1. bitkit-docker at ff07520 (feat: add a jade emulator bitkit-docker#45): ./start.sh, then ./scripts/jade-emulator start (each journey names the JADE_* settings it needs; docs/jade-emulator.md has the recipes).
  2. A regtest debug build with JADE_EMULATOR=true; the app reaches the emulator at 10.0.2.2:30121 (JADE_EMULATOR_URL overrides it).
  3. Interactive journeys press the device's buttons with ./scripts/jade-emulator press, pin and passphrase in bitkit-docker.

Journeys

  • J1: new jade-connect-sign.xml — pairs the emulated Jade, verifies a receive address on it and sends from it
  • J2: new jade-sign-on-device.xml — declining on the device cancels the send; approving it sends
  • J3: new jade-wrong-pin.xml — a wrong PIN shows the Found step's message, then the right PIN pairs
  • J4: new jade-network-mismatch.xml — a mainnet Jade shows the network mismatch message
  • J5: new jade-uninitialized.xml — a Jade with no seed shows the not set up message
  • J6: new jade-wallet-mismatch.xml — a Jade with another seed shows the different wallet message
  • J7: new jade-psbt-too-large.xml — a send over 200 inputs shows the transaction too large message
  • J8: new jade-device-locked.xml — logging out on the device shows the busy message
  • J9: new jade-passphrase.xml — a passphrase typed on the Jade pairs as a second wallet of the same Jade

Manual Tests

N/A

Automated Checks

  • added JadeEmulatorTransportTest.kt — the emulator is listed only while its port answers, and reads and writes go over the socket
  • updated JadeTransportTest.kt — emulator paths go to the TCP transport, and a closed emulator socket reports the Jade disconnected
  • updated HwConnectViewModelTest.kt — the wrong PIN message stays when the next scan finds the same Jade

Evidence

  • J1 to J9 driven on the Android emulator, dev debug build, regtest, before this branch was rebased onto master; each showed the expected step or message.
  • On 9f5af34: J2 declined then approved a 50,000 sat send, and a send signed after the emulator restarted under the app (the first request reports the disconnect, the next reconnects and asks for the PIN).

Gaps

  • J1 and J3 to J9 were not driven again after the rebase; master's hardware send changes are covered by J2 and the unit suite.
  • Bluetooth, USB and QR mode need a physical Jade.

Models used

  • Planning/scoping: Claude Opus 5.5 (reasoning: medium)
  • Implementation: Claude Opus 5.5 (reasoning: medium)
  • Review: Claude Sonnet 5.5 (reasoning: high)
  • Review rounds: 1

Verified: JadeEmulatorTransportTest and JadeTransportTest pass; dev debug on an emulator paired, verified and signed a send against the jade emulator
Adds a journey for each hardware__jade_* error the app can reach, for signing on the device and for a passphrase wallet. Keeps the Found step's wrong PIN message while the next scan finds the same Jade, and closes the emulator socket when a connect fails.

Verified: just compile, just test and just lint pass
A closed emulator socket now reports the Jade as disconnected, as a USB detach or dropped Bluetooth link does, so the next request reconnects instead of reusing a dead session.

Verified: just compile, just test and just lint pass; on an emulator a send signed after the Jade emulator restarted under the app
@ovitrif ovitrif self-assigned this Nov 25, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T22:08:38.896990Z 9f5af34 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ovitrif
ovitrif requested review from a team, jvsena42 and piotr-iohk and removed request for a team November 25, 2026 22:07
@ovitrif ovitrif modified the milestone: 3.3.0 Nov 25, 2026
@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Adds a debug-only TCP connection to the Jade emulator and nine journeys covering pairing, receiving, signing and Jade error messages.

  • Debug builds can find and use a Jade emulator over TCP.
  • A closed emulator socket clears the Jade session for a fresh connection.
  • The Found Jade screen keeps errors when the same device returns.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Jade scan] --> B{Debug emulator enabled?}
  B -- Yes --> C[Check TCP endpoint]
  C --> D[Offer Jade Emulator]
  D --> E[Open socket and exchange bytes]
  E --> F{Socket disconnected?}
  F -- Yes --> G[Emit external disconnect]
  G --> H[Clear live Jade session]
  B -- No --> I[USB and Bluetooth only]
Loading

Reviews (1) · Last reviewed commit: "fix: reconnect the jade emulator after i..." · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Regtest APK

Built from 9f5af34 (run).

Download bitkit-dev-debug universal APK (expires in 30 days).

@talosmachina talosmachina left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findings. Adds a debug-only TCP transport to the Jade emulator, routes tcp: paths to it, reports a closed socket as an external disconnect, keeps the Found step's connect error when the same Jade is shown again, and adds journeys J1 to J9. Reviewed 9f5af34, full tier, static: per the repo's agent rules an automated review does not build the Android branch here, so this rests on the code and on CI.

What I checked, and 6 candidates I ruled out

Read in full: JadeEmulatorTransport.kt, the JadeTransport.kt diff with scanDevices, the USB and BLE close/read paths and emitExternalDisconnect, HwConnectViewModel.kt (onFoundRoute, onConnectClick, onConnectFailed, startSearching), the three test files, build.gradle.kts build config fields.
Call sites traced: JadeRepo.observeExternalDisconnects, disconnect, disconnectStaleSession, cancelPendingConnection, findKnownDeviceCandidates (hasUsbPermission filter), HardwareSheet Found route.
Journeys: every testTag the nine Jade journeys assert exists in app/src/main (literal or through the Tab-, Suggestion-, AssetButton- builders).
CI: build-and-test, lint, detekt, build-local green; e2e and compose-ui still running at review time.

Ruled out

  • Emulator reachable in a release build: JADE_EMULATOR is forced to false for every non-debug variant, and isEmulatorPath is gated on it, so a tcp: path falls through to the USB branch there.
  • Emulator dropped by the USB permission filter on reconnect: hasUsbPermission returns true for an emulator path before touching UsbManager.
  • Stale connect error kept on a later visit: onConnectClick, startSearching and cancelConnect all clear errorMessage; only a re-entry of Found for the same foundDeviceId keeps it, which HwConnectViewModelTest pins both ways.
  • Scan probe fighting an open session: scanDevices skips the probe while a socket for the path is held.
  • A user close during an in-flight read emitted as an external disconnect: possible (the emulator path never adds to userInitiatedCloseSet), but debug-only and observeExternalDisconnects drops it once connected is cleared; below the posting tier.
  • Chunk size: the emulator path gets MAX_CHUNK_SIZE (509), the same as serial USB.

Merge confidence: 4/5, no findings, but e2e was still running and the branch was not built here.

Reviewer model: Claude Opus 5.5
Reasoning effort: Not exposed (this review session does not report its reasoning setting)

@piotr-iohk piotr-iohk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA review

Scope: full PR at 9f5af34, re-reviewed after explicit full review request.

2 actionable findings — resolve or provide an evidence-backed rebuttal.

No defects were identified in the production code changes (app/build.gradle.kts, JadeEmulatorTransport, JadeTransport, and HwConnectViewModel.onFoundRoute): JADE_EMULATOR is forced false in release builds, the TCP transport respects QEMU's single-client constraint by skipping reachability probes while open, clamps soTimeout to avoid blocking indefinitely, and routes DISCONNECTED results through socket close and emitExternalDisconnect. HwConnectViewModel.onFoundRoute preserves an existing connect error only when reopening the same foundDeviceId, while retry, cancel, dismiss, and different-device paths clear it. One LOW defect was found in the new jade-psbt-too-large.xml journey setup command.

Compatibility and parity checks (read-only comparison sources, not full reviews):

  • Dependency synonymdev/bitkit-docker#45 at ff07520 (compatibility contracts only: jade-emulator port, CLI subcommands, environment variables, interactive button sequences, and recipes): 10.0.2.2:30121 routing, scripts/jade-emulator commands/env vars, and button sequences match. Two discrepancies were noted: journeys/hardware-wallet/jade-psbt-too-large.xml omits periodic mining during the 200-send loop (reported as a finding), and the PR #2052 Setup section references ./start.sh, whereas bitkit-docker starts with docker compose up -d (as journeys/hardware-wallet/README.md already states).
  • Twin synonymdev/bitkit-ios#1441 at 428cff5 (scoped to Jade emulator transport and the 9 journeys): transport behavior and journey specs align aside from documented platform differences (jade-device-locked.xml expects Android's busy toast vs iOS PIN re-prompt, and Android's HwConnectViewModel error-preservation fix). The iOS copy of jade-psbt-too-large.xml has the same unmined 200-send loop.

Validation and limitations: CI build-and-test passed on 9f5af34; local Gradle unit test execution was unavailable in this review environment due to a missing Android SDK. Unit tests cover emulator read-side disconnect (JadeTransportTest), while write-side IOException disconnect reporting in JadeTransport.writeChunk was verified by source analysis only.

Recommended before device testing

  • Update the setup command in journeys/hardware-wallet/jade-psbt-too-large.xml to mine every 20 sends so J6 can fund 200 UTXOs on a fresh bitkit-docker stack.
  • Clarify step 1 of the PR QA Setup to run docker compose up -d instead of ./start.sh in bitkit-docker.

Device testing: not performed in this review. The 9 new journeys (J1–J9) remain to be run against an Android emulator or device with synonymdev/bitkit-docker#45; physical USB and BLE transports remain outside emulator coverage.

Earlier findings reconciled at this revision: 1 still present.

Findings

  • [LOW] Mine periodically in jade-psbt-too-large.xml setup to avoid Bitcoin Core's 25-tx mempool chain limit — inline at journeys/hardware-wallet/jade-psbt-too-large.xml:8.
  • [MEDIUM] Fix J5 uninitialized Jade error mismatch against Android output — inline at journeys/hardware-wallet/jade-uninitialized.xml:18. Still present from an earlier unpublished review.

Reviewer model: gemini-4-neon
Reasoning effort: high

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code scan at 9f5af34: no HIGH/MEDIUM from me. One LOW, inline.

I reviewed this as a hardware-wallet signing change despite the test: label: it adds JadeEmulatorTransport to app/src/main, routes JadeTransport through it, changes the build config, and changes the Found step for every vendor (HwConnectViewModel.onFoundRoute), with a fixed changelog fragment.

Checked and clean:

  • Release exposure: JADE_EMULATOR is forced false unless variant.buildType == "debug" (app/build.gradle.kts:446-450), and only debug/release build types exist. With it false, isEmulatorPath/scanDevices return early and every JadeTransport branch falls through to the unchanged BLE/USB calls. Host/port come only from build-time JADE_EMULATOR_URL; nothing from a path, scan result, deeplink or stored device can redirect the socket. No workflow sets the flag.
  • Real USB/BLE Jade: the JadeTransport diff is additive branches in front of unchanged calls; closeAllConnections adds a no-op closeAll() on an empty map.
  • onFoundRoute keeping errorMessage for the same foundDeviceId: retry (onConnectClick), new search (startSearching), success (onConnected), Cancel/Back (sheet dispose → resetState()) and a different device all clear it. No stale-error path.
  • Journeys: all asserted tags and quoted strings exist at head; J3, J6, J7, J8, J9 traced through the code. J5 is piotr-iohk's open thread, not repeated here. Same 9 file names on synonymdev/bitkit-ios#1441; 7 byte-identical, jade-connect-sign.xml differs only in identifiers, jade-device-locked.xml adapted and documented in the suite README.
  • CI green at this head.

perf: not relevant for shipped builds (scanDevices returns immediately when disabled).

Device gate (partial): 9f5af34 — not run yet; J1–J9 need the Jade emulator from bitkit-docker. Device result to follow.

Reviewer model: Opus 5.5 (claude-opus-5-5) coordinating; Fable 5.2 (claude-fable-5-2) primary review
Reasoning effort: Not exposed

@jvsena42

Copy link
Copy Markdown
Member

Device gate (partial): 9f5af34 — J1 (jade-connect-sign.xml) passed on the Android emulator (API 37) against the bitkit-docker Jade emulator (firmware 1.0.41-dirty, interactive mode), staging regtest.

  • Connect: 7 s from socket open to paired. Sign: about 13 s from tap to broadcast, success screen 17 s after the tap. Sent 50 000 sats from the Jade, one "Sent −50 141" row.
  • Emulator restarted under a paired app: the next request reconnects in the same tap, as the PR describes.
10:25:59.102 INFO [JadeEmulatorTransport.kt:63] Opened Jade emulator 'tcp:10.0.2.2:30121'
10:26:00.677 INFO [JadeRepo.kt:663] Connected Jade 'tcp:10.0.2.2:30121' firmware '1.0.41-dirty' state 'LOCKED'
10:26:05.991 DEBUG [HwConnectViewModel.kt:374] Paired hardware device 'tcp:10.0.2.2:30121' as 'jade:serial:000000000000'
10:33:03.568 INFO [CoreService.kt:1593] Created sent onchain activity for txid 58ad7b91…563770 from send result

Still running: J2–J9.

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 9f5af34. Open LOWs: the XML one from my earlier review and one new journey step, inline. Fix them here or in a follow-up issue, and reply on each thread with which. J5 fails on device exactly as piotr-iohk's open MEDIUM says; I've added the device output on that thread rather than raising it again.

Device gate: 9f5af34 — journeys: 8 passed, 1 failed (jade-uninitialized.xml step 4, piotr-iohk's thread). Run on the Android emulator (API 37) against the bitkit-docker Jade emulator (firmware 1.0.41-dirty), staging regtest; J7 on the local regtest.

  • J1 connect-sign: paired in 7 s, signed and broadcast 50 000 sats about 13 s after the tap (success screen 17 s).
  • J2 sign-on-device: decline leaves the sign screen with no payment; approve sends once (balance −50 141, one Sent row), success 9 s after the press.
  • J3 wrong PIN: "Wrong PIN. Try again on your Jade." stays on Found from 0 to 36 s. Back and reopen, or Cancel and reopen, show no stale error. Retrying with the right PIN clears it and pairs. No re-scan ran in that window, so persistence under repeated scans isn't shown.
  • J4 network mismatch, J6 wallet mismatch, J8 device locked (info toast, no hang), J9 passphrase (second wallet listed at 0): pass.
  • J7 PSBT too large: 200 UTXOs funded; signPsbt failed [AppError='size=92036, max=16384'], the documented toast, no broadcast.
    perf: not relevant (debug-only transport); l10n: no UI text changed.
    ⚠️ Not verified: real USB replug, BLE re-discovery and the Trezor path through the changed onFoundRoute; the emulator only covers the TCP transport.

Reviewer model: Opus 5.5 (claude-opus-5-5) coordinating; Fable 5.2 (claude-fable-5-2, reasoning medium) primary review and device runbook; Sonnet 5.5 (claude-sonnet-5-5, reasoning low) device driver
Reasoning effort: Not exposed (coordinator)

@ovitrif

ovitrif commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Merging: approved by @jvsena42 with CI green. The four review points (J5 text, J1 Show details, psbt journey mining and XML) go in a follow-up PR, linked in their threads.

@ovitrif
ovitrif merged commit 90e9f64 into master Nov 26, 2026
24 checks passed
@ovitrif
ovitrif deleted the feat/jade-emulator branch November 26, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants