Skip to content

Commit c52c843

Browse files
committed
Test JDC pool fallback functionality
1 parent 36e00e8 commit c52c843

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

roles/tests-integration/tests/jd_integration.rs

+42-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
//
55
// Note that it is enough to call `start_tracing()` once in the test suite to enable tracing for
66
// all tests. This is because tracing is a global setting.
7+
use const_sv2::{MESSAGE_TYPE_SETUP_CONNECTION, MESSAGE_TYPE_SUBMIT_SHARES_SUCCESS};
78
use integration_tests_sv2::*;
8-
9-
use roles_logic_sv2::parsers::{CommonMessages, PoolMessages};
9+
use roles_logic_sv2::{
10+
mining_sv2::SubmitSharesError,
11+
parsers::{CommonMessages, Mining, PoolMessages},
12+
};
13+
use sniffer::{InterceptMessage, MessageDirection};
14+
use std::convert::TryInto;
1015

1116
// This test verifies that the `jds` (Job Decleration Server) does not panic when the `jdc`
1217
// (Job Decleration Client) shuts down.
@@ -41,3 +46,38 @@ async fn jds_should_not_panic_if_jdc_shutsdown() {
4146
let (_jdc, _jdc_addr) = start_jdc(vec![pool_addr], tp_addr, sniffer_addr).await;
4247
assert_common_message!(sniffer.next_message_from_downstream(), SetupConnection);
4348
}
49+
50+
// Start JDClient with two pools in the pool list config. The test forces the first pool to send a
51+
// share submission rejection by altering a message(MINING_SET_NEW_PREV_HASH) sent by the pool. The
52+
// test verifies that the second pool will be used as a fallback.
53+
#[tokio::test]
54+
async fn test_jdc_pool_fallback_after_submit_rejection() {
55+
let (_tp, tp_addr) = start_template_provider(None);
56+
let (_pool, pool_addr) = start_pool(Some(tp_addr)).await;
57+
let (sniffer_1, sniffer_addr) = start_sniffer(
58+
"0".to_string(),
59+
pool_addr,
60+
false,
61+
Some(vec![InterceptMessage::new(
62+
MessageDirection::ToDownstream,
63+
MESSAGE_TYPE_SUBMIT_SHARES_SUCCESS,
64+
PoolMessages::Mining(Mining::SubmitSharesError(SubmitSharesError {
65+
channel_id: 0,
66+
sequence_number: 0,
67+
error_code: "invalid-nonce".to_string().into_bytes().try_into().unwrap(),
68+
})),
69+
)]),
70+
)
71+
.await;
72+
let (_pool_2, pool_addr_2) = start_pool(Some(tp_addr)).await;
73+
let (sniffer_2, sniffer_addr_2) =
74+
start_sniffer("1".to_string(), pool_addr_2, false, None).await;
75+
let (_jds, jds_addr) = start_jds(tp_addr).await;
76+
let (_jdc, jdc_addr) = start_jdc(vec![sniffer_addr, sniffer_addr_2], tp_addr, jds_addr).await;
77+
assert_common_message!(&sniffer_1.next_message_from_downstream(), SetupConnection);
78+
let (_translator, sv2_translator_addr) = start_sv2_translator(jdc_addr).await;
79+
let _ = start_mining_device_sv1(sv2_translator_addr, true).await;
80+
sniffer_2
81+
.wait_for_message_type(MessageDirection::ToUpstream, MESSAGE_TYPE_SETUP_CONNECTION)
82+
.await;
83+
}

0 commit comments

Comments
 (0)