diff --git a/dash-spv/CLAUDE.md b/dash-spv/CLAUDE.md index dacd9771e..7e4b59bdb 100644 --- a/dash-spv/CLAUDE.md +++ b/dash-spv/CLAUDE.md @@ -54,18 +54,17 @@ cargo run --example filter_sync cargo test # Run specific test files -cargo test --test handshake_test cargo test --test header_sync_test cargo test --test storage_test # Run individual test functions -cargo test --test handshake_test test_handshake_with_mainnet_peer +cargo test --test peer_test test_peer_connection # Run tests with output cargo test -- --nocapture # Run single test with debug output -cargo test --test handshake_test test_handshake_with_mainnet_peer -- --nocapture +cargo test --test peer_test test_peer_connection -- --nocapture ``` ### Code Quality @@ -187,10 +186,10 @@ Use domain-specific error types: **Common Debug Commands:** ```bash # Run with tracing output -RUST_LOG=debug cargo test --test test_handshake_with_mainnet_peer -- --nocapture +RUST_LOG=debug cargo test --test peer_test test_peer_connection -- --nocapture -# Run specific test with verbose output -cargo test --test handshake_test test_handshake_with_mainnet_peer -- --nocapture --test-threads=1 +# Run specific test with verbose output +cargo test --test peer_test test_peer_connection -- --nocapture --test-threads=1 # Check storage state ls -la data*/headers/ diff --git a/dash-spv/tests/handshake_test.rs b/dash-spv/tests/handshake_test.rs deleted file mode 100644 index c7c6073e8..000000000 --- a/dash-spv/tests/handshake_test.rs +++ /dev/null @@ -1,112 +0,0 @@ -//! Integration tests for network handshake functionality. - -use std::net::SocketAddr; -use std::time::Duration; - -use dash_spv::network::{HandshakeManager, NetworkManager, Peer, PeerNetworkManager}; -use dash_spv::{ClientConfig, Network}; - -#[tokio::test] -async fn test_handshake_with_mainnet_peer() { - // Initialize logging for test output - let _ = env_logger::builder().filter_level(log::LevelFilter::Debug).is_test(true).try_init(); - - let peer_addr: SocketAddr = "127.0.0.1:9999".parse().expect("Valid peer address"); - let result = Peer::connect(peer_addr, 10, Network::Mainnet).await; - - match result { - Ok(mut connection) => { - let mut handshake_manager = - HandshakeManager::new(Network::Mainnet, Some("handshake_test".parse().unwrap())); - handshake_manager.perform_handshake(&mut connection).await.expect("Handshake failed"); - println!("✓ Handshake successful with peer {}", peer_addr); - assert!( - connection.is_connected(), - "Peer should be connected after successful handshake" - ); - - // Check peer info - assert_eq!(connection.address(), peer_addr, "Peer address should match"); - assert!(connection.is_connected(), "Peer should be marked as connected"); - - // Clean disconnect - connection.disconnect().await.expect("Failed to disconnect"); - assert!(!connection.is_connected(), "Network should be disconnected"); - } - Err(e) => { - println!("✗ Handshake failed with peer {}: {}", peer_addr, e); - // For CI/testing environments where the peer might not be available, - // we'll make this a warning rather than a failure - println!("Note: This test requires a Dash Core node running at 127.0.0.1:9999"); - println!("Error details: {}", e); - } - } -} - -#[tokio::test] -async fn test_handshake_timeout() { - // Test connection timeout behavior using TEST-NET-1 from RFC 5737. - // https://datatracker.ietf.org/doc/html/rfc5737 - // This IP range is reserved for documentation and will never respond. - let peer_addr: SocketAddr = "192.0.2.1:9999".parse().expect("Valid peer address"); - let start = std::time::Instant::now(); - let result = Peer::connect(peer_addr, 2, Network::Mainnet).await; - let elapsed = start.elapsed(); - - assert!(result.is_err(), "Connection should fail for unreachable peer"); - assert!( - elapsed >= Duration::from_secs(1), - "Should respect timeout duration (elapsed: {:?})", - elapsed - ); - assert!( - elapsed < Duration::from_secs(5), - "Should not take excessively long beyond timeout (elapsed: {:?})", - elapsed - ); -} - -#[tokio::test(flavor = "multi_thread", worker_threads = 2)] -async fn test_network_manager_creation() { - let temp_dir = tempfile::TempDir::new().expect("Failed to create temporary directory"); - let config = - ClientConfig::new(Network::Mainnet).with_storage_path(temp_dir.path().to_path_buf()); - let network = PeerNetworkManager::new(&config).await; - - assert!(network.is_ok(), "Network manager creation should succeed"); - let network = network.unwrap(); - - assert_eq!(network.peer_count(), 0, "Should start with no peers"); -} - -#[tokio::test] -async fn test_multiple_connect_disconnect_cycles() { - let peer_addr: SocketAddr = "127.0.0.1:9999".parse().expect("Valid peer address"); - let mut connection = Peer::new(peer_addr, Duration::from_secs(10), Network::Mainnet); - - // Try multiple connect/disconnect cycles - for i in 1..=3 { - println!("Attempt {} to connect to {}", i, peer_addr); - - match connection.connect_instance().await { - Ok(_) => { - assert!(connection.is_connected(), "Should be connected after successful connect"); - - // Brief delay - tokio::time::sleep(Duration::from_millis(100)).await; - - // Disconnect - let disconnect_result = connection.disconnect().await; - assert!(disconnect_result.is_ok(), "Disconnect should succeed"); - assert!(!connection.is_connected(), "Should be disconnected after disconnect"); - - // Brief delay before next attempt - tokio::time::sleep(Duration::from_millis(100)).await; - } - Err(e) => { - println!("Connection attempt {} failed: {}", i, e); - break; - } - } - } -} diff --git a/dash-spv/tests/test_plan.md b/dash-spv/tests/test_plan.md index 67f336c91..0375f7077 100644 --- a/dash-spv/tests/test_plan.md +++ b/dash-spv/tests/test_plan.md @@ -7,13 +7,7 @@ This document outlines a systematic testing approach for the Dash SPV client, or - **Network**: Dash mainnet - **Test Type**: Integration tests with real network connectivity -## 1. Network Layer Tests ✅ (3/4 passing) - -### File: `tests/handshake_test.rs` (MOSTLY COMPLETED) -- [x] **Basic handshake with mainnet peer** - Tests successful connection and handshake -- [⚠️] **Handshake timeout handling** - Tests timeout behavior (timeout test needs adjustment) -- [x] **Network manager lifecycle** - Tests creation, connection state management -- [x] **Multiple connect/disconnect cycles** - Tests robustness of connection handling +## 1. Network Layer Tests ### Planned Additional Network Tests - [ ] **Message sending and receiving** - Test basic message exchange after handshake