Compare commits

...
Author SHA1 Message Date
dddf74f274 Merge pull request 'android wallet: self-heal the stored wallet_rpc_bin, gate Start/Create, one info banner' (#202) from wt/t_d63f9279 into main
All checks were successful
android-ci / android (push) Successful in 11m30s
Reviewed-on: #202
2026-10-31 05:33:17 +00:00
a0b704cd09 Merge branch 'main' into wt/t_d63f9279
Some checks failed
android-ci / android (pull_request) Has been cancelled
2026-10-31 05:33:07 +00:00
agent
3cd70ca9b5
android wallet: self-heal the stored wallet_rpc_bin, gate Start/Create, one info banner
All checks were successful
android-ci / android (pull_request) Successful in 11m51s
Device report (v0.7.0): Start died with `spawn monero-wallet-rpc: No such
file or directory`, and Create answered with the desktop TUI's `wallet not
configured — open F7 …`. Both were reachable states on the phone, so the
screen offered two dead ends.

- WireViewModel: `healStoredWalletBin()` re-points a stored wallet_rpc_bin
  that this device cannot execute at the resolved nativeLibraryDir path,
  preserving kind/mode/host/port/datadir/filename, skipping receive-only,
  and never overwriting a stored path that is a real executable file. It
  runs on wallet-screen open and again at the top of `startWalletChild()`,
  which then re-reads the stored record and refuses to spawn when the path
  still cannot run — writing the named path instead of ENOENT.
- Gate: `startGateReason()` = existing `startBlockedReason()` plus
  `storedWalletBinBlockedReason()`, which names the stored path, the
  resolved path, or the absent-binary message (unchanged strings).
  `shouldStartAfterSelectingChain()` now takes that reason, so a mode tap
  stores the source but cannot launch what Start would refuse.
- Create/Import: `walletSetupBlockedReason()` disables both controls with a
  sentence until the child answers; the TUI's unconfigured copy is mapped by
  `walletFailureText` to a phone sentence, so `open F7` and
  ONIONWIRE_WALLET_RPC never render.
- Banner: `walletFailureBanner()` paints `WALLET_NOT_OPEN_TEXT` as one info
  banner (or nothing when the No-wallet-open hint is already up), never as
  the red `Wallet error`; the sticky error is cleared when a wallet opens.
  Real failures (connect refusals, exited) still paint red.

Tests: 241/241 `:app:testDebugUnitTest`, including the four required cases.
Not verified on a device — no adb/device on this host.
2026-10-31 01:10:34 -04:00
6 changed files with 528 additions and 17 deletions

View file

@ -15,6 +15,9 @@ import com.siriusdevops.onionwire.keepalive.KeepAliveStatus
import com.siriusdevops.onionwire.keepalive.NodeHost
import com.siriusdevops.onionwire.ui.SeedBackupGate
import com.siriusdevops.onionwire.ui.WalletKeyOrigin
import com.siriusdevops.onionwire.ui.NO_CHAIN_SOURCE_NOTICE
import com.siriusdevops.onionwire.ui.storedWalletBinBlockedReason
import com.siriusdevops.onionwire.ui.walletBinHealPath
import com.siriusdevops.onionwire.ui.walletFailureText
import com.siriusdevops.onionwire.wallet.ChainStorage
import com.siriusdevops.onionwire.wallet.NO_WALLET_RPC_MESSAGE
@ -1015,10 +1018,72 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
*/
fun chainFreeBytes(): Long? = ChainStorage.freeBytes(home)
/**
* Repairs a stored `walletRpcBin` this device cannot execute, and reports
* whether it wrote anything back.
*
* A wallet-child record written by an older install can carry the bare name
* `monero-wallet-rpc` (or an empty string). Nothing in an APK sandbox
* resolves a bare name on `PATH`, so `start_wallet_child` spawns it and dies
* with `No such file or directory` — while the Start gate, which only ever
* looked at the *resolved* bundle, stayed green. This re-points the stored
* record at the absolute `nativeLibraryDir` path this install actually
* carries, before anything is spawned.
*
* What it deliberately does not do:
* - it never changes `kind`, host, port, mode, datadir or wallet filename —
* a repair of the binary is not a change of chain source;
* - it does nothing for receive-only (`ChainChoice.NONE`), which stores a
* bin it never spawns;
* - it never overwrites a stored path that exists and is executable, even
* when that path is not the bundled binary — a user who pointed at a real
* file keeps it;
* - it never fails loudly: a repair that cannot be made leaves the stored
* record alone, and the gate then names the path it will try to spawn.
*/
suspend fun healStoredWalletBin(bins: WalletChildBinaryPaths): Result<Boolean> =
withContext(Dispatchers.IO) {
runCatching {
val wire = requireWire()
val stored = runCatching { wire.chainSource() }.getOrNull()
?: return@runCatching false
if (stored.kind == ChainChoice.NONE) return@runCatching false
val healed = walletBinHealPath(stored.walletRpcBin, bins.walletRpc)
?: return@runCatching false
wire.setChainSource(
ChainConfig(
kind = stored.kind,
monerodBin = stored.monerodBin,
monerodDatadir = stored.monerodDatadir,
host = stored.host,
port = stored.port,
walletRpcBin = healed,
artiBin = stored.artiBin,
walletFilename = stored.walletFilename,
mainnet = stored.mainnet,
prune = stored.prune,
),
)
true
}
}.onSuccess { healed ->
if (healed) {
refreshChainSource()
refreshWalletChild()
}
}
/**
* Kick off start on [viewModelScope] so leaving the composition does not
* cancel Cuprate launch. Returns immediately; watch [walletChildStarting]
* and [walletChildError]. Core status stays `off` until the node answers.
*
* Self-heals the stored binary first, then re-reads that stored record and
* refuses to spawn when it still names a path this device cannot run. The
* screen's gate is the primary door, but an auto-start from a mode tap is
* not the only caller: this is the last place that can stop a doomed spawn,
* and the reason it writes is the named path rather than the core's opaque
* `spawn monero-wallet-rpc: …`.
*/
fun startWalletChild() {
if (!startInFlight.compareAndSet(false, true)) return
@ -1026,6 +1091,20 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
_walletChildError.value = null
viewModelScope.launch {
try {
val bins = bundledBinaries()
healStoredWalletBin(bins)
val stored = withContext(Dispatchers.IO) {
runCatching { requireWire().chainSource() }.getOrNull()
}
if (stored == null || stored.kind == ChainChoice.NONE) {
_walletChildError.value = NO_CHAIN_SOURCE_NOTICE
return@launch
}
val blocked = storedWalletBinBlockedReason(stored.walletRpcBin, bins.walletRpc)
if (blocked != null) {
_walletChildError.value = blocked
return@launch
}
val started = withContext(Dispatchers.IO) {
runCatching { requireWire().startWalletChild() }
}

View file

@ -2,6 +2,7 @@ package com.siriusdevops.onionwire.ui
import com.siriusdevops.onionwire.wallet.NO_WALLET_RPC_MESSAGE
import com.siriusdevops.onionwire.wallet.WalletChildBinaryPaths
import java.io.File
import java.util.Locale
/**
@ -446,13 +447,21 @@ fun selectedCuprateMode(inProcess: Boolean, mainnet: Boolean, prune: Boolean): C
/**
* Tapping a mode used to only persist `ChainConfig`, which looked like a no-op
* besides the storage line. Start when the storage floor would allow Start and
* a launch is not already in flight.
* besides the storage line. Start when the storage floor would allow Start,
* **the Start gate itself would allow it**, and a launch is not already in
* flight.
*
* [startBlocked] is the same reason the Start button is disabled by
* (`startGateReason`). A mode tap stores the source either way, but persisting
* a choice must never launch a child the gate would refuse — the old
* storage-only predicate is exactly how an auto-start slipped past a stored
* binary that could not run.
*/
fun shouldStartAfterSelectingChain(
storageBlocked: String?,
starting: Boolean,
): Boolean = storageBlocked == null && !starting
startBlocked: String? = null,
): Boolean = storageBlocked == null && startBlocked == null && !starting
/**
* Bytes as a screen-sized string. Binary units (a "GB" that is really a GiB is how
@ -609,7 +618,7 @@ fun startBlockedReason(
// control *is* Stop, so Start is never offered. Kept as a pure predicate so
// a stale status read cannot turn the one control into a no-op tap.
input.running -> "The wallet is already running."
!input.configured -> "No chain source yet: the wallet needs a daemon to dial."
!input.configured -> NO_CHAIN_SOURCE_NOTICE
// The stored source is the app's own node but this build has no daemon: the
// option is readable and unstoppable, so say it before the user presses Start.
input.chainInProcess && !input.nodeAvailable -> CUPRATE_NOT_IN_BUILD_NOTICE
@ -617,6 +626,172 @@ fun startBlockedReason(
else -> null
}
/** The stored config names no chain source, so there is no daemon to dial. */
const val NO_CHAIN_SOURCE_NOTICE: String =
"No chain source yet: the wallet needs a daemon to dial."
/**
* Whether [path] is a file this process may `exec`, measured the way the kernel
* will measure it at spawn time. A missing file and an existing file without
* the execute bit are both "cannot run here" — they differ only in errno.
*
* Never throws: a path the filesystem refuses to answer for is not executable.
*/
fun isExecutableWalletBin(path: String): Boolean =
runCatching { File(path).let { it.isFile && it.canExecute() } }.getOrDefault(false)
/**
* The absolute path the stored config should keep instead of [storedBin], or
* `null` when the stored path is already runnable here (or there is nothing
* better to offer).
*
* This is the repair rule behind the self-heal. A record written by an older
* install can carry the bare name `monero-wallet-rpc` (or nothing at all),
* which nothing in an APK sandbox resolves on `PATH`; the spawn then dies with
* `ENOENT` and the screen had no way to say why. When this build *does* carry
* the binary at a resolved absolute path, that path replaces the unusable one.
*
* It never overwrites a path the user pointed at that actually runs: an
* existing, executable file is left alone even when it is not the bundled one.
*/
fun walletBinHealPath(
storedBin: String?,
resolvedBin: String?,
executable: (String) -> Boolean = ::isExecutableWalletBin,
): String? {
val resolved = resolvedBin?.takeIf { it.isNotBlank() } ?: return null
val stored = storedBin?.trim().orEmpty()
if (stored.isNotEmpty() && executable(stored)) return null
return resolved
}
/**
* Why the **stored** `ChainConfig.walletRpcBin` will not produce a child, or
* `null` when it will. [startBlockedReason] only ever sees the *resolved*
* binaries, so a stale path saved by an older install passed that gate and
* then failed inside `spawn`.
*
* The reason always names the path it is about, so the next failure report
* carries its own cause instead of the opaque `spawn monero-wallet-rpc: No such
* file or directory`. A store that holds no path at all is named as such —
* "stored bin missing" is a distinct condition from "this build ships none".
*/
fun storedWalletBinBlockedReason(
storedBin: String?,
resolvedBin: String?,
executable: (String) -> Boolean = ::isExecutableWalletBin,
): String? {
if (resolvedBin.isNullOrBlank()) return NO_WALLET_RPC_MESSAGE
val stored = storedBin?.trim().orEmpty()
if (stored.isEmpty()) {
return "No wallet binary path is stored for this chain source, so there is nothing to " +
"spawn. This build ships $resolvedBin — pick a chain source to store it."
}
if (executable(stored)) return null
return "The stored wallet binary cannot be run on this device: $stored. " +
"This build ships $resolvedBin."
}
/**
* The full **Start** gate: the eligibility rules above plus the stored binary.
*
* [startBlockedReason] runs first so its established copy and ordering (no
* binary in this build, start in flight, no chain source) is unchanged; the
* stored-path check is the new second half. Together they make a populated
* `bins` insufficient on its own — which was the hole that let a bare stored
* name through.
*/
fun startGateReason(
bins: WalletChildBinaryPaths,
input: WalletChildInput?,
storedWalletBin: String?,
onionDaemon: Boolean = false,
starting: Boolean = false,
executable: (String) -> Boolean = ::isExecutableWalletBin,
): String? =
startBlockedReason(bins, input, onionDaemon, starting)
?: storedWalletBinBlockedReason(storedWalletBin, bins.walletRpc, executable)
/**
* Why **Create wallet** / **Import wallet** cannot be offered yet, or `null`
* when they can.
*
* Both are RPC calls (`create_wallet` / `restore_deterministic_wallet`) against
* the running child. With no child the call cannot succeed, and the core's
* refusal is the desktop TUI's `wallet not configured — open F7 …` — a key that
* does not exist on a phone. Collecting a passphrase only to print that is the
* second dead end this screen must not offer.
*/
fun walletSetupBlockedReason(input: WalletChildInput?): String? =
when (walletChildPhase(input)) {
WalletChildPhase.Unread -> READING_CHILD_NOTICE
WalletChildPhase.Off -> WALLET_SETUP_NEEDS_CHILD
WalletChildPhase.Connecting -> WALLET_SETUP_STARTING
is WalletChildPhase.Exited, is WalletChildPhase.Unrecognised -> WALLET_SETUP_NEEDS_CHILD
WalletChildPhase.Syncing, WalletChildPhase.Ready -> null
}
/** Shown on the disabled Create / Import controls when no wallet process is up. */
const val WALLET_SETUP_NEEDS_CHILD: String =
"Create and Import need the wallet process running. Start it on the node card first."
/** Shown while the child is up but its RPC has not answered yet. */
const val WALLET_SETUP_STARTING: String =
"The wallet is still starting. Wait until it answers, then create or import."
/** Tone of the one failure banner a card may paint. */
enum class WalletFailureTone {
/** Information about a state the app is in, not a failed call. */
Info,
/** A call actually failed. */
Error,
}
/**
* The banner a card should paint for a display-ready failure string, or `null`
* when it should paint none.
*
* [WALLET_NOT_OPEN_TEXT] is documented as a *state*, not a failure — a running
* child with no wallet file open answers every read with the daemon's `-13`,
* and that is exactly what first-run looks like. It nevertheless reached the
* node card's red `Wallet error` banner, duplicating the `No wallet open` info
* banner directly above it. This decision is keyed on the *mapped* text only:
* the mapping in [walletFailureText] is untouched, so nothing raw becomes
* visible, and only the paint changes.
*
* - [walletOpen] true: the state has ended, so a stale no-wallet sentence is
* dropped entirely.
* - [openHintVisible] true: the info banner above already says it — one
* sentence, once.
* - otherwise the sentence is still information, so it is painted as
* [WalletFailureTone.Info] rather than red.
*/
fun walletFailureBanner(
text: String?,
openHintVisible: Boolean,
walletOpen: Boolean,
): WalletFailureBanner? {
val shown = text?.takeIf { it.isNotBlank() } ?: return null
return if (shown == WALLET_NOT_OPEN_TEXT) {
when {
walletOpen -> null
openHintVisible -> null
else -> WalletFailureBanner(shown, WalletFailureTone.Info, "No wallet open")
}
} else {
WalletFailureBanner(shown, WalletFailureTone.Error, "Wallet error")
}
}
/** One banner: its sentence, its tone, and its title. */
data class WalletFailureBanner(
val text: String,
val tone: WalletFailureTone,
val title: String,
)
/**
* Why **Stop** is not actionable, or `null` when it is. `stop_wallet_child` is
* idempotent in the core, so this is only about not offering a no-op button.

View file

@ -176,6 +176,31 @@ const val WALLET_DAEMON_REFUSED_TEXT: String =
"The wallet daemon refused that request and gave no readable reason. Check the wallet " +
"on the wallet screen, then try again."
/**
* The desktop TUI's refusal, in the phone's words.
*
* `src/wallet.rs::NOT_CONFIGURED_MSG` is written for the Linux TUI: "wallet not
* configured — open F7 to set it up, or set ONIONWIRE_WALLET_RPC". Neither `F7`
* nor an environment variable exists on the phone, and the actual condition is
* simply that no wallet child is running. Printing that string was the second
* dead end on the device: a user who typed a passphrase into Create got told to
* press a key that is not on the device.
*/
const val WALLET_RPC_NOT_RUNNING_TEXT: String =
"The wallet process is not running, so there is nothing to open a wallet on. " +
"Start it on the node card, then create or import."
/**
* The TUI's unconfigured copy, and nothing else: the F7 hint, the phrase
* "wallet not configured", or an instruction to set `ONIONWIRE_WALLET_RPC`.
* All three describe the same fact — no wallet RPC to dial — and none of them
* is actionable on a phone.
*/
private val TUI_WALLET_NOT_CONFIGURED = Regex(
"""open\s*f7|wallet not configured|ONIONWIRE_WALLET_RPC""",
RegexOption.IGNORE_CASE,
)
/**
* A failure string safe to put on screen, or `null` when there is nothing to
* show.
@ -201,6 +226,9 @@ internal fun walletFailureText(raw: String?): String? {
val text = raw?.trim().orEmpty()
return when {
text.isEmpty() -> null
// Before the JSON / -13 filters: the TUI's refusal is a plain sentence
// the raw pass-through would otherwise let reach the phone verbatim.
TUI_WALLET_NOT_CONFIGURED.containsMatchIn(text) -> WALLET_RPC_NOT_RUNNING_TEXT
NO_WALLET_FILE.containsMatchIn(text) || RAW_RPC_CODE.containsMatchIn(text) ->
WALLET_NOT_OPEN_TEXT
RAW_JSON.containsMatchIn(text) -> WALLET_DAEMON_REFUSED_TEXT

View file

@ -169,6 +169,11 @@ fun WalletScreen(
LaunchedEffect(Unit) {
reload()
vm.refreshChainSource()
// Self-heal before the gate is asked: a stored `wallet_rpc_bin` left by
// an older install can point at a path this device cannot execute, and
// the bundled binary is the right answer for it. The gate below then
// names the path only when no repair was possible.
vm.healStoredWalletBin(bins)
}
// The same reads again, once the wallet has actually answered. They are
@ -262,22 +267,33 @@ fun WalletScreen(
// about a seed they do not have.
val walletReadable = balance != null && balance != "off" && balance != "err"
val walletOpen = child?.walletOpen == true
// A sticky failure captured while no wallet was open is not a
// failure once one is: drop it, so the red line does not outlive
// the state that produced it.
LaunchedEffect(walletOpen) {
if (walletOpen) vm.clearWalletChildError()
}
val unbacked = SeedBackupGate.warningVisible(seedConfirmed, walletReadable)
if (unbacked) {
UnbackedSeedCard(error = error, onBackUpSeed = { openSeedBackup() })
}
val phase = walletChildPhase(childInput)
// Create and Import are RPC calls against the running child. With no
// child up they can only fail, and the failure is the TUI's `open F7`
// copy — so the controls stay dead and say why instead.
val setupBlocked = walletSetupBlockedReason(childInput)
WalletHeroCard(
balance = balance,
address = address,
walletOpen = walletOpen,
phase = phase,
showQr = showQr,
setupBlocked = setupBlocked,
onToggleQr = { showQr = !showQr },
onOpenWallets = onOpenWallets,
onCreate = { setup = SetupKind.Create },
onImport = { setup = SetupKind.Import },
onCreate = { if (setupBlocked == null) setup = SetupKind.Create },
onImport = { if (setupBlocked == null) setup = SetupKind.Import },
onInvoice = { composer = PayKind.Invoice },
onTip = { composer = PayKind.Tip },
onBackUpSeed = if (
@ -336,9 +352,12 @@ fun WalletScreen(
.onFailure { daemonError = walletFailureText(it.message ?: it.toString()) }
.onSuccess {
// Selecting a mode stores it and, when the
// storage floor would allow Start, starts the
// node: a mode button that only rewrites a
// storage line reads as a no-op.
// storage floor *and* the Start gate would allow
// a launch, starts the node. The stored binary is
// what the just-saved config holds; the gate
// asks it the same question Start does, so a
// mode tap can never launch a child Start would
// have refused.
if (shouldStartAfterSelectingChain(
chainStorageBlockedReason(
vm.chainFreeBytes(),
@ -346,6 +365,10 @@ fun WalletScreen(
prune = prune,
),
starting = starting,
startBlocked = storedWalletBinBlockedReason(
bins.walletRpc,
bins.walletRpc,
),
)
) {
vm.startWalletChild()
@ -442,6 +465,12 @@ private fun WalletHeroCard(
walletOpen: Boolean,
phase: WalletChildPhase,
showQr: Boolean,
/**
* Why Create / Import cannot be offered yet, or `null` when they can. From
* [walletSetupBlockedReason]: both flows are RPC calls against a running
* wallet child, so a stopped child is a dead end the screen may not offer.
*/
setupBlocked: String?,
onToggleQr: () -> Unit,
onOpenWallets: () -> Unit,
onCreate: () -> Unit,
@ -502,16 +531,30 @@ private fun WalletHeroCard(
OwButton(
text = "Create Wallet",
variant = OwButtonVariant.Primary,
enabled = setupBlocked == null,
onClick = onCreate,
modifier = Modifier.weight(1f).testTag("wallet-create"),
)
OwButton(
text = "Import Wallet",
variant = OwButtonVariant.Secondary,
enabled = setupBlocked == null,
onClick = onImport,
modifier = Modifier.weight(1f).testTag("wallet-import"),
)
}
// Why the two flows are dead, in a sentence rather than a grey pair
// of buttons. The only fix is on the node card below, so the copy
// points there.
setupBlocked?.let {
Spacer(Modifier.height(8.dp))
OwAlertBanner(
variant = OwAlertVariant.Info,
title = "Wallet not running",
description = it,
modifier = Modifier.testTag("wallet-setup-blocked"),
)
}
// Invoicing does not need a wallet file: the core resolves the payee
// address from the profile (`no receive address — set profile xmr or
// ONIONWIRE_WALLET_RPC` is the both-missing case). Hiding the action
@ -614,16 +657,27 @@ private fun WalletHeroCard(
OwButton(
text = "New wallet",
variant = OwButtonVariant.Outline,
enabled = setupBlocked == null,
onClick = onCreate,
modifier = Modifier.weight(1f).testTag("wallet-create"),
)
OwButton(
text = "Import wallet",
variant = OwButtonVariant.Outline,
enabled = setupBlocked == null,
onClick = onImport,
modifier = Modifier.weight(1f).testTag("wallet-import"),
)
}
setupBlocked?.let {
Spacer(Modifier.height(8.dp))
OwAlertBanner(
variant = OwAlertVariant.Info,
title = "Wallet not running",
description = it,
modifier = Modifier.testTag("wallet-setup-blocked"),
)
}
// The recovery path for a wallet whose seed was missed: a quiet action,
// because a healthy wallet needs it rarely and a seed is a spend key.
// While the seed is unconfirmed the strip above carries the button
@ -690,7 +744,10 @@ private fun NodeCard(
val progress = syncProgress(input?.height ?: 0uL, input?.targetHeight ?: 0uL)
val node = nodePhase(input)
val onionDaemon = chain?.kind == ChainChoice.REMOTE && isOnionHost(chain.host)
val startWhy = startBlockedReason(bins, input, onionDaemon, starting)
// The full gate: eligibility *and* the stored binary this build will
// actually spawn. A populated `bins` alone used to pass, which is how a
// stored bare name got as far as `spawn` and failed with ENOENT.
val startWhy = startGateReason(bins, input, chain?.walletRpcBin, onionDaemon, starting)
?: if (inProcess) {
chainStorageBlockedReason(
nodeFreeBytes,
@ -976,15 +1033,28 @@ private fun NodeCard(
// acts, like the chat screen's load error. Filtered through
// `walletFailureText`: the daemon's own `-13 No wallet file` / JSON
// answer is not a sentence about this app and never reaches the screen.
//
// "No wallet open" is a state, not a failure: the info banner above
// already owns it, so it is not painted red and not printed twice.
val failure = walletFailureText(input?.lastError) ?: actionError ?: daemonError
failure?.let {
Spacer(Modifier.height(8.dp))
OwAlertBanner(
variant = OwAlertVariant.Error,
title = "Wallet error",
description = it,
modifier = Modifier.testTag("wallet-child-error"),
)
walletFailureBanner(
text = it,
openHintVisible = openHint != null,
walletOpen = walletOpen,
)?.let { banner ->
Spacer(Modifier.height(8.dp))
OwAlertBanner(
variant = if (banner.tone == WalletFailureTone.Info) {
OwAlertVariant.Info
} else {
OwAlertVariant.Error
},
title = banner.title,
description = banner.text,
modifier = Modifier.testTag("wallet-child-error"),
)
}
}
}
}

View file

@ -621,4 +621,140 @@ class WalletChildStatusTextTest {
nodeStatusHead(input("syncing", running = true, chainSource = "remote daemon")).title,
)
}
// --- the stored wallet binary: heal before spawn, then gate on it -------
private val hostsBundled = "/data/app/~~abc/onionwire-1/lib/arm64/libmonerowalletrpc.so"
@Test
fun a_stored_bare_name_is_repaired_to_the_bundled_absolute_path() {
// A record written by an older install: a bare name nothing in an APK
// sandbox resolves on PATH. The repair is the absolute path this
// install actually carries.
assertEquals(hostsBundled, walletBinHealPath("monero-wallet-rpc", hostsBundled) { false })
assertEquals("an empty stored bin is healed too", hostsBundled, walletBinHealPath("", hostsBundled) { false })
assertEquals("and a missing field", hostsBundled, walletBinHealPath(null, hostsBundled) { false })
}
@Test
fun a_stored_path_that_actually_runs_is_never_overwritten() {
val userBin = "/data/user/0/com.siriusdevops.onionwire/files/monero-wallet-rpc"
assertNull(
"a real executable file the user pointed at is left alone",
walletBinHealPath(userBin, hostsBundled) { it == userBin },
)
assertNull(
"a bundled path already stored needs no write",
walletBinHealPath(hostsBundled, hostsBundled) { it == hostsBundled },
)
}
@Test
fun no_bundled_binary_means_there_is_nothing_to_repair_with() {
assertNull(walletBinHealPath("monero-wallet-rpc", null) { false })
assertNull(walletBinHealPath("monero-wallet-rpc", " ") { false })
}
@Test
fun a_stored_bin_missing_on_the_device_blocks_start_and_names_the_path() {
val why = startGateReason(bundled, input("off"), "monero-wallet-rpc") { false }
assertNotNull("a stored path that cannot run must block Start", why)
assertTrue("the reason names the stored path it is about", why!!.contains("monero-wallet-rpc"))
assertTrue("and the path this build does carry", why.contains(bundled.walletRpc!!))
assertTrue("and says it cannot run", why.contains("cannot be run"))
assertFalse(
"a gate that refuses never lets a mode tap auto-start",
shouldStartAfterSelectingChain(storageBlocked = null, starting = false, startBlocked = why),
)
}
@Test
fun an_absent_resolved_bin_blocks_with_the_resolved_absence_message() {
// Nothing in this build to spawn: the established string, unchanged.
val why = startGateReason(noBinary, input("off"), "/stale/libmonerowalletrpc.so") { false }
assertEquals(NO_WALLET_RPC_MESSAGE, why)
assertFalse(shouldStartAfterSelectingChain(null, false, why))
}
@Test
fun a_runnable_stored_bin_passes_the_gate() {
assertNull(startGateReason(bundled, input("off"), bundled.walletRpc) { it == bundled.walletRpc })
assertNull(storedWalletBinBlockedReason(bundled.walletRpc, bundled.walletRpc) { true })
}
@Test
fun the_gate_keeps_the_established_start_ordering() {
// Reading the status still wins over a stored-path complaint: the
// existing copy and its order were not rewritten to make room.
assertEquals(READING_CHILD_NOTICE, startGateReason(bundled, null, null) { false })
assertEquals(
NO_CHAIN_SOURCE_NOTICE,
startGateReason(bundled, input("off", configured = false, chainSource = "receive-only"), null) { false },
)
}
@Test
fun a_mode_tap_stores_the_source_but_cannot_auto_start_what_the_gate_refuses() {
assertTrue(shouldStartAfterSelectingChain(storageBlocked = null, starting = false))
assertTrue(
shouldStartAfterSelectingChain(storageBlocked = null, starting = false, startBlocked = null),
)
assertFalse(
shouldStartAfterSelectingChain(
storageBlocked = null,
starting = false,
startBlocked = "The stored wallet binary cannot be run on this device: …",
),
)
}
@Test
fun create_and_import_are_blocked_without_a_running_child() {
assertEquals(WALLET_SETUP_NEEDS_CHILD, walletSetupBlockedReason(input("off")))
assertEquals(WALLET_SETUP_NEEDS_CHILD, walletSetupBlockedReason(input("exited", lastError = "spawn …")))
assertEquals(WALLET_SETUP_NEEDS_CHILD, walletSetupBlockedReason(input("mining")))
assertEquals(WALLET_SETUP_STARTING, walletSetupBlockedReason(input("connecting", running = true)))
assertEquals(READING_CHILD_NOTICE, walletSetupBlockedReason(null))
assertNull(
"a syncing wallet answers RPC, so a create is fine",
walletSetupBlockedReason(input("syncing", running = true)),
)
assertNull(walletSetupBlockedReason(input("ready", running = true)))
}
// --- the no-wallet-open state is information, not a failure ------------
@Test
fun the_no_wallet_open_state_is_information_never_the_red_failure() {
// The `No wallet open` info banner owns this sentence; printing it a
// second time in red is the duplicate the device report caught.
assertNull(
"already said once by the info banner above",
walletFailureBanner(WALLET_NOT_OPEN_TEXT, openHintVisible = true, walletOpen = false),
)
val alone = walletFailureBanner(WALLET_NOT_OPEN_TEXT, openHintVisible = false, walletOpen = false)
assertNotNull(alone)
assertEquals(WalletFailureTone.Info, alone!!.tone)
assertEquals("No wallet open", alone.title)
assertEquals(WALLET_NOT_OPEN_TEXT, alone.text)
assertNull(
"the state ended when a wallet was opened",
walletFailureBanner(WALLET_NOT_OPEN_TEXT, openHintVisible = false, walletOpen = true),
)
}
@Test
fun a_real_failure_still_paints_red() {
val refused = walletFailureText("wallet connect: Connection refused (os error 111)")!!
val banner = walletFailureBanner(refused, openHintVisible = true, walletOpen = false)!!
assertEquals("a refusal is still a failure", WalletFailureTone.Error, banner.tone)
assertEquals("Wallet error", banner.title)
assertEquals(refused, banner.text)
val exited = walletFailureText("spawn monero-wallet-rpc: No such file or directory (os error 2)")!!
assertEquals(WalletFailureTone.Error, walletFailureBanner(exited, false, false)!!.tone)
assertNull(walletFailureBanner(null, true, false))
assertNull(walletFailureBanner(" ", true, false))
}
}

View file

@ -477,4 +477,27 @@ class WalletManagerTest {
assertTrue(shouldReloadWalletReads("ready"))
assertTrue(shouldReloadWalletReads(" Ready "))
}
@Test
fun the_tui_not_configured_copy_is_mapped_and_never_rendered_verbatim() {
// `src/wallet.rs::NOT_CONFIGURED_MSG` is the desktop TUI's refusal. A
// phone has no F7 key and no ONIONWIRE_WALLET_RPC, so that sentence is
// the second dead end the device report caught: a passphrase was typed
// into Create, and the screen answered with a keyboard shortcut.
val tui = "wallet not configured — open F7 to set it up, or set ONIONWIRE_WALLET_RPC"
val shown = walletFailureText(tui)
assertEquals(WALLET_RPC_NOT_RUNNING_TEXT, shown)
assertFalse("no F7 reaches the screen", shown!!.contains("F7"))
assertFalse("no env var name either", shown.contains("ONIONWIRE_WALLET_RPC"))
assertTrue("the phone sentence says what to do", shown.contains("Start it on the node card"))
// Each fragment alone is the same fact and is mapped too; case and
// spacing are not load-bearing.
assertEquals(WALLET_RPC_NOT_RUNNING_TEXT, walletFailureText("Open F7"))
assertEquals(WALLET_RPC_NOT_RUNNING_TEXT, walletFailureText("Wallet Not Configured"))
assertEquals(WALLET_RPC_NOT_RUNNING_TEXT, walletFailureText("set ONIONWIRE_WALLET_RPC"))
// And it is idempotent: the sticky error card re-filters its own text.
assertEquals(WALLET_RPC_NOT_RUNNING_TEXT, walletFailureText(shown))
}
}