v0.2.5-pre.007
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-wallet-lib/unit_tests/persistence.rs
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
fn temp_directory() -> std::io::Result<tempfile::TempDir> {
|
||||
return tempfile::tempdir();
|
||||
@@ -128,3 +128,28 @@ fn persisted_full_vector_opens_view_and_owner_through_file_apis() {
|
||||
assert_eq!(view.alias(), std::option::Option::Some("pre005-vector-wallet"));
|
||||
assert_eq!(owner.alias(), std::option::Option::Some("pre005-vector-wallet"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replacement_fault_before_publish_preserves_the_previous_wallet_bytes() {
|
||||
let directory = temp_directory().expect("Wallet replacement test directory must be creatable");
|
||||
let destination = directory.path().join("replace-fault.kspwallet");
|
||||
let original = b"ORIGINAL-WALLET-CANARY";
|
||||
let replacement = b"REPLACEMENT-WALLET-CANARY";
|
||||
std::fs::write(destination.as_path(), original).expect("replacement test original must be writable");
|
||||
|
||||
let result = crate::persistence::replace_wallet_fault_before_publish(destination.as_path(), replacement);
|
||||
assert_eq!(result.expect_err("injected replacement fault must fail").code(), crate::ERROR_CODE_ATOMIC_PERSISTENCE_FAILED);
|
||||
assert_eq!(std::fs::read(destination.as_path()).expect("original Wallet bytes must remain readable"), original);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replacement_requires_an_existing_regular_file_and_replaces_complete_content() {
|
||||
let directory = temp_directory().expect("Wallet replacement test directory must be creatable");
|
||||
let destination = directory.path().join("replace.kspwallet");
|
||||
let missing = crate::persistence::replace_wallet_for_test(destination.as_path(), b"replacement");
|
||||
assert_eq!(missing.expect_err("replacement must not create a missing Wallet destination").code(), crate::ERROR_CODE_IO_FAILED);
|
||||
|
||||
std::fs::write(destination.as_path(), b"old").expect("replacement test original must be writable");
|
||||
crate::persistence::replace_wallet_for_test(destination.as_path(), b"new-complete-wallet").expect("existing Wallet replacement must succeed");
|
||||
assert_eq!(std::fs::read(destination.as_path()).expect("replaced Wallet must be readable"), b"new-complete-wallet");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user