Files
khadhroony-solana-project/crates/ksp-wallet-lib/tests/public_api.rs

115 lines
5.4 KiB
Rust

// file: crates/ksp-wallet-lib/tests/public_api.rs
// version: 6
//! Public API canaries for the Wallet foundation.
fn accepts_view_handle(_: std::option::Option<&ksp_wallet_lib::WalletView>) {}
fn accepts_owner_handle(_: std::option::Option<&ksp_wallet_lib::WalletOwner>) {}
#[test]
fn capability_and_handle_types_are_available_from_crate_root() {
assert_eq!(ksp_wallet_lib::WalletCapability::View, ksp_wallet_lib::WalletCapability::View);
assert_ne!(ksp_wallet_lib::WalletCapability::View, ksp_wallet_lib::WalletCapability::Owner);
accepts_view_handle(std::option::Option::None);
accepts_owner_handle(std::option::Option::None);
}
#[test]
fn password_types_redact_public_debug_output() {
let view = ksp_wallet_lib::ViewPassword::new(std::string::String::from("PUBLIC-VIEW-CANARY"));
let owner = ksp_wallet_lib::OwnerPassword::new(std::string::String::from("PUBLIC-OWNER-CANARY"));
let view_debug = format!("{view:?}");
let owner_debug = format!("{owner:?}");
assert!(!view_debug.contains("PUBLIC-VIEW-CANARY"));
assert!(!owner_debug.contains("PUBLIC-OWNER-CANARY"));
assert!(std::mem::needs_drop::<ksp_wallet_lib::ViewPassword>());
assert!(std::mem::needs_drop::<ksp_wallet_lib::OwnerPassword>());
}
#[test]
fn metadata_projection_methods_use_core_pubkey_contract() {
let pubkey_method: fn(&ksp_wallet_lib::WalletInfo) -> &ksp_core_lib::Pubkey = ksp_wallet_lib::WalletInfo::pubkey;
let view_pubkey_method: fn(&ksp_wallet_lib::WalletView) -> &ksp_core_lib::Pubkey = ksp_wallet_lib::WalletView::pubkey;
let owner_pubkey_method: fn(&ksp_wallet_lib::WalletOwner) -> &ksp_core_lib::Pubkey = ksp_wallet_lib::WalletOwner::pubkey;
let _ = pubkey_method;
let _ = view_pubkey_method;
let _ = owner_pubkey_method;
}
#[test]
fn wallet_error_codes_are_available_from_crate_root() {
let codes = [
ksp_wallet_lib::ERROR_CODE_FORMAT_INVALID,
ksp_wallet_lib::ERROR_CODE_FORMAT_VERSION_UNSUPPORTED,
ksp_wallet_lib::ERROR_CODE_CRYPTO_PARAMETERS_INVALID,
ksp_wallet_lib::ERROR_CODE_CRYPTO_OPERATION_FAILED,
ksp_wallet_lib::ERROR_CODE_RANDOMNESS_FAILED,
ksp_wallet_lib::ERROR_CODE_AUTHENTICATION_FAILED,
ksp_wallet_lib::ERROR_CODE_VIEW_UNLOCK_FAILED,
ksp_wallet_lib::ERROR_CODE_OWNER_UNLOCK_FAILED,
ksp_wallet_lib::ERROR_CODE_CAPABILITY_INSUFFICIENT,
ksp_wallet_lib::ERROR_CODE_IO_FAILED,
ksp_wallet_lib::ERROR_CODE_DESTINATION_EXISTS,
ksp_wallet_lib::ERROR_CODE_ATOMIC_PERSISTENCE_FAILED,
ksp_wallet_lib::ERROR_CODE_TRANSFER_FORMAT_UNSUPPORTED,
ksp_wallet_lib::ERROR_CODE_KEY_MATERIAL_INVALID,
ksp_wallet_lib::ERROR_CODE_SIGNATURE_FAILED,
];
assert_eq!(codes.len(), 15);
for code in codes {
assert_eq!(code.domain(), "wallet");
}
}
#[test]
fn strict_v1_envelope_and_transcript_are_available_from_crate_root() -> ksp_core_lib::Result<()> {
let source = include_bytes!("fixtures/kspwallet_v1_wire_only.json");
let envelope = match ksp_wallet_lib::KspWalletEnvelopeV1::parse_json(source) {
std::result::Result::Ok(envelope) => envelope,
std::result::Result::Err(error) => return std::result::Result::Err(error),
};
assert_eq!(envelope.format_version(), ksp_wallet_lib::KSPWALLET_FORMAT_VERSION_V1);
assert_eq!(envelope.owner_slot().role(), ksp_wallet_lib::WalletKeySlotRoleV1::Owner);
assert!(envelope.view_descriptor().enabled());
assert!(!envelope.state_transcript().is_empty());
assert!(!envelope.owner_slot_aad().is_empty());
assert!(envelope.view_slot_aad().is_some());
assert!(!envelope.compartment_aad(ksp_wallet_lib::WalletCompartmentKindV1::Metadata).is_empty());
return std::result::Result::Ok(());
}
#[test]
fn public_pre_005_create_open_and_calibrated_defaults_are_available_from_crate_root() {
let _ = ksp_wallet_lib::create_wallet_v1;
let _ = ksp_wallet_lib::open_wallet_view_v1;
let _ = ksp_wallet_lib::open_wallet_owner_v1;
let _ = ksp_wallet_lib::inspect_locked_wallet_v1;
let metadata = ksp_wallet_lib::WalletCreateMetadataV1::default();
assert_eq!(format!("{metadata:?}"), "WalletCreateMetadataV1 { alias: None, note_count: 0 }");
assert_eq!(ksp_wallet_lib::KSPWALLET_V1_DEFAULT_ARGON2_MEMORY_KIB, 65_536);
assert_eq!(ksp_wallet_lib::KSPWALLET_V1_DEFAULT_ARGON2_ITERATIONS, 3);
assert_eq!(ksp_wallet_lib::KSPWALLET_V1_DEFAULT_ARGON2_PARALLELISM, 1);
assert_eq!(ksp_wallet_lib::KSPWALLET_V1_DEFAULT_KDF_SALT_BYTES, 32);
}
#[test]
fn public_pre_006_file_persistence_surface_is_available_from_crate_root() {
let path = std::path::Path::new("not-polled.kspwallet");
let owner_password = ksp_wallet_lib::OwnerPassword::new(std::string::String::from("public-pre006-owner-password"));
let create_future =
ksp_wallet_lib::create_wallet_file_v1(path, owner_password, std::option::Option::None, ksp_wallet_lib::WalletCreateMetadataV1::default());
drop(create_future);
let view_password = ksp_wallet_lib::ViewPassword::new(std::string::String::from("public-pre006-view-password"));
let view_future = ksp_wallet_lib::open_wallet_view_file_v1(path, view_password);
drop(view_future);
let owner_password = ksp_wallet_lib::OwnerPassword::new(std::string::String::from("public-pre006-owner-password"));
let owner_future = ksp_wallet_lib::open_wallet_owner_file_v1(path, owner_password);
drop(owner_future);
let inspect_future = ksp_wallet_lib::inspect_locked_wallet_file_v1(path);
drop(inspect_future);
}