Skip to content

Commit

Permalink
Add translator_sv2 test
Browse files Browse the repository at this point in the history
  • Loading branch information
jbesraa committed Dec 12, 2024
1 parent 22da418 commit a7551ff
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
8 changes: 5 additions & 3 deletions roles/tests-integration/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ pub async fn start_pool(
let pool = test_pool.pool.clone();
let pool_clone = pool.clone();
tokio::task::spawn(async move {
assert!(pool_clone.start().await.is_ok());
let ret = pool_clone.start().await;
dbg!(&ret);
assert!(ret.is_ok());
});
// Wait a bit to let the pool exchange initial messages with the TP
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
Expand Down Expand Up @@ -395,9 +397,9 @@ pub async fn start_sv2_translator(upstream: SocketAddr) -> SocketAddr {
.expect("failed");
let listening_address = get_available_address();
let listening_port = listening_address.port();
let hashrate = measure_hashrate(3) as f32 / 100.0;
let hashrate = measure_hashrate(1) as f32 / 20.0;
let min_individual_miner_hashrate = hashrate;
let shares_per_minute = 60.0;
let shares_per_minute = 100.0;
let channel_diff_update_interval = 60;
let channel_nominal_hashrate = hashrate;
let downstream_difficulty_config =
Expand Down
58 changes: 56 additions & 2 deletions roles/tests-integration/tests/pool_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ mod common;
use std::convert::TryInto;

use common::{InterceptMessage, MessageDirection};
use const_sv2::MESSAGE_TYPE_SETUP_CONNECTION_ERROR;
use const_sv2::{
MESSAGE_TYPE_SETUP_CONNECTION, MESSAGE_TYPE_SETUP_CONNECTION_ERROR,
MESSAGE_TYPE_SUBMIT_SHARES_EXTENDED,
};
use roles_logic_sv2::{
common_messages_sv2::{Protocol, SetupConnection, SetupConnectionError},
parsers::{CommonMessages, PoolMessages, TemplateDistribution},
parsers::{CommonMessages, Mining, PoolMessages, TemplateDistribution},
};

// This test starts a Template Provider and a Pool, and checks if they exchange the correct
Expand Down Expand Up @@ -94,3 +97,54 @@ async fn test_sniffer_interrupter() {
assert_common_message!(&sniffer.next_message_from_downstream(), SetupConnection);
assert_common_message!(&sniffer.next_message_from_upstream(), SetupConnectionError);
}

// covers
// https://github.com/stratum-mining/stratum/blob/main/test/message-generator/test/translation-proxy/translation-proxy.json
#[tokio::test]
async fn translation_proxy() {
let pool_translator_sniffer_addr = common::get_available_address();
let tp_addr = common::get_available_address();
let pool_addr = common::get_available_address();

let pool_translator_sniffer = common::start_sniffer(
"0".to_string(),
pool_translator_sniffer_addr,
pool_addr,
false,
None,
)
.await;
let _tp = common::start_template_provider(tp_addr.port()).await;
let _pool = common::start_pool(Some(pool_addr), Some(tp_addr)).await;
let tproxy_addr = common::start_sv2_translator(pool_translator_sniffer_addr).await;
let _mining_device = common::start_mining_device_sv1(tproxy_addr).await;
pool_translator_sniffer
.wait_for_message_type(MessageDirection::ToUpstream, MESSAGE_TYPE_SETUP_CONNECTION)
.await;
assert_common_message!(
&pool_translator_sniffer.next_message_from_downstream(),
SetupConnection
);
assert_common_message!(
&pool_translator_sniffer.next_message_from_upstream(),
SetupConnectionSuccess
);
assert_mining_message!(
&pool_translator_sniffer.next_message_from_downstream(),
OpenExtendedMiningChannel
);
assert_mining_message!(
&pool_translator_sniffer.next_message_from_upstream(),
OpenExtendedMiningChannelSuccess
);
assert_mining_message!(
&pool_translator_sniffer.next_message_from_upstream(),
NewExtendedMiningJob
);
pool_translator_sniffer
.wait_for_message_type(
MessageDirection::ToUpstream,
MESSAGE_TYPE_SUBMIT_SHARES_EXTENDED,
)
.await;
}

0 comments on commit a7551ff

Please sign in to comment.