NAC_Blockchain/nvm_v2/cross_layer_test.rs

46 lines
1.6 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 跨层类型兼容性测试
// 验证L0和L1层使用相同的NAC UDM类型定义
use nvm_l0::types::{Address as L0Address, Hash as L0Hash};
use nvm_l1::types::{Address as L1Address, Hash as L1Hash};
fn main() {
println!("=== NAC跨层类型兼容性测试 ===\n");
// 测试1: Address类型兼容性
println!("测试1: Address类型兼容性");
let addr_bytes = [1u8; 32];
let l0_addr = L0Address::new(addr_bytes);
let l1_addr = L1Address::new(addr_bytes);
println!(" L0 Address: {}", l0_addr.to_hex());
println!(" L1 Address: {}", l1_addr.to_hex());
assert_eq!(l0_addr.to_hex(), l1_addr.to_hex(), "Address类型不兼容");
println!(" ✅ Address类型兼容\n");
// 测试2: Hash类型兼容性
println!("测试2: Hash类型兼容性");
let data = b"hello world";
let l0_hash = L0Hash::sha3_384(data);
let l1_hash = L1Hash::sha3_384(data);
println!(" L0 Hash: {}", l0_hash.to_hex());
println!(" L1 Hash: {}", l1_hash.to_hex());
assert_eq!(l0_hash.to_hex(), l1_hash.to_hex(), "Hash类型不兼容");
println!(" ✅ Hash类型兼容\n");
// 测试3: 类型可以互相传递
println!("测试3: 类型传递测试");
fn process_address(addr: L0Address) -> String {
addr.to_hex()
}
// L1的Address应该可以传递给接受L0 Address的函数
// 因为它们实际上是同一个类型来自NAC UDM
let result = process_address(l1_addr);
println!(" 传递结果: {}", result);
println!(" ✅ 类型可以跨层传递\n");
println!("=== 所有测试通过!===");
}