From ab2e07b75014062192b15cd646ccad681572486c Mon Sep 17 00:00:00 2001 From: jbesraa Date: Fri, 31 Jan 2025 18:10:32 +0200 Subject: [PATCH 1/5] Add `tracing-subscriber` to testing This should allow us to examine the logs from the roles that are using `tracing` crate for logging. As a default only ERROR logs will be shown, in order to examine a different level of logging, `RUST_LOG` env variable should be modified. For example `RUST_LOG=info cargo test --test '*'` --- roles/Cargo.lock | 67 +++++++++++++++++++ roles/tests-integration/Cargo.toml | 1 + roles/tests-integration/lib/mod.rs | 15 ++++- .../tests/pool_integration.rs | 4 +- .../tests/sniffer_integration.rs | 1 + .../tests/translator_integration.rs | 1 + 6 files changed, 85 insertions(+), 4 deletions(-) diff --git a/roles/Cargo.lock b/roles/Cargo.lock index aa614065cb..38031f9283 100644 --- a/roles/Cargo.lock +++ b/roles/Cargo.lock @@ -75,6 +75,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "allocator-api2" version = "0.2.21" @@ -1404,6 +1413,7 @@ dependencies = [ "tar", "tokio", "tracing", + "tracing-subscriber", "translator_sv2", ] @@ -1589,6 +1599,15 @@ dependencies = [ "value-bag", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "memchr" version = "2.7.4" @@ -2099,6 +2118,50 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.9", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + [[package]] name = "ring" version = "0.17.8" @@ -2711,10 +2774,14 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" dependencies = [ + "matchers", "nu-ansi-term", + "once_cell", + "regex", "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", ] diff --git a/roles/tests-integration/Cargo.toml b/roles/tests-integration/Cargo.toml index a4ff3091d2..18cbd15e7d 100644 --- a/roles/tests-integration/Cargo.toml +++ b/roles/tests-integration/Cargo.toml @@ -33,6 +33,7 @@ tracing = "0.1.40" translator_sv2 = { path = "../translator" } rand = "0.8.4" stratum-common = { path = "../../common" } +tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } [lib] path = "lib/mod.rs" diff --git a/roles/tests-integration/lib/mod.rs b/roles/tests-integration/lib/mod.rs index c6cb7354c6..efeb650959 100644 --- a/roles/tests-integration/lib/mod.rs +++ b/roles/tests-integration/lib/mod.rs @@ -3,20 +3,31 @@ use jd_client::JobDeclaratorClient; use jd_server::JobDeclaratorServer; use key_utils::{Secp256k1PublicKey, Secp256k1SecretKey}; use pool_sv2::PoolSv2; -use translator_sv2::TranslatorSv2; - use rand::{thread_rng, Rng}; use std::{ convert::{TryFrom, TryInto}, net::SocketAddr, str::FromStr, + sync::Once, }; +use tracing_subscriber::EnvFilter; +use translator_sv2::TranslatorSv2; use utils::get_available_address; pub mod sniffer; pub mod template_provider; mod utils; +static LOGGER: Once = Once::new(); + +pub fn start_tracing() { + LOGGER.call_once(|| { + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); + }); +} + pub async fn start_sniffer( identifier: String, upstream: SocketAddr, diff --git a/roles/tests-integration/tests/pool_integration.rs b/roles/tests-integration/tests/pool_integration.rs index 94c832a0dd..4ca06c86c1 100644 --- a/roles/tests-integration/tests/pool_integration.rs +++ b/roles/tests-integration/tests/pool_integration.rs @@ -1,10 +1,9 @@ -use integration_tests_sv2::*; - use crate::sniffer::MessageDirection; use const_sv2::{ MESSAGE_TYPE_MINING_SET_NEW_PREV_HASH, MESSAGE_TYPE_NEW_EXTENDED_MINING_JOB, MESSAGE_TYPE_NEW_TEMPLATE, }; +use integration_tests_sv2::*; use roles_logic_sv2::{ common_messages_sv2::{Protocol, SetupConnection}, parsers::{AnyMessage, CommonMessages, Mining, PoolMessages, TemplateDistribution}, @@ -16,6 +15,7 @@ use roles_logic_sv2::{ // Pool will connect to the Sniffer, and the Sniffer will connect to the Template Provider. #[tokio::test] async fn success_pool_template_provider_connection() { + start_tracing(); let (_tp, tp_addr) = start_template_provider(None).await; let (sniffer, sniffer_addr) = start_sniffer("".to_string(), tp_addr, true, None).await; let _ = start_pool(Some(sniffer_addr)).await; diff --git a/roles/tests-integration/tests/sniffer_integration.rs b/roles/tests-integration/tests/sniffer_integration.rs index d6be3d3eb3..fc91bf9454 100644 --- a/roles/tests-integration/tests/sniffer_integration.rs +++ b/roles/tests-integration/tests/sniffer_integration.rs @@ -16,6 +16,7 @@ use std::convert::TryInto; // TP -> sniffer_a -> sniffer_b -> Pool #[tokio::test] async fn test_sniffer_intercept_to_downstream() { + start_tracing(); let (_tp, tp_addr) = start_template_provider(None).await; let message_replacement = PoolMessages::Common(CommonMessages::SetupConnectionError(SetupConnectionError { diff --git a/roles/tests-integration/tests/translator_integration.rs b/roles/tests-integration/tests/translator_integration.rs index 6aabfb4cab..c01dd6bea1 100644 --- a/roles/tests-integration/tests/translator_integration.rs +++ b/roles/tests-integration/tests/translator_integration.rs @@ -8,6 +8,7 @@ use roles_logic_sv2::parsers::{CommonMessages, Mining, PoolMessages}; // shares. #[tokio::test] async fn translation_proxy() { + start_tracing(); let (_tp, tp_addr) = start_template_provider(None).await; let (_pool, pool_addr) = start_pool(Some(tp_addr)).await; let (pool_translator_sniffer, pool_translator_sniffer_addr) = From bc22779412a844ae5f5385ef62e013a2fccefa7d Mon Sep 17 00:00:00 2001 From: jbesraa Date: Mon, 10 Feb 2025 09:35:37 +0200 Subject: [PATCH 2/5] Use linux 64bit target ..previously musl were used --- .github/workflows/integration-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index 04da4b1167..d539386d8a 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -14,7 +14,7 @@ jobs: - ubuntu-latest include: - os: ubuntu-latest - target: x86_64-unknown-linux-musl + target: x86_64-unknown-linux-gnu steps: - name: Use stable toolchain From 8468e6c96cf702a35e72d9edfef6243aaa8a607b Mon Sep 17 00:00:00 2001 From: jbesraa Date: Mon, 10 Feb 2025 09:36:26 +0200 Subject: [PATCH 3/5] Show `debug` level logs for integration tests in CI .. for more verbosity --- .github/workflows/integration-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml index d539386d8a..44f98e2e9e 100644 --- a/.github/workflows/integration-tests.yaml +++ b/.github/workflows/integration-tests.yaml @@ -26,4 +26,4 @@ jobs: - name: Roles Integration Tests run: | - cargo test --manifest-path=roles/Cargo.toml --verbose --test '*' -- --nocapture + RUST_LOG=debug cargo test --manifest-path=roles/Cargo.toml --verbose --test '*' -- --nocapture From f8396812d6afb652a005166bc4a6b149142abcfc Mon Sep 17 00:00:00 2001 From: jbesraa Date: Mon, 10 Feb 2025 09:55:38 +0200 Subject: [PATCH 4/5] Add top level docs for itests --- roles/tests-integration/tests/jd_integration.rs | 10 ++++++++-- roles/tests-integration/tests/pool_integration.rs | 6 ++++++ roles/tests-integration/tests/sniffer_integration.rs | 8 ++++++++ .../tests-integration/tests/translator_integration.rs | 6 ++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/roles/tests-integration/tests/jd_integration.rs b/roles/tests-integration/tests/jd_integration.rs index 58b98d0989..dee21e5701 100644 --- a/roles/tests-integration/tests/jd_integration.rs +++ b/roles/tests-integration/tests/jd_integration.rs @@ -1,9 +1,15 @@ +// This file contains integration tests for the `JDC/S` module. +// +// `JDC/S` are modules that implements the Job Decleration roles in the Stratum V2 protocol. +// +// Note that it is enough to call `start_tracing()` once in the test suite to enable tracing for +// all tests. This is because tracing is a global setting. use integration_tests_sv2::*; use roles_logic_sv2::parsers::{CommonMessages, PoolMessages}; -// This test verifies that the `jds` (Job Distributor Server) does not panic when the `jdc` -// (Job Distributor Client) shuts down. +// This test verifies that the `jds` (Job Decleration Server) does not panic when the `jdc` +// (Job Decleration Client) shuts down. // // The test follows these steps: // 1. Start a Template Provider (`tp`) and a Pool. diff --git a/roles/tests-integration/tests/pool_integration.rs b/roles/tests-integration/tests/pool_integration.rs index 4ca06c86c1..924224d63e 100644 --- a/roles/tests-integration/tests/pool_integration.rs +++ b/roles/tests-integration/tests/pool_integration.rs @@ -1,3 +1,9 @@ +// This file contains integration tests for the `PoolSv2` module. +// +// `PoolSv2` is a module that implements the Pool role in the Stratum V2 protocol. +// +// Note that it is enough to call `start_tracing()` once in the test suite to enable tracing for +// all tests. This is because tracing is a global setting. use crate::sniffer::MessageDirection; use const_sv2::{ MESSAGE_TYPE_MINING_SET_NEW_PREV_HASH, MESSAGE_TYPE_NEW_EXTENDED_MINING_JOB, diff --git a/roles/tests-integration/tests/sniffer_integration.rs b/roles/tests-integration/tests/sniffer_integration.rs index fc91bf9454..86878ed537 100644 --- a/roles/tests-integration/tests/sniffer_integration.rs +++ b/roles/tests-integration/tests/sniffer_integration.rs @@ -1,3 +1,11 @@ +// This file contains integration tests for the `Sniffer` module. +// +// `Sniffer` is a useful tool to perform Man-in-the-Middle setups for testing purposes. It can +// intercept messages and replace them with others, as well as assert that certain messages were +// received. +// +// Note that it is enough to call `start_tracing()` once in the test suite to enable tracing for +// all tests. This is because tracing is a global setting. use const_sv2::{ MESSAGE_TYPE_SETUP_CONNECTION, MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS, MESSAGE_TYPE_SET_NEW_PREV_HASH, diff --git a/roles/tests-integration/tests/translator_integration.rs b/roles/tests-integration/tests/translator_integration.rs index c01dd6bea1..e89248101e 100644 --- a/roles/tests-integration/tests/translator_integration.rs +++ b/roles/tests-integration/tests/translator_integration.rs @@ -1,3 +1,9 @@ +// This file contains integration tests for the `TranslatorSv2` module. +// +// `TranslatorSv2` is a module that implements the Translator role in the Stratum V2 protocol. +// +// Note that it is enough to call `start_tracing()` once in the test suite to enable tracing for +// all tests. This is because tracing is a global setting. use const_sv2::{MESSAGE_TYPE_SETUP_CONNECTION, MESSAGE_TYPE_SUBMIT_SHARES_EXTENDED}; use integration_tests_sv2::{sniffer::*, *}; use roles_logic_sv2::parsers::{CommonMessages, Mining, PoolMessages}; From c92ee2a0d3ffef24f0fca439d3d8a83a2626181c Mon Sep 17 00:00:00 2001 From: jbesraa Date: Mon, 10 Feb 2025 09:56:36 +0200 Subject: [PATCH 5/5] Change test name .. ..to more descriptive one --- roles/tests-integration/tests/translator_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/tests-integration/tests/translator_integration.rs b/roles/tests-integration/tests/translator_integration.rs index e89248101e..af425a3da5 100644 --- a/roles/tests-integration/tests/translator_integration.rs +++ b/roles/tests-integration/tests/translator_integration.rs @@ -13,7 +13,7 @@ use roles_logic_sv2::parsers::{CommonMessages, Mining, PoolMessages}; // the pool exchange the correct messages upon connection. And that the miner is able to submit // shares. #[tokio::test] -async fn translation_proxy() { +async fn translate_sv1_to_sv2_successfully() { start_tracing(); let (_tp, tp_addr) = start_template_provider(None).await; let (_pool, pool_addr) = start_pool(Some(tp_addr)).await;