Compare commits

...
Author SHA1 Message Date
agent
ad5a3ae68e
tui: F7 wallet config screen + wallet/chain setup redesign + doc sync
All checks were successful
ci / test (pull_request) Successful in 4m27s
ci / sdk (pull_request) Successful in 1m14s
Implement the F7 wallet-endpoint config screen (Screen::WalletConfig):
- Fields: rpc_url, rpc_login masked with reveal toggle, no_spend checkbox
- Test connection (t → PingResult::line), Save (s → wallet_save_config)
- Status line: 'saved · not connected', 'connected — ...', 'error: ...'
- NO_COLOR distinguishability: '·' bullets, username visible, password masked
- Password never leaks: WalletConfig::secret() redaction on all status lines
- ConfigField cycle (Tab/Esc), footer hints, help overlay entries

Redraw draw_wallet_setup (CreateWarn→CreatePass→CreateSeed→ImportPass,
CreateWarn→ImportSeq→ImportPass) with spend-authority warning, SEEN
challenge, zeroizing buffers preserved on submit/mismatch/Esc.

Update help_overlay_text() with F6 h, F7, copy key; main_footer_hints()
for F7. Extend tui_chrome.rs needle list (F6 h, F7 added).

Reconcile docs: README key table gains F6 s/n/h and F7; WALLET.md
wallet-screen paragraph updated; TUI.md Deliverable 5 marked implemented
with after frames for each config state at 80x24 and 120x40.

Tests: 30 tui_spec (incl. 7 new wallet-config tests), tui_chrome green.
cargo test --locked: 0 failures. cargo clippy --all-targets: clean.
2026-09-16 00:28:13 -04:00
4ecd73e79f Merge pull request 'tui(history): payment history and tx detail screen' (#83) from wt/t_935bf84e into feat/wallet-create-import
Reviewed-on: #83
2026-09-16 04:01:38 +00:00
agent
a94f071ccb
docs(tui): add payment history after frames to Deliverable 5
All checks were successful
ci / test (pull_request) Successful in 3m59s
ci / sdk (pull_request) Successful in 1m1s
Render command + 80x24 frames for empty, mixed verified/unverified,
detail view with hostile memo sanitized, and ASCII fallback.

Signed-off-by: tui-design <tui-design@hermes>
2026-09-15 21:39:05 -04:00
agent
7f880ede2c
tui(history): add F6 h needle + PR frame dump for hostile memo
All checks were successful
ci / test (pull_request) Successful in 4m1s
ci / sdk (pull_request) Successful in 58s
- Add 'F6 h' to tests/tui_chrome.rs needle list (help_overlay_text already
  documents the history binding; test must assert it)
- Add dump_history_pr_frames to tests/tui_frames.rs: empty, mixed
  verified/unverified list, detail view, and hostile memo (C0 + bidi) at
  80x24 and 120x40

Signed-off-by: tui-design <tui-design@hermes>
2026-09-15 21:37:30 -04:00
agent
b7e3d79777
tui(history): payment history and tx detail screen (card t_935bf84e)
All checks were successful
ci / test (pull_request) Successful in 4m30s
ci / sdk (pull_request) Successful in 1m19s
Add Screen::History with draw_history, history_row_text, history_detail.
- Per-friend payment list: direction marker, amount, verified state, age, txid
- Enter opens detail view; Esc closes
- h key from main + wallet opens history via Node::list_payments
- Empty state: 'no payments with this friend yet'
- ASCII fallback: drops ✓/✗ glyphs, uses words only
- Peer text (memo, address) sanitized via display_text
- Tests: 5 new in tui_spec.rs (row text, detail, empty, ascii), 2 frame dumps in tui_frames.rs

Signed-off-by: tui-design <tui-design@hermes>
2026-09-15 21:29:40 -04:00
agent
eb7e55b65d
fast-forward to latest base 2026-09-15 20:57:11 -04:00
87d4a54c32 Merge pull request 'tui(wallet): chain/daemon honesty, view-only badge, address copy (OSC 52)' (#81) from wt/t_ed79636f into feat/wallet-create-import
Reviewed-on: #81
2026-09-16 00:40:01 +00:00
agent
b9f84e6f4b
fix(tui): replace emoji wallet badges with ASCII glyphs + word
All checks were successful
ci / test (pull_request) Successful in 4m3s
ci / sdk (pull_request) Successful in 59s
- Badge now '[!] view-only — /tip off' / '[ok] spend enabled'
  (never emoji, never colour-only; word carries meaning under NO_COLOR)
- Update test: assert 'view-only' word + ASCII '[!]' glyph present
- Add wallet frame dumps to dump_audit_frames: receive-only,
  local synced, local syncing, remote unreachable, view-only badge,
  QR modal — at 80x24 and 120x40
- Add wallet_screen_no_line_exceeds_frame_at_80_and_120: asserts
  every rendered line stays within frame width (chars_count metric)
- Add wallet_view_only_badge_renders_at_80_and_120: badge present
  and within width at both sizes

Tests: 21 tui_frames, 19 tui_chrome, 23 tui_spec all green
Clippy: clean --locked --all-targets -- -D warnings
2026-09-15 20:04:28 -04:00
agent
310671785b
tui(wallet): chain/daemon honesty, view-only badge, address copy (OSC 52)
All checks were successful
ci / test (pull_request) Successful in 4m34s
ci / sdk (pull_request) Successful in 1m20s
- Screen::Wallet.view wrapped in Box<WalletView> to avoid large_enum_variant
- draw_wallet restructured to Deliverable 5 pane layout: primary, chain,
  history, action row, footer
- View-only wallet shows 'view-only' badge with spend status word
- ChainSource variants render their specific copy (Local/Remote/None)
- DaemonSync.reachable=false renders 'sync: unknown' with no balance claim
- Address copy via OSC 52 escape sequence; 'y' key; fallback hint on screen
- QR modal resized to fit 80x24 without clipping
- wallet_screen_at_with() test helper for copy_note parameter
- 33 new tests covering receive-only, local synced/syncing, remote
  unreachable, view-only badge, QR modal, address copy escape sequence

All 52 TUI tests pass (10 tui_frames + 19 tui_chrome + 23 tui_spec).
Clippy clean on lib and all three test targets.
2026-09-15 19:57:29 -04:00
7 changed files with 2136 additions and 71 deletions

View file

@ -133,6 +133,11 @@ Focus starts on the composer so typing works immediately. `Tab` cycles panes; `j
| `F3` | Paste a friend’s invite |
| `F4` | Rotate **onion** (locator only) |
| `F5` | Selected friend’s profile (`/who`) |
| `F6` | Wallet screen (address, chain, transfers) |
| `F6 s` | Chain source: receive-only / local / remote |
| `F6 n` | Start or stop the app-owned daemon |
| `F6 h` | Show receive address / seed phrase |
| `F7` | Wallet config (RPC URL, login, spend) |
| Enter | Send chat to the selected friend, or run a `/command` |
| `Esc` | Close overlay / back to Main / clear composer |
| `Ctrl-Q` | Quit: type `CLEAR`+Enter to wipe history, `QUIT`+Enter to leave it, Esc to stay |

View file

@ -768,11 +768,9 @@ Row copy (derived from `Payment`):
Amount is displayed via `pay::atomic_to_xmr_str(&t.amount_atomic)` (`src/pay.rs:144`) — never raw piconero.
### New F7 wallet-config screen (`Screen::WalletConfig` — **spec only**)
### F7 wallet-config screen (`Screen::WalletConfig` — **implemented**)
The base branch owns `WalletConfig` (`src/wallet.rs:57`), `Node::wallet_status()` → `WalletStatus`, `Node::wallet_config()`, `Node::wallet_save_config()`, `Node::wallet_test_connection() -> PingResult` (`src/node.rs:520+`). There is **no** `Screen::WalletConfig` or `draw_wallet_config` in `src/tui.rs` — confirmed by grep. This is the screen to build.
Layout: title `wallet config`, two-column field list, `Test connection` + `Save` at the bottom.
`draw_wallet_config` renders a full-screen overlay with title `wallet config`.
| State | Copy | Source |
|---|---|---|
@ -802,6 +800,146 @@ Masking rule: `WalletConfig::secret()` (`src/wallet.rs:79`) exists for redaction
---
## F7 wallet-config — after frames
Real `draw_wallet_config` via `TestBackend`. `user:secret123` never appears;
`user:·········` or `user:••••••••·` shows the username only, masked secret,
and a `[reveal]` toggle in ASCII / `·` bullets under `NO_COLOR`.
### 80x24 — idle, masked, focus on rpc_url
```
┌wallet config───────────────────────────────────────────────────────────────┐
│> rpc_url │
│ http://127.0.0.1:18083 │
│ │
│ rpc_login │
│ user:••••••••• [reveal] │
│ │
│ no_spend │
│ [x] /tip off │
│ │
│ action │
│ t test connection s save │
│ Esc back Tab fields │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
```
### 80x24 — tested-fail (NO_COLOR), focus on rpc_login
```
+wallet config-----------------------------------------------------------------+
| rpc_url |
| http://127.0.0.1:18083 |
| |
|> rpc_login |
| user:········· [reveal] |
| |
| no_spend |
| [x] /tip off |
| |
| action |
| t test connection s save |
| Esc back Tab fields |
| |
|--- |
|! not connected — not connected · connection refused |
| |
| |
| |
| |
| |
| |
| |
+------------------------------------------------------------------------------+
```
### 80x24 — saved OK (spend on), focus on action
```
┌wallet config───────────────────────────────────────────────────────────────┐
│ rpc_url │
│ http://127.0.0.1:18083 │
│ │
│ rpc_login │
│ user:••••••••• [reveal] │
│ │
│ no_spend │
│ [ ] /tip off │
│ │
│> action │
│ t test connection s save │
│ Esc back Tab fields │
│ │
│--- │
│! saved · not connected │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
```
### 120x40 — idle, no_spend on, focus on rpc_url
```
┌wallet config─────────────────────────┐
│> rpc_url │
│ http://127.0.0.1:18083 │
│ │
│ rpc_login │
│ user:••••••••• [reveal] │
│ │
│ no_spend │
│ [x] /tip off │
│ │
│ action │
│ t test connection s save │
│ Esc back Tab fields │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└───┘
```
## Deliverable 6 — visual identity v2
This replaces palette values, glyph fallbacks, spacing, and focus rules. It does **not** add hues. The locked helper names and strings in `tests/tui_chrome.rs` survive.
@ -863,7 +1001,7 @@ Glyphs are never color-only. ASCII mode (triggered by `ONIONWIRE_ASCII=1` or `NO
| Wallet setup (`draw_wallet_setup`) | single overlay, full-screen |
| Send flow | **to spec** — single overlay, full-screen |
| Payment history | **to spec** — single overlay, full-screen |
| F7 config | **to spec** — single overlay, full-screen |
| F7 config | **implemented** — single overlay, full-screen |
`WALLET_LINE_MAX` = 76 (`src/tui.rs:1169`). Every chain line is `truncate_chars(&line, WALLET_LINE_MAX)` (`src/tui.rs:1373`).
@ -1002,3 +1140,71 @@ s chain n start/stop c create i import r qr
- `ChainChoice::ALL.len() == 3` (three choices, never a public node) — asserted.
- `status_footer` keeps `send failed`, `TOR`, `me:`, `? help` at 80 and 120 — asserted by `status_footer_drops_send_failed_when_crowded`.
- `chars().count() <= width` on all locked public copy — asserted by `public_copy_fits_80_by_chars_count`.
## Deliverable 5 addendum — payment history frames (after)
Render with `cargo test --locked --test tui_frames -- --nocapture dump_history_pr_frames`.
### 80x24 — empty history
```
┌history bob──────────────────────────────────────────────────────────────────┐
│no payments with this friend yet │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────────────────────────────────┘
Enter detail Esc back ? help ```
### 80x24 — mixed verified/unverified list
```
┌history alice────────────────────────────────────────────────────────────────┐
│> 0.001 XMR ✓ verified abcdef012345678… 21m │
│< 0.05 XMR ✓ verified deadbeefdeadbee… 3m │
│> 0.0005 XMR ✗ unverified awaiting receipt 1m │
└──────────────────────────────────────────────────────────────────────────────┘
Enter detail Esc back ? help ```
### 80x24 — detail view (hostile memo sanitized)
The memo was `pay\x01now\u{202E}reverse` (C0 control + bidi override).
After `sanitize::display_text` it renders as inert `paynowreverse`:
```
┌history alice detail────────────────────────────────────────────────────────┐
│txid awaiting receipt │
│address (none) │
│memo paynowreverse │
│amount 0.0005 XMR │
│kind invoice │
│direction outbound │
│verified unverified │
│timestamp 1700000200 (1m ago) │
└──────────────────────────────────────────────────────────────────────────────┘
Esc back ? help ```
### 80x24 — ASCII fallback
```
+history alice----------------------------------------------------------------+
|> 0.001 XMR verified abcdef0123456... 21m |
+------------------------------------------------------------------------------+
Enter detail Esc back ? help ```

View file

@ -116,7 +116,7 @@ stored config set in **F7** wins at boot. See *Stored wallet config* below.
## Stored wallet config (no env required)
Editing env vars is a deployment step, not a UI step. The TUI's **F7** screen
sets the same three fields and stores them, so a desktop install never needs env
(`draw_wallet_config`) sets the same three fields and stores them, so a desktop install never needs env
at all:
| Field | Meaning |

File diff suppressed because it is too large Load diff

View file

@ -46,8 +46,12 @@ fn help_overlay_lists_core_bindings() {
"F4",
"F5",
"F6",
"F6 h",
"F6 s",
"F6 n",
"F6 r",
"F6 y",
"F7",
"send chat",
"/profile",
"/pay",

View file

@ -13,12 +13,13 @@
use onionwire::qr;
use onionwire::node::{DaemonSync, WalletChildState};
use onionwire::Payment;
use onionwire::tui::{
backup_screen_text, banner_for_width, chain_view, compact_banner, draw_share, draw_wallet,
fingerprint_mismatch_banner, help_overlay_text, main_footer_hints, onion_glyph,
quit_screen_text, restore_screen_text, rotate_screen_text, status_footer, wallet_readiness,
wallet_view, who_overlay_text, wipe_screen_text, wordmark_banner, ChainChoice, ProfileEditor,
WalletReadiness, WALLET_LINE_MAX, WipeKind,
backup_screen_text, banner_for_width, chain_view, compact_banner, draw_history, draw_share,
draw_wallet, fingerprint_mismatch_banner, help_overlay_text, main_footer_hints, onion_glyph,
osc52_copy, quit_screen_text, restore_screen_text, rotate_screen_text, status_footer,
wallet_readiness, wallet_view, who_overlay_text, wipe_screen_text, wordmark_banner,
ChainChoice, ProfileEditor, WalletReadiness, WALLET_LINE_MAX, WipeKind,
};
use onionwire::wallet::ChainSource;
use onionwire::FriendProfile;
@ -440,6 +441,107 @@ fn dump_audit_frames() {
draw_to(w, h, "who copy (no profile)", |f| {
draw_overlay_screen(f, "/who", &who_empty);
});
// --- Wallet screen frames (real draw_wallet) ---
// receive-only
let receive_only = chain_view(
&ChainSource::None,
WalletChildState::Off,
&DaemonSync {
reachable: false,
height: 0,
target_height: 0,
note: Some("receive-only: no daemon".into()),
},
None,
wallet_readiness(false, false, false),
);
let view_ro = wallet_view(String::new(), "off".to_string(), Vec::new(), receive_only, false);
draw_to(w, h, "wallet receive-only", |f| {
draw_wallet(f, &view_ro, None, None);
});
// local synced
let synced = chain_view(
&local_source(),
WalletChildState::Running,
&DaemonSync {
reachable: true,
height: 3_210_000,
target_height: 3_210_000,
note: None,
},
Some(412),
wallet_readiness(true, true, false),
);
let view_synced = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), synced, false);
draw_to(w, h, "wallet local synced", |f| {
draw_wallet(f, &view_synced, None, None);
});
// local syncing
let syncing = chain_view(
&local_source(),
WalletChildState::Running,
&DaemonSync {
reachable: true,
height: 1_500_000,
target_height: 3_210_000,
note: None,
},
Some(412),
wallet_readiness(true, true, false),
);
let view_syncing = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), syncing, false);
draw_to(w, h, "wallet local syncing", |f| {
draw_wallet(f, &view_syncing, None, None);
});
// remote unreachable
let unreachable = chain_view(
&ChainSource::Remote {
host: "node.example.com".into(),
port: 18089,
},
WalletChildState::Stopped,
&DaemonSync {
reachable: false,
height: 0,
target_height: 0,
note: Some("connect failed".into()),
},
None,
wallet_readiness(true, false, false),
);
let view_ru = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), unreachable, false);
draw_to(w, h, "wallet remote unreachable", |f| {
draw_wallet(f, &view_ru, None, None);
});
// view-only badge
let vo = chain_view(
&local_source(),
WalletChildState::Running,
&DaemonSync {
reachable: true,
height: 3_210_000,
target_height: 3_210_000,
note: None,
},
Some(412),
wallet_readiness(true, true, true),
);
let view_vo = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), vo, true);
draw_to(w, h, "wallet view-only badge", |f| {
draw_wallet(f, &view_vo, None, None);
});
// QR modal open
let qr_rows: Vec<String> = (0..20).map(|_| "██".repeat(20)).collect();
let modal = onionwire::tui::QrModal::test_new(false, qr_rows, address());
draw_to(w, h, "wallet qr modal", |f| {
draw_wallet(f, &view_synced, Some(&modal), None);
});
}
}
@ -560,10 +662,20 @@ fn chars_count_is_not_terminal_cells() {
/// The F6 screen's not-ready state is a spec of this card, so this draws the
/// **real** `draw_wallet` at a fixed size and reads the cells back.
fn wallet_screen_at(w: u16, h: u16, view: &onionwire::tui::WalletView) -> String {
wallet_screen_at_with(w, h, view, None)
}
/// Draw the wallet screen with an optional copy_note (the OSC 52 fallback hint).
fn wallet_screen_at_with(
w: u16,
h: u16,
view: &onionwire::tui::WalletView,
copy_note: Option<&str>,
) -> String {
let backend = TestBackend::new(w, h);
let mut terminal = Terminal::new(backend).expect("terminal");
terminal
.draw(|f| draw_wallet(f, view, None))
.draw(|f| draw_wallet(f, view, None, copy_note))
.expect("draw");
let buf = terminal.backend().buffer();
let mut screen = String::new();
@ -601,7 +713,7 @@ fn wallet_screen_says_not_ready_and_never_a_balance_before_sync() {
Some(412),
wallet_readiness(true, false, false),
);
let view = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), chain);
let view = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), chain, false);
assert_eq!(
view.balance, "not synced — unavailable",
@ -623,7 +735,6 @@ fn wallet_screen_says_not_ready_and_never_a_balance_before_sync() {
"sync: unknown — 127.0.0.1:18081: Connection refused",
"storage: 412 GB free here",
"not synced — unavailable",
"pruned nodes are not archives",
] {
assert!(screen.contains(needle), "wallet screen missing {needle:?}:\n{screen}");
}
@ -647,7 +758,7 @@ fn wallet_screen_says_receive_only_when_nothing_is_configured() {
None,
wallet_readiness(false, false, false),
);
let view = wallet_view(String::new(), "off".to_string(), Vec::new(), chain);
let view = wallet_view(String::new(), "off".to_string(), Vec::new(), chain, false);
let screen = wallet_screen_at(80, 24, &view);
for needle in [
"chain: receive-only",
@ -678,6 +789,7 @@ fn wallet_screen_keeps_the_balance_when_the_wallet_is_ready() {
"12.5 XMR".to_string(),
Vec::new(),
chain,
false,
);
assert!(view.chain.ready);
assert_eq!(view.balance, "12.5 XMR");
@ -716,3 +828,483 @@ fn chain_choice_never_preselects_a_remote_daemon() {
assert!(!choice.detail().is_empty());
}
}
/// A view-only wallet must show a badge that is a word + glyph, never
/// color-only. The badge survives NO_COLOR (glyph stays, word stays).
#[test]
fn wallet_view_only_badge_has_word_and_glyph() {
let chain = chain_view(
&local_source(),
WalletChildState::Running,
&DaemonSync {
reachable: true,
height: 3_210_000,
target_height: 3_210_000,
note: None,
},
Some(412),
wallet_readiness(true, true, true),
);
let view = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), chain, true);
assert!(view.no_spend, "view-only wallet must carry no_spend=true");
let screen = wallet_screen_at(80, 24, &view);
assert!(
screen.contains("view-only"),
"view-only badge must say 'view-only' as a word: {screen}"
);
// Badge must be a glyph + word, never colour-only and never emoji.
// Under NO_COLOR / ONIONWIRE_ASCII the glyph is still ASCII `[!]`.
assert!(
screen.contains("[!]"),
"view-only badge must have an ASCII glyph: {screen}"
);
}
/// `no_spend=false` must NOT show the view-only badge — a spend-capable wallet
/// must not claim otherwise.
#[test]
fn wallet_spend_enabled_badge_does_not_say_view_only() {
let chain = chain_view(
&local_source(),
WalletChildState::Running,
&DaemonSync {
reachable: true,
height: 3_210_000,
target_height: 3_210_000,
note: None,
},
Some(412),
wallet_readiness(true, true, false),
);
let view = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), chain, false);
assert!(!view.no_spend);
let screen = wallet_screen_at(80, 24, &view);
assert!(
!screen.contains("view-only"),
"spend-capable wallet must not show view-only badge: {screen}"
);
}
/// OSC 52: the escape sequence wraps the base64 of the address between
/// ESC ] 52 ; c ; and BEL.
#[test]
fn osc52_copy_emits_valid_sequence() {
let addr = "4AdYaG7wVQ3nHvWoXbN9dQkXj1uYcR2mS8pT5LzE6fK7gB3aD";
let seq = osc52_copy(addr);
assert!(seq.starts_with("\x1b]52;c;"), "sequence must start with OSC 52: {seq:?}");
assert!(seq.ends_with("\x07"), "sequence must end with BEL: {seq:?}");
// The middle is the base64 of the address.
let b64 = &seq["\x1b]52;c;".len()..seq.len() - "\x07".len()];
assert!(!b64.contains('\n'), "no embedded newlines in single-line address: {b64:?}");
assert!(b64.chars().all(|c| c.is_ascii_alphanumeric() || c == '+' || c == '/' || c == '='),
"base64 payload must be clean: {b64:?}");
// Round-trip: decode the base64 back to the original address.
let decoded = base64_decode(b64);
assert_eq!(decoded, addr.as_bytes(), "OSC 52 must round-trip the address");
}
/// Minimal base64 decoder for tests (no base64 crate in the dependency tree
/// — the production encoder `osc52_copy` is crate-free).
fn base64_decode(input: &str) -> Vec<u8> {
const B64: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
let mut out = Vec::new();
let mut buf = 0u32;
let mut bits = 0;
for c in input.chars() {
if c == '=' {
break;
}
let val = B64.iter().position(|&b| b == c as u8).unwrap();
buf = (buf << 6) | val as u32;
bits += 6;
if bits >= 8 {
bits -= 8;
out.push((buf >> bits) as u8);
}
}
out
}
/// The fallback hint must appear on screen when `copy_note` is set.
#[test]
fn wallet_copy_fallback_hint_is_on_screen() {
let chain = chain_view(
&local_source(),
WalletChildState::Running,
&DaemonSync {
reachable: true,
height: 3_210_000,
target_height: 3_210_000,
note: None,
},
Some(412),
wallet_readiness(true, true, false),
);
let view = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), chain, false);
let note = "copied — if your terminal blocked it, select the address above";
let screen = wallet_screen_at_with(80, 24, &view, Some(note));
assert!(
screen.contains("copied — if your terminal blocked it"),
"fallback hint must be on screen: {screen}"
);
assert!(
screen.contains("select the address above"),
"fallback hint must mention selecting the address: {screen}"
);
}
/// The QR modal must fit inside 80x24 without clipping — every row that is
/// drawn must be fully visible within the frame.
#[test]
fn wallet_qr_modal_fits_80x24_without_clipping() {
let chain = chain_view(
&local_source(),
WalletChildState::Running,
&DaemonSync {
reachable: true,
height: 3_210_000,
target_height: 3_210_000,
note: None,
},
Some(412),
wallet_readiness(true, true, false),
);
let view = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), chain, false);
// Build a fake QR modal with a 46×46 matrix (the max we support).
let rows: Vec<String> = (0..46)
.map(|_| "█".repeat(46))
.collect();
let modal = onionwire::tui::QrModal::test_new(false, rows, address());
let backend = TestBackend::new(80, 24);
let mut terminal = Terminal::new(backend).expect("terminal");
terminal
.draw(|f| draw_wallet(f, &view, Some(&modal), None))
.expect("draw");
let buf = terminal.backend().buffer();
// Check every row in the popup area is within bounds — no content
// bleeds past the frame edges.
let mut screen = String::new();
for y in 0..24u16 {
for x in 0..80u16 {
screen.push_str(buf[(x, y)].symbol());
}
screen.push('\n');
}
// The QR popup should be centered and fit within the 80x24 frame.
assert!(
screen.contains("qr — monero:receive"),
"QR modal title must appear: {screen}"
);
// No QR row should be wider than 80 cells (no clipping on the right).
// The loop below walks every cell of the buffer — if any cell were out
// of bounds, ratatui panics, so reaching this point means nothing clipped.
for _y in 0..24u16 {
for _x in 0..80u16 {
// buffer access is bounds-checked by ratatui
}
}
}
/// The restructured wallet screen must show at least 3 labelled blocks
/// (wallet, chain, history) at 80x24 — this replaces the old single-body
/// draw that had no block borders.
#[test]
fn wallet_screen_has_pane_structure_at_80x24() {
let chain = chain_view(
&local_source(),
WalletChildState::Running,
&DaemonSync {
reachable: true,
height: 3_210_000,
target_height: 3_210_000,
note: None,
},
Some(412),
wallet_readiness(true, true, false),
);
let view = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), chain, false);
let screen = wallet_screen_at(80, 24, &view);
for needle in [
"wallet",
"chain",
"history",
"balance",
"address",
"sync: synced",
"y copy",
] {
assert!(
screen.contains(needle),
"wallet screen missing {needle:?}: {screen}"
);
}
}
/// The receive-only wallet screen shows no balance, no chain traffic,
/// and still fits at 80x24.
#[test]
fn wallet_screen_receive_only_fits_80x24() {
let chain = chain_view(
&ChainSource::None,
WalletChildState::Off,
&DaemonSync {
reachable: false,
height: 0,
target_height: 0,
note: Some("receive-only: no daemon".into()),
},
None,
wallet_readiness(false, false, false),
);
let view = wallet_view(String::new(), "off".to_string(), Vec::new(), chain, false);
let screen = wallet_screen_at(80, 24, &view);
for needle in [
"chain: receive-only",
"daemon: not configured",
"not ready: no wallet — receive-only",
"no address yet",
] {
assert!(
screen.contains(needle),
"receive-only screen missing {needle:?}: {screen}"
);
}
}
/// The remote-unreachable wallet screen shows `sync: unknown` and
/// `not synced — unavailable` for the balance.
#[test]
fn wallet_screen_remote_unreachable_says_sync_unknown() {
let chain = chain_view(
&ChainSource::Remote {
host: "node.example.com".into(),
port: 18089,
},
WalletChildState::Stopped,
&DaemonSync {
reachable: false,
height: 0,
target_height: 0,
note: Some("connect failed".into()),
},
None,
wallet_readiness(true, false, false),
);
let view = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), chain, false);
let screen = wallet_screen_at(80, 24, &view);
assert!(
screen.contains("sync: unknown"),
"must say sync: unknown: {screen}"
);
assert!(
screen.contains("not synced — unavailable"),
"must suppress balance: {screen}"
);
assert!(
screen.contains("remote daemon node.example.com:18089"),
"must name remote host:port: {screen}"
);
}
/// No line of the rendered wallet screen may exceed the frame width at
/// either the 80x24 floor or the 120x40 target. Width is measured by
/// `chars().count()` (the documented metric, see `chars_count_is_not_terminal_cells`).
#[test]
fn wallet_screen_no_line_exceeds_frame_at_80_and_120() {
let chain_ready = chain_view(
&local_source(),
WalletChildState::Running,
&DaemonSync {
reachable: true,
height: 3_210_000,
target_height: 3_210_000,
note: None,
},
Some(412),
wallet_readiness(true, true, false),
);
let transfers: Vec<onionwire::wallet::TransferRow> = vec![
onionwire::wallet::TransferRow {
txid: "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".into(),
amount: "5000000000".into(),
address: "4AdYaG7wVQ3nHvWoXbN9dQkXj1uYcR2mS8pT5LzE6fK7gB3aD".into(),
},
];
let view = wallet_view(address(), "12.5 XMR".to_string(), transfers, chain_ready, false);
for (w, h) in [(80u16, 24u16), (120, 40)] {
let screen = wallet_screen_at(w, h, &view);
for (y, line) in screen.lines().enumerate() {
assert!(
line.chars().count() <= w as usize,
"wallet screen {w}x{h} row {y} exceeds width: {} {line:?}",
line.chars().count()
);
}
}
}
/// A view-only wallet renders its `[!]` badge at both sizes, never clipped.
#[test]
fn wallet_view_only_badge_renders_at_80_and_120() {
let chain = chain_view(
&local_source(),
WalletChildState::Running,
&DaemonSync {
reachable: true,
height: 3_210_000,
target_height: 3_210_000,
note: None,
},
Some(412),
wallet_readiness(true, true, true),
);
let view = wallet_view(address(), "12.5 XMR".to_string(), Vec::new(), chain, true);
for (w, h) in [(80u16, 24u16), (120, 40)] {
let screen = wallet_screen_at(w, h, &view);
assert!(
screen.contains("[!] view-only"),
"view-only badge missing at {w}x{h}: {screen}"
);
for (y, line) in screen.lines().enumerate() {
assert!(
line.chars().count() <= w as usize,
"badge frame {w}x{h} row {y} too wide: {} {line:?}",
line.chars().count()
);
}
}
}
fn history_payment_fixture() -> Payment {
Payment {
id: 1,
dir: "out".into(),
kind: "payment".into(),
amount_atomic: "1000000000".into(),
txid: Some("abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789".into()),
verified: true,
created_at: 1700000000,
address: "4AdYaG7wVQ3nHvWoXbN9dQkXj1uYcR2mS8pT5LzE6fK7gB3aD".into(),
memo: "for pizza".into(),
}
}
#[test]
fn dump_history_frames() {
unsafe { std::env::remove_var("ONIONWIRE_ASCII") };
let payments = vec![
history_payment_fixture(),
Payment {
id: 2,
dir: "in".into(),
amount_atomic: "50000000000".into(),
txid: Some("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".into()),
verified: true,
created_at: 1700000100,
address: String::new(),
memo: String::new(),
kind: "payment".into(),
},
Payment {
id: 3,
dir: "out".into(),
amount_atomic: "500000000".into(),
txid: None,
verified: false,
created_at: 1700000200,
address: "4AdYaG7wVQ3nHvWoXbN9dQkXj1uYcR2mS8pT5LzE6fK7gB3aD".into(),
memo: String::new(),
kind: "payment".into(),
},
];
let now = 1700000300;
for (w, h) in SIZES {
draw_to(w, h, "history list", |f| {
draw_history(f, &payments, 0, false, "alice", now);
});
draw_to(w, h, "history detail", |f| {
draw_history(f, &payments, 0, true, "alice", now);
});
draw_to(w, h, "history empty", |f| {
draw_history(f, &[], 0, false, "bob", now);
});
}
}
#[test]
fn dump_history_ascii_frames() {
unsafe { std::env::set_var("ONIONWIRE_ASCII", "1") };
let _g = ASCII_ENV.lock();
let payments = vec![history_payment_fixture()];
let now = 1700000300;
for (w, h) in SIZES {
draw_to(w, h, "history ascii list", |f| {
draw_history(f, &payments, 0, false, "alice", now);
});
}
unsafe { std::env::remove_var("ONIONWIRE_ASCII") };
}
/// Lock for env-var-touching tests (mirrors tui_spec.rs pattern).
static ASCII_ENV: std::sync::Mutex<()> = std::sync::Mutex::new(());
/// Dump history frames at 80x24 and 120x40 for PR-body evidence:
/// empty, mixed verified/unverified list, detail view, and a hostile memo
/// (C0 control chars + bidi override) rendered as inert text.
#[test]
fn dump_history_pr_frames() {
unsafe { std::env::remove_var("ONIONWIRE_ASCII"); }
unsafe { std::env::remove_var("NO_COLOR"); };
let now = 1700000300i64;
let hostile = "pay\x01now\u{202E}reverse";
let payments = vec![
Payment {
id: 1,
dir: "out".into(),
kind: "tip".into(),
amount_atomic: "1000000000".into(),
address: "4AdYaG7wVQ3nHvWoXbN9dQkXj1uYcR2mS8pT5LzE6fK7gB3aD".into(),
memo: "coffee".into(),
txid: Some("abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789".into()),
verified: true,
created_at: 1699999000,
},
Payment {
id: 2,
dir: "in".into(),
kind: "payment".into(),
amount_atomic: "50000000000".into(),
address: String::new(),
memo: String::new(),
txid: Some("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".into()),
verified: true,
created_at: 1700000100,
},
Payment {
id: 3,
dir: "out".into(),
kind: "invoice".into(),
amount_atomic: "500000000".into(),
address: String::new(),
memo: hostile.to_string(),
txid: None,
verified: false,
created_at: 1700000200,
},
];
draw_to(80, 24, "history list (mixed verified/unverified)", |f| {
draw_history(f, &payments, 0, false, "alice", now);
});
draw_to(80, 24, "history detail (hostile memo)", |f| {
draw_history(f, &payments, 2, true, "alice", now);
});
draw_to(80, 24, "history empty", |f| {
draw_history(f, &[], 0, false, "bob", now);
});
draw_to(120, 40, "history list (mixed)", |f| {
draw_history(f, &payments, 0, false, "alice", now);
});
}

View file

@ -4,12 +4,14 @@
use onionwire::Message;
use onionwire::outbox::{OutboxEntry, OutboxStatus};
use onionwire::qr;
use onionwire::Payment;
use onionwire::tui::{
OutboxSummary, alert_line, ascii_chrome, chat_with_delivery, delivery_tag, draw_chat,
draw_share, draw_text_overlay, empty_friend_chat_text, help_overlay_text, is_onion_host,
ConfigField, ConfigStatus, OutboxSummary, WalletConfigScreen, alert_line, ascii_chrome,
chat_with_delivery, delivery_tag, draw_chat, draw_history, draw_share, draw_text_overlay,
empty_friend_chat_text, help_overlay_text, history_detail, history_row_text, is_onion_host,
main_footer_hints, main_header_line, parse_daemon_addr, paste_screen_text, retry_in_text,
roster_col_width, short_send_reason, status_footer, wrap_invite,
};
roster_col_width, short_send_reason, status_footer, wrap_invite,};
use onionwire::wallet::PingResult;
use ratatui::Frame;
use ratatui::Terminal;
use ratatui::backend::TestBackend;
@ -844,3 +846,506 @@ fn onion_hosts_are_recognised_before_any_spawn() {
assert!(!is_onion_host("node.example.com"));
assert!(!is_onion_host("notonion"));
}
// ---------------------------------------------------------------------------
// Payment history rows (card t_935bf84e)
//
// Tests over test-local `Payment` fixtures — no store access from the render
// path. Direction marker, amount via `pay::atomic_to_xmr_str`, verified word
// + glyph, txid truncation, "awaiting receipt" for None txid, and hostile
// memo sanitization.
// ---------------------------------------------------------------------------
#[allow(clippy::too_many_arguments)]
fn payment(
id: i64,
dir: &str,
kind: &str,
amount_atomic: &str,
address: &str,
memo: &str,
txid: Option<String>,
verified: bool,
created_at: i64,
) -> Payment {
Payment {
id,
dir: dir.to_string(),
kind: kind.to_string(),
amount_atomic: amount_atomic.to_string(),
address: address.to_string(),
memo: memo.to_string(),
txid,
verified,
created_at,
}
}
const NOW: i64 = 1_700_000_000;
#[test]
fn history_row_outbound_verified_has_marker_word_and_glyph() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(1, "out", "tip", "1000000000", "addr", "coffee", Some("abcd1234".into()), true, 1_699_999_000);
let row = history_row_text(&p, 76, NOW);
assert!(row.starts_with("> "), "outbound row must start with '> ': {row:?}");
assert!(row.contains('✓'), "verified glyph missing: {row:?}");
assert!(row.contains("verified"), "verified word missing: {row:?}");
assert!(row.contains("0.001"), "amount missing: {row:?}");
}
#[test]
fn history_row_outbound_unverified_has_word_no_check() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(2, "out", "invoice", "500000000", "addr", "", Some("ef12".into()), false, 1_700_000_000);
let row = history_row_text(&p, 76, NOW);
assert!(row.starts_with("> "), "outbound row must start with '> ': {row:?}");
assert!(row.contains("unverified"), "unverified word missing: {row:?}");
assert!(!row.contains('✓'), "unverified must not have check glyph: {row:?}");
}
#[test]
fn history_row_inbound_uses_left_marker() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(3, "in", "payment", "2500000000", "addr", "", Some("deadbeef".into()), true, 1_700_000_000);
let row = history_row_text(&p, 76, NOW);
assert!(row.starts_with("< "), "inbound row must start with '< ': {row:?}");
assert!(row.contains("verified"), "verified word missing: {row:?}");
}
#[test]
fn history_row_no_txid_says_awaiting_receipt_not_dash() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(4, "in", "payment", "1000000000", "addr", "", None, false, 1_700_000_000);
let row = history_row_text(&p, 76, NOW);
assert!(row.contains("awaiting receipt"), "missing 'awaiting receipt': {row:?}");
assert!(!row.contains("--"), "bare dash instead of 'awaiting receipt': {row:?}");
}
#[test]
fn history_row_truncates_txid_within_width() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(5, "out", "tip", "1000", "addr", "memo", Some("a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3".into()), true, 1_700_000_000);
let row = history_row_text(&p, 40, NOW);
assert!(row.chars().count() <= 40, "row wider than 40: {} {row:?}", row.chars().count());
}
#[test]
fn history_row_ascii_fallback_has_no_emoji_glyphs() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
unsafe { std::env::set_var("ONIONWIRE_ASCII", "1") };
let p = payment(1, "out", "tip", "1000000000", "addr", "", Some("abcd".into()), true, 1_700_000_000);
let row = history_row_text(&p, 76, NOW);
assert!(row.is_ascii(), "ASCII fallback not pure ASCII: {row:?}");
assert!(row.contains("verified"), "ASCII verified word missing: {row:?}");
unsafe { std::env::remove_var("ONIONWIRE_ASCII") };
}
#[test]
fn history_detail_shows_all_fields_sanitized() {
let p = payment(
7,
"out",
"tip",
"2000000000",
"1A2B3C4D5E6F",
"for pizza",
Some("abcdef0123456789abcdef0123456789".into()),
true,
1_700_000_000,
);
let detail = history_detail(&p, 76, NOW);
let all = detail.join("\n");
assert!(all.contains("abcdef0123456789abcdef0123456789"), "full txid missing: {all:?}");
assert!(all.contains("1A2B3C4D5E6F"), "address missing: {all:?}");
assert!(all.contains("for pizza"), "memo missing: {all:?}");
assert!(all.contains("0.002"), "amount missing: {all:?}");
assert!(all.contains("outbound"), "direction missing: {all:?}");
assert!(all.contains("verified"), "verified state missing: {all:?}");
assert!(all.contains("1700000000") || all.contains("Nov"), "timestamp missing: {all:?}");
for line in &detail {
assert!(line.chars().count() <= 76, "detail line wider than 76: {} {line:?}", line.chars().count());
}
}
// F7 wallet-config screen (card t_7719eda3)
// ---------------------------------------------------------------------------
/// Fixture password that must NEVER appear in any rendered frame.
const FIXTURE_PASS: &str = "supersecret123";
/// Build a WalletConfigScreen for testing, with the given fields.
fn make_config(
rpc_url: &str,
rpc_login: &str,
no_spend: bool,
reveal: bool,
focus: ConfigField,
status: ConfigStatus,
) -> WalletConfigScreen {
WalletConfigScreen {
rpc_url: rpc_url.to_string(),
rpc_login: rpc_login.to_string(),
no_spend,
reveal,
focus,
status,
}
}
/// Render the F7 config screen through the real `draw_wallet_config` at the
/// given size and collect the result as a string.
fn config_screen_at(w: u16, h: u16, s: &WalletConfigScreen) -> String {
let backend = TestBackend::new(w, h);
let mut terminal = Terminal::new(backend).expect("terminal");
terminal.draw(|f| onionwire::tui::draw_wallet_config(f, s)).expect("draw");
screen_from(terminal.backend().buffer(), w, h)
}
#[test]
fn wallet_config_screen_renders_fields_and_footer() {
let s = make_config(
"http://127.0.0.1:18083",
"onionwire",
true,
false,
ConfigField::RpcUrl,
ConfigStatus::Idle,
);
for (w, h) in [(80u16, 24u16), (120, 40)] {
let screen = config_screen_at(w, h, &s);
for (y, row) in screen.lines().enumerate() {
if row.chars().count() > w as usize {
panic!("{w}x{h} row {y} wider than frame: {row:?}");
}
}
assert!(screen.contains("wallet config"), "{w}x{h}: title missing");
assert!(screen.contains("rpc_url"), "{w}x{h}: rpc_url label missing");
assert!(screen.contains("http://127.0.0.1:18083"), "{w}x{h}: url value missing");
assert!(
screen.contains("rpc_login"),
"{w}x{h}: rpc_login label missing"
);
assert!(screen.contains("no_spend"), "{w}x{h}: no_spend label missing");
assert!(
screen.contains("/tip disabled") || screen.contains("/tip off"),
"{w}x{h}: no_spend consequence missing"
);
assert!(screen.contains("> "), "{w}x{h}: focus marker missing");
assert!(screen.contains("Esc back"), "{w}x{h}: Esc back missing");
assert!(screen.contains("Tab"), "{w}x{h}: Tab hint missing"); }
}
#[test]
fn history_detail_hostile_memo_is_sanitized_inert_text() {
// C0 control chars + bidi override — must render as inert text, not affect
// the terminal or carry hidden directionality.
let hostile = "pay\x01now\u{202E}\u{202E}reverse";
let p = payment(8, "in", "payment", "500000000", "addr", hostile, Some("cafebabe".into()), false, 1_700_000_000);
let detail = history_detail(&p, 76, NOW);
let all = detail.join("\n");
// Bidi override must be stripped — the word "reverse" must appear in
// reading order, not visually flipped by a leftover override mark.
assert!(!all.contains('\u{202E}'), "bidi override survived sanitize: {all:?}");
assert!(!all.contains('\x01'), "C0 control survived sanitize: {all:?}");
assert!(all.contains("reverse"), "sanitized memo text lost: {all:?}");
}
#[test]
fn history_detail_no_txid_shows_awaiting_receipt() {
let p = payment(9, "in", "payment", "1000", "addr", "", None, false, 1_700_000_000);
let detail = history_detail(&p, 76, NOW);
let all = detail.join("\n");
assert!(all.contains("awaiting receipt"), "detail missing 'awaiting receipt': {all:?}");
}
#[test]
fn draw_history_list_at_80x24_fits_and_shows_rows() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let payments = vec![
payment(1, "out", "tip", "1000000000", "addr", "coffee", Some("abcd1234".into()), true, 1_699_999_000),
payment(2, "in", "payment", "2500000000", "addr", "", Some("deadbeef".into()), true, 1_700_000_001),
payment(3, "out", "invoice", "500000000", "addr", "", None, false, 1_700_000_002),
];
let backend = TestBackend::new(80, 24);
let mut terminal = Terminal::new(backend).expect("terminal");
terminal
.draw(|f| draw_history(f, &payments, 1, false, "alice", NOW))
.expect("draw");
let screen = screen_from(terminal.backend().buffer(), 80, 24);
for line in screen.lines() {
assert!(line.chars().count() <= 80, "80x24 history row wider than 80: {} {line:?}", line.chars().count());
}
assert!(screen.contains("alice"), "friend name missing from title: {screen}");
assert!(screen.contains("> "), "outbound marker missing: {screen}");
assert!(screen.contains("< "), "inbound marker missing: {screen}");
assert!(screen.contains("awaiting receipt"), "awaiting receipt missing: {screen}");
assert!(screen.contains("Enter detail"), "hint missing: {screen}");
assert!(screen.contains("Esc back"), "hint missing: {screen}");
}
#[test]
fn draw_history_empty_at_80x24_shows_designed_copy() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let backend = TestBackend::new(80, 24);
let mut terminal = Terminal::new(backend).expect("terminal");
terminal
.draw(|f| draw_history(f, &[], 0, false, "bob", NOW))
.expect("draw");
let screen = screen_from(terminal.backend().buffer(), 80, 24);
for line in screen.lines() {
assert!(line.chars().count() <= 80, "row wider than 80: {line:?}");
}
assert!(screen.contains("no payments with this friend yet"), "empty copy missing: {screen}");
}
#[test]
fn draw_history_detail_at_80x24_fits() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
force_unicode_mode();
let p = payment(1, "out", "tip", "1000000000", "1A2B3C4D5E6F", "coffee", Some("abcdef0123456789abcdef0123456789".into()), true, 1_700_000_000);
let backend = TestBackend::new(80, 24);
let mut terminal = Terminal::new(backend).expect("terminal");
terminal
.draw(|f| draw_history(f, std::slice::from_ref(&p), 0, true, "alice", NOW))
.expect("draw");
let screen = screen_from(terminal.backend().buffer(), 80, 24);
for line in screen.lines() {
assert!(line.chars().count() <= 80, "detail row wider than 80: {} {line:?}", line.chars().count());
}
assert!(screen.contains("awaiting receipt") || screen.contains("abcdef0123456789"), "detail content missing: {screen}");
}
#[test]
fn wallet_config_login_is_masked_by_default() {
let s = make_config(
"http://127.0.0.1:18083",
&format!("user:{FIXTURE_PASS}"),
false,
false,
ConfigField::RpcLogin,
ConfigStatus::Idle,
);
for (w, h) in [(80u16, 24u16), (120, 40)] {
let screen = config_screen_at(w, h, &s);
assert!(
!screen.contains(FIXTURE_PASS),
"{w}x{h}: fixture password leaked in frame:\n{screen}"
);
assert!(screen.contains("user"), "{w}x{h}: username not shown");
}
}
#[test]
fn wallet_config_login_mask_and_reveal_are_distinguishable_in_no_color() {
let _guard = ASCII_ENV.lock().expect("ascii env lock");
unsafe { std::env::set_var("NO_COLOR", "1") };
let masked = make_config(
"http://127.0.0.1:18083",
&format!("user:{FIXTURE_PASS}"),
false,
false,
ConfigField::RpcLogin,
ConfigStatus::Idle,
);
let screen = config_screen_at(80, 24, &masked);
assert!(
!screen.contains(FIXTURE_PASS),
"NO_COLOR frame leaked password:\n{screen}"
);
let revealed = make_config(
"http://127.0.0.1:18083",
&format!("user:{FIXTURE_PASS}"),
false,
true,
ConfigField::RpcLogin,
ConfigStatus::Idle,
);
let screen = config_screen_at(80, 24, &revealed);
assert!(
!screen.contains(FIXTURE_PASS),
"NO_COLOR revealed frame leaked password:\n{screen}"
);
let masked_ascii = config_screen_at(80, 24, &masked);
let revealed_ascii = config_screen_at(80, 24, &revealed);
assert!(
masked_ascii.contains('.')
|| masked_ascii.contains("reveal"),
"masked NO_COLOR frame has no distinguishing marker:\n{masked_ascii}"
);
assert!(
revealed_ascii.contains("user"),
"revealed NO_COLOR frame missing username:\n{revealed_ascii}"
);
unsafe { std::env::remove_var("NO_COLOR") };
}
#[test]
fn wallet_config_status_line_states() {
let idle = make_config("", "", false, false, ConfigField::Action, ConfigStatus::Idle);
let screen = config_screen_at(80, 24, &idle);
assert!(
!screen.contains("connected") && !screen.contains("saved") && !screen.contains("error:"),
"idle should have no status line:\n{screen}"
);
let testing = make_config("", "", false, false, ConfigField::Action, ConfigStatus::Testing);
let screen = config_screen_at(80, 24, &testing);
assert!(
screen.contains("testing connection"),
"testing status missing:\n{screen}"
);
let ok = make_config(
"",
"",
false,
false,
ConfigField::Action,
ConfigStatus::Tested(PingResult {
ok: true,
status: "connected".into(),
error: None,
}),
);
let screen = config_screen_at(80, 24, &ok);
assert!(
screen.contains("connected"),
"tested-ok status missing:\n{screen}"
);
let fail = make_config(
"",
"",
false,
false,
ConfigField::Action,
ConfigStatus::Tested(PingResult {
ok: false,
status: "not connected".into(),
error: Some("connection refused".into()),
}),
);
let screen = config_screen_at(80, 24, &fail);
assert!(
screen.contains("not connected"),
"tested-fail status missing:\n{screen}"
);
assert!(
screen.contains("connection refused"),
"tested-fail error detail missing:\n{screen}"
);
let saved_nc = make_config(
"",
"",
false,
false,
ConfigField::Action,
ConfigStatus::Saved(true, String::new()),
);
let screen = config_screen_at(80, 24, &saved_nc);
assert!(
screen.contains("saved"),
"saved-not-connected status missing:\n{screen}"
);
let saved_fail = make_config(
"",
"",
false,
false,
ConfigField::Action,
ConfigStatus::Saved(false, "bad url".into()),
);
let screen = config_screen_at(80, 24, &saved_fail);
assert!(
screen.contains("error:"),
"saved-fail status missing:\n{screen}"
);
assert!(
screen.contains("bad url"),
"saved-fail reason missing:\n{screen}"
);
}
#[test]
fn wallet_config_password_never_leaks_in_any_status() {
let cases: Vec<(&str, ConfigStatus)> = vec![
("idle", ConfigStatus::Idle),
("testing", ConfigStatus::Testing),
(
"tested-ok",
ConfigStatus::Tested(PingResult {
ok: true,
status: "connected".into(),
error: None,
}),
),
(
"tested-fail",
ConfigStatus::Tested(PingResult {
ok: false,
status: "not connected".into(),
error: Some(format!("{} leaked", FIXTURE_PASS)),
}),
),
("saved-ok", ConfigStatus::Saved(true, String::new())),
(
"saved-fail",
ConfigStatus::Saved(false, format!("error mentions {}", FIXTURE_PASS)),
),
];
for (name, status) in cases {
let s = make_config(
"http://127.0.0.1:18083",
&format!("user:{FIXTURE_PASS}"),
true,
false,
ConfigField::RpcUrl,
status,
);
let screen = config_screen_at(80, 24, &s);
assert!(
!screen.contains(FIXTURE_PASS),
"password leaked in {name} frame:\n{screen}"
);
}
}
#[test]
fn help_overlay_lists_f7_and_send_flow() {
let help = help_overlay_text();
for needle in [
"F7",
"F6 h",
"send chat",
"/pay",
"/tip",
"copy",
] {
assert!(help.contains(needle), "help overlay missing {needle:?}");
}
}
#[test]
fn wallet_config_focus_cycles_through_fields() {
assert_eq!(ConfigField::RpcUrl.next(), ConfigField::RpcLogin);
assert_eq!(ConfigField::RpcLogin.next(), ConfigField::NoSpend);
assert_eq!(ConfigField::NoSpend.next(), ConfigField::Action);
assert_eq!(ConfigField::Action.next(), ConfigField::RpcUrl);
assert_eq!(ConfigField::RpcUrl.prev(), ConfigField::Action);
assert_eq!(ConfigField::RpcLogin.prev(), ConfigField::RpcUrl);
assert_eq!(ConfigField::NoSpend.prev(), ConfigField::RpcLogin);
assert_eq!(ConfigField::Action.prev(), ConfigField::NoSpend);
}