tui: the Cuprate start path answers get_info, and the Linux TUI includes it
Some checks failed
ci / test (pull_request) Failing after 2m50s
ci / sdk (pull_request) Successful in 1m23s
android-ci / android (pull_request) Successful in 12m40s

Node::start_wallet_child is the call the TUI makes. The test stores an
in-process testnet source, starts the child, and checks the typed daemon
client's get_info. It does not bootstrap Tor.

cuprate-daemon is now in the Linux TUI default, so a release build of the
onionwire bin links the daemon with no extra feature flag. A build with
--no-default-features still refuses with NO_FEATURE_MSG. cuprated keeps
default-features = false so Cuprate's arti feature cannot pull arti-client
0.44 next to OnionWire's 0.46.

Cargo.lock is unchanged: cuprated was already an optional dependency.
This commit is contained in:
agent 2026-10-08 10:59:45 -04:00
commit a466c43764
No known key found for this signature in database
6 changed files with 218 additions and 11 deletions

View file

@ -3364,12 +3364,55 @@ pub(crate) mod tests {
node.stop_wallet_child().expect("stop");
}
/// Holds [`crate::wallet_child::test_support::unrestricted_port_lock`] on a
/// thread of its own. The guard is not `Send`, and this test awaits, so the
/// async fn must not hold it (`clippy::await_holding_lock`).
#[cfg(feature = "cuprate-daemon")]
struct UnrestrictedPortHold {
tx: Option<std::sync::mpsc::Sender<()>>,
handle: Option<std::thread::JoinHandle<()>>,
}
#[cfg(feature = "cuprate-daemon")]
impl UnrestrictedPortHold {
fn new() -> Self {
let (ready_tx, ready_rx) = std::sync::mpsc::channel();
let (tx, rx) = std::sync::mpsc::channel();
let handle = std::thread::spawn(move || {
let _guard = crate::wallet_child::test_support::unrestricted_port_lock();
let _ = ready_tx.send(());
let _ = rx.recv();
});
ready_rx
.recv()
.expect("the port lock thread must answer before the test binds");
Self {
tx: Some(tx),
handle: Some(handle),
}
}
}
#[cfg(feature = "cuprate-daemon")]
impl Drop for UnrestrictedPortHold {
fn drop(&mut self) {
drop(self.tx.take());
if let Some(handle) = self.handle.take() {
let _ = handle.join();
}
}
}
/// The case the user hit: the wallet RPC is refused (`os error 111`) while
/// the chain source is this box's own daemon. The status still shows the
/// chain's height and target — asked of the daemon directly — and the state
/// stays `connecting`, because the *wallet* is what did not answer.
#[tokio::test]
async fn a_refused_wallet_rpc_falls_back_to_the_local_daemons_own_height() {
// The in-process launch tests bind this same port. Hold it for the
// whole test so a default build (feature on) does not race them.
#[cfg(feature = "cuprate-daemon")]
let _port = UnrestrictedPortHold::new();
let dir = tempfile::tempdir().unwrap();
let home = dir.path().join("child");
let Some(()) = mock_daemon_on_default_port(1160, 3_090_939).await else {
@ -3458,6 +3501,149 @@ pub(crate) mod tests {
assert!(err.contains("no chain source configured"), "{err}");
}
/// The call the TUI makes. A direct `CuprateNode::launch` does not prove
/// `start_wallet_child` pointed the wallet child at that node.
///
/// Testnet, no peers: RPC answers at genesis. Not a sync.
#[cfg(feature = "cuprate-daemon")]
#[test]
fn start_wallet_child_in_process_cuprate_answers_get_info() {
let _port = crate::wallet_child::test_support::unrestricted_port_lock();
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("runtime");
rt.block_on(start_wallet_child_in_process_cuprate_answers_get_info_inner());
}
#[cfg(feature = "cuprate-daemon")]
async fn start_wallet_child_in_process_cuprate_answers_get_info_inner() {
let dir = tempfile::tempdir().unwrap();
let home = dir.path().join("child");
let node = offline_node(&home, Arc::new(NoDial));
let log = dir.path().join("wallet-rpc.argv");
let bin = fake_child_bin(
&dir.path().join("fake-bins"),
"monero-wallet-rpc",
&log,
"sleep 60",
);
node.set_in_process_cuprate(ChainNetwork::Testnet, false)
.expect("store an in-process testnet source");
let mut cfg = node.wallet_child_config();
let ChainSource::InProcessCuprate {
datadir,
network,
prune,
} = &cfg.source
else {
panic!("stored source is not in-process: {:?}", cfg.source);
};
assert_eq!(*network, ChainNetwork::Testnet);
assert!(!prune);
assert!(
datadir.starts_with(&home),
"datadir must live under the wallet home: {}",
datadir.display()
);
let datadir = datadir.clone();
cfg.wallet_rpc_bin = bin;
node.set_wallet_child_config(&cfg)
.expect("point the child at the fake wallet rpc");
assert!(
WalletChild::chain_copy(&node.wallet_child_config().source)
.contains(crate::cuprate::TESTNET_ONLY),
"an in-process status line must keep the testnet caveat"
);
let _hold = PublishedPortHold::watching(std::slice::from_ref(&log));
node.start_wallet_child()
.expect("the TUI start path launches the in-process daemon");
let addr = format!("127.0.0.1:{DEFAULT_MONEROD_RPC_PORT}");
let mut argv = String::new();
for _ in 0..200 {
argv = std::fs::read_to_string(&log).unwrap_or_default();
if argv.contains("--daemon-address") {
break;
}
tokio::time::sleep(Duration::from_millis(10)).await;
}
let lines: Vec<&str> = argv.lines().collect();
assert!(
lines
.windows(2)
.any(|w| w == ["--daemon-address", addr.as_str()]),
"the wallet child must be pointed at the in-process RPC, got {argv}"
);
let budget = Duration::from_secs(5);
let mut info = None;
for _ in 0..40 {
if let Ok(got) = wallet::daemon_get_info(&addr, budget).await {
info = Some(got);
break;
}
tokio::time::sleep(Duration::from_millis(250)).await;
}
let info = info.expect("the unrestricted RPC the child points at never answered get_info");
assert!(info.height >= 1, "genesis is height 1: {info:?}");
assert_eq!(
info.target_height, 0,
"a testnet node with no peers reports no target: {info:?}"
);
assert!(
datadir.join("testnet").join("fjall").is_dir(),
"the chain store must live under the wallet home: {}",
datadir.display()
);
node.stop_wallet_child().expect("stop");
let mut closed = false;
for _ in 0..40 {
if tokio::net::TcpStream::connect(&addr).await.is_err() {
closed = true;
break;
}
tokio::time::sleep(Duration::from_millis(250)).await;
}
assert!(
closed,
"the unrestricted RPC was still accepting after stop_wallet_child"
);
}
/// Same call, feature off: the refusal names the feature and spawns nothing.
#[cfg(not(feature = "cuprate-daemon"))]
#[tokio::test]
async fn start_wallet_child_without_the_feature_returns_no_feature_msg() {
let dir = tempfile::tempdir().unwrap();
let home = dir.path().join("child");
let node = offline_node(&home, Arc::new(NoDial));
let log = dir.path().join("wallet-rpc.argv");
let bin = fake_child_bin(
&dir.path().join("fake-bins"),
"monero-wallet-rpc",
&log,
"sleep 30",
);
node.set_in_process_cuprate(ChainNetwork::Testnet, false)
.expect("store an in-process source");
let mut cfg = node.wallet_child_config();
cfg.wallet_rpc_bin = bin;
node.set_wallet_child_config(&cfg).expect("set bin");
let err = node
.start_wallet_child()
.expect_err("a build without the feature must not start a daemon");
assert!(err.contains(crate::cuprate::NO_FEATURE_MSG), "{err}");
assert!(
!log.exists(),
"the wallet RPC must not be spawned against a daemon that never started"
);
assert!(!node.wallet_child_status().running, "{err}");
}
/// The start path honours `with_wallet_rpc_bin` — the configured absolute
/// path is what gets spawned, not a name off `PATH` — and the status tracks
/// the real process.