62 lines
3.3 KiB
Rust
62 lines
3.3 KiB
Rust
// file: crates/ksp-interface-lib/tests/release_completeness.rs
|
|
// version: 3
|
|
|
|
//! Release-completeness canaries for the public `ksp-interface-lib` surface.
|
|
|
|
fn crate_root_source() -> std::result::Result<std::string::String, std::io::Error> {
|
|
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src/lib.rs");
|
|
return std::fs::read_to_string(path);
|
|
}
|
|
|
|
#[test]
|
|
fn v0_3_5_pre_002_foundation_keeps_one_error_code_and_adds_one_passive_acquisition_family() {
|
|
assert_eq!(ksp_interface_lib::ERROR_CODE_PROGRAM_INSTRUCTION_LIMIT_EXCEEDED.domain(), "interface");
|
|
assert_eq!(ksp_interface_lib::ERROR_CODE_PROGRAM_INSTRUCTION_LIMIT_EXCEEDED.code(), "program_instruction_limit_exceeded");
|
|
assert_eq!(ksp_interface_lib::MAX_PROGRAM_INSTRUCTION_ACCOUNTS, 255);
|
|
assert_eq!(ksp_interface_lib::MAX_PROGRAM_INSTRUCTION_DATA_LEN, 10_240);
|
|
let program_id = ksp_interface_lib::Pubkey::new_from_array([0xB1_u8; 32]);
|
|
let account = ksp_interface_lib::ProgramAccountMeta::readonly(ksp_interface_lib::Pubkey::new_from_array([0xB2_u8; 32]), false);
|
|
let instruction_result = ksp_interface_lib::ProgramInstruction::try_new(program_id, std::vec![account], std::vec![0xB3_u8]);
|
|
assert!(instruction_result.is_ok());
|
|
let lifecycle = ksp_interface_lib::SlotLifecycleEvent::new(u64::MAX, ksp_interface_lib::SlotLifecycleStage::Rooted);
|
|
assert_eq!(lifecycle.slot(), u64::MAX);
|
|
assert_eq!(lifecycle.stage(), ksp_interface_lib::SlotLifecycleStage::Rooted);
|
|
}
|
|
|
|
#[test]
|
|
fn v0_3_5_pre_002_exact_crate_root_export_inventory_includes_slot_lifecycle() -> std::result::Result<(), std::io::Error> {
|
|
let source = match crate_root_source() {
|
|
Ok(source) => source,
|
|
Err(error) => return Err(error),
|
|
};
|
|
let public_use_count = source.lines().filter(|line| return line.starts_with("pub use ")).count();
|
|
assert_eq!(public_use_count, 8);
|
|
assert!(source.contains("pub use self::error::ERROR_CODE_PROGRAM_INSTRUCTION_LIMIT_EXCEEDED;"));
|
|
assert!(source.contains("pub use self::program_account_meta::MAX_PROGRAM_INSTRUCTION_ACCOUNTS;"));
|
|
assert!(source.contains("pub use self::program_account_meta::ProgramAccountMeta;"));
|
|
assert!(source.contains("pub use self::program_instruction::MAX_PROGRAM_INSTRUCTION_DATA_LEN;"));
|
|
assert!(source.contains("pub use self::program_instruction::ProgramInstruction;"));
|
|
assert!(source.contains("pub use self::slot_lifecycle::SlotLifecycleEvent;"));
|
|
assert!(source.contains("pub use self::slot_lifecycle::SlotLifecycleStage;"));
|
|
assert!(source.contains("pub use ksp_core_lib::Pubkey;"));
|
|
return Ok(());
|
|
}
|
|
|
|
#[test]
|
|
fn v0_3_5_pre_002_production_module_inventory_adds_only_slot_lifecycle() -> std::result::Result<(), std::io::Error> {
|
|
let source = match crate_root_source() {
|
|
Ok(source) => source,
|
|
Err(error) => return Err(error),
|
|
};
|
|
let modules = source
|
|
.lines()
|
|
.filter_map(|line| return line.strip_prefix("mod ").and_then(|module| return module.strip_suffix(';')))
|
|
.collect::<std::vec::Vec<_>>();
|
|
assert_eq!(modules, std::vec!["error", "program_account_meta", "program_instruction", "slot_lifecycle"]);
|
|
assert!(!source.contains("serde"));
|
|
assert!(!source.contains("tracing"));
|
|
assert!(!source.contains("ksp_onchain_transport"));
|
|
assert!(!source.contains("ksp_store"));
|
|
return Ok(());
|
|
}
|