diff options
Diffstat (limited to 'src/simtest')
| -rw-r--r-- | src/simtest/identity.rs | 31 | ||||
| -rw-r--r-- | src/simtest/timing.rs | 16 |
2 files changed, 33 insertions, 14 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; diff --git a/src/simtest/timing.rs b/src/simtest/timing.rs index ce1dfd5..20ad15c 100644 --- a/src/simtest/timing.rs +++ b/src/simtest/timing.rs @@ -10,7 +10,7 @@ use crate::document::replica::Epoch; use crate::state::{AppState, Liveness}; use crate::swarm::bootstrap::Start; use crate::transport::sim::LinkParams; -use crate::transport::{HeadsSummary, HelloRequest, Keepalive, MessageKind, ParsedMessage, RunId}; +use crate::transport::{HeadsSummary, HelloRequest, MessageKind, ParsedMessage, RunId, Status}; /// Long enough for anything that should happen within a few keepalives. const SOON: Duration = Duration::from_secs(10); @@ -311,8 +311,8 @@ async fn late_epoch_does_not_flip_a_peers_epoch() { handshake: 1, }) }; - let ping = |epoch: Epoch, epoch_seq: u32| { - ParsedMessage::Ping(Keepalive { + let status = |epoch: Epoch, epoch_seq: u32| { + ParsedMessage::Status(Status { heads: HeadsSummary::of(Vec::new()), epoch, epoch_seq, @@ -336,20 +336,20 @@ async fn late_epoch_does_not_flip_a_peers_epoch() { // The ghost switched twice; we hear of the second switch first. sim.net - .inject("ghost", "a", &ping(epoch(2), 2)) + .inject("ghost", "a", &status(epoch(2), 2)) .await .unwrap(); assert_eq!(recorded().await, (Some(epoch(2)), Some(2))); - // The PING from between the switches arrives late: ignored. + // The STATUS from between the switches arrives late: ignored. sim.net - .inject("ghost", "a", &ping(epoch(1), 1)) + .inject("ghost", "a", &status(epoch(1), 1)) .await .unwrap(); assert_eq!(recorded().await, (Some(epoch(2)), Some(2))); // So is one from before both. sim.net - .inject("ghost", "a", &ping(Epoch::GENESIS, 0)) + .inject("ghost", "a", &status(Epoch::GENESIS, 0)) .await .unwrap(); assert_eq!(recorded().await, (Some(epoch(2)), Some(2))); @@ -366,7 +366,7 @@ async fn late_epoch_does_not_flip_a_peers_epoch() { Some(second_run) ); sim.net - .inject("ghost", "a", &ping(epoch(3), 1)) + .inject("ghost", "a", &status(epoch(3), 1)) .await .unwrap(); assert_eq!(recorded().await, (Some(epoch(3)), Some(1))); |
