| Crates.io | helia-interop |
| lib.rs | helia-interop |
| version | 0.1.3 |
| created_at | 2025-10-08 11:36:40.153978+00 |
| updated_at | 2025-10-11 04:07:14.709658+00 |
| description | Interoperability testing and compatibility utilities for Helia |
| homepage | https://github.com/cyberfly-io/rust-helia |
| repository | https://github.com/cyberfly-io/rust-helia |
| max_upload_size | |
| id | 1873897 |
| size | 187,049 |
Interoperability testing and compatibility utilities for Helia IPFS implementations.
This crate provides utilities for testing and verifying interoperability between different Helia implementations and IPFS nodes. It includes test utilities, compatibility checking, and benchmarking tools.
Add this to your Cargo.toml:
[dependencies]
helia-interop = "0.1.0"
use helia_interop::test_utils::verify_helia_basic;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), String> {
let helia = helia::create_helia_default().await
.map_err(|e| e.to_string())?;
// Verify basic functionality
verify_helia_basic(Arc::new(helia)).await?;
println!("Helia instance verified successfully!");
Ok(())
}
use helia_interop::test_utils::patterns;
// Generate test data
let data = patterns::generate_test_data(1024); // 1KB of test data
assert_eq!(data.len(), 1024);
// Use predefined patterns
let hello = patterns::HELLO_WORLD;
let empty = patterns::EMPTY;
let large = patterns::LARGE_TEXT;
use helia_interop::compat::VersionInfo;
let current_version = VersionInfo::new(1, 0, 0);
let other_version = VersionInfo::new(1, 5, 3);
let incompatible = VersionInfo::new(2, 0, 0);
// Check compatibility
assert!(current_version.is_compatible_with(&other_version));
assert!(!current_version.is_compatible_with(&incompatible));
println!("Version: {}", current_version); // "1.0.0"
use helia_interop::bench::bench_async;
#[tokio::main]
async fn main() {
// Benchmark an async operation
let result = bench_async("block_put", 100, || async {
// Your async operation here
tokio::time::sleep(std::time::Duration::from_micros(100)).await;
}).await;
println!("{}", result);
// Output: "block_put: 100 iterations in 10.5ms (9523.81 ops/sec)"
println!("Average: {:?}", result.avg_duration());
}
test_utilsTest utilities for verifying Helia implementations:
verify_helia_basic(): Verify basic Helia functionalitypatterns: Common test data patterns
generate_test_data(size): Generate test dataHELLO_WORLD: "Hello, World!" bytesEMPTY: Empty bytesLARGE_TEXT: Lorem ipsum textcompatVersion compatibility utilities:
VersionInfo: Version information struct
new(major, minor, patch): Create version infois_compatible_with(&other): Check compatibilitybenchBenchmarking utilities:
BenchResult: Benchmark result struct
avg_duration(): Average duration per iterationoperations_per_second(): Throughput calculationbench_async(): Run async benchmarksuse helia_interop::{test_utils, compat, bench};
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Check version compatibility
let current = compat::VersionInfo::new(1, 0, 0);
let required = compat::VersionInfo::new(1, 0, 0);
if !current.is_compatible_with(&required) {
return Err("Incompatible versions".into());
}
// Create and verify Helia instance
let helia = helia::create_helia_default().await?;
test_utils::verify_helia_basic(Arc::new(helia.clone())).await
.map_err(|e| e.to_string())?;
// Generate test data
let test_data = test_utils::patterns::generate_test_data(1024);
// Benchmark block storage
let helia_arc = Arc::new(helia);
let result = bench::bench_async("block_operations", 10, || {
let helia = helia_arc.clone();
let data = test_data.clone();
async move {
// Perform operations
}
}).await;
println!("Benchmark: {}", result);
Ok(())
}
Run the test suite:
cargo test
Current tests:
test_generate_test_data: Verify test data generationtest_version_compatibility: Verify version compatibility checkingtest_version_display: Verify version display formattingtest_bench_async: Verify async benchmarkingContributions are welcome! Areas for improvement:
Licensed under either of
at your option.