use color_eyre::eyre::Result;
use zebra_chain::{
block,
parameters::Network::{self, *},
};
use zebra_test::prelude::*;
use crate::common::sync::{
sync_until, MempoolBehavior, STOP_AT_HEIGHT_REGEX, STOP_ON_LOAD_TIMEOUT,
TINY_CHECKPOINT_TEST_HEIGHT, TINY_CHECKPOINT_TIMEOUT,
};
#[test]
fn sync_one_checkpoint_mainnet() -> Result<()> {
sync_until(
TINY_CHECKPOINT_TEST_HEIGHT,
&Mainnet,
STOP_AT_HEIGHT_REGEX,
TINY_CHECKPOINT_TIMEOUT,
None,
MempoolBehavior::ShouldNotActivate,
true,
true,
)
.map(|_tempdir| ())
}
#[allow(dead_code)]
fn sync_one_checkpoint_testnet() -> Result<()> {
sync_until(
TINY_CHECKPOINT_TEST_HEIGHT,
&Network::new_default_testnet(),
STOP_AT_HEIGHT_REGEX,
TINY_CHECKPOINT_TIMEOUT,
None,
MempoolBehavior::ShouldNotActivate,
true,
true,
)
.map(|_tempdir| ())
}
#[test]
fn restart_stop_at_height() -> Result<()> {
let _init_guard = zebra_test::init();
restart_stop_at_height_for_network(Network::Mainnet, TINY_CHECKPOINT_TEST_HEIGHT)?;
Ok(())
}
fn restart_stop_at_height_for_network(network: Network, height: block::Height) -> Result<()> {
let reuse_tempdir = sync_until(
height,
&network,
STOP_AT_HEIGHT_REGEX,
TINY_CHECKPOINT_TIMEOUT,
None,
MempoolBehavior::ShouldNotActivate,
true,
true,
)?;
sync_until(
height,
&network,
"state is already at the configured height",
STOP_ON_LOAD_TIMEOUT,
reuse_tempdir,
MempoolBehavior::ShouldNotActivate,
true,
false,
)?;
Ok(())
}