diff --git a/roles/tests-integration/tests/sniffer_integration.rs b/roles/tests-integration/tests/sniffer_integration.rs index 7cd812c85..821dff703 100644 --- a/roles/tests-integration/tests/sniffer_integration.rs +++ b/roles/tests-integration/tests/sniffer_integration.rs @@ -7,10 +7,15 @@ use roles_logic_sv2::{ use sniffer::{InterceptMessage, MessageDirection}; use std::convert::TryInto; +// this test aims to assert that Sniffer is able to intercept and replace some message +// sniffer_a replaces a SetupConnectionSuccess from TP with a SetupConnectionError directed at Pool +// sniffer_b asserts that Pool is about to receive a SetupConnectionError +// TP -> sniffer_a -> sniffer_b -> Pool #[tokio::test] async fn test_sniffer_intercept() { - let (_tp, tp_addr) = start_template_provider(None).await; use const_sv2::MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS; + + let (_tp, tp_addr) = start_template_provider(None).await; let message_replacement = PoolMessages::Common(CommonMessages::SetupConnectionError(SetupConnectionError { flags: 0, @@ -26,9 +31,18 @@ async fn test_sniffer_intercept() { message_replacement, MESSAGE_TYPE_SETUP_CONNECTION_ERROR, ); - let (sniffer, sniffer_addr) = - start_sniffer("".to_string(), tp_addr, false, Some(vec![intercept])).await; - let _ = start_pool(Some(sniffer_addr)).await; - assert_common_message!(&sniffer.next_message_from_downstream(), SetupConnection); - assert_common_message!(&sniffer.next_message_from_upstream(), SetupConnectionError); + + // this sniffer will replace SetupConnectionSuccess with SetupConnectionError + let (_sniffer_a, sniffer_a_addr) = + start_sniffer("A".to_string(), tp_addr, false, Some(vec![intercept])).await; + + // this sniffer will assert SetupConnectionSuccess was correctly replaced with SetupConnectionError + let (sniffer_b, sniffer_b_addr) = + start_sniffer("B".to_string(), sniffer_a_addr, false, None).await; + + let _ = start_pool(Some(sniffer_b_addr)).await; + + // assert sniffer_a functionality of replacing messages work as expected (goal of this test) + assert_common_message!(&sniffer_b.next_message_from_upstream(), SetupConnectionError); + }