|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
#![no_std] |
|
|
|
|
#![allow(dead_code)] |
|
|
|
|
|
|
|
|
|
extern crate alloc; |
|
|
|
|
#[cfg(feature = "std")] |
|
|
|
@ -17,7 +18,7 @@ mod tunnel;
|
|
|
|
|
mod tests { |
|
|
|
|
mod iron_force { |
|
|
|
|
#[test] |
|
|
|
|
fn creation_works() { |
|
|
|
|
fn creation() { |
|
|
|
|
use crate::ironforce::IronForce; |
|
|
|
|
IronForce::new(); |
|
|
|
|
} |
|
|
|
@ -48,7 +49,7 @@ mod tests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_invalid_sign() { |
|
|
|
|
fn invalid_sign() { |
|
|
|
|
let key_pack = Keys::gen(); |
|
|
|
|
let mut msg = Message::new( |
|
|
|
|
MsgType::MultiCast, Vec::<u8>::new(), &key_pack, |
|
|
|
@ -58,7 +59,7 @@ mod tests {
|
|
|
|
|
msg.hash = [0; 64].to_vec(); |
|
|
|
|
msg.sign = crate::message::Sign::Signed( |
|
|
|
|
key_pack.get_public(), |
|
|
|
|
key_pack.sign(&msg.content_hash) |
|
|
|
|
key_pack.sign(&msg.content_hash), |
|
|
|
|
); |
|
|
|
|
assert!(!&msg.verify()); |
|
|
|
|
} |
|
|
|
@ -71,4 +72,54 @@ mod tests {
|
|
|
|
|
msg.get_hash(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
mod tunnel { |
|
|
|
|
use crate::tunnel::Tunnel; |
|
|
|
|
use crate::crypto::PublicKey; |
|
|
|
|
|
|
|
|
|
fn key(i: u8) -> PublicKey { |
|
|
|
|
PublicKey { key: [i; 32] } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn create_test_tunnel() -> Tunnel { |
|
|
|
|
Tunnel::from_vec([ |
|
|
|
|
key(0), key(1), key(2), key(3), key(4) |
|
|
|
|
].to_vec()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn creation() { |
|
|
|
|
create_test_tunnel(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_next() { |
|
|
|
|
let tunnel = create_test_tunnel(); |
|
|
|
|
assert_eq!(tunnel.next(&key(1), &key(3)), Some(key(2))); |
|
|
|
|
assert_eq!(tunnel.next(&key(2), &key(0)), Some(key(1))); |
|
|
|
|
assert_eq!(tunnel.next(&key(2), &key(2)), None); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn is_in_tunnel() { |
|
|
|
|
let tunnel = create_test_tunnel(); |
|
|
|
|
assert!(tunnel.is_in_tunnel(&key(0))); |
|
|
|
|
assert!(tunnel.is_in_tunnel(&key(1))); |
|
|
|
|
assert!(tunnel.is_in_tunnel(&key(4))); |
|
|
|
|
assert!(!tunnel.is_in_tunnel(&key(5))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn tunnel_to() { |
|
|
|
|
let tunnel = create_test_tunnel(); |
|
|
|
|
let me = &key(2); |
|
|
|
|
assert_eq!(tunnel.tunnel_to(me, &key(5)), None); |
|
|
|
|
assert_eq!(tunnel.tunnel_to(me, &key(3)), Some( |
|
|
|
|
Tunnel::from_vec([key(2), key(3)].to_vec()) |
|
|
|
|
)); |
|
|
|
|
assert_eq!(tunnel.tunnel_to(me, &key(0)), Some( |
|
|
|
|
Tunnel::from_vec([key(0), key(1), key(2)].to_vec()) |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|