diff --git a/ios/CoveTests/CloudBackupIOSSafetyHelpersTests.swift b/ios/CoveTests/CloudBackupIOSSafetyHelpersTests.swift index 3613237de..5bf45da33 100644 --- a/ios/CoveTests/CloudBackupIOSSafetyHelpersTests.swift +++ b/ios/CoveTests/CloudBackupIOSSafetyHelpersTests.swift @@ -457,7 +457,8 @@ final class CloudBackupIOSSafetyHelpersTests: XCTestCase { @MainActor func testBackupReadUsesLocalTargetBeforeMetadata() async throws { - let fixture = makeICloudMetadataFixture() + // a slow simulator can exceed a short deadline on the direct read and fall back to metadata + let fixture = makeICloudMetadataFixture(defaultTimeout: 60) defer { fixture.removeContainer() } let location = try XCTUnwrap(backupLocations().first) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 05622f6c9..9217f5034 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ "act-zero", "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -304,7 +304,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -362,7 +362,7 @@ dependencies = [ "rustc-hash", "serde", "serde_derive", - "syn", + "syn 2.0.117", ] [[package]] @@ -402,13 +402,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.89" +version = "0.1.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 3.0.6", ] [[package]] @@ -1162,7 +1162,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -1586,7 +1586,6 @@ dependencies = [ "hex", "minicbor 2.2.1", "pubport", - "serde_json", "thiserror 2.0.18", "tracing", "uniffi", @@ -1823,7 +1822,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -1861,7 +1860,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn", + "syn 2.0.117", "unicode-xid", ] @@ -1932,7 +1931,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -2006,7 +2005,7 @@ checksum = "44f23cf4b44bfce11a86ace86f8a73ffdec849c9fd00a386a53d278bd9e81fb3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -2313,7 +2312,7 @@ checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -2824,7 +2823,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 2.0.117", "unic-langid", ] @@ -2838,7 +2837,7 @@ dependencies = [ "i18n-config", "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3034,7 +3033,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3121,7 +3120,7 @@ checksum = "e000de030ff8022ea1da3f466fbb0f3a809f5e51ed31f6dd931c35181ad8e6d7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3166,7 +3165,7 @@ dependencies = [ "quote", "rustc_version", "simd_cesu8", - "syn", + "syn 2.0.117", ] [[package]] @@ -3185,7 +3184,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" dependencies = [ "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3415,7 +3414,7 @@ checksum = "bd2209fff77f705b00c737016a48e73733d7fbccb8b007194db148f03561fb70" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3426,7 +3425,7 @@ checksum = "294f0a0c161c510e9746adf546b8b044fbb0b00677d7dfc9a2452f9fdf63439b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3607,7 +3606,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3864,7 +3863,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3893,7 +3892,7 @@ checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -4033,7 +4032,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn", + "syn 2.0.117", ] [[package]] @@ -4064,7 +4063,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -4092,7 +4091,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4488a4a36b9a4ba6b9334a32a39971f77c1436ec82c38707bce707699cc3bbcb" dependencies = [ "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -4578,7 +4577,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn", + "syn 2.0.117", "walkdir", ] @@ -4774,7 +4773,7 @@ checksum = "1783eabc414609e28a5ba76aee5ddd52199f7107a0b24c2e9746a1ecc34a683d" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -4907,7 +4906,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -5114,7 +5113,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -5134,6 +5133,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "sync_wrapper" version = "1.0.2" @@ -5151,7 +5161,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -5208,7 +5218,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -5219,7 +5229,7 @@ checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -5294,7 +5304,7 @@ checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -5432,7 +5442,7 @@ checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -5649,7 +5659,7 @@ dependencies = [ "indexmap", "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -5663,7 +5673,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn", + "syn 2.0.117", "toml 1.1.2+spec-1.1.0", "uniffi_meta", ] @@ -5889,7 +5899,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn", + "syn 2.0.117", "wasm-bindgen-shared", ] @@ -6232,7 +6242,7 @@ dependencies = [ "heck", "indexmap", "prettyplease", - "syn", + "syn 2.0.117", "wasm-metadata", "wit-bindgen-core", "wit-component", @@ -6248,7 +6258,7 @@ dependencies = [ "prettyplease", "proc-macro2", "quote", - "syn", + "syn 2.0.117", "wit-bindgen-core", "wit-bindgen-rust", ] @@ -6388,7 +6398,7 @@ checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", "synstructure", ] @@ -6409,7 +6419,7 @@ checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -6429,7 +6439,7 @@ checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", "synstructure", ] @@ -6450,7 +6460,7 @@ checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -6484,7 +6494,7 @@ checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] diff --git a/rust/crates/cove-bdk-progressive-scan/src/core.rs b/rust/crates/cove-bdk-progressive-scan/src/core.rs index 6494bc288..d7de2152b 100644 --- a/rust/crates/cove-bdk-progressive-scan/src/core.rs +++ b/rust/crates/cove-bdk-progressive-scan/src/core.rs @@ -217,7 +217,9 @@ pub(crate) fn prevout_fetch_plan(update: &TxUpdate) -> Ve #[cfg(test)] mod tests { - use bdk_wallet::chain::bitcoin::{ScriptBuf, Transaction, absolute, transaction}; + use bdk_wallet::chain::bitcoin::{ + OutPoint, ScriptBuf, Transaction, TxIn, absolute, transaction, + }; use bdk_wallet::chain::spk_client::SpkWithExpectedTxids; use super::{SpkBatcher, StopGapTracker, prevout_fetch_plan}; @@ -264,7 +266,7 @@ mod tests { Transaction { version: transaction::Version::TWO, lock_time: absolute::LockTime::ZERO, - input: Vec::new(), + input: vec![TxIn { previous_output: OutPoint::null(), ..TxIn::default() }], output: Vec::new(), } .into(), diff --git a/rust/crates/cove-bip39/src/lib.rs b/rust/crates/cove-bip39/src/lib.rs index 5c343972a..6406e22d2 100644 --- a/rust/crates/cove-bip39/src/lib.rs +++ b/rust/crates/cove-bip39/src/lib.rs @@ -200,8 +200,6 @@ mod test { .words() .collect::>(); - assert_eq!(words.len(), 24); - let first_11 = words[..23].join(" "); let last = words.last().unwrap().to_string(); diff --git a/rust/crates/cove-cspp/src/backup_data.rs b/rust/crates/cove-cspp/src/backup_data.rs index 5aac6deb0..0260622e3 100644 --- a/rust/crates/cove-cspp/src/backup_data.rs +++ b/rust/crates/cove-cspp/src/backup_data.rs @@ -408,19 +408,6 @@ mod tests { assert_eq!(WalletBackupVersion::try_from(3), Err(UnsupportedWalletBackupVersion(3))); } - #[test] - fn encrypted_wallet_backup_reports_typed_version() { - let backup = EncryptedWalletBackup { - version: 2, - remote_metadata: RemotePayloadMetadata::default(), - wallet_salt: [0xAA; 32], - nonce: [0xBB; 12], - ciphertext: vec![], - }; - - assert_eq!(backup.backup_version(), Ok(WalletBackupVersion::V2)); - } - #[test] fn encrypted_wallet_backup_json_defaults_missing_payload_metadata() { let json = serde_json::json!({ diff --git a/rust/crates/cove-nfc/src/lib.rs b/rust/crates/cove-nfc/src/lib.rs index bbd0c33a0..642557168 100644 --- a/rust/crates/cove-nfc/src/lib.rs +++ b/rust/crates/cove-nfc/src/lib.rs @@ -258,7 +258,6 @@ mod tests { let mut chunks_processed = 0; let export_bytes = export_bytes(); - assert_eq!(export_bytes.len(), 3044); for chunk in export_bytes.chunks(100) { let mut chunk_data = std::mem::take(&mut data); diff --git a/rust/crates/cove-nfc/src/parser.rs b/rust/crates/cove-nfc/src/parser.rs index d0ecc75b6..bbde1c483 100644 --- a/rust/crates/cove-nfc/src/parser.rs +++ b/rust/crates/cove-nfc/src/parser.rs @@ -283,7 +283,6 @@ mod tests { // export let export = &EXPORT[0..3043]; let mut data = super::stream::new(export); - assert_eq!(data.len(), export.len()); let message_info = parse_message_info(&mut data).unwrap(); assert_eq!(message_info.full_message_length, 3043); diff --git a/rust/crates/cove-types/src/fees.rs b/rust/crates/cove-types/src/fees.rs index 0c9ee2165..00161ea21 100644 --- a/rust/crates/cove-types/src/fees.rs +++ b/rust/crates/cove-types/src/fees.rs @@ -520,22 +520,6 @@ mod tests { assert_eq!(option_with_total.sats_per_vbyte_string(), "3.20 sats/vbyte"); } - #[test] - fn fee_rate_options_without_totals_use_no_total_constructor() { - let base = FeeRateOptions { - fast: FeeRateOption::new(FeeSpeed::Fast, 3.2), - medium: FeeRateOption::new(FeeSpeed::Medium, 2.1), - slow: FeeRateOption::new(FeeSpeed::Slow, 1.0), - }; - - let options = FeeRateOptionsWithTotalFee::without_totals(base); - - assert_eq!(options.fast, FeeRateOptionWithTotalFee::without_total(base.fast)); - assert_eq!(options.medium, FeeRateOptionWithTotalFee::without_total(base.medium)); - assert_eq!(options.slow, FeeRateOptionWithTotalFee::without_total(base.slow)); - assert_eq!(options.custom, None); - } - #[test] fn grouped_integer_formatting_matches_platform_number_format() { assert_eq!(0_u32.thousands_int(), "0"); diff --git a/rust/crates/cove-types/src/transaction/tx_id.rs b/rust/crates/cove-types/src/transaction/tx_id.rs index 01f3bbee8..4e760a31f 100644 --- a/rust/crates/cove-types/src/transaction/tx_id.rs +++ b/rust/crates/cove-types/src/transaction/tx_id.rs @@ -122,18 +122,3 @@ impl redb::Value for TxId { redb::TypeName::new("cove::transaction::TxId") } } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_txid_borrow() { - let txid = TxId::preview_new(); - let txid_borrow: &bitcoin::Txid = txid.borrow(); - assert_eq!(txid_borrow, &txid.0); - - let txid_borrow: &TxId = txid.borrow(); - assert_eq!(txid_borrow, &txid); - } -} diff --git a/rust/crates/cove-ur/Cargo.toml b/rust/crates/cove-ur/Cargo.toml index 860878eb3..a32566dd4 100644 --- a/rust/crates/cove-ur/Cargo.toml +++ b/rust/crates/cove-ur/Cargo.toml @@ -19,8 +19,5 @@ hex = { workspace = true } tracing = { workspace = true } cove-util = { path = "../cove-util" } -[dev-dependencies] -serde_json = { workspace = true } - [lints] workspace = true diff --git a/rust/crates/cove-ur/src/crypto_psbt.rs b/rust/crates/cove-ur/src/crypto_psbt.rs index 7f25faef9..05e28a9b8 100644 --- a/rust/crates/cove-ur/src/crypto_psbt.rs +++ b/rust/crates/cove-ur/src/crypto_psbt.rs @@ -210,13 +210,6 @@ mod tests { BdkPsbt::deserialize(&bytes).unwrap() } - #[test] - fn test_crypto_psbt_new() { - let psbt = test_psbt(); - let crypto_psbt = CryptoPsbt::new(psbt.clone()); - assert_eq!(crypto_psbt.psbt(), &psbt); - } - #[test] fn test_crypto_psbt_from_bytes() { let bytes = hex::decode(TEST_PSBT_HEX).unwrap(); @@ -246,14 +239,9 @@ mod tests { let cbor = crypto_psbt.to_cbor().unwrap(); assert!(!cbor.is_empty()); + // cbor major type 2 is byte string assert_eq!(cbor[0] >> 5, 2); - - let mut expected_cbor = Vec::new(); - let mut encoder = Encoder::new(&mut expected_cbor); - encoder.bytes(&crypto_psbt.to_bytes()).unwrap(); - - assert_eq!(cbor, expected_cbor); } #[test] diff --git a/rust/crates/cove-ur/src/crypto_seed.rs b/rust/crates/cove-ur/src/crypto_seed.rs index 0b70dbbb7..dd6e62de9 100644 --- a/rust/crates/cove-ur/src/crypto_seed.rs +++ b/rust/crates/cove-ur/src/crypto_seed.rs @@ -191,18 +191,6 @@ mod tests { use super::*; use std::str::FromStr; - #[test] - fn test_crypto_seed_new() { - // 16-byte entropy (128 bits = 12 word mnemonic) - let entropy = vec![0x12; 16]; - let seed = CryptoSeed::new(entropy.clone()); - - assert_eq!(seed.payload, entropy); - assert!(seed.creation_date.is_none()); - assert!(seed.name.is_none()); - assert!(seed.note.is_none()); - } - #[test] fn test_crypto_seed_from_mnemonic() { let mnemonic_str = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; diff --git a/rust/crates/cove-ur/src/lib.rs b/rust/crates/cove-ur/src/lib.rs index 748739f5c..2c16766ab 100644 --- a/rust/crates/cove-ur/src/lib.rs +++ b/rust/crates/cove-ur/src/lib.rs @@ -83,12 +83,5 @@ mod tests { // verify we get the original JSON back let decoded_json = std::str::from_utf8(decoded_bytes).unwrap(); assert_eq!(decoded_json, passport_json); - - // parse the JSON and verify key fields - let parsed: serde_json::Value = serde_json::from_str(decoded_json).unwrap(); - assert_eq!(parsed["xfp"].as_str().unwrap(), "73c5da0a"); - assert_eq!(parsed["bip84"]["deriv"].as_str().unwrap(), "m/84'/0'/0'"); - assert!(parsed["bip84"]["xpub"].as_str().unwrap().starts_with("zpub")); - assert!(parsed["bip84"]["first"].as_str().unwrap().starts_with("bc1q")); } } diff --git a/rust/src/backup/recovery/tests.rs b/rust/src/backup/recovery/tests.rs index de77d0664..a39b1fccc 100644 --- a/rust/src/backup/recovery/tests.rs +++ b/rust/src/backup/recovery/tests.rs @@ -567,6 +567,31 @@ fn empty_wallet_data_directory_is_not_an_occupied_restore_artifact() { fs::remove_dir(directory).unwrap(); } +#[cfg(unix)] +#[test] +fn unreadable_wallet_data_blocks_restore_snapshot() { + use std::os::unix::fs::PermissionsExt as _; + + let _guard = crate::test_support::global_state_test_lock().blocking_lock(); + crate::database::test_support::delete_database(); + crate::test_support::init_test_keychain(); + crate::test_support::shared_mock_keychain().reset(); + + let wallet_id = WalletId::preview_new_random(); + let directory = crate::database::wallet_data::wallet_data_directory_path(&wallet_id); + fs::create_dir_all(&directory).unwrap(); + fs::set_permissions(&directory, fs::Permissions::from_mode(0o000)).unwrap(); + + let id = ValidatedRestoreWalletId::validate(&wallet_id).unwrap(); + let result = RestoreArtifactSnapshot::capture(&id); + + fs::set_permissions(&directory, fs::Permissions::from_mode(0o755)).unwrap(); + fs::remove_dir(&directory).unwrap(); + + // unreadable wallet data must not look like an empty restore target + assert!(matches!(result, Err(BackupError::Restore(_)))); +} + #[test] fn nested_wallet_data_cleanup_preserves_existing_entries() { let _guard = crate::test_support::global_state_test_lock().blocking_lock(); diff --git a/rust/src/database/cloud_backup.rs b/rust/src/database/cloud_backup.rs index 6cb35ab20..8cf15106e 100644 --- a/rust/src/database/cloud_backup.rs +++ b/rust/src/database/cloud_backup.rs @@ -330,13 +330,6 @@ mod tests { assert_eq!(state.disabling().map(|disabling| disabling.disable_generation), Some(7)); } - #[test] - fn reset_enable_does_not_inherit_pending_restore_all_marker() { - let enabled = PersistedCloudBackupState::mark_enabled_reset_verification(20, 3); - - assert!(enabled.pending_restore_all().is_none()); - } - #[test] fn verification_prompt_requires_newer_request() { let state = configured_state( @@ -368,43 +361,4 @@ mod tests { assert!(!state.should_prompt_verification()); } - - #[test] - fn blob_sync_state_helpers_reflect_state() { - let confirmed = PersistedCloudBlobSyncState::wallet( - "ns-1".into(), - "wallet-a".into(), - "wallet-a".into(), - PersistedCloudBlobState::Confirmed(CloudBlobConfirmedState { - revision_hash: "rev-1".into(), - confirmed_at: 42, - }), - ); - - assert!(!confirmed.is_dirty()); - - let dirty = confirmed - .with_state(PersistedCloudBlobState::Dirty(CloudBlobDirtyState { changed_at: 10 })); - - assert!(dirty.is_dirty()); - } - - #[test] - fn uploaded_pending_confirmation_tracks_attempts() { - let state = PersistedCloudBlobSyncState::wallet( - "ns-1".into(), - "wallet-a".into(), - "wallet-a".into(), - PersistedCloudBlobState::UploadedPendingConfirmation( - CloudBlobUploadedPendingConfirmationState { - revision_hash: "rev-1".into(), - uploaded_at: 10, - attempt_count: 3, - last_checked_at: Some(12), - }, - ), - ); - - assert!(state.is_uploaded_pending_confirmation()); - } } diff --git a/rust/src/database/historical_price/record.rs b/rust/src/database/historical_price/record.rs index 3ac108092..b10ab2455 100644 --- a/rust/src/database/historical_price/record.rs +++ b/rust/src/database/historical_price/record.rs @@ -289,15 +289,6 @@ mod tests { assert_eq!(CurrencyFlag::from(rec), expected); } - #[test] - fn round_trip_flag_bits() { - let rec = make_record(true, false, true, false, true, false); - let flag = CurrencyFlag::from(rec); - let raw: u8 = flag.bits(); - let parsed = CurrencyFlag::from_bits_truncate(raw); - assert_eq!(parsed, flag); - } - #[test] fn round_trip_records() { let record = HistoricalPriceRecord { diff --git a/rust/src/database/migration/bdk.rs b/rust/src/database/migration/bdk.rs index 2414e81cd..13656fe7b 100644 --- a/rust/src/database/migration/bdk.rs +++ b/rust/src/database/migration/bdk.rs @@ -5,7 +5,7 @@ use std::{ sync::Arc, }; -use eyre::{Context as _, Result, bail}; +use eyre::{Context as _, Result, bail, eyre}; use tracing::{error, info, warn}; use crate::bootstrap::Migration; @@ -162,8 +162,8 @@ fn checkpoint_plaintext_auxiliary_files(path: &Path) -> Result<()> { clean_auxiliary_files(path); Ok(()) } - Ok(busy) => bail!("plaintext WAL checkpoint busy={busy} at {}", path.display()), - Err(error) => bail!("plaintext WAL checkpoint failed at {}: {error}", path.display()), + Ok(busy) => Err(eyre!("plaintext WAL checkpoint busy={busy} at {}", path.display())), + Err(error) => Err(eyre!("plaintext WAL checkpoint failed at {}: {error}", path.display())), } } diff --git a/rust/src/database/migration/redb.rs b/rust/src/database/migration/redb.rs index 231e2710b..1a1a64cbb 100644 --- a/rust/src/database/migration/redb.rs +++ b/rust/src/database/migration/redb.rs @@ -335,7 +335,7 @@ fn preserved_plaintext_path(source: &Path) -> Result { return Ok(candidate); } - eyre::bail!("failed to find a path for preserving plaintext source {}", source.display()) + Err(eyre::eyre!("failed to find a path for preserving plaintext source {}", source.display())) } fn main_table_policy(source_path: &Path) -> TableCopyPolicy { diff --git a/rust/src/database/migration/redb/recovery.rs b/rust/src/database/migration/redb/recovery.rs index 818f687ea..f0de7ba65 100644 --- a/rust/src/database/migration/redb/recovery.rs +++ b/rust/src/database/migration/redb/recovery.rs @@ -273,5 +273,5 @@ fn preserve_corrupt_file(path: &Path) -> Result { return Ok(candidate); } - eyre::bail!("failed to find a path for preserving corrupt database {}", path.display()) + Err(eyre::eyre!("failed to find a path for preserving corrupt database {}", path.display())) } diff --git a/rust/src/database/wallet_data.rs b/rust/src/database/wallet_data.rs index 4c4ae7676..0020c0354 100644 --- a/rust/src/database/wallet_data.rs +++ b/rust/src/database/wallet_data.rs @@ -600,19 +600,6 @@ pub(crate) fn remove_wallet_artifact(path: &Path) -> std::io::Result<()> { } } -#[cfg(test)] -fn directory_contains_wallet_data(directory: &Path) -> bool { - let metadata = match std::fs::symlink_metadata(directory) { - Ok(metadata) => metadata, - Err(error) => return error.kind() != std::io::ErrorKind::NotFound, - }; - if metadata.file_type().is_symlink() || !metadata.is_dir() { - return true; - } - - std::fs::read_dir(directory).map(|mut entries| entries.next().is_some()).unwrap_or(true) -} - /// Drop all cached wallet data connections and open locks pub fn clear_database_connections() { DATABASE_CONNECTIONS.write().clear(); @@ -699,15 +686,6 @@ mod tests { use super::*; - #[test] - fn unreadable_wallet_data_path_is_treated_as_occupied() { - let tmp = tempfile::tempdir().expect("failed to create temp dir"); - let parent_file = tmp.path().join("not-a-directory"); - std::fs::write(&parent_file, b"occupied").expect("failed to create parent file"); - - assert!(directory_contains_wallet_data(&parent_file.join("wallet"))); - } - #[test] fn deleting_missing_wallet_data_does_not_create_its_directory() { let wallet_id = WalletId::preview_new_random(); @@ -865,26 +843,6 @@ mod tests { assert_eq!(db.get_receive_address_cache().unwrap(), Some(cache)); } - #[test] - fn receive_address_cache_visible_window_start_updates_timer_only() { - let wallet_id = WalletId::preview_new_random(); - let cache = ReceiveAddressCache { - derivation_index: 7, - first_shown_at_secs: 1_700_000_000, - wallet_id: wallet_id.clone(), - network: Network::Signet, - address_type: WalletAddressType::NativeSegwit, - }; - - let reset = cache.with_visible_window_start(1_700_000_300); - - assert_eq!(reset.derivation_index, 7); - assert_eq!(reset.first_shown_at_secs, 1_700_000_300); - assert_eq!(reset.wallet_id, wallet_id); - assert_eq!(reset.network, Network::Signet); - assert_eq!(reset.address_type, WalletAddressType::NativeSegwit); - } - #[test] fn delete_receive_address_cache_clears_cache() { let wallet_id = WalletId::preview_new_random(); diff --git a/rust/src/diagnostics.rs b/rust/src/diagnostics.rs index cc855e505..26c4d3fa6 100644 --- a/rust/src/diagnostics.rs +++ b/rust/src/diagnostics.rs @@ -451,7 +451,6 @@ mod tests { assert!(preview.contains(" DeepVerificationReport { - DeepVerificationReport { - master_key_wrapper_repaired: false, - local_master_key_repaired: false, - credential_recovered: false, - wallets_verified: 0, - wallet_issues: Default::default(), - detail: None, - } - } - - #[test] - fn manual_verification_preserves_source() { - let effect = CloudBackupVerificationCoordinator::begin_manual( - CloudBackupVerificationSource::Onboarding, - ); - - assert_eq!( - effect.presentation, - Some(CloudBackupVerificationPresentation::ManualVerifying { - source: CloudBackupVerificationSource::Onboarding - }) - ); - assert_eq!(effect.verification, Some(VerificationState::Verifying)); - } - #[test] fn background_confirmation_clears_interactive_verification() { let effect = CloudBackupVerificationCoordinator::begin_background_confirmation( @@ -240,22 +214,6 @@ mod tests { ); } - #[test] - fn completion_preserves_source() { - let effect = CloudBackupVerificationCoordinator::complete( - CloudBackupVerificationSource::CloudBackupDetail, - default_report(), - ); - - assert_eq!( - effect.presentation, - Some(CloudBackupVerificationPresentation::Completed { - source: CloudBackupVerificationSource::CloudBackupDetail - }) - ); - assert!(matches!(effect.verification, Some(VerificationState::Verified(_)))); - } - #[test] fn failed_preserves_source() { let failure = DeepVerificationFailure::retry("verification failed", None, None); @@ -291,69 +249,13 @@ mod tests { ); } - #[test] - fn decision_transitions_preserve_source() { - let decision = CloudBackupVerificationCoordinator::needs_decision( - CloudBackupVerificationReason::BackupChanged, - CloudBackupVerificationSource::RootPrompt, - ); - - assert_eq!( - decision.presentation, - Some(CloudBackupVerificationPresentation::NeedsDecision { - reason: CloudBackupVerificationReason::BackupChanged, - source: CloudBackupVerificationSource::RootPrompt, - }) - ); - - let hidden = CloudBackupVerificationCoordinator::dismiss_decision( - CloudBackupVerificationSource::RootPrompt, - ); - - assert_eq!( - hidden.presentation, - Some(CloudBackupVerificationPresentation::Hidden { - source: Some(CloudBackupVerificationSource::RootPrompt), - }) - ); - } - - #[test] - fn current_source_preserves_background_source() { - assert_eq!( - CloudBackupVerificationCoordinator::current_source( - &CloudBackupVerificationPresentation::BackgroundConfirming( - CloudBackupVerificationSource::Onboarding, - ), - ), - CloudBackupVerificationSource::Onboarding - ); - } - #[test] fn current_source_uses_embedded_or_default_source() { - assert_eq!( - CloudBackupVerificationCoordinator::current_source( - &CloudBackupVerificationPresentation::Hidden { - source: Some(CloudBackupVerificationSource::CloudBackupDetail), - }, - ), - CloudBackupVerificationSource::CloudBackupDetail - ); assert_eq!( CloudBackupVerificationCoordinator::current_source( &CloudBackupVerificationPresentation::Hidden { source: None }, ), CloudBackupVerificationSource::Settings ); - assert_eq!( - CloudBackupVerificationCoordinator::current_source( - &CloudBackupVerificationPresentation::NeedsDecision { - reason: CloudBackupVerificationReason::BackupChanged, - source: CloudBackupVerificationSource::Onboarding, - }, - ), - CloudBackupVerificationSource::Onboarding - ); } } diff --git a/rust/src/manager/cloud_backup_manager/wallets.rs b/rust/src/manager/cloud_backup_manager/wallets.rs index fd318d054..e1cd1e346 100644 --- a/rust/src/manager/cloud_backup_manager/wallets.rs +++ b/rust/src/manager/cloud_backup_manager/wallets.rs @@ -95,8 +95,3 @@ pub(crate) use payload::{ pub(crate) use restore::{ WalletBackupLookup, WalletBackupReader, WalletRestoreOutcome, WalletRestoreSession, }; - -#[cfg(test)] -pub(crate) mod tests { - pub(crate) use super::payload::convert_cloud_secret; -} diff --git a/rust/src/manager/cloud_backup_manager/wallets/passkey/material.rs b/rust/src/manager/cloud_backup_manager/wallets/passkey/material.rs index b65a68d7f..ef4b40230 100644 --- a/rust/src/manager/cloud_backup_manager/wallets/passkey/material.rs +++ b/rust/src/manager/cloud_backup_manager/wallets/passkey/material.rs @@ -391,20 +391,6 @@ mod tests { assert_eq!(passkey_name_suffix_for_timestamp(timestamp), "09IX"); } - #[test] - fn passkey_provider_hint_preserves_registration_suffix() { - let hint = passkey_provider_hint( - PasskeyRegistrationResult { - credential_id: vec![1, 2, 3], - provider_aaguid: "ea9b8d66-4d01-1d21-3ce4-b6b48cb575d4".into(), - registered_platform: PasskeyRegistrationPlatform::Android, - }, - "09IX".into(), - ); - - assert_eq!(hint.name_suffix, "09IX"); - } - #[test] fn android_passkey_association_error_uses_actionable_message() { let source = PasskeyError::RequestFailed { diff --git a/rust/src/manager/reconcile_channel.rs b/rust/src/manager/reconcile_channel.rs index 5fae97670..05485ac1c 100644 --- a/rust/src/manager/reconcile_channel.rs +++ b/rust/src/manager/reconcile_channel.rs @@ -153,15 +153,6 @@ mod tests { Three, } - #[test] - fn send_sync_forwards_single_message() { - let channel = ReconcileChannel::new(1); - - channel.send_sync(TestMessage::One); - - assert_eq!(channel.receiver().recv().unwrap(), SingleOrMany::Single(TestMessage::One)); - } - #[test] fn deferred_sender_flushes_many_messages_on_drop() { let channel = ReconcileChannel::new(1); diff --git a/rust/src/manager/send_flow_manager/state.rs b/rust/src/manager/send_flow_manager/state.rs index 6bc4385bc..757c706d1 100644 --- a/rust/src/manager/send_flow_manager/state.rs +++ b/rust/src/manager/send_flow_manager/state.rs @@ -213,7 +213,6 @@ mod tests { let state = SendFlowManagerState::new(metadata, balance); - assert_eq!(state.wallet_balance.as_ref().unwrap().spendable().as_sats(), 50_000); assert_eq!(state.unlocked_spendable_sats, None); assert!(!state.lock_state_load_failed); } diff --git a/rust/src/manager/wallet_manager.rs b/rust/src/manager/wallet_manager.rs index f445193b7..2fb2996a7 100644 --- a/rust/src/manager/wallet_manager.rs +++ b/rust/src/manager/wallet_manager.rs @@ -1336,8 +1336,8 @@ mod tests { use bitcoin::Amount; use super::{ - Balance, BalancePresentation, Error, RustWalletManager, WalletLedgerState, WalletLoadState, - WalletManagerError, WalletScanPhase, WalletScanProgress, WalletScanStatus, WalletSnapshot, + Balance, Error, RustWalletManager, WalletLedgerState, WalletLoadState, WalletManagerError, + WalletScanPhase, WalletScanProgress, WalletScanStatus, WalletSnapshot, initial_state_from_snapshot, initial_state_from_snapshot_with_pending_unsigned_transactions, ledger_state, preview_ledger_ready_metadata, @@ -1421,32 +1421,6 @@ mod tests { ); } - #[test] - fn initial_state_from_snapshot_uses_idle_ledger_state_and_matching_balance_presentation() { - let metadata = WalletMetadata::preview_new(); - let snapshot = WalletSnapshot { balance: Balance::zero(), transactions: Vec::new() }; - - let state = initial_state_from_snapshot( - metadata.clone(), - WalletScanStatus::Idle, - snapshot, - Vec::new(), - ); - - let expected_ledger_state = - WalletLedgerState::InitialScanIncomplete(ledger_state::InitialScanActivity::Idle); - assert_eq!(state.metadata, metadata); - assert_eq!(state.load_state, WalletLoadState::Loading); - assert_eq!(state.scan_status, WalletScanStatus::Idle); - assert_eq!(state.ledger_state, expected_ledger_state); - assert_eq!( - state.balance_presentation, - BalancePresentation::for_ledger_state(expected_ledger_state) - ); - assert_eq!(state.balance.as_ref(), &Balance::zero()); - assert!(state.unsigned_transactions.is_empty()); - } - #[test] fn initial_state_from_snapshot_marks_completed_idle_wallet_loaded() { let metadata = preview_ledger_ready_metadata(WalletMetadata::preview_new()); @@ -1457,7 +1431,6 @@ mod tests { assert_eq!(state.ledger_state, WalletLedgerState::Complete); assert_eq!(state.load_state, WalletLoadState::Loaded(Vec::new())); - assert_eq!(state.scan_status, WalletScanStatus::Idle); } #[test] @@ -1473,7 +1446,6 @@ mod tests { WalletLedgerState::InitialScanIncomplete(ledger_state::InitialScanActivity::Idle) ); assert_eq!(state.load_state, WalletLoadState::Loading); - assert_eq!(state.scan_status, WalletScanStatus::Idle); } #[test] @@ -1495,7 +1467,6 @@ mod tests { WalletLedgerState::InitialScanIncomplete(ledger_state::InitialScanActivity::Active) ); assert_eq!(state.load_state, WalletLoadState::Scanning(transactions)); - assert_eq!(state.scan_status, WalletScanStatus::Scanning(progress())); } #[test] @@ -1514,7 +1485,6 @@ mod tests { WalletLedgerState::InitialScanIncomplete(ledger_state::InitialScanActivity::Idle) ); assert_eq!(state.load_state, WalletLoadState::Scanning(transactions)); - assert_eq!(state.scan_status, WalletScanStatus::Idle); } #[test] diff --git a/rust/src/manager/wallet_manager/actor.rs b/rust/src/manager/wallet_manager/actor.rs index dd0b7aa47..a490017b0 100644 --- a/rust/src/manager/wallet_manager/actor.rs +++ b/rust/src/manager/wallet_manager/actor.rs @@ -1422,15 +1422,6 @@ const fn full_scan_updates_initial_metadata(full_scan_type: FullScanType) -> boo should_update_full_scan_metadata(full_scan_type) } -#[cfg(test)] -fn metadata_with_full_scan_performed( - mut metadata: WalletMetadata, - completed_at: u64, -) -> WalletMetadata { - metadata.internal.performed_full_scan_at = Some(completed_at); - metadata -} - fn should_accept_wallet_scan_generation( current_generation: WalletScanGeneration, event_generation: WalletScanGeneration, @@ -1741,7 +1732,6 @@ mod tests { Transaction as BdkTransaction, TxIn, TxOut, Txid, absolute::LockTime, hashes::Hash as _, transaction::Version, }; - use cove_bdk_progressive_scan::ScanUpdate; use cove_device::keychain::Keychain; use cove_tokio::FutureTimeoutExt as _; use cove_types::{ @@ -1750,7 +1740,7 @@ mod tests { }; use parking_lot::RwLock; use std::{ - collections::{BTreeMap, HashSet}, + collections::HashSet, str::FromStr as _, sync::{ Arc, @@ -1771,7 +1761,6 @@ mod tests { ActorState, EMPTY_WALLET_SCAN_PROGRESS_DELAY, FullScanType, InitialScanRoute, RETURNING_WALLET_SCAN_PROGRESS_DELAY, ScanProgressStart, SingleOrMany, address_type_patch, full_scan_updates_initial_metadata, initial_scan_route, ledger_ready_for_spend, - metadata_with_full_scan_performed, progressive_scan_update_response, reset_scan_lifecycle_state_for_address_type_switch, should_accept_wallet_scan_generation, should_skip_recent_scan, trusted_spendable_output, wallet_scan_progress_start, }; @@ -2471,19 +2460,6 @@ mod tests { } } - #[test] - fn progressive_scan_update_response_preserves_last_active_indices() { - let scan_update = ScanUpdate { - chain_update: None, - tx_update: Default::default(), - last_active_indices: BTreeMap::from([(KeychainKind::External, 7)]), - }; - - let response = progressive_scan_update_response(scan_update); - - assert_eq!(response.last_active_indices, BTreeMap::from([(KeychainKind::External, 7)])); - } - #[test] fn trusted_spendable_output_matches_bdk_balance_categories() { let confirmed_external = local_output(KeychainKind::External, confirmed_position()); @@ -4274,19 +4250,6 @@ mod tests { assert!(!full_scan_updates_initial_metadata(FullScanType::Rescan(20))); } - #[test] - fn full_scan_metadata_update_preserves_current_public_fields() { - let mut metadata = WalletMetadata::preview_new(); - metadata.name = "renamed while scanning".to_string(); - metadata.selected_unit = crate::transaction::Unit::Sat; - - let updated = metadata_with_full_scan_performed(metadata.clone(), 123); - - assert_eq!(updated.name, metadata.name); - assert_eq!(updated.selected_unit, metadata.selected_unit); - assert_eq!(updated.internal.performed_full_scan_at, Some(123)); - } - #[test] fn spend_guard_rejects_incomplete_initial_scan() { assert_eq!(ledger_ready_for_spend(false), Err(super::Error::InitialScanIncomplete)); diff --git a/rust/src/manager/wallet_manager/actor/scan.rs b/rust/src/manager/wallet_manager/actor/scan.rs index 2d761c367..efe173614 100644 --- a/rust/src/manager/wallet_manager/actor/scan.rs +++ b/rust/src/manager/wallet_manager/actor/scan.rs @@ -979,12 +979,11 @@ mod tests { FullScanType, ProgressiveFullScanResult, ProgressiveScanRunner, RunningScan, SCAN_PARTIAL_FLUSH_INTERVAL, SCAN_PROGRESS_BASIS_POINTS, SCAN_PROGRESS_INTERVAL, ScanActorGeneration, ScanFlushCadence, ScanFlushDecision, ScanProgressStart, - ScanRequestOrder, WalletScanActor, WalletScanEvent, WalletScanEventKind, - WalletScanGeneration, WalletScanPhase, WalletScanProgress, WalletScanStatus, - initial_scan_status, is_cancelled_progressive_scan, scan_progress_basis_points, - should_accept_scan_generation, should_flush_pending_after_scan_result, - should_forward_scan_progress, should_reveal_delayed_progress, - should_update_full_scan_metadata, + ScanRequestOrder, WalletScanActor, WalletScanGeneration, WalletScanPhase, + WalletScanProgress, WalletScanStatus, initial_scan_status, is_cancelled_progressive_scan, + scan_progress_basis_points, should_accept_scan_generation, + should_flush_pending_after_scan_result, should_forward_scan_progress, + should_reveal_delayed_progress, should_update_full_scan_metadata, }; fn scan_runner(scan: RunningScan) -> ProgressiveScanRunner { @@ -1401,15 +1400,4 @@ mod tests { assert!(!Actor::error(&mut scan_actor, error).await); assert!(scan_actor.active_wallet_generation.is_none()); } - - #[test] - fn wallet_scan_event_carries_wallet_generation() { - let generation = WalletScanGeneration::INITIAL.next(); - let event = WalletScanEvent::new( - generation, - WalletScanEventKind::StatusChanged(WalletScanStatus::Idle), - ); - - assert_eq!(event.generation(), generation); - } } diff --git a/rust/src/manager/wallet_manager/balance_presentation.rs b/rust/src/manager/wallet_manager/balance_presentation.rs index 6e9bb2ce3..a609a106c 100644 --- a/rust/src/manager/wallet_manager/balance_presentation.rs +++ b/rust/src/manager/wallet_manager/balance_presentation.rs @@ -29,38 +29,3 @@ impl BalancePresentation { pub fn balance_presentation_provisional() -> BalancePresentation { BalancePresentation::provisional() } - -#[cfg(test)] -mod tests { - use super::*; - - use super::super::ledger_state::InitialScanActivity; - - #[test] - fn complete_ledger_uses_normal_balance_presentation() { - assert_eq!( - BalancePresentation::for_ledger_state(WalletLedgerState::Complete), - BalancePresentation::normal() - ); - } - - #[test] - fn incomplete_active_initial_scan_uses_provisional_balance_presentation() { - assert_eq!( - BalancePresentation::for_ledger_state(WalletLedgerState::InitialScanIncomplete( - InitialScanActivity::Active - )), - BalancePresentation::provisional() - ); - } - - #[test] - fn incomplete_idle_initial_scan_uses_provisional_balance_presentation() { - assert_eq!( - BalancePresentation::for_ledger_state(WalletLedgerState::InitialScanIncomplete( - InitialScanActivity::Idle - )), - BalancePresentation::provisional() - ); - } -} diff --git a/rust/src/manager/wallet_manager/receive_address.rs b/rust/src/manager/wallet_manager/receive_address.rs index adc341e86..47217aae7 100644 --- a/rust/src/manager/wallet_manager/receive_address.rs +++ b/rust/src/manager/wallet_manager/receive_address.rs @@ -256,13 +256,6 @@ mod tests { assert!(session.visible_state().is_none()); } - #[test] - fn cached_state_expires_exactly_five_minutes_after_visible_window_start() { - let state = ReceiveAddressState::cached(1, address(0), ReceiveAddressStatus::Fresh, 1_000); - - assert_eq!(state.expires_at_secs, Some(1_000 + CACHE_WINDOW.as_secs())); - } - #[test] fn refresh_delay_uses_visible_window_expiry() { let state = @@ -295,16 +288,6 @@ mod tests { assert_eq!(paid.expires_at_secs, None); } - #[test] - fn default_presentation_copies_with_idle_refresh_state() { - let session = ReceiveAddressSession::default(); - - let presentation = session.presentation(); - - assert_eq!(presentation.copy_policy, ReceiveAddressCopyPolicy::Copy); - assert_eq!(presentation.refresh_state, ReceiveAddressRefreshState::Idle); - } - #[test] fn presentation_payment_received_confirms_copy() { let mut session = ReceiveAddressSession::default(); @@ -316,18 +299,6 @@ mod tests { let presentation = session.presentation(); assert_eq!(presentation.copy_policy, ReceiveAddressCopyPolicy::ConfirmPaidAddress); - assert_eq!(presentation.refresh_state, ReceiveAddressRefreshState::Idle); - } - - #[test] - fn presentation_uses_session_refresh_state() { - let mut session = ReceiveAddressSession::default(); - - session.set_refresh_state(ReceiveAddressRefreshState::Refreshing); - assert_eq!(session.presentation().refresh_state, ReceiveAddressRefreshState::Refreshing); - - session.set_refresh_state(ReceiveAddressRefreshState::Failed); - assert_eq!(session.presentation().refresh_state, ReceiveAddressRefreshState::Failed); } #[test] diff --git a/rust/src/node.rs b/rust/src/node.rs index 518f7fe12..0cf403ca7 100644 --- a/rust/src/node.rs +++ b/rust/src/node.rs @@ -144,7 +144,6 @@ mod tests { let node = node(); let renamed = Node { name: "Renamed".to_string(), ..node.clone() }; - assert_ne!(node, renamed); assert_eq!(node.connection_identity(), renamed.connection_identity()); } diff --git a/rust/src/router.rs b/rust/src/router.rs index e99d350b5..0e24d0beb 100644 --- a/rust/src/router.rs +++ b/rust/src/router.rs @@ -487,7 +487,6 @@ mod tests { let current = Route::TransactionDetails { id: wallet_id.clone(), tx_id: tx_id.clone() }; let next = Route::TransactionDetails { id: wallet_id, tx_id }; - assert!(current.is_equal(next.clone())); assert!(current.is_same_navigation_destination(next)); } diff --git a/rust/src/seed_qr.rs b/rust/src/seed_qr.rs index cebdc666b..99f419c2a 100644 --- a/rust/src/seed_qr.rs +++ b/rust/src/seed_qr.rs @@ -207,17 +207,8 @@ pub mod tests { #[test] fn test_parse_data_into_word_indexes_12_words() { - let bytes: Vec = vec![ - 0b01011011, 0b10111101, 0b10011101, 0b01110001, 0b10101000, 0b11101100, 0b01111001, - 0b10010000, 0b10000011, 0b00011010, 0b11111111, 0b00110101, 0b10011101, 0b01000010, - 0b01100101, 0b01000101, - ]; - let hex = "5bbd9d71a8ec7990831aff359d426545"; - let hex_bytes = hex::decode(hex).unwrap(); - - assert_eq!(bytes, hex_bytes); - let bytes = hex_bytes; + let bytes = hex::decode(hex).unwrap(); let seed_qr = SeedQr::try_from_data(&bytes).unwrap(); let expected = "forum undo fragile fade shy sign arrest garment culture tube off merit" diff --git a/rust/src/signed_import.rs b/rust/src/signed_import.rs index 515c2c590..5416bd325 100644 --- a/rust/src/signed_import.rs +++ b/rust/src/signed_import.rs @@ -267,14 +267,6 @@ mod tests { ); } - #[test] - fn test_psbt_accessors() { - let parsed = SignedTransactionOrPsbt::try_from_bytes(&make_signed_psbt_bytes()).unwrap(); - assert!(matches!(parsed, SignedTransactionOrPsbt::SignedPsbt(_))); - assert!(parsed.psbt().is_some()); - assert!(parsed.transaction().is_none()); - } - #[test] fn test_whitespace_handling() { let padded = format!(" {} ", hex::encode(make_signed_psbt_bytes())); diff --git a/rust/src/tap_card/tap_signer_reader.rs b/rust/src/tap_card/tap_signer_reader.rs index 16f0a9891..c5ad25418 100644 --- a/rust/src/tap_card/tap_signer_reader.rs +++ b/rust/src/tap_card/tap_signer_reader.rs @@ -2162,8 +2162,7 @@ mod tests { #[test] fn setup_chain_code_is_optional_but_strictly_32_bytes_when_provided() { let cvc = Arc::new(TapSignerCvc::try_new("123456".to_string()).unwrap()); - let generated = SetupCmd::try_new(cvc.clone(), cvc.clone(), None).unwrap(); - assert_eq!(generated.chain_code.len(), 32); + SetupCmd::try_new(cvc.clone(), cvc.clone(), None).unwrap(); assert!(matches!( SetupCmd::try_new(cvc.clone(), cvc.clone(), Some(vec![0; 31])), @@ -2441,8 +2440,11 @@ mod tests { }; let response = TapSignerResponse::Backup(vec![0xde, 0xad, 0xbe, 0xef]); - assert!(!format!("{complete:?}").contains("deadbeef")); - assert!(!format!("{response:?}").contains("deadbeef")); + // derived Debug prints bytes as decimal, so check both encodings + for debug in [format!("{complete:?}"), format!("{response:?}")] { + assert!(!debug.contains("deadbeef"), "{debug}"); + assert!(!debug.contains("222, 173, 190, 239"), "{debug}"); + } } #[test] diff --git a/rust/src/transaction/transaction_details.rs b/rust/src/transaction/transaction_details.rs index 834c40008..d8b2e0312 100644 --- a/rust/src/transaction/transaction_details.rs +++ b/rust/src/transaction/transaction_details.rs @@ -650,58 +650,8 @@ fn fmt_historical_fiat(amount: f64, currency: FiatCurrency) -> String { #[cfg(test)] mod tests { use super::*; - use bitcoin::Sequence; use cove_types::unit::BitcoinUnit; - /// Mirrors the detection logic in `try_new`: returns `true` when any input - /// sequence signals opt-in RBF (nSequence < 0xFFFFFFFE, per BIP 125). - fn compute_is_rbf_signaling(sequences: &[Sequence]) -> bool { - sequences.iter().any(bitcoin::Sequence::is_rbf) - } - - #[test] - fn sequence_below_threshold_signals_rbf() { - // 0xFFFFFFFD is the highest value that still signals RBF - assert!(compute_is_rbf_signaling(&[Sequence(0xFFFFFFFD)])); - } - - #[test] - fn sequence_at_threshold_does_not_signal_rbf() { - // 0xFFFFFFFE (Sequence::ENABLE_LOCKTIME_NO_RBF) does NOT signal RBF - assert!(!compute_is_rbf_signaling(&[Sequence(0xFFFFFFFE)])); - } - - #[test] - fn final_sequence_does_not_signal_rbf() { - // 0xFFFFFFFF (Sequence::MAX) is fully final - assert!(!compute_is_rbf_signaling(&[Sequence::MAX])); - } - - #[test] - fn zero_sequence_signals_rbf() { - // Sequence(0) is commonly used by wallets to signal RBF - assert!(compute_is_rbf_signaling(&[Sequence::ZERO])); - } - - #[test] - fn any_rbf_input_makes_tx_replaceable() { - // BIP 125: a tx is replaceable if *any* input signals RBF - let sequences = vec![Sequence::MAX, Sequence(0xFFFFFFFD), Sequence::MAX]; - assert!(compute_is_rbf_signaling(&sequences)); - } - - #[test] - fn all_final_inputs_means_not_replaceable() { - let sequences = vec![Sequence::MAX, Sequence(0xFFFFFFFE), Sequence::MAX]; - assert!(!compute_is_rbf_signaling(&sequences)); - } - - #[test] - fn preview_constructors_default_to_not_rbf() { - assert!(!TransactionDetails::preview_new_confirmed().is_rbf_signaling); - assert!(!TransactionDetails::preview_pending_sent().is_rbf_signaling); - } - #[test] fn confirmed_transaction_always_has_at_least_one_confirmation() { assert_eq!(confirmed_transaction_confirmation_count(840_000, 839_999).get(), 1); @@ -722,7 +672,6 @@ mod tests { ); assert_eq!(presentation.confirmations(), None); - assert!(!presentation.details().is_confirmed()); } #[test] @@ -736,7 +685,6 @@ mod tests { let presentation = TransactionDetailsPresentation::new(details, 839_999); assert_eq!(presentation.confirmations(), Some(1)); - assert!(presentation.details().is_confirmed()); } #[test] diff --git a/rust/src/ur.rs b/rust/src/ur.rs index 0cb7227fb..d3052e41f 100644 --- a/rust/src/ur.rs +++ b/rust/src/ur.rs @@ -90,30 +90,4 @@ mod tests { assert_eq!(UrType::from_str("bytes"), UrType::Bytes); assert!(matches!(UrType::from_str("unknown-type"), UrType::Unknown(_))); } - - #[test] - fn test_ur_result_helpers() { - let psbt = UrResult::new(vec![1, 2, 3], UrType::CryptoPsbt); - assert!(psbt.is_psbt()); - assert!(!psbt.is_seed()); - assert!(!psbt.is_hdkey()); - - let seed = UrResult::new(vec![4, 5, 6], UrType::CryptoSeed); - assert!(!seed.is_psbt()); - assert!(seed.is_seed()); - assert!(!seed.is_hdkey()); - - let hdkey = UrResult::new(vec![7, 8, 9], UrType::CryptoHdkey); - assert!(!hdkey.is_psbt()); - assert!(!hdkey.is_seed()); - assert!(hdkey.is_hdkey()); - } - - #[test] - fn test_ur_result_data_access() { - let data = vec![1, 2, 3, 4, 5]; - let result = UrResult::new(data.clone(), UrType::Bytes); - assert_eq!(result.data(), data); - assert_eq!(result.ur_type(), UrType::Bytes); - } } diff --git a/rust/src/wallet/addressing.rs b/rust/src/wallet/addressing.rs index 60b7cd2a5..b870647a6 100644 --- a/rust/src/wallet/addressing.rs +++ b/rust/src/wallet/addressing.rs @@ -399,12 +399,19 @@ impl Wallet { } pub fn unreserve_tx_change_addresses(&mut self, tx: &bdk_wallet::bitcoin::Transaction) { - for txout in &tx.output { - if let Some((KeychainKind::Internal, index)) = - self.bdk.derivation_of_spk(txout.script_pubkey.clone()) - { - self.bdk.unmark_used(KeychainKind::Internal, index); - } + unreserve_tx_change_addresses(&mut self.bdk, tx); + } +} + +fn unreserve_tx_change_addresses( + wallet: &mut bdk_wallet::Wallet, + tx: &bdk_wallet::bitcoin::Transaction, +) { + for txout in &tx.output { + if let Some((KeychainKind::Internal, index)) = + wallet.derivation_of_spk(txout.script_pubkey.clone()) + { + wallet.unmark_used(KeychainKind::Internal, index); } } } @@ -639,19 +646,6 @@ mod tests { wallet.list_unused_addresses(keychain).any(|address| address.index == index) } - fn unreserve_tx_change_addresses( - wallet: &mut bdk_wallet::Wallet, - tx: &bdk_wallet::bitcoin::Transaction, - ) { - for txout in &tx.output { - if let Some((KeychainKind::Internal, index)) = - wallet.derivation_of_spk(txout.script_pubkey.clone()) - { - wallet.unmark_used(KeychainKind::Internal, index); - } - } - } - #[test] fn unreserve_tx_change_addresses_releases_reserved_change_index() { let (mut wallet, _) = get_funded_wallet_wpkh(); @@ -736,13 +730,16 @@ mod tests { let mut wallet = test_bdk_wallet(); let gap_limit = u32::from(GAP_LIMIT); let _ = wallet.reveal_addresses_to(KeychainKind::External, gap_limit + 2).last(); + + // a used index ahead of the unused ones separates the capped prefix from the normal scan + assert!(wallet.mark_used(KeychainKind::External, 0)); let mut request = receive_prioritized_full_scan_request(&wallet); let indexes = scan_indexes(&mut request, KeychainKind::External, GAP_LIMIT as usize + 2); - let expected_prefix = (0..gap_limit).collect::>(); + let expected_prefix = (1..=gap_limit).collect::>(); assert_eq!(&indexes[..GAP_LIMIT as usize], expected_prefix.as_slice()); - assert_eq!(indexes[GAP_LIMIT as usize], gap_limit); + assert_eq!(indexes[GAP_LIMIT as usize], 0); } #[test] diff --git a/rust/src/wallet_identity.rs b/rust/src/wallet_identity.rs index 6eee3e4b4..9fda43d74 100644 --- a/rust/src/wallet_identity.rs +++ b/rust/src/wallet_identity.rs @@ -224,17 +224,6 @@ mod tests { ); } - #[test] - fn descriptor_identity_wins_over_xpub_identity() { - let descriptors = descriptor_pair(0); - let xpub = descriptors.external.xpub().unwrap(); - - assert_ne!( - PublicWalletIdentity::from_descriptors(&descriptors), - PublicWalletIdentity::from_xpub(xpub) - ); - } - #[test] fn xpub_default_address_type_synthesizes_native_segwit_descriptor_identity() { let descriptors = descriptor_pair(0); diff --git a/rust/src/wallet_lifecycle/tests.rs b/rust/src/wallet_lifecycle/tests.rs index 9505a7810..5c3536fd5 100644 --- a/rust/src/wallet_lifecycle/tests.rs +++ b/rust/src/wallet_lifecycle/tests.rs @@ -700,12 +700,6 @@ fn ordinary_close_defers_to_claimed_destructive_phase() { drop(manager); } -#[test] -fn deadline_tiers_escalate_from_five_to_twenty_seconds() { - assert_eq!(ShutdownDeadlineTier::Initial.duration(), std::time::Duration::from_secs(5)); - assert_eq!(ShutdownDeadlineTier::Retry.duration(), std::time::Duration::from_secs(20)); -} - #[test] fn cancelled_attempt_cannot_authorize_retry() { let coordinator: &'static WalletLifecycleCoordinator = diff --git a/rust/src/word_verify_state_machine.rs b/rust/src/word_verify_state_machine.rs index dcd2107c0..8f178a77a 100644 --- a/rust/src/word_verify_state_machine.rs +++ b/rust/src/word_verify_state_machine.rs @@ -253,7 +253,6 @@ mod tests { let sm = WordVerifyStateMachine::new(validator, 1); assert_eq!(sm.state(), WordCheckState::None); - assert_eq!(sm.word_number(), 1); assert!(!sm.is_complete()); } diff --git a/rust/xtask/src/android_device.rs b/rust/xtask/src/android_device.rs index 3126f3f38..fa2fbfd8d 100644 --- a/rust/xtask/src/android_device.rs +++ b/rust/xtask/src/android_device.rs @@ -268,7 +268,7 @@ fn resolve_serial(devices: &[AndroidDevice], serial: &str) -> Result Result { match devices { - [] => color_eyre::eyre::bail!("No connected Android device found"), + [] => Err(color_eyre::eyre::eyre!("No connected Android device found")), [device] => Ok(device.clone()), _ => select_with_fzf(devices), } diff --git a/rust/xtask/src/mobile_artifact.rs b/rust/xtask/src/mobile_artifact.rs index f2d44495d..7cde263e3 100644 --- a/rust/xtask/src/mobile_artifact.rs +++ b/rust/xtask/src/mobile_artifact.rs @@ -758,8 +758,8 @@ fn reject_zip_unsafe_entry_type(name: &str, unix_mode: Option) -> Result<() let file_type = unix_mode & 0o170000; match file_type { - 0o120000 => color_eyre::eyre::bail!("Artifact ZIP entry is a symlink: {name}"), - 0o010000 => color_eyre::eyre::bail!("Artifact ZIP entry is a FIFO: {name}"), + 0o120000 => Err(color_eyre::eyre::eyre!("Artifact ZIP entry is a symlink: {name}")), + 0o010000 => Err(color_eyre::eyre::eyre!("Artifact ZIP entry is a FIFO: {name}")), _ => Ok(()), } } diff --git a/rust/xtask/src/version.rs b/rust/xtask/src/version.rs index 0f6ffc809..c369aafa2 100644 --- a/rust/xtask/src/version.rs +++ b/rust/xtask/src/version.rs @@ -143,7 +143,7 @@ fn calculate_bumped_version(current_version: &str, bump_type: &str) -> Result { patch += 1; } - _ => color_eyre::eyre::bail!("Bump type must be 'major', 'minor', or 'patch'"), + _ => return Err(color_eyre::eyre::eyre!("Bump type must be 'major', 'minor', or 'patch'")), } Ok(format!("{major}.{minor}.{patch}"))