|
4 | 4 | //
|
5 | 5 | // Note that it is enough to call `start_tracing()` once in the test suite to enable tracing for
|
6 | 6 | // all tests. This is because tracing is a global setting.
|
| 7 | +use const_sv2::{MESSAGE_TYPE_SETUP_CONNECTION, MESSAGE_TYPE_SUBMIT_SHARES_SUCCESS}; |
7 | 8 | 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; |
10 | 15 |
|
11 | 16 | // This test verifies that the `jds` (Job Decleration Server) does not panic when the `jdc`
|
12 | 17 | // (Job Decleration Client) shuts down.
|
@@ -41,3 +46,38 @@ async fn jds_should_not_panic_if_jdc_shutsdown() {
|
41 | 46 | let (_jdc, _jdc_addr) = start_jdc(vec![pool_addr], tp_addr, sniffer_addr).await;
|
42 | 47 | assert_common_message!(sniffer.next_message_from_downstream(), SetupConnection);
|
43 | 48 | }
|
| 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