tui: the Cuprate start path answers get_info, and the Linux TUI includes it
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:
parent
c550a197ac
commit
a466c43764
6 changed files with 218 additions and 11 deletions
|
|
@ -11,7 +11,8 @@
|
|||
//! Locked facts this module encodes:
|
||||
//!
|
||||
//! * `cuprated` is a **git** dependency pinned to a revision, behind the
|
||||
//! `cuprate-daemon` feature, off by default. Cuprate is pre-1.0 and is not
|
||||
//! `cuprate-daemon` feature, which the Linux TUI default includes. A
|
||||
//! `--no-default-features` build does not. Cuprate is pre-1.0 and is not
|
||||
//! published to crates.io (every Cuprate crate there is a `0.0.0-placeholder`
|
||||
//! name reservation), so a pinned revision is the only honest way to depend on
|
||||
//! it.
|
||||
|
|
|
|||
186
src/node.rs
186
src/node.rs
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -2150,6 +2150,7 @@ mod tests {
|
|||
#[cfg(feature = "cuprate-daemon")]
|
||||
#[test]
|
||||
fn in_process_source_launches_a_daemon_and_stop_shuts_it_down() {
|
||||
let _port = super::test_support::unrestricted_port_lock();
|
||||
let dir = tmp_dir("cuprate-on");
|
||||
let store = open_store(&dir);
|
||||
let rpc_log = dir.join("wallet-rpc.argv");
|
||||
|
|
@ -2204,6 +2205,7 @@ mod tests {
|
|||
#[cfg(feature = "cuprate-daemon")]
|
||||
#[test]
|
||||
fn a_start_that_fails_after_the_daemon_came_up_leaves_nothing_running() {
|
||||
let _port = super::test_support::unrestricted_port_lock();
|
||||
let dir = tmp_dir("cuprate-late-failure");
|
||||
let store = open_store(&dir);
|
||||
let rpc_log = dir.join("wallet-rpc.argv");
|
||||
|
|
@ -2370,6 +2372,18 @@ pub(crate) mod test_support {
|
|||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
/// Every in-process launch binds [`DEFAULT_MONEROD_RPC_PORT`]. `cargo test`
|
||||
/// runs those tests in parallel, so they take this for the whole launch
|
||||
/// and the stop that follows.
|
||||
///
|
||||
/// ponytail: one process-wide lock. A free port per launch would also have
|
||||
/// to move the wallet child's `--daemon-address`, which is the constant.
|
||||
#[cfg(feature = "cuprate-daemon")]
|
||||
pub(crate) fn unrestricted_port_lock() -> std::sync::MutexGuard<'static, ()> {
|
||||
static LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||
LOCK.lock().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
/// Holds every `--rpc-bind-port` a watched argv log publishes, for as long
|
||||
/// as this value lives.
|
||||
///
|
||||
|
|
|
|||
Loading…
Reference in a new issue