From a4d5b5d4d84508ab1a7139eaa6be9612ce56f510 Mon Sep 17 00:00:00 2001 From: jbesraa Date: Wed, 4 Sep 2024 13:32:23 +0300 Subject: [PATCH] Add integration test for `PoolSv2` --- .github/workflows/test.yaml | 4 ++++ roles/Cargo.lock | 2 +- roles/tests-integration/tests/common/mod.rs | 12 +++++++--- .../tests/pool_integration.rs | 22 +++++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 roles/tests-integration/tests/pool_integration.rs diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5b669ebc0b..a2f63deb48 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -40,6 +40,10 @@ jobs: cargo build --manifest-path=roles/Cargo.toml cargo build --manifest-path=utils/Cargo.toml + - name: Roles Integration Tests + run: | + cargo test --manifest-path=roles/Cargo.toml --verbose --test '*' -- --nocapture + - name: Run sv1-client-and-server example run: | cargo run --manifest-path=examples/sv1-client-and-server/Cargo.toml --bin client_and_server -- 60 diff --git a/roles/Cargo.lock b/roles/Cargo.lock index 068af953f4..12d710ffce 100644 --- a/roles/Cargo.lock +++ b/roles/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" diff --git a/roles/tests-integration/tests/common/mod.rs b/roles/tests-integration/tests/common/mod.rs index 0a8734f44b..558d71db6e 100644 --- a/roles/tests-integration/tests/common/mod.rs +++ b/roles/tests-integration/tests/common/mod.rs @@ -215,7 +215,11 @@ impl TestPoolSv2 { template_provider_address: Option, ) -> Self { use pool_sv2::mining_pool::{CoinbaseOutput, Configuration}; - let pool_port = get_available_port(); + let pool_port = if let Some(listen_addr) = listening_address { + listen_addr.port() + } else { + get_available_port() + }; let listening_address = listening_address .unwrap_or(SocketAddr::from_str(&format!("127.0.0.1:{}", pool_port)).unwrap()); let is_pool_port_open = is_port_open(listening_address); @@ -248,8 +252,10 @@ impl TestPoolSv2 { cert_validity_sec, pool_signature, ); - let template_provider_config = - pool_sv2::mining_pool::TemplateProviderConfig::new(tp_address, None); + let template_provider_config = pool_sv2::mining_pool::TemplateProviderConfig::new( + tp_address, + Some(authority_public_key), + ); let authority_config = pool_sv2::mining_pool::AuthorityConfig::new(authority_public_key, authority_secret_key); let config = Configuration::new( diff --git a/roles/tests-integration/tests/pool_integration.rs b/roles/tests-integration/tests/pool_integration.rs new file mode 100644 index 0000000000..ab417d663b --- /dev/null +++ b/roles/tests-integration/tests/pool_integration.rs @@ -0,0 +1,22 @@ +mod common; + +use const_sv2::{ + MESSAGE_TYPE_COINBASE_OUTPUT_DATA_SIZE, MESSAGE_TYPE_NEW_TEMPLATE, + MESSAGE_TYPE_SETUP_CONNECTION, MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS, + MESSAGE_TYPE_SET_NEW_PREV_HASH, +}; + +#[tokio::test] +async fn success_pool_template_provider_connection() { + let sniffer_addr = common::get_available_address(); + let tp_addr = common::get_available_address(); + let pool_addr = common::get_available_address(); + let _tp = common::start_template_provider(tp_addr.port()).await; + let sniffer = common::start_sniffer(tp_addr, sniffer_addr).await; + let _ = common::start_pool(Some(pool_addr), None, Some(sniffer_addr)).await; + assert!(sniffer.expect_downstream_message(MESSAGE_TYPE_SETUP_CONNECTION)); + assert!(sniffer.expect_upstream_message(MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS)); + assert!(sniffer.expect_downstream_message(MESSAGE_TYPE_COINBASE_OUTPUT_DATA_SIZE)); + assert!(sniffer.expect_upstream_message(MESSAGE_TYPE_NEW_TEMPLATE)); + assert!(sniffer.expect_upstream_message(MESSAGE_TYPE_SET_NEW_PREV_HASH)); +}