92 lines
4.1 KiB
Rust
92 lines
4.1 KiB
Rust
// file: crates/ksp-wallet-lib/tests/dependency_boundary.rs
|
|
// version: 8
|
|
|
|
//! Wallet-specific dependency and ownership canaries.
|
|
|
|
fn crate_root() -> std::path::PathBuf {
|
|
return std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
}
|
|
|
|
fn rust_source_files(directory: &std::path::Path) -> std::io::Result<std::vec::Vec<std::path::PathBuf>> {
|
|
let entries = match std::fs::read_dir(directory) {
|
|
std::result::Result::Ok(entries) => entries,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
let mut files = std::vec::Vec::new();
|
|
for entry in entries {
|
|
let entry = match entry {
|
|
std::result::Result::Ok(entry) => entry,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
let path = entry.path();
|
|
if path.is_dir() {
|
|
let nested_files = match rust_source_files(path.as_path()) {
|
|
std::result::Result::Ok(nested_files) => nested_files,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
files.extend(nested_files);
|
|
} else if path.extension() == std::option::Option::Some(std::ffi::OsStr::new("rs")) {
|
|
files.push(path);
|
|
}
|
|
}
|
|
return std::result::Result::Ok(files);
|
|
}
|
|
|
|
#[test]
|
|
fn wallet_manifest_preserves_dependency_firewall() -> std::io::Result<()> {
|
|
let manifest = match std::fs::read_to_string(crate_root().join("Cargo.toml")) {
|
|
std::result::Result::Ok(manifest) => manifest,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
assert!(manifest.contains("ksp-core-lib"));
|
|
assert!(manifest.contains("ksp-logging-lib"));
|
|
assert!(manifest.contains("argon2 = { workspace = true, features = [\"alloc\", \"zeroize\"] }"));
|
|
assert!(manifest.contains("chacha20poly1305 = { workspace = true, features = [\"alloc\", \"zeroize\"] }"));
|
|
assert!(manifest.contains("ed25519-dalek = { workspace = true, features = [\"signature\", \"zeroize\"] }"));
|
|
assert!(manifest.contains("getrandom.workspace = true"));
|
|
assert!(manifest.contains("base64.workspace = true"));
|
|
assert!(manifest.contains("serde = { workspace = true, features = [\"derive\"] }"));
|
|
assert!(manifest.contains("serde_json.workspace = true"));
|
|
assert!(manifest.contains("solana-keypair.workspace = true"));
|
|
assert!(manifest.contains("tokio = { workspace = true, features = [\"rt\"] }"));
|
|
assert!(manifest.contains("tempfile.workspace = true"));
|
|
assert!(manifest.contains("zeroize.workspace = true"));
|
|
for forbidden in [
|
|
"ksp-config-lib",
|
|
"ksp-onchain-transport-lib",
|
|
"ksp-execution-policy-api",
|
|
"ksp-store-api",
|
|
"ksp-store-lib",
|
|
"tauri",
|
|
"tracing =",
|
|
"solana-pubkey",
|
|
] {
|
|
assert!(!manifest.contains(forbidden), "forbidden direct Wallet dependency detected: {forbidden}");
|
|
}
|
|
return std::result::Result::Ok(());
|
|
}
|
|
|
|
#[test]
|
|
fn wallet_sources_use_core_pubkey_logging_facade_and_no_environment() -> std::io::Result<()> {
|
|
let source_files = match rust_source_files(crate_root().join("src").as_path()) {
|
|
std::result::Result::Ok(source_files) => source_files,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
let mut all_source = std::string::String::new();
|
|
for source_file in source_files {
|
|
let source = match std::fs::read_to_string(source_file.as_path()) {
|
|
std::result::Result::Ok(source) => source,
|
|
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
|
};
|
|
all_source.push_str(source.as_str());
|
|
}
|
|
assert!(all_source.contains("ksp_core_lib::Pubkey"));
|
|
assert!(all_source.contains("ksp_logging_lib::trace!"));
|
|
assert!(all_source.contains("pub(crate) const TRACING_TARGET: &str = \"ksp-wallet-lib\";"));
|
|
assert!(!all_source.contains("solana_pubkey::"));
|
|
assert!(!all_source.contains("std::env::"));
|
|
let direct_tracing_path = ["tracing", "::"].concat();
|
|
assert!(!all_source.contains(direct_tracing_path.as_str()));
|
|
return std::result::Result::Ok(());
|
|
}
|