Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions integration-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 118 additions & 0 deletions integration-tests/tests/jd_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,124 @@ async fn jds_reject_setup_connection_without_declare_tx_data_flag() {
shutdown_all!(pool);
}

// This test verifies that JDS rejects SetupConnection requesting only protocol version 3,
// since JDS only supports version 2, responding with a SetupConnectionError carrying the
// protocol-version-mismatch error code.
#[tokio::test]
async fn jds_reject_setup_connection_with_unsupported_version() {
start_tracing();
let (tp, _tp_addr) = start_template_provider(None, DifficultyLevel::Low);
let (pool, _pool_addr, jds_addr, _) =
start_pool_with_jds(tp.bitcoin_core(), vec![], vec![], false).await;
let (sniffer, sniffer_addr) = start_sniffer("mock-jds", jds_addr, false, vec![], None);
let _mock_downstream = MockDownstream::new(
sniffer_addr,
WithSetup::yes(SetupConnectionOwned {
protocol: Protocol::JobDeclarationProtocol,
min_version: 3,
max_version: 3,
flags: 0,
endpoint_host: "0.0.0.0".try_into().unwrap(),
endpoint_port: 0,
vendor: "integration-test".try_into().unwrap(),
hardware_version: "".try_into().unwrap(),
firmware: "".try_into().unwrap(),
device_id: "".try_into().unwrap(),
}),
)
.start()
.await;

sniffer
.wait_for_message_type(MessageDirection::ToUpstream, MESSAGE_TYPE_SETUP_CONNECTION)
.await;
sniffer
.wait_for_message_type(
MessageDirection::ToDownstream,
MESSAGE_TYPE_SETUP_CONNECTION_ERROR,
)
.await;

let setup_connection_error = sniffer.next_message_from_upstream();
let setup_connection_error = match setup_connection_error {
Some((
_,
AnyMessageOwned::Common(parsers_sv2::CommonMessagesOwned::SetupConnectionError(msg)),
)) => msg,
msg => panic!("Expected SetupConnectionError message, found: {:?}", msg),
};
assert_eq!(
setup_connection_error.error_code.as_utf8_or_hex(),
ERROR_CODE_SETUP_CONNECTION_PROTOCOL_VERSION_MISMATCH,
"SetupConnectionError message error code should be protocol-version-mismatch"
);

shutdown_all!(pool);
}

// This test verifies that JDC rejects a downstream SetupConnection requesting only protocol
// version 3, since JDC only supports version 2 on its downstream interface, responding with a
// SetupConnectionError carrying the protocol-version-mismatch error code.
#[tokio::test]
async fn jdc_reject_downstream_setup_connection_with_unsupported_version() {
start_tracing();
let (tp, tp_addr) = start_template_provider(None, DifficultyLevel::Low);
let (pool, pool_addr, jds_addr, _) =
start_pool_with_jds(tp.bitcoin_core(), vec![], vec![], false).await;
let (jdc, jdc_addr, _) = start_jdc(
&[(pool_addr, jds_addr)],
sv2_tp_config(tp_addr),
vec![],
vec![],
false,
None,
);
let (sniffer, sniffer_addr) = start_sniffer("mock-jdc", jdc_addr, false, vec![], None);
let _mock_downstream = MockDownstream::new(
sniffer_addr,
WithSetup::yes(SetupConnectionOwned {
protocol: Protocol::MiningProtocol,
min_version: 3,
max_version: 3,
flags: 0,
endpoint_host: "0.0.0.0".try_into().unwrap(),
endpoint_port: 0,
vendor: "integration-test".try_into().unwrap(),
hardware_version: "".try_into().unwrap(),
firmware: "".try_into().unwrap(),
device_id: "".try_into().unwrap(),
}),
)
.start()
.await;

sniffer
.wait_for_message_type(MessageDirection::ToUpstream, MESSAGE_TYPE_SETUP_CONNECTION)
.await;
sniffer
.wait_for_message_type(
MessageDirection::ToDownstream,
MESSAGE_TYPE_SETUP_CONNECTION_ERROR,
)
.await;

let setup_connection_error = sniffer.next_message_from_upstream();
let setup_connection_error = match setup_connection_error {
Some((
_,
AnyMessageOwned::Common(parsers_sv2::CommonMessagesOwned::SetupConnectionError(msg)),
)) => msg,
msg => panic!("Expected SetupConnectionError message, found: {:?}", msg),
};
assert_eq!(
setup_connection_error.error_code.as_utf8_or_hex(),
ERROR_CODE_SETUP_CONNECTION_PROTOCOL_VERSION_MISMATCH,
"SetupConnectionError message error code should be protocol-version-mismatch"
);

shutdown_all!(jdc, pool);
}

#[tokio::test]
async fn jdc_coinbase_only_mode_rejected_by_jds() {
start_tracing();
Expand Down
50 changes: 50 additions & 0 deletions integration-tests/tests/pool_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,56 @@ async fn pool_reject_setup_connection_with_non_mining_protocol() {
shutdown_all!(translator, pool);
}

// The test runs a pool and a mock downstream that sends a SetupConnection message requesting
// only protocol version 3. Since the pool only supports version 2, this test asserts that the
// pool responds with a SetupConnectionError carrying the protocol-version-mismatch error code.
#[tokio::test]
async fn pool_reject_setup_connection_with_unsupported_version() {
start_tracing();
let (_tp, tp_addr) = start_template_provider(None, DifficultyLevel::Low);
let (pool, pool_addr, _) = start_pool(sv2_tp_config(tp_addr), vec![], vec![], false).await;
let (sniffer, sniffer_addr) = start_sniffer("0", pool_addr, false, vec![], None);
let _mock_downstream = MockDownstream::new(
sniffer_addr,
WithSetup::yes(SetupConnectionOwned {
protocol: Protocol::MiningProtocol,
min_version: 3,
max_version: 3,
flags: 0,
endpoint_host: "0.0.0.0".try_into().unwrap(),
endpoint_port: 0,
vendor: "integration-test".try_into().unwrap(),
hardware_version: "".try_into().unwrap(),
firmware: "".try_into().unwrap(),
device_id: "".try_into().unwrap(),
}),
)
.start()
.await;

sniffer
.wait_for_message_type(MessageDirection::ToUpstream, MESSAGE_TYPE_SETUP_CONNECTION)
.await;
sniffer
.wait_for_message_type(
MessageDirection::ToDownstream,
MESSAGE_TYPE_SETUP_CONNECTION_ERROR,
)
.await;

let setup_connection_error = sniffer.next_message_from_upstream();
let setup_connection_error = match setup_connection_error {
Some((_, AnyMessageOwned::Common(CommonMessagesOwned::SetupConnectionError(msg)))) => msg,
msg => panic!("Expected SetupConnectionError message, found: {:?}", msg),
};
assert_eq!(
setup_connection_error.error_code.as_utf8_or_hex(),
ERROR_CODE_SETUP_CONNECTION_PROTOCOL_VERSION_MISMATCH,
"SetupConnectionError message error code should be protocol-version-mismatch"
);
shutdown_all!(pool);
}

// This test verifies that pool rejects SetCustomMiningJob when it is started without embedded JDS
// (`start_pool` with no `[jds]` config).
#[tokio::test]
Expand Down
Loading
Loading