diff options
Diffstat (limited to 'src/simtest/identity.rs')
| -rw-r--r-- | src/simtest/identity.rs | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/simtest/identity.rs b/src/simtest/identity.rs index ed35389..3d235b0 100644 --- a/src/simtest/identity.rs +++ b/src/simtest/identity.rs @@ -14,7 +14,7 @@ use crate::swarm::bootstrap::Start; use crate::swarm::members; use crate::transport::identity::{WHO_LABEL, signed}; use crate::transport::sim::SimNet; -use crate::transport::{HeadsSummary, IdentityProof, Keepalive, ParsedMessage, Transport}; +use crate::transport::{HeadsSummary, IdentityProof, ParsedMessage, Status, Transport}; const SOON: Duration = Duration::from_secs(20); @@ -41,6 +41,22 @@ async fn nodes_are_their_node_ids() { for node in [&a, &b, &c] { peers_are_node_ids(node).await; } + // Where a sends to b: where b proved itself, on the sim's transport. + let destination = a.transport.destination(b.local_id()).unwrap(); + assert_eq!( + ( + destination.address.as_str(), + destination.proven, + destination.connection + ), + ("sim:b", true, None) + ); + // Its only path, measured by keepalives once there were any. + assert_eq!(destination.paths.len(), 1); + assert_eq!(destination.paths[0].address, "sim:b"); + let stats = a.transport.stats(); + assert_eq!(stats.identity.unwrap().proven["sim"], 2); + assert!(stats.libp2p.is_none()); let (b_id, c_id) = (b.local_id().to_owned(), c.local_id().to_owned()); let a = &a; sim.wait_until( @@ -83,8 +99,8 @@ async fn members_find_each_other_through_the_member_list() { } } -fn ping(node: &AppState) -> ParsedMessage { - ParsedMessage::Ping(Keepalive { +fn status(node: &AppState) -> ParsedMessage { + ParsedMessage::Status(Status { heads: HeadsSummary::of(Vec::new()), epoch: node.local_epoch(), epoch_seq: 0, @@ -115,15 +131,18 @@ async fn a_proof_holds_only_at_its_address() { who(&ghost, "sim:ghost", "sim:b"), ] { sim.net.inject("ghost", "a", &forged).await.unwrap(); - sim.net.inject("ghost", "a", &ping(&a)).await.unwrap(); + sim.net.inject("ghost", "a", &status(&a)).await.unwrap(); assert!(a.get_peer_state(&ghost.id()).await.is_none()); } + let counts = a.transport.stats().identity.unwrap().counts; + assert_eq!(counts.proofs_rejected, 2); + assert!(counts.dropped_unproven >= 2); sim.net .inject("ghost", "a", &who(&ghost, "sim:ghost", "sim:a")) .await .unwrap(); - sim.net.inject("ghost", "a", &ping(&a)).await.unwrap(); + sim.net.inject("ghost", "a", &status(&a)).await.unwrap(); assert!(a.get_peer_state(&ghost.id()).await.is_some()); // Known by its node ID, not by its address. assert!(a.get_peer_state("ghost").await.is_none()); @@ -176,7 +195,7 @@ async fn nodes_on_both_transports_carry_the_others() { #[cfg(feature = "libp2p")] #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn nodes_over_libp2p() { - use crate::transport::p2p::{Libp2pConfig, Libp2pTransport}; + use crate::transport::libp2p::{Libp2pConfig, Libp2pTransport}; use ::libp2p::identity::Keypair; use sha2::Digest; |
