android: build the SDK with cuprate-daemon and offer the on-device node

Part 3 of "cuprated built in": the chain daemon now ships inside the APK and the
wallet screen can pick it.

Build (android/sdk/build.gradle.kts)
- `cargoBuildAndroid` runs `cargo ndk … build --release --lib --features
  cuprate-daemon`. The Android target only: `cargoHostLib` / `uniffiBindgen` stay
  feature-free, because the host cdylib exists only so `uniffi-bindgen --library`
  can dlopen it and the UniFFI surface does not fork on a cargo feature.
- The link needs the NDK's libc++ and compiler-rt builtins explicitly (RandomX is
  C++ and its aarch64 JIT calls `__clear_cache`; `randomx-rs` links the NDK's stub
  `libstdc++.a`). `cargo ndk --link-builtins` covers the builtins only, so the
  whole set is spelled out as per-ABI `CARGO_TARGET_<TRIPLE>_RUSTFLAGS` — a global
  `RUSTFLAGS` would break the host build scripts. The linker is the NDK clang
  driver at the app's API level, named explicitly, because the dev machines pin
  the API 21 wrapper for `aarch64-linux-android` and API 21 fails this link.
- `ANDROID_NDK` is exported alongside `ANDROID_NDK_HOME`/`NDK_HOME`: without it
  `cmake-rs` aborts and `randomx-rs`'s build script panics.
- The task logs the feature it builds with, so CI carries the request, not just
  the task name.

Wallet screen
- Third chain source, **On-device node (Cuprate)**, beside the daemon field and
  Receive-only. Stored as `ChainChoice.InProcessCuprate` with an empty
  `monerod_datadir`, which the SDK resolves to `$ONIONWIRE_HOME/chain`. Existing
  Save daemon / Receive-only / Start / Stop behaviour is unchanged.
- The status line grows `· node <word>` from `WalletChildStatus.node_state` for
  this source only, fail-closed on an unrecognised word. No sync height: the SDK
  exposes none, so the screen does not show a number it cannot get.
- Storage honesty: free space on the chain store's filesystem, and Start is
  refused below a 3 GiB floor or when that filesystem cannot be read. The floor is
  a floor, not a sync estimate — nothing here exposes one.
- The pre-production warning (quoted user book, testnet only, Cuprate issue #278)
  is a sentence above Start, assertable in a test. Opt-in, never a default.
- The daemon field's hint no longer suggests a loopback daemon on the phone.

CI
- `android-ci.yml` extracts `lib/<abi>/libonionwire_sdk.so` from the built APK and
  fails the job unless it contains `target_max_memory`, a rodata literal compiled
  only under `cuprate-daemon`. v0.7.0's shipped `.so` has zero of them, so this
  separates "in the artifact" from "requested".

Docs
- `android/CUPRATE_DAEMON.md`: the build wiring, the link line, the CI gate, and
  an explicit "not verified on a device" section. `MONERO_BINARIES.md` points at
  it for the chain source that is not a binary.
This commit is contained in:
sirius 2026-09-18 15:34:30 -04:00 • committed by agent
commit e6b6bc8dd6
No known key found for this signature in database
9 changed files with 807 additions and 11 deletions

View file

@ -11,6 +11,7 @@ import com.siriusdevops.onionwire.crypto.StoredPassphraseStore
import com.siriusdevops.onionwire.keepalive.KeepAliveService
import com.siriusdevops.onionwire.keepalive.KeepAliveStatus
import com.siriusdevops.onionwire.keepalive.NodeHost
import com.siriusdevops.onionwire.wallet.ChainStorage
import com.siriusdevops.onionwire.wallet.NO_WALLET_RPC_MESSAGE
import com.siriusdevops.onionwire.wallet.WalletChildBinaries
import com.siriusdevops.onionwire.wallet.WalletChildBinaryPaths
@ -722,6 +723,48 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
refreshWalletChild()
}
/**
* The third chain source: the chain daemon **inside this app** (Cuprate), no
* `monerod` binary and no remote operator. Stores the setting; [startWalletChild]
* is what launches the node *and* the wallet child (one call in the core).
*
* `monerodDatadir` is left empty on purpose: the SDK resolves that to
* `$ONIONWIRE_HOME/chain`, the same per-identity directory a spawned `monerod`
* would use, so Kotlin never invents an absolute path. `monero-wallet-rpc` is
* still required — Cuprate has no wallet layer, so the subprocess stays, and the
* core rejects a config without it.
*/
suspend fun setInProcessCuprate(bins: WalletChildBinaryPaths): Result<Unit> =
withContext(Dispatchers.IO) {
runCatching {
requireWire().setChainSource(
ChainConfig(
kind = ChainChoice.IN_PROCESS_CUPRATE,
monerodBin = "",
monerodDatadir = "",
host = "",
port = 0u,
walletRpcBin = bins.walletRpc.orEmpty(),
// Inert for this source: an in-process node is loopback
// clearnet, so the core never spawns the SOCKS child.
artiBin = expectedArtiPath(),
walletFilename = WalletChildBinaries.WALLET_FILENAME,
),
)
}
}.onSuccess {
_walletChildError.value = null
refreshChainSource()
refreshWalletChild()
}
/**
* Free bytes on the filesystem the in-process chain store grows into, or
* `null` when it cannot be read. The screen shows this before the user commits
* to a store on the device; it is a measurement, not an estimate.
*/
fun chainFreeBytes(): Long? = ChainStorage.freeBytes(home)
/**
* Spawns the child (and its daemon/SOCKS siblings) and returns what the core
* reached.

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.util.Locale
/**
* One snapshot of the app-owned wallet child, as the wallet screen sees it.
@ -25,6 +26,25 @@ data class WalletChildInput(
val configured: Boolean,
/** The core's label: `receive-only` / `local node` / `remote onion daemon` / `remote daemon`. */
val chainSource: String,
/**
* The configured source runs the chain daemon **inside this app** (Cuprate)
* rather than spawning `monerod` or dialling a remote one — the core's
* `chain_in_process`. When true the line grows a node segment, because there
* is no separate daemon process for the state word to describe.
*/
val chainInProcess: Boolean = false,
/**
* This build carries `cuprate-daemon`, so the in-process node can actually
* start — the core's `node_available`. `false` means the option is stored but
* a start can only fail: say so before the user commits, never after.
*/
val nodeAvailable: Boolean = true,
/**
* The node's own word — the core's `node_state`: `off` / `starting` /
* `syncing` / `ready` / `exited`. **Empty** for every other chain source, and
* empty for an in-process source that has not been read yet.
*/
val nodeState: String = "",
val lastError: String? = null,
)
@ -133,6 +153,98 @@ sealed interface WalletChildPhase {
/** Cells of an unrecognised state word kept on the status line. */
const val UNRECOGNISED_BUDGET: Int = 16
/**
* The in-process node's own word, for the chain sources that have one.
*
* Same fail-closed rule as [WalletChildPhase]: an unrecognised word is never
* [Ready]. [Absent] is not a node state at all — it is "this chain source has no
* node segment on the line", which is true of receive-only, a spawned `monerod`
* and a remote daemon, and also of an in-process source the core has not reported
* a node word for yet. Nothing is inferred to fill it in.
*/
sealed interface NodePhase {
/** Stable handle for Compose semantics and tests. */
val testTag: String
/** Word drawn after `node`, or empty for [Absent]. */
val label: String
/** What a screen reader announces. Always a sentence. */
val contentDescription: String
/** No node segment: not an in-process chain source. */
data object Absent : NodePhase {
override val testTag: String = "node-absent"
override val label: String = ""
override val contentDescription: String = "No on-device node"
}
/** The app's own node is not running. */
data object Off : NodePhase {
override val testTag: String = "node-off"
override val label: String = "off"
override val contentDescription: String = "The on-device node is off"
}
/** The node is up; its loopback RPC has not answered yet. */
data object Starting : NodePhase {
override val testTag: String = "node-starting"
override val label: String = "starting"
override val contentDescription: String =
"The on-device node is starting; its RPC has not answered yet"
}
/** The node answers; its chain is not at the tip. */
data object Syncing : NodePhase {
override val testTag: String = "node-syncing"
override val label: String = "syncing"
override val contentDescription: String =
"The on-device node is syncing; the chain is not at the tip yet"
}
/** The node answers and its chain is at the tip. */
data object Ready : NodePhase {
override val testTag: String = "node-ready"
override val label: String = "ready"
override val contentDescription: String = "The on-device node is ready"
}
/** A started node is gone. */
data object Exited : NodePhase {
override val testTag: String = "node-exited"
override val label: String = "exited"
override val contentDescription: String = "The on-device node exited"
}
/** A node word this build does not know. Fail-closed: never [Ready]. */
data class Unrecognised(val raw: String) : NodePhase {
override val testTag: String = "node-unrecognised"
override val label: String = "unknown (${shortSendReason(raw, UNRECOGNISED_BUDGET)})"
override val contentDescription: String =
"The on-device node reported a state this build does not know"
}
}
/**
* Maps the core's `node_state` onto a [NodePhase].
*
* [NodePhase.Absent] for a source that has no node (or no word yet); anything the
* five words do not cover is [NodePhase.Unrecognised] — never [NodePhase.Ready].
*/
fun nodePhase(input: WalletChildInput?): NodePhase {
if (input == null || !input.chainInProcess) return NodePhase.Absent
return when (val state = input.nodeState.trim().lowercase()) {
"" -> NodePhase.Absent
"off" -> NodePhase.Off
"starting" -> NodePhase.Starting
"syncing" -> NodePhase.Syncing
"ready" -> NodePhase.Ready
"exited" -> NodePhase.Exited
else -> NodePhase.Unrecognised(state)
}
}
/**
* Maps the core's `state` word onto a [WalletChildPhase]. Case- and
* whitespace-tolerant; anything else is [WalletChildPhase.Unrecognised].
@ -161,11 +273,18 @@ fun walletChildPhase(input: WalletChildInput?): WalletChildPhase {
fun walletChildLine(input: WalletChildInput?): String {
val phase = walletChildPhase(input)
val source = input?.chainSource?.takeIf { it.isNotBlank() } ?: "no chain source"
val node = nodePhase(input)
val why = input?.lastError?.takeIf { it.isNotBlank() }
return buildString {
append(phase.label)
append(" · ")
append(source)
// Only an in-process source has a node of its own to name. The node word
// is the core's, rendered as-is — there is no second state machine here.
if (node !is NodePhase.Absent) {
append(" · node ")
append(node.label)
}
when {
why != null -> append(" — ").append(shortSendReason(why))
phase is WalletChildPhase.Exited -> append(" — the child process is gone")
@ -184,6 +303,80 @@ const val ONION_NEEDS_ARTI_NOTICE: String =
/** Shown while the first `wallet_status()` read is still in flight. */
const val READING_CHILD_NOTICE: String = "Reading the wallet child status…"
/**
* The caveat the on-device node is offered with, **before** Start.
*
* Cuprate's own user book says *"do NOT use cuprated for any serious purposes"*,
* its `monerod` RPC parity is incomplete (Cuprate issue #278, and the four gaps
* measured in this repo are in `docs/cuprate-launch-spike.md`), and the daemon
* this app launches is pinned to **testnet** (`src/cuprate.rs`). One sentence, not
* a glyph: the choice is opt-in and never a default, and a user who reads only
* this line still knows what they picked.
*/
const val CUPRATE_PREPRODUCTION_WARNING: String =
"On-device node is Cuprate, which is pre-production: its own user book says do NOT use " +
"cuprated for any serious purposes, it runs testnet only here (mainnet is unvalidated), " +
"and its monerod RPC parity is incomplete (Cuprate issue #278). Try the in-process " +
"path; do not hold funds on it."
/**
* This build was compiled without the `cuprate-daemon` feature, so the stored
* on-device chain source can be read back but can never start. Mirrors the core's
* own refusal (`onionwire::cuprate::NO_FEATURE_MSG`) rather than inventing a
* second wording for the same fact.
*/
const val CUPRATE_NOT_IN_BUILD_NOTICE: String =
"This build has no in-process chain daemon, so the on-device node cannot start."
/**
* Free space the chain store's filesystem must have before the on-device node is
* started.
*
* A **floor**, not a sync estimate, and deliberately so: nothing in this stack
* exposes one. `WalletChildStatus` carries no size field, and Cuprate's own
* restricted RPC reports a hardcoded 5 GiB `database_size` placeholder (see
* `src/cuprate.rs`), so a number taken from the node would be fiction. What can be
* measured honestly is the free space on the filesystem the fjall store grows
* into, and the device can be told when that is not enough.
*/
const val CHAIN_FREE_SPACE_FLOOR_BYTES: Long = 3L * 1024 * 1024 * 1024
/**
* What the chain store costs, in the user's terms: the free space this device
* actually has, and what the node does *not* tell us.
*/
fun chainStorageLine(freeBytes: Long?): String = when {
freeBytes == null ->
"chain store: free space on this device could not be read."
else ->
"chain store: ${formatBytes(freeBytes)} free on this device — a synced testnet store " +
"grows into it. The node reports no size estimate of its own."
}
/**
* Why the on-device node must not be started on this device, or `null` when it
* may. Fail-closed on an unreadable filesystem: an unknown free space is not
* reported as enough.
*/
fun chainStorageBlockedReason(freeBytes: Long?): String? = when {
freeBytes == null ->
"Free space on the chain store's filesystem could not be read, so it is not known to fit."
freeBytes < CHAIN_FREE_SPACE_FLOOR_BYTES ->
"Not enough space for the chain store: ${formatBytes(freeBytes)} free, and the " +
"on-device node needs at least ${formatBytes(CHAIN_FREE_SPACE_FLOOR_BYTES)}."
else -> null
}
/**
* Bytes as a screen-sized string. Binary units (a "GB" that is really a GiB is how
* a store that needs 3 GiB ends up on a device with 2.8).
*/
fun formatBytes(bytes: Long): String = when {
bytes >= 1L shl 30 -> String.format(Locale.US, "%.1f GiB", bytes.toDouble() / (1L shl 30))
bytes >= 1L shl 20 -> String.format(Locale.US, "%.0f MiB", bytes.toDouble() / (1L shl 20))
else -> "$bytes B"
}
/**
* Why **Start** is not actionable, or `null` when it is.
*
@ -200,6 +393,9 @@ fun startBlockedReason(
input == null -> READING_CHILD_NOTICE
input.running -> "The wallet child is already running."
!input.configured -> "No chain source yet: a wallet child needs a daemon to dial."
// 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
onionDaemon && bins.arti == null -> ONION_NEEDS_ARTI_NOTICE
else -> null
}

View file

@ -80,6 +80,10 @@ fun WalletScreen(
// the life of the process.
val bins = remember { vm.bundledBinaries() }
val childInput = child?.toInput()
// Free space on the filesystem the in-process chain store grows into. Read
// once per composition of the screen: it is the same filesystem for the life
// of the process, and the number is only a commit-time gate.
val nodeFreeBytes = remember { vm.chainFreeBytes() }
var showQr by remember { mutableStateOf(false) }
var balance by remember { mutableStateOf<String?>(null) }
var address by remember { mutableStateOf<String?>(null) }
@ -221,6 +225,7 @@ fun WalletScreen(
bins = bins,
input = childInput,
chain = chain,
nodeFreeBytes = nodeFreeBytes,
actionError = childError,
daemonText = daemonText,
daemonError = daemonError,
@ -247,6 +252,13 @@ fun WalletScreen(
.onFailure { daemonError = it.message ?: it.toString() }
}
},
onInProcessNode = {
daemonError = null
scope.launch {
vm.setInProcessCuprate(bins)
.onFailure { daemonError = it.message ?: it.toString() }
}
},
onStart = { scope.launch { vm.startWalletChild() } },
onStop = { scope.launch { vm.stopWalletChild() } },
)
@ -572,35 +584,50 @@ private fun WalletSetupCard(
}
/**
* The app-owned `monero-wallet-rpc` control (issue #107).
* The app-owned `monero-wallet-rpc` control (issue #107), now with the third chain
* source: the chain daemon **inside this app** (Cuprate).
*
* **Start** / **Stop** drive `Wire::start_wallet_child` / `stop_wallet_child`
* through [WireViewModel]; the status line is `Wire::wallet_status()` rendered
* verbatim, so a child that died reads `exited` and never `off`.
* verbatim, so a child that died reads `exited` and never `off`, and an in-process
* source grows a `node <word>` segment that is the core's own `node_state`.
*
* The card is deliberately talkative about what it *cannot* do: no bundled
* binary, no chain source, or a `.onion` daemon with no bundled `arti` SOCKS
* child each get their own sentence, because a Start button that can only fail
* is worse than no button. There is no "starting…" state to hide behind — the
* only spinner-free words on screen are the core's own.
* binary, no chain source, a `.onion` daemon with no bundled `arti` SOCKS child,
* or a build without `cuprate-daemon` each get their own sentence, because a Start
* button that can only fail is worse than no button. There is no "starting…" state
* to hide behind — the only spinner-free words on screen are the core's own.
*
* The on-device node is opt-in and carries its pre-production warning **above the
* Start button**, plus the free space on the filesystem its fjall store grows
* into. A device that cannot hold the chain is told before it commits, not left to
* fail at sync time.
*/
@Composable
private fun WalletChildCard(
bins: WalletChildBinaryPaths,
input: WalletChildInput?,
chain: ChainConfig?,
nodeFreeBytes: Long?,
actionError: String?,
daemonText: String,
daemonError: String?,
onDaemonText: (String) -> Unit,
onSaveDaemon: () -> Unit,
onReceiveOnly: () -> Unit,
onInProcessNode: () -> Unit,
onStart: () -> Unit,
onStop: () -> Unit,
) {
val phase = walletChildPhase(input)
val node = nodePhase(input)
val onionDaemon = chain?.kind == ChainChoice.REMOTE && isOnionHost(chain.host)
// The selection is in-process as soon as it is stored, before the first status
// read comes back: the warning and the storage line must not wait for the
// poller, or the user would press Start having seen neither.
val inProcess = input?.chainInProcess == true || chain?.kind == ChainChoice.IN_PROCESS_CUPRATE
val startWhy = startBlockedReason(bins, input, onionDaemon)
?: if (inProcess) chainStorageBlockedReason(nodeFreeBytes) else null
val stopWhy = stopBlockedReason(input)
Card(
@ -615,8 +642,9 @@ private fun WalletChildCard(
Text("wallet daemon", style = MaterialTheme.typography.titleSmall)
Spacer(Modifier.height(6.dp))
// The core's own words: `ready · remote onion daemon`. Tagged with
// the phase so a UI test can assert `exited` is never `off`.
// The core's own words: `ready · remote onion daemon`, plus
// `· node syncing` for the in-process source. Tagged with the phase so
// a UI test can assert `exited` is never `off`.
Text(
walletChildLine(input),
style = MaterialTheme.typography.bodySmall,
@ -629,6 +657,23 @@ private fun WalletChildCard(
},
)
// The node's own word, when there is one, as its own assertable line:
// an unrecognised node state can never be read as ready.
if (node !is NodePhase.Absent) {
Text(
"node: ${node.label}",
style = MaterialTheme.typography.labelSmall,
fontFamily = FontFamily.Monospace,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier
.fillMaxWidth()
.testTag(node.testTag)
.semantics(mergeDescendants = true) {
contentDescription = node.contentDescription
},
)
}
if (!bins.walletRpcBundled) {
Spacer(Modifier.height(6.dp))
Text(
@ -648,8 +693,9 @@ private fun WalletChildCard(
label = { Text("daemon host:port") },
supportingText = {
Text(
"e.g. 127.0.0.1:18089 for a local daemon you run yourself, " +
"or a node's clearnet address.",
"A daemon on your LAN (e.g. 192.168.1.20:18089) or a public node's " +
"clearnet address. A phone cannot run monerod — for a chain with no " +
"daemon at all, use the on-device node below.",
style = MaterialTheme.typography.labelSmall,
)
},
@ -677,6 +723,38 @@ private fun WalletChildCard(
) { Text("Receive-only") }
}
// The third chain source. Never a default: selecting it is what stores
// `ChainChoice.InProcessCuprate`, and the warning below is what the user
// reads before Start.
Spacer(Modifier.height(8.dp))
OutlinedButton(
onClick = onInProcessNode,
modifier = Modifier
.fillMaxWidth()
.testTag("wallet-chain-in-process"),
) { Text("On-device node (Cuprate)") }
if (inProcess) {
Spacer(Modifier.height(8.dp))
Text(
CUPRATE_PREPRODUCTION_WARNING,
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier
.fillMaxWidth()
.testTag("wallet-cuprate-warning"),
)
Spacer(Modifier.height(4.dp))
Text(
chainStorageLine(nodeFreeBytes),
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier
.fillMaxWidth()
.testTag("wallet-chain-storage"),
)
}
Spacer(Modifier.height(8.dp))
Row(
modifier = Modifier.fillMaxWidth(),
@ -738,6 +816,9 @@ internal fun WalletChildStatus.toInput(): WalletChildInput = WalletChildInput(
running = running,
configured = configured,
chainSource = chainSource,
chainInProcess = chainInProcess,
nodeAvailable = nodeAvailable,
nodeState = nodeState,
lastError = lastError,
)

View file

@ -0,0 +1,30 @@
package com.siriusdevops.onionwire.wallet
import android.os.StatFs
import java.io.File
/**
* Free space on the filesystem the in-process chain store grows into.
*
* The chain source this is for is Cuprate's fjall store under
* `$ONIONWIRE_HOME/chain` (`WireViewModel.home` is `filesDir/onionwire`), which is
* the same filesystem as `filesDir` — so `StatFs` on the app's own data directory
* answers the question the user is actually being asked: *will this fit here?*
*
* It is a **measurement, not an estimate**: nothing in the SDK exposes a chain
* size (`WalletChildStatus` has no size field, and Cuprate's restricted RPC
* reports a hardcoded 5 GiB placeholder — `src/cuprate.rs`). The floor the screen
* applies to this number is [com.siriusdevops.onionwire.ui.CHAIN_FREE_SPACE_FLOOR_BYTES],
* and it is documented there as a floor rather than a sync estimate.
*
* `null` means "could not be read", and the screen treats that as fail-closed: an
* unknown free space is not reported as enough. Kept out of the JVM unit tests on
* purpose — `StatFs` is an Android class, so the pure formatting and the gate live
* in `ui/WalletChildStatusText.kt` where they are covered without a device.
*/
object ChainStorage {
/** Free bytes on [path]'s filesystem, or `null` when it cannot be read. */
fun freeBytes(path: File): Long? = runCatching { StatFs(path.absolutePath).availableBytes }
.getOrNull()
}

View file

@ -26,12 +26,18 @@ class WalletChildStatusTextTest {
running: Boolean = false,
configured: Boolean = true,
chainSource: String = "remote daemon",
chainInProcess: Boolean = false,
nodeAvailable: Boolean = true,
nodeState: String = "",
lastError: String? = null,
) = WalletChildInput(
state = state,
running = running,
configured = configured,
chainSource = chainSource,
chainInProcess = chainInProcess,
nodeAvailable = nodeAvailable,
nodeState = nodeState,
lastError = lastError,
)
@ -240,4 +246,132 @@ class WalletChildStatusTextTest {
val parsed = parseDaemonAddress("127.0.0.1:18089")!!
assertEquals("127.0.0.1:18089", parsed.text)
}
// --- the on-device node (Cuprate) ---------------------------------------
private fun node(
state: String = "syncing",
chainSource: String = "in-process node",
nodeState: String,
nodeAvailable: Boolean = true,
running: Boolean = true,
) = input(
state = state,
running = running,
chainSource = chainSource,
chainInProcess = true,
nodeAvailable = nodeAvailable,
nodeState = nodeState,
)
@Test
fun each_core_node_state_maps_to_its_own_phase() {
assertTrue(nodePhase(node(nodeState = "off")) is NodePhase.Off)
assertTrue(nodePhase(node(nodeState = "starting")) is NodePhase.Starting)
assertTrue(nodePhase(node(nodeState = "syncing")) is NodePhase.Syncing)
assertTrue(nodePhase(node(nodeState = "ready")) is NodePhase.Ready)
assertTrue(nodePhase(node(nodeState = "exited")) is NodePhase.Exited)
}
@Test
fun only_an_in_process_source_has_a_node_segment() {
assertTrue(nodePhase(input("ready", running = true)) is NodePhase.Absent)
assertTrue(nodePhase(null) is NodePhase.Absent)
// In-process, but the core has not reported a node word yet: no segment,
// rather than an invented one.
assertTrue(nodePhase(node(nodeState = "")) is NodePhase.Absent)
}
@Test
fun an_unknown_node_state_is_never_ready() {
val phase = nodePhase(node(nodeState = "mining"))
assertTrue(phase is NodePhase.Unrecognised)
assertFalse("an unknown node word must not read as ready", phase is NodePhase.Ready)
assertTrue(phase.label.startsWith("unknown"))
}
@Test
fun the_line_grows_a_node_segment_for_the_in_process_source() {
assertEquals(
"syncing · in-process node · node syncing",
walletChildLine(node(state = "syncing", nodeState = "syncing")),
)
assertEquals(
"ready · in-process node · node ready",
walletChildLine(node(state = "ready", nodeState = "ready")),
)
}
@Test
fun the_line_has_no_node_segment_for_the_other_sources() {
assertFalse(walletChildLine(input("ready", running = true)).contains("node "))
assertFalse(walletChildLine(input("off", chainSource = "receive-only")).contains("node "))
}
@Test
fun start_is_blocked_when_the_build_has_no_in_process_daemon() {
val why = startBlockedReason(
bundled,
node(state = "off", nodeState = "off", nodeAvailable = false, running = false),
)
assertEquals(CUPRATE_NOT_IN_BUILD_NOTICE, why)
assertNull(
"a build that carries the daemon is not blocked",
startBlockedReason(
bundled,
node(state = "off", nodeState = "off", nodeAvailable = true, running = false),
),
)
}
@Test
fun the_preproduction_warning_is_a_sentence_a_user_can_act_on() {
val warning = CUPRATE_PREPRODUCTION_WARNING
assertTrue("it names the software", warning.contains("Cuprate"))
assertTrue("it quotes the user book", warning.contains("do NOT use cuprated"))
assertTrue("it names the parity gap", warning.contains("Cuprate issue #278"))
assertTrue("it says testnet", warning.contains("testnet"))
assertTrue("it is a sentence, not a glyph", warning.trim().endsWith("."))
assertTrue("it is long enough to be a sentence", warning.length > 80)
}
// --- storage honesty ----------------------------------------------------
@Test
fun storage_is_blocked_when_free_space_is_unreadable() {
assertTrue(chainStorageBlockedReason(null)!!.contains("could not be read"))
}
@Test
fun storage_is_blocked_below_the_floor() {
val why = chainStorageBlockedReason(CHAIN_FREE_SPACE_FLOOR_BYTES - 1)
assertNotNull(why)
assertTrue(why!!, why.contains("Not enough space"))
assertTrue("the number is on screen", why.contains("3.0 GiB"))
}
@Test
fun storage_is_allowed_at_and_above_the_floor() {
assertNull(chainStorageBlockedReason(CHAIN_FREE_SPACE_FLOOR_BYTES))
assertNull(chainStorageBlockedReason(64L * 1024 * 1024 * 1024))
}
@Test
fun the_storage_line_reports_the_measured_number() {
val line = chainStorageLine(41L * 1024 * 1024 * 1024)
assertTrue(line, line.contains("41.0 GiB"))
assertTrue("it says what the number is not", line.contains("no size estimate"))
assertTrue(
"an unreadable filesystem says so",
chainStorageLine(null).contains("could not be read"),
)
}
@Test
fun bytes_are_formatted_in_binary_units() {
assertEquals("512 B", formatBytes(512))
assertEquals("2 MiB", formatBytes(2L * 1024 * 1024))
assertEquals("1.5 GiB", formatBytes(3L * 1024 * 1024 * 1024 / 2))
assertEquals("3.0 GiB", formatBytes(CHAIN_FREE_SPACE_FLOOR_BYTES))
}
}