183 lines
6.6 KiB
Rust
183 lines
6.6 KiB
Rust
// file: crates/ksp-interface-lib/tests/dependency_boundary.rs
|
|
// version: 8
|
|
|
|
//! Dependency and passive-surface canaries for the Interface foundation.
|
|
|
|
#[test]
|
|
fn pre_002_manifest_has_exact_core_only_runtime_dependency() {
|
|
let manifest = include_str!("../Cargo.toml");
|
|
let dependencies_tail = manifest.split("[dependencies]").nth(1);
|
|
assert!(dependencies_tail.is_some(), "Interface dependencies section must exist");
|
|
let dependencies_tail = match dependencies_tail {
|
|
std::option::Option::Some(value) => value,
|
|
std::option::Option::None => return,
|
|
};
|
|
let dependencies = match dependencies_tail.split("[lints]").next() {
|
|
std::option::Option::Some(value) => value,
|
|
std::option::Option::None => return,
|
|
};
|
|
assert_eq!(manifest_dependency_names(dependencies), std::vec!["ksp-core-lib"]);
|
|
for forbidden in [
|
|
"ksp-config-lib",
|
|
"ksp-logging-lib",
|
|
"ksp-offchain-transport-lib",
|
|
"ksp-onchain-transport-lib",
|
|
"ksp-program-api",
|
|
"ksp-program-lib",
|
|
"ksp-store-api",
|
|
"ksp-store-lib",
|
|
"ksp-wallet-lib",
|
|
"borsh",
|
|
"bincode",
|
|
"reqwest",
|
|
"serde",
|
|
"serde_json",
|
|
"solana-instruction",
|
|
"tauri",
|
|
"tokio",
|
|
"tonic",
|
|
"tracing",
|
|
"wincode",
|
|
] {
|
|
assert!(!dependencies.contains(forbidden), "forbidden Interface dependency detected: {forbidden}");
|
|
}
|
|
return;
|
|
}
|
|
|
|
#[test]
|
|
fn pre_005_surface_remains_passive_without_codecs_or_runtime_logging() {
|
|
let crate_root = include_str!("../src/lib.rs");
|
|
assert!(crate_root.contains("ProgramAccountMeta"));
|
|
assert!(crate_root.contains("MAX_PROGRAM_INSTRUCTION_ACCOUNTS"));
|
|
assert!(crate_root.contains("ERROR_CODE_PROGRAM_INSTRUCTION_LIMIT_EXCEEDED"));
|
|
assert!(crate_root.contains("ProgramInstruction"));
|
|
assert!(crate_root.contains("MAX_PROGRAM_INSTRUCTION_DATA_LEN"));
|
|
assert!(!crate_root.contains("TRACING_TARGET"));
|
|
assert!(!crate_root.contains("ksp_logging_lib"));
|
|
assert!(!std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src/constants.rs").exists());
|
|
let instruction_source = include_str!("../src/program_instruction.rs");
|
|
for forbidden in ["serde", "borsh", "bincode", "wincode", "solana_instruction", "ksp_logging_lib", "TRACING_TARGET"] {
|
|
assert!(!instruction_source.contains(forbidden), "forbidden Interface surface detected: {forbidden}");
|
|
}
|
|
return;
|
|
}
|
|
|
|
fn manifest_dependency_names(section: &str) -> std::vec::Vec<&str> {
|
|
let mut names = std::vec::Vec::new();
|
|
for line in section.lines() {
|
|
let content = match line.split('#').next() {
|
|
std::option::Option::Some(value) => value.trim(),
|
|
std::option::Option::None => continue,
|
|
};
|
|
if content.is_empty() {
|
|
continue;
|
|
}
|
|
let name = match content.split('=').next() {
|
|
std::option::Option::Some(value) => value.trim().trim_end_matches(".workspace"),
|
|
std::option::Option::None => continue,
|
|
};
|
|
if !name.is_empty() {
|
|
names.push(name);
|
|
}
|
|
}
|
|
names.sort_unstable();
|
|
return names;
|
|
}
|
|
|
|
#[test]
|
|
fn pre_005_all_production_sources_preserve_the_dependency_firewall() {
|
|
let production_sources = [
|
|
include_str!("../src/error.rs"),
|
|
include_str!("../src/lib.rs"),
|
|
include_str!("../src/program_account_meta.rs"),
|
|
include_str!("../src/program_instruction.rs"),
|
|
include_str!("../src/slot_lifecycle.rs"),
|
|
include_str!("../src/transaction_execution.rs"),
|
|
];
|
|
for source in production_sources {
|
|
for forbidden in [
|
|
"borsh::",
|
|
"bincode::",
|
|
"ksp_config_lib::",
|
|
"ksp_logging_lib::",
|
|
"ksp_offchain_transport_lib::",
|
|
"ksp_onchain_transport_lib::",
|
|
"ksp_program_api::",
|
|
"ksp_program_lib::",
|
|
"ksp_store_api::",
|
|
"ksp_store_lib::",
|
|
"ksp_wallet_lib::",
|
|
"reqwest::",
|
|
"serde::",
|
|
"serde_json::",
|
|
"solana_instruction::",
|
|
"tauri::",
|
|
"tokio::",
|
|
"tonic::",
|
|
concat!("tracing", "::"),
|
|
"wincode::",
|
|
] {
|
|
assert!(!source.contains(forbidden), "forbidden production dependency path detected: {forbidden}");
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
#[test]
|
|
fn pre_005_instruction_source_has_no_narrowing_cast_or_hidden_codec_entry_point() {
|
|
let instruction_source = include_str!("../src/program_instruction.rs");
|
|
for forbidden in [" as u8", " as u16", " as u32", " as u64", "serialize", "deserialize", "encode", "decode"] {
|
|
assert!(!instruction_source.contains(forbidden), "forbidden instruction implementation pattern detected: {forbidden}");
|
|
}
|
|
return;
|
|
}
|
|
|
|
#[test]
|
|
fn v0_3_5_pre_004_acquisition_sources_remain_provider_neutral_and_runtime_free() {
|
|
let acquisition_sources = [include_str!("../src/slot_lifecycle.rs"), include_str!("../src/transaction_execution.rs")];
|
|
for source in acquisition_sources {
|
|
for forbidden in [
|
|
"borsh::",
|
|
"bincode::",
|
|
"ksp_config_lib::",
|
|
"ksp_logging_lib::",
|
|
"ksp_onchain_transport_lib::",
|
|
"ksp_store_api::",
|
|
"ksp_store_lib::",
|
|
"reqwest::",
|
|
"serde::",
|
|
"serde_json::",
|
|
"solana_instruction::",
|
|
"tauri::",
|
|
"tokio::",
|
|
"tonic::",
|
|
concat!("tracing", "::"),
|
|
"wincode::",
|
|
] {
|
|
assert!(!source.contains(forbidden), "forbidden acquisition dependency path detected: {forbidden}");
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
#[test]
|
|
fn v0_3_5_pre_005_manifest_keeps_exact_core_only_graph_without_features_or_hidden_dependency_sections() {
|
|
let manifest = include_str!("../Cargo.toml");
|
|
assert!(!manifest.contains("[features]"));
|
|
assert!(!manifest.contains("[dev-dependencies]"));
|
|
assert!(!manifest.contains("[build-dependencies]"));
|
|
assert_eq!(manifest.matches("[dependencies]").count(), 1);
|
|
let dependencies_tail = manifest.split("[dependencies]").nth(1);
|
|
assert!(dependencies_tail.is_some(), "Interface dependencies section must exist");
|
|
let dependencies_tail = match dependencies_tail {
|
|
std::option::Option::Some(value) => value,
|
|
std::option::Option::None => return,
|
|
};
|
|
let dependencies = match dependencies_tail.split("[lints]").next() {
|
|
std::option::Option::Some(value) => value,
|
|
std::option::Option::None => return,
|
|
};
|
|
assert_eq!(manifest_dependency_names(dependencies), std::vec!["ksp-core-lib"]);
|
|
return;
|
|
}
|