From 85433a87d9c5b2ed7b21cd49e5e85be5c1c27574 Mon Sep 17 00:00:00 2001 From: plebhash Date: Thu, 9 Jan 2025 11:05:45 -0300 Subject: [PATCH] expand `test_sniffer_intercept` to make test comprehensive.. we need 2 sniffers to assert the message was correctly replaced and fully delivered over the TCP connection --- .../tests/sniffer_integration.rs | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/roles/tests-integration/tests/sniffer_integration.rs b/roles/tests-integration/tests/sniffer_integration.rs index 7cd812c85..dd316f721 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,21 @@ 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 + ); }