test(lite-backend): port the core-crate tests to the current API

The lite backend core's in-crate tests no longer compiled (119 errors in
lightwallet/tests.rs and the lightclient and walletzkey test modules):
they still used the old LightWallet::new and send_to_address signatures,
the removed extfvks/extsks/zaddress fields and the old new_from_phrase
and do_send arities. So `cargo test` built nothing and no backend change
could be checked against them.

Port them, and the commands and checkpoints tests, to the current API,
touching only #[cfg(test)] code:
- LightWallet::new takes 4 arguments, send_to_address 7 (with an
  explicit default fee, returning (txid, raw tx)), new_from_phrase 5 and
  do_send 2; keys are read through zkeys and tkeys;
- every config uses the "main" chain: creating a wallet on the "test"
  chain panics in base58_pubkey_address, so LightClient::unconnected
  (which hard-codes "test") is no longer used;
- every LightClient lives in a temporary data dir, so a test cannot
  write to the real ~/.silentdragonxlite or ~/.zcash-params;
- ten send_to_address recipient lists garbled by an upstream change in
  2020 are restored from the upstream history.

Expectations that contradicted deliberate current behaviour are updated;
none is ignored:
- a pending send's mempool entry sits at the tip, not tip+1, and
  zbalance no longer counts a note with a pending spend;
- keys cannot be added to an encrypted wallet, so the encrypted-receive
  tests derive their second address before encrypting;
- the t-address vectors are m/44'/141'/0'/0/{0,1}, checked against an
  independent BIP32 derivation; the z-address vectors record the current
  output;
- test_addresses and test_checkpoints follow the current address count
  and checkpoint tables.

All 43 tests pass on the unchanged production code (three runs) and
leave the real wallet and params directories untouched; that list is the
regression baseline for the following commits. They cover balances,
address derivation, bookkeeping, the mempool, encryption, serialization
and rollback, but none verifies a proof, an anchor or a witness.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 09:50:03 -05:00
co-authored by Claude Opus 5.5
parent 3f13d79ccb
commit 8895038c40
5 changed files with 196 additions and 168 deletions
@@ -1758,9 +1758,17 @@ pub mod tests {
static ref TEST_SEED: String = "youth strong sweet gorilla hammer unhappy congress stamp left stereo riot salute road tag clean toilet artefact fork certain leopard entire civil degree wonder".to_string();
}
// Every client here is on the "main" chain (the "test" chain, which LightClient::unconnected
// hard-codes, panics in base58_pubkey_address when the wallet is created) and lives in a temp
// data dir, so nothing is ever written to the real ~/.silentdragonxlite.
fn main_config(tmp: &TempDir) -> LightClientConfig {
LightClientConfig::create_unconnected("main".to_string(), tmp.path().to_str().map(|s| s.to_string()))
}
#[test]
pub fn test_encrypt_decrypt() {
let lc = super::LightClient::unconnected(TEST_SEED.to_string(), None).unwrap();
let tmp = TempDir::new("lctest").unwrap();
let lc = LightClient::new_from_phrase(TEST_SEED.to_string(), &main_config(&tmp), 0, 0, false).unwrap();
assert!(!lc.do_export(None).is_err());
assert!(!lc.do_new_address("zs").is_err());
@@ -1773,7 +1781,7 @@ pub mod tests {
assert!(lc.do_seed_phrase().is_err());
assert!(lc.do_new_address("R").is_err());
assert!(lc.do_new_address("zs").is_err());
assert!(lc.do_send(vec![("zs", 0, None)]).is_err());
assert!(lc.do_send(vec![("zs", 0, None)], &10000).is_err());
// Do a unlock, and make sure it all works now
lc.wallet.write().unwrap().unlock("password".to_string()).unwrap();
@@ -1793,11 +1801,12 @@ pub mod tests {
#[test]
pub fn test_addresses() {
let lc = super::LightClient::unconnected(TEST_SEED.to_string(), None).unwrap();
let tmp = TempDir::new("lctest").unwrap();
let lc = LightClient::new_from_phrase(TEST_SEED.to_string(), &main_config(&tmp), 0, 50, false).unwrap();
{
let addresses = lc.do_address();
// When restoring from seed, there should be 5+1 addresses
// When restoring from seed with 50 extra z-addresses, there should be 50+1 z and 5+1 t addresses
assert_eq!(addresses["z_addresses"].len(), 51);
assert_eq!(addresses["t_addresses"].len(), 6);
}
@@ -1811,21 +1820,23 @@ pub mod tests {
let addresses = lc.do_address();
assert_eq!(addresses["z_addresses"].len(), 52);
assert_eq!(addresses["z_addresses"][49], zaddr1);
assert_eq!(addresses["z_addresses"][50], zaddr2);
assert_eq!(addresses["z_addresses"].len(), 53);
assert_eq!(addresses["z_addresses"][51], zaddr1);
assert_eq!(addresses["z_addresses"][52], zaddr2);
assert_eq!(addresses["t_addresses"].len(), 8);
assert_eq!(addresses["t_addresses"][6], taddr1);
assert_eq!(addresses["t_addresses"][7], taddr2);
use std::sync::{Arc, RwLock, Mutex};
use std::sync::atomic::AtomicBool;
use crate::lightclient::{WalletStatus, LightWallet};
// When creating a new wallet, there is only 1 address
let config = LightClientConfig::create_unconnected("test".to_string(), None);
let tmp2 = TempDir::new("lctest").unwrap();
let config = main_config(&tmp2);
let lc = LightClient {
wallet : Arc::new(RwLock::new(LightWallet::new(None, &config, 0).unwrap())),
wallet : Arc::new(RwLock::new(LightWallet::new(None, &config, 0, 0).unwrap())),
config : config,
sapling_output : vec![],
sapling_spend : vec![],
@@ -1843,7 +1854,8 @@ pub mod tests {
#[test]
pub fn test_bad_import() {
let lc = super::LightClient::unconnected(TEST_SEED.to_string(), None).unwrap();
let tmp = TempDir::new("lctest").unwrap();
let lc = LightClient::new_from_phrase(TEST_SEED.to_string(), &main_config(&tmp), 0, 0, false).unwrap();
assert!(lc.do_import_sk("bad_priv_key".to_string(), 0).is_err());
assert!(lc.do_import_vk("bad_view_key".to_string(), 0).is_err());
@@ -1857,7 +1869,7 @@ pub fn test_bad_import() {
let dir_name = tmp.path().to_str().map(|s| s.to_string());
// A lightclient to a new, empty directory works.
let config = LightClientConfig::create_unconnected("test".to_string(), dir_name);
let config = LightClientConfig::create_unconnected("main".to_string(), dir_name);
let lc = LightClient::new(&config, 0).unwrap();
let seed = lc.do_seed_phrase().unwrap()["seed"].as_str().unwrap().to_string();
lc.do_save().unwrap();
@@ -1866,7 +1878,7 @@ pub fn test_bad_import() {
assert!(LightClient::new(&config, 0).is_err());
// new_from_phrase will not work either, again, because wallet file exists
assert!(LightClient::new_from_phrase(TEST_SEED.to_string(), &config, 0, false).is_err());
assert!(LightClient::new_from_phrase(TEST_SEED.to_string(), &config, 0, 0, false).is_err());
// Creating a lightclient to the same dir without a seed should re-read the same wallet
// file and therefore the same seed phrase
@@ -1879,13 +1891,13 @@ pub fn test_bad_import() {
let tmp = TempDir::new("lctest").unwrap();
let dir_name = tmp.path().to_str().map(|s| s.to_string());
let config = LightClientConfig::create_unconnected("test".to_string(), dir_name);
let config = LightClientConfig::create_unconnected("main".to_string(), dir_name);
// read_from_disk will fail, because the dir doesn't exist
assert!(LightClient::read_from_disk(&config).is_err());
// New from phrase should work becase a file doesn't exist already
let lc = LightClient::new_from_phrase(TEST_SEED.to_string(), &config, 0, false).unwrap();
let lc = LightClient::new_from_phrase(TEST_SEED.to_string(), &config, 0, 0, false).unwrap();
assert_eq!(TEST_SEED.to_string(), lc.do_seed_phrase().unwrap()["seed"].as_str().unwrap().to_string());
lc.do_save().unwrap();
@@ -1902,7 +1914,7 @@ pub fn test_bad_import() {
let dir_name = tmp.path().to_str().map(|s| s.to_string());
// A lightclient to a new, empty directory works.
let config = LightClientConfig::create_unconnected("test".to_string(), dir_name);
let config = LightClientConfig::create_unconnected("main".to_string(), dir_name);
let lc = LightClient::new(&config, 0).unwrap();
let seed = lc.do_seed_phrase().unwrap()["seed"].as_str().unwrap().to_string();
lc.do_save().unwrap();