Skip to content

Commit

Permalink
expand test_sniffer_intercept to make test comprehensive..
Browse files Browse the repository at this point in the history
we need 2 sniffers to assert the message was correctly replaced and fully delivered over the TCP connection
  • Loading branch information
plebhash committed Jan 9, 2025
1 parent 32101ff commit 85433a8
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions roles/tests-integration/tests/sniffer_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
);
}

0 comments on commit 85433a8

Please sign in to comment.