#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod coverage_tests_api {
use super::*;
fn minimal_wasm_module() -> Vec<u8> {
vec![
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, ]
}
fn simple_function_wasm() -> Vec<u8> {
vec![
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x05, 0x01, 0x60, 0x00, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x41, 0x01, 0x41, 0x02, 0x6a, 0x0b, ]
}
fn memory_wasm() -> Vec<u8> {
vec![
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x05, 0x04, 0x01, 0x01, 0x02, 0x10, ]
}
fn mixed_instructions_wasm() -> Vec<u8> {
vec![
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x05, 0x01, 0x60, 0x00, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x05, 0x03, 0x01, 0x00, 0x01, 0x0a, 0x11, 0x01, 0x0f, 0x00, 0x02, 0x7f, 0x41, 0x00, 0x28, 0x02, 0x00, 0x41, 0x01, 0x6a, 0x0c, 0x00, 0x0b, 0x0b, ]
}
#[tokio::test]
async fn test_analyze_wasm_module_minimal() {
let result = analyze_wasm_module(&minimal_wasm_module()).await;
assert!(result.is_ok());
let analysis = result.unwrap();
assert_eq!(analysis.instruction_mix.total_instructions, 0);
assert!(analysis.vulnerability_patterns.is_empty());
}
#[tokio::test]
async fn test_analyze_wasm_module_simple_function() {
let result = analyze_wasm_module(&simple_function_wasm()).await;
assert!(result.is_ok());
let analysis = result.unwrap();
assert!(analysis.instruction_mix.total_instructions > 0);
}
#[tokio::test]
async fn test_analyze_wasm_module_mixed_instructions() {
let result = analyze_wasm_module(&mixed_instructions_wasm()).await;
assert!(result.is_ok());
let analysis = result.unwrap();
assert!(analysis.instruction_mix.control_flow > 0);
assert!(analysis.instruction_mix.memory_ops > 0);
assert!(analysis.instruction_mix.arithmetic > 0);
}
#[tokio::test]
async fn test_analyze_wasm_module_invalid_binary() {
let invalid = vec![0x00, 0x01, 0x02, 0x03]; let result = analyze_wasm_module(&invalid).await;
assert!(result.is_err());
}
#[tokio::test]
async fn test_analyze_wasm_module_empty_input() {
let result = analyze_wasm_module(&[]).await;
assert!(result.is_err());
}
#[test]
fn test_verify_wasm_safety_minimal() {
let result = verify_wasm_safety(&minimal_wasm_module());
assert!(result.is_ok());
let verification = result.unwrap();
assert!(verification.is_safe());
}
#[test]
fn test_verify_wasm_safety_simple_function() {
let result = verify_wasm_safety(&simple_function_wasm());
assert!(result.is_ok());
let verification = result.unwrap();
assert!(verification.is_safe());
}
#[test]
fn test_verify_wasm_safety_mixed_instructions() {
let result = verify_wasm_safety(&mixed_instructions_wasm());
assert!(result.is_ok());
}
#[test]
fn test_verify_wasm_safety_invalid_binary() {
let invalid = vec![0x00, 0x01, 0x02, 0x03];
let result = verify_wasm_safety(&invalid);
assert!(result.is_err());
}
#[test]
fn test_verify_wasm_safety_empty_input() {
let result = verify_wasm_safety(&[]);
assert!(result.is_err());
}
#[tokio::test]
async fn test_profile_wasm_module_minimal() {
let result = profile_wasm_module(&minimal_wasm_module()).await;
assert!(result.is_ok());
let report = result.unwrap();
assert_eq!(report.instruction_mix.total_instructions, 0);
}
#[tokio::test]
async fn test_profile_wasm_module_simple_function() {
let result = profile_wasm_module(&simple_function_wasm()).await;
assert!(result.is_ok());
let report = result.unwrap();
assert!(report.instruction_mix.total_instructions > 0);
}
#[tokio::test]
async fn test_profile_wasm_module_with_memory() {
let result = profile_wasm_module(&memory_wasm()).await;
assert!(result.is_ok());
let report = result.unwrap();
assert_eq!(report.memory_usage.initial_pages, 2);
assert_eq!(report.memory_usage.max_pages, Some(16));
}
#[tokio::test]
async fn test_profile_wasm_module_mixed_instructions() {
let result = profile_wasm_module(&mixed_instructions_wasm()).await;
assert!(result.is_ok());
let report = result.unwrap();
assert!(report.instruction_mix.control_flow > 0);
assert!(report.instruction_mix.memory_ops > 0);
assert!(report.instruction_mix.arithmetic > 0);
}
#[tokio::test]
async fn test_profile_wasm_module_invalid_binary() {
let invalid = vec![0x00, 0x01, 0x02, 0x03];
let result = profile_wasm_module(&invalid).await;
assert!(result.is_err());
}
#[tokio::test]
async fn test_profile_wasm_module_empty_input() {
let result = profile_wasm_module(&[]).await;
assert!(result.is_err());
}
}