-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::{net::SocketAddr, str::FromStr, time::Duration}; | ||
|
||
use tokio::time::sleep; | ||
|
||
use crate::utils::{get_available_port, is_port_open}; | ||
|
||
mod common; | ||
mod utils; | ||
|
||
#[tokio::test] | ||
async fn success_pool_template_provider_connection() { | ||
let template_provider_port = get_available_port().unwrap(); | ||
let template_provider = common::TestTemplateProvider::start(template_provider_port); | ||
template_provider.generate_blocks(16); | ||
let pool_port = get_available_port().unwrap(); | ||
let pool_listening_address = SocketAddr::from_str(&format!("127.0.0.1:{}", pool_port)).unwrap(); | ||
let is_pool_port_open = is_port_open(pool_listening_address); | ||
assert_eq!(is_pool_port_open, false); | ||
let pool = common::TestPoolSv2::new( | ||
pool_listening_address, | ||
None, | ||
Some(SocketAddr::from_str(&format!("127.0.0.1:{}", template_provider_port)).unwrap()), | ||
); | ||
let state = pool.state().await.safe_lock(|s| s.clone()).unwrap(); | ||
assert_eq!(state, pool_sv2::PoolState::Initial); | ||
let _pool = pool.clone(); | ||
tokio::task::spawn(async move { | ||
let _ = _pool.start().await; | ||
}); | ||
// Wait for the pool to start. | ||
sleep(Duration::from_secs(1)).await; | ||
loop { | ||
if is_port_open(pool_listening_address) { | ||
break; | ||
} | ||
} | ||
let state = pool.state().await.safe_lock(|s| s.clone()).unwrap(); | ||
assert_eq!(state, pool_sv2::PoolState::Running); | ||
template_provider.stop(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn pool_bad_coinbase_output() { | ||
let template_provider_port = get_available_port().unwrap(); | ||
let template_provider = common::TestTemplateProvider::start(template_provider_port); | ||
template_provider.generate_blocks(16); | ||
let pool_port = get_available_port().unwrap(); | ||
let pool_listening_address = SocketAddr::from_str(&format!("127.0.0.1:{}", pool_port)).unwrap(); | ||
let is_pool_port_open = is_port_open(pool_listening_address); | ||
assert_eq!(is_pool_port_open, false); | ||
let coinbase_output = vec![pool_sv2::mining_pool::CoinbaseOutput::new( | ||
"P2PK".to_string(), | ||
"04466d7fcae563e5cb09a0d1870bb580344804617879a14949cf22285f1bae3f276728176c3c6431f8eeda4538dc37c865e2784f3a9e77d044f33e407797e1278".to_string(), | ||
)]; | ||
let pool = common::TestPoolSv2::new( | ||
pool_listening_address, | ||
Some(coinbase_output), | ||
Some(SocketAddr::from_str(&format!("127.0.0.1:{}", template_provider_port)).unwrap()), | ||
) | ||
.clone(); | ||
let state = pool.state().await.safe_lock(|s| s.clone()).unwrap(); | ||
assert_eq!(state, pool_sv2::PoolState::Initial); | ||
assert!(pool.start().await.is_err()); | ||
let state = pool.state().await.safe_lock(|s| s.clone()).unwrap(); | ||
assert_eq!(state, pool_sv2::PoolState::Initial); | ||
template_provider.stop(); | ||
} |