Skip to content

Commit

Permalink
Disable tests of the scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
upbqdn committed Jun 10, 2024
1 parent 93425f9 commit cfecd64
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 190 deletions.
3 changes: 2 additions & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ case "$1" in
elif [[ "${TEST_SCAN_START_WHERE_LEFT}" -eq "1" ]]; then
# Test that the scanner can continue scanning where it was left when zebrad restarts.
check_directory_files "${ZEBRA_CACHED_STATE_DIR}"
run_cargo_test "shielded-scan" "scan_start_where_left"
# TODO: Move this test once we have the new scanner binary.
# run_cargo_test "shielded-scan" "scan_start_where_left"

elif [[ "${TEST_SCAN_TASK_COMMANDS}" -eq "1" ]]; then
# Test that the scanner can continue scanning where it was left when zebrad restarts.
Expand Down
381 changes: 192 additions & 189 deletions zebrad/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2903,195 +2903,198 @@ async fn fully_synced_rpc_z_getsubtreesbyindex_snapshot_test() -> Result<()> {
Ok(())
}

/// Test that the scanner task gets started when the node starts.
#[test]
#[cfg(feature = "shielded-scan")]
fn scan_task_starts() -> Result<()> {
use indexmap::IndexMap;
use zebra_scan::tests::ZECPAGES_SAPLING_VIEWING_KEY;

let _init_guard = zebra_test::init();

let test_type = TestType::LaunchWithEmptyState {
launches_lightwalletd: false,
};
let mut config = default_test_config(&Mainnet)?;
let mut keys = IndexMap::new();
keys.insert(ZECPAGES_SAPLING_VIEWING_KEY.to_string(), 1);
config.shielded_scan.sapling_keys_to_scan = keys;

// Start zebra with the config.
let mut zebrad = testdir()?
.with_exact_config(&config)?
.spawn_child(args!["start"])?
.with_timeout(test_type.zebrad_timeout());

// Check scanner was started.
zebrad.expect_stdout_line_matches("loaded Zebra scanner cache")?;

// Look for 2 scanner notices indicating we are below sapling activation.
zebrad.expect_stdout_line_matches("scanner is waiting for Sapling activation. Current tip: [0-9]{1,4}, Sapling activation: 419200")?;
zebrad.expect_stdout_line_matches("scanner is waiting for Sapling activation. Current tip: [0-9]{1,4}, Sapling activation: 419200")?;

// Kill the node.
zebrad.kill(false)?;

// Check that scan task started and the first scanning is done.
let output = zebrad.wait_with_output()?;

// Make sure the command was killed
output.assert_was_killed()?;
output.assert_failure()?;

Ok(())
}

/// Test that the scanner gRPC server starts when the node starts.
#[tokio::test]
#[cfg(all(feature = "shielded-scan", not(target_os = "windows")))]
async fn scan_rpc_server_starts() -> Result<()> {
use zebra_grpc::scanner::{scanner_client::ScannerClient, Empty};

let _init_guard = zebra_test::init();

let test_type = TestType::LaunchWithEmptyState {
launches_lightwalletd: false,
};

let port = random_known_port();
let listen_addr = format!("127.0.0.1:{port}");
let mut config = default_test_config(&Mainnet)?;
config.shielded_scan.listen_addr = Some(listen_addr.parse()?);

// Start zebra with the config.
let mut zebrad = testdir()?
.with_exact_config(&config)?
.spawn_child(args!["start"])?
.with_timeout(test_type.zebrad_timeout());

// Wait until gRPC server is starting.
tokio::time::sleep(LAUNCH_DELAY).await;
zebrad.expect_stdout_line_matches("starting scan gRPC server")?;
tokio::time::sleep(Duration::from_secs(1)).await;

let mut client = ScannerClient::connect(format!("http://{listen_addr}")).await?;

let request = tonic::Request::new(Empty {});

client.get_info(request).await?;

// Kill the node.
zebrad.kill(false)?;

// Check that scan task started and the first scanning is done.
let output = zebrad.wait_with_output()?;

// Make sure the command was killed
output.assert_was_killed()?;
output.assert_failure()?;

Ok(())
}

/// Test that the scanner can continue scanning where it was left when zebrad restarts.
///
/// Needs a cache state close to the tip. A possible way to run it locally is:
///
/// export ZEBRA_CACHED_STATE_DIR="/path/to/zebra/state"
/// cargo test scan_start_where_left --features="shielded-scan" -- --ignored --nocapture
///
/// The test will run zebrad with a key to scan, scan the first few blocks after sapling and then stops.
/// Then it will restart zebrad and check that it resumes scanning where it was left.
///
/// Note: This test will remove all the contents you may have in the ZEBRA_CACHED_STATE_DIR/private-scan directory
/// so it can start with an empty scanning state.
#[ignore]
#[test]
#[cfg(feature = "shielded-scan")]
fn scan_start_where_left() -> Result<()> {
use indexmap::IndexMap;
use zebra_scan::{storage::db::SCANNER_DATABASE_KIND, tests::ZECPAGES_SAPLING_VIEWING_KEY};

let _init_guard = zebra_test::init();

// use `UpdateZebraCachedStateNoRpc` as the test type to make sure a zebrad cache state is available.
let test_type = TestType::UpdateZebraCachedStateNoRpc;
if let Some(cache_dir) = test_type.zebrad_state_path("scan test") {
// Add a key to the config
let mut config = default_test_config(&Mainnet)?;
let mut keys = IndexMap::new();
keys.insert(ZECPAGES_SAPLING_VIEWING_KEY.to_string(), 1);
config.shielded_scan.sapling_keys_to_scan = keys;

// Add the cache dir to shielded scan, make it the same as the zebrad cache state.
config
.shielded_scan
.db_config_mut()
.cache_dir
.clone_from(&cache_dir);
config.shielded_scan.db_config_mut().ephemeral = false;

// Add the cache dir to state.
config.state.cache_dir.clone_from(&cache_dir);
config.state.ephemeral = false;

// Remove the scan directory before starting.
let scan_db_path = cache_dir.join(SCANNER_DATABASE_KIND);
fs::remove_dir_all(std::path::Path::new(&scan_db_path)).ok();

// Start zebra with the config.
let mut zebrad = testdir()?
.with_exact_config(&config)?
.spawn_child(args!["start"])?
.with_timeout(test_type.zebrad_timeout());

// Check scanner was started.
zebrad.expect_stdout_line_matches("loaded Zebra scanner cache")?;

// The first time
zebrad.expect_stdout_line_matches(
r"Scanning the blockchain for key 0, started at block 419200, now at block 420000",
)?;

// Make sure scanner scans a few blocks.
zebrad.expect_stdout_line_matches(
r"Scanning the blockchain for key 0, started at block 419200, now at block 430000",
)?;
zebrad.expect_stdout_line_matches(
r"Scanning the blockchain for key 0, started at block 419200, now at block 440000",
)?;

// Kill the node.
zebrad.kill(false)?;
let output = zebrad.wait_with_output()?;

// Make sure the command was killed
output.assert_was_killed()?;
output.assert_failure()?;

// Start the node again.
let mut zebrad = testdir()?
.with_exact_config(&config)?
.spawn_child(args!["start"])?
.with_timeout(test_type.zebrad_timeout());

// Resuming message.
zebrad.expect_stdout_line_matches(
"Last scanned height for key number 0 is 439000, resuming at 439001",
)?;
zebrad.expect_stdout_line_matches("loaded Zebra scanner cache")?;

// Start scanning where it was left.
zebrad.expect_stdout_line_matches(
r"Scanning the blockchain for key 0, started at block 439001, now at block 440000",
)?;
zebrad.expect_stdout_line_matches(
r"Scanning the blockchain for key 0, started at block 439001, now at block 450000",
)?;
}

Ok(())
}
// TODO: Move this test once we have the new scanner binary.
// /// Test that the scanner task gets started when the node starts.
// #[test]
// #[cfg(feature = "shielded-scan")]
// fn scan_task_starts() -> Result<()> {
// use indexmap::IndexMap;
// use zebra_scan::tests::ZECPAGES_SAPLING_VIEWING_KEY;

// let _init_guard = zebra_test::init();

// let test_type = TestType::LaunchWithEmptyState {
// launches_lightwalletd: false,
// };
// let mut config = default_test_config(&Mainnet)?;
// let mut keys = IndexMap::new();
// keys.insert(ZECPAGES_SAPLING_VIEWING_KEY.to_string(), 1);
// config.shielded_scan.sapling_keys_to_scan = keys;

// // Start zebra with the config.
// let mut zebrad = testdir()?
// .with_exact_config(&config)?
// .spawn_child(args!["start"])?
// .with_timeout(test_type.zebrad_timeout());

// // Check scanner was started.
// zebrad.expect_stdout_line_matches("loaded Zebra scanner cache")?;

// // Look for 2 scanner notices indicating we are below sapling activation.
// zebrad.expect_stdout_line_matches("scanner is waiting for Sapling activation. Current tip: [0-9]{1,4}, Sapling activation: 419200")?;
// zebrad.expect_stdout_line_matches("scanner is waiting for Sapling activation. Current tip: [0-9]{1,4}, Sapling activation: 419200")?;

// // Kill the node.
// zebrad.kill(false)?;

// // Check that scan task started and the first scanning is done.
// let output = zebrad.wait_with_output()?;

// // Make sure the command was killed
// output.assert_was_killed()?;
// output.assert_failure()?;

// Ok(())
// }

// TODO: Move this test once we have the new scanner binary.
// /// Test that the scanner gRPC server starts when the node starts.
// #[tokio::test]
// #[cfg(all(feature = "shielded-scan", not(target_os = "windows")))]
// async fn scan_rpc_server_starts() -> Result<()> {
// use zebra_grpc::scanner::{scanner_client::ScannerClient, Empty};

// let _init_guard = zebra_test::init();

// let test_type = TestType::LaunchWithEmptyState {
// launches_lightwalletd: false,
// };

// let port = random_known_port();
// let listen_addr = format!("127.0.0.1:{port}");
// let mut config = default_test_config(&Mainnet)?;
// config.shielded_scan.listen_addr = Some(listen_addr.parse()?);

// // Start zebra with the config.
// let mut zebrad = testdir()?
// .with_exact_config(&config)?
// .spawn_child(args!["start"])?
// .with_timeout(test_type.zebrad_timeout());

// // Wait until gRPC server is starting.
// tokio::time::sleep(LAUNCH_DELAY).await;
// zebrad.expect_stdout_line_matches("starting scan gRPC server")?;
// tokio::time::sleep(Duration::from_secs(1)).await;

// let mut client = ScannerClient::connect(format!("http://{listen_addr}")).await?;

// let request = tonic::Request::new(Empty {});

// client.get_info(request).await?;

// // Kill the node.
// zebrad.kill(false)?;

// // Check that scan task started and the first scanning is done.
// let output = zebrad.wait_with_output()?;

// // Make sure the command was killed
// output.assert_was_killed()?;
// output.assert_failure()?;

// Ok(())
// }

// TODO: Move this test once we have the new scanner binary.
// /// Test that the scanner can continue scanning where it was left when zebrad restarts.
// ///
// /// Needs a cache state close to the tip. A possible way to run it locally is:
// ///
// /// export ZEBRA_CACHED_STATE_DIR="/path/to/zebra/state"
// /// cargo test scan_start_where_left --features="shielded-scan" -- --ignored --nocapture
// ///
// /// The test will run zebrad with a key to scan, scan the first few blocks after sapling and then stops.
// /// Then it will restart zebrad and check that it resumes scanning where it was left.
// ///
// /// Note: This test will remove all the contents you may have in the ZEBRA_CACHED_STATE_DIR/private-scan directory
// /// so it can start with an empty scanning state.
// #[ignore]
// #[test]
// #[cfg(feature = "shielded-scan")]
// fn scan_start_where_left() -> Result<()> {
// use indexmap::IndexMap;
// use zebra_scan::{storage::db::SCANNER_DATABASE_KIND, tests::ZECPAGES_SAPLING_VIEWING_KEY};

// let _init_guard = zebra_test::init();

// // use `UpdateZebraCachedStateNoRpc` as the test type to make sure a zebrad cache state is available.
// let test_type = TestType::UpdateZebraCachedStateNoRpc;
// if let Some(cache_dir) = test_type.zebrad_state_path("scan test") {
// // Add a key to the config
// let mut config = default_test_config(&Mainnet)?;
// let mut keys = IndexMap::new();
// keys.insert(ZECPAGES_SAPLING_VIEWING_KEY.to_string(), 1);
// config.shielded_scan.sapling_keys_to_scan = keys;

// // Add the cache dir to shielded scan, make it the same as the zebrad cache state.
// config
// .shielded_scan
// .db_config_mut()
// .cache_dir
// .clone_from(&cache_dir);
// config.shielded_scan.db_config_mut().ephemeral = false;

// // Add the cache dir to state.
// config.state.cache_dir.clone_from(&cache_dir);
// config.state.ephemeral = false;

// // Remove the scan directory before starting.
// let scan_db_path = cache_dir.join(SCANNER_DATABASE_KIND);
// fs::remove_dir_all(std::path::Path::new(&scan_db_path)).ok();

// // Start zebra with the config.
// let mut zebrad = testdir()?
// .with_exact_config(&config)?
// .spawn_child(args!["start"])?
// .with_timeout(test_type.zebrad_timeout());

// // Check scanner was started.
// zebrad.expect_stdout_line_matches("loaded Zebra scanner cache")?;

// // The first time
// zebrad.expect_stdout_line_matches(
// r"Scanning the blockchain for key 0, started at block 419200, now at block 420000",
// )?;

// // Make sure scanner scans a few blocks.
// zebrad.expect_stdout_line_matches(
// r"Scanning the blockchain for key 0, started at block 419200, now at block 430000",
// )?;
// zebrad.expect_stdout_line_matches(
// r"Scanning the blockchain for key 0, started at block 419200, now at block 440000",
// )?;

// // Kill the node.
// zebrad.kill(false)?;
// let output = zebrad.wait_with_output()?;

// // Make sure the command was killed
// output.assert_was_killed()?;
// output.assert_failure()?;

// // Start the node again.
// let mut zebrad = testdir()?
// .with_exact_config(&config)?
// .spawn_child(args!["start"])?
// .with_timeout(test_type.zebrad_timeout());

// // Resuming message.
// zebrad.expect_stdout_line_matches(
// "Last scanned height for key number 0 is 439000, resuming at 439001",
// )?;
// zebrad.expect_stdout_line_matches("loaded Zebra scanner cache")?;

// // Start scanning where it was left.
// zebrad.expect_stdout_line_matches(
// r"Scanning the blockchain for key 0, started at block 439001, now at block 440000",
// )?;
// zebrad.expect_stdout_line_matches(
// r"Scanning the blockchain for key 0, started at block 439001, now at block 450000",
// )?;
// }

// Ok(())
// }

// TODO: Add this test to CI (#8236)
/// Tests successful:
Expand Down

0 comments on commit cfecd64

Please sign in to comment.