Skip to content

Commit

Permalink
Add integration test for mining device auth..
Browse files Browse the repository at this point in the history
failure with a pool.

This test run a `TemplateProvider`, `PoolSv2` and a `mining_device`
with the auth-failure flag enable which will result in the `PoolSv2` to
reject the `mining_device`.
  • Loading branch information
jbesraa committed Sep 16, 2024
1 parent 1b4cafa commit 2700a7d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions roles/Cargo.lock

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

4 changes: 4 additions & 0 deletions roles/tests-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ tar = "0.4.41"
pool_sv2 = { version = "0.1.0", path = "../pool" }
key-utils = { version = "1.0.0", path = "../../utils/key-utils" }
tokio = { version = "1.16.1", features = ["full"] }
mining_device = { version = "0.1.1", path = "../test-utils/mining-device" }

[lib]
path = "tests/common/mod.rs"

[features]
mining_device_reject_auth = ["pool_sv2/MG_reject_auth", "mining_device/abort_mining"]
10 changes: 10 additions & 0 deletions roles/tests-integration/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,13 @@ pub async fn start_template_provider_and_pool() -> Result<(PoolSv2, u16, Templat
template_provider_port,
))
}

pub struct TestMiningDevice;

impl TestMiningDevice {
pub async fn start(pool_address: SocketAddr) -> Result<(), pool_sv2::error::PoolError> {
mining_device::connect(pool_address.to_string(), None, None, None, 0)
.await
.map_err(|e| e.into())
}
}
46 changes: 46 additions & 0 deletions roles/tests-integration/tests/pool_integration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::str::FromStr;

use common::is_port_open;

mod common;

#[tokio::test]
Expand Down Expand Up @@ -29,3 +31,47 @@ async fn pool_bad_coinbase_output() {
assert_eq!(state, pool_sv2::PoolState::Initial);
template_provider.stop();
}

#[cfg(feature = "mining_device_reject_auth")]
#[tokio::test]
async fn pool_remove_downstream_after_bad_auth() {
let (template_provider, template_provider_port) = common::start_template_provider().await;
let test_pool = common::TestPoolSv2::new(
None,
None,
Some(
std::net::SocketAddr::from_str(&format!("127.0.0.1:{}", template_provider_port))
.unwrap(),
),
);
let pool = test_pool.pool.clone();
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;
});
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
// Wait for the pool to start.
let pool_port = test_pool.port;
let pool_listening_address =
std::net::SocketAddr::from_str(&format!("127.0.0.1:{}", pool_port)).unwrap();
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(pool_sv2::DroppedDownstreams::new())
);
assert!(common::TestMiningDevice::start(pool_listening_address)
.await
.is_err());
let state = pool.state().await.safe_lock(|s| s.clone()).unwrap();
let mut dropped_downstreams = pool_sv2::DroppedDownstreams::new();
dropped_downstreams.push(1);
assert_eq!(state, pool_sv2::PoolState::Running(dropped_downstreams));
template_provider.stop();
}

0 comments on commit 2700a7d

Please sign in to comment.