Skip to content

Commit

Permalink
Turn a function argument into an enum field
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Apr 25, 2022
1 parent 8869ce8 commit ee9c679
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
27 changes: 14 additions & 13 deletions zebrad/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ async fn rpc_endpoint() -> Result<()> {
#[test]
#[cfg(not(target_os = "windows"))]
fn lightwalletd_integration() -> Result<()> {
lightwalletd_integration_test(LaunchWithEmptyState, false)
lightwalletd_integration_test(LaunchWithEmptyState)
}

/// Make sure `lightwalletd` can sync from Zebra, in update sync mode.
Expand All @@ -1013,7 +1013,7 @@ fn lightwalletd_integration() -> Result<()> {
#[test]
#[cfg(not(target_os = "windows"))]
fn lightwalletd_update_sync() -> Result<()> {
lightwalletd_integration_test(UpdateCachedState, false)
lightwalletd_integration_test(UpdateCachedState)
}

/// Make sure `lightwalletd` can fully sync from genesis using Zebra.
Expand All @@ -1026,7 +1026,9 @@ fn lightwalletd_update_sync() -> Result<()> {
#[ignore]
#[cfg(not(target_os = "windows"))]
fn lightwalletd_full_sync() -> Result<()> {
lightwalletd_integration_test(FullSyncFromGenesis, false)
lightwalletd_integration_test(FullSyncFromGenesis {
allow_lightwalletd_cached_state: false,
})
}

/// Make sure `lightwalletd` can sync from Zebra, in all available modes.
Expand All @@ -1041,14 +1043,16 @@ fn lightwalletd_full_sync() -> Result<()> {
#[ignore]
#[cfg(not(target_os = "windows"))]
fn lightwalletd_test_suite() -> Result<()> {
lightwalletd_integration_test(LaunchWithEmptyState, false)?;
lightwalletd_integration_test(LaunchWithEmptyState)?;

// Only runs when ZEBRA_CACHED_STATE_PATH is set.
// When manually running the test suite, allow cached state in the full sync test.
lightwalletd_integration_test(FullSyncFromGenesis, true)?;
lightwalletd_integration_test(FullSyncFromGenesis {
allow_lightwalletd_cached_state: true,
})?;

// Only runs when LIGHTWALLETD_DATA_DIR and ZEBRA_CACHED_STATE_PATH are set
lightwalletd_integration_test(UpdateCachedState, false)?;
lightwalletd_integration_test(UpdateCachedState)?;

Ok(())
}
Expand All @@ -1059,10 +1063,7 @@ fn lightwalletd_test_suite() -> Result<()> {
///
/// The random ports in this test can cause [rare port conflicts.](#Note on port conflict)
#[cfg(not(target_os = "windows"))]
fn lightwalletd_integration_test(
test_type: LightwalletdTestType,
allow_cached_state_for_full_sync: bool,
) -> Result<()> {
fn lightwalletd_integration_test(test_type: LightwalletdTestType) -> Result<()> {
zebra_test::init();

// Skip the test unless the user specifically asked for it
Expand Down Expand Up @@ -1106,7 +1107,7 @@ fn lightwalletd_integration_test(
let (zebrad_failure_messages, zebrad_ignore_messages) = test_type.zebrad_failure_messages();

let (lightwalletd_failure_messages, lightwalletd_ignore_messages) =
test_type.lightwalletd_failure_messages(allow_cached_state_for_full_sync);
test_type.lightwalletd_failure_messages();

// Launch zebrad
let zdir = testdir()?.with_exact_config(&config)?;
Expand Down Expand Up @@ -1164,7 +1165,7 @@ fn lightwalletd_integration_test(
if test_type.needs_lightwalletd_cached_state() {
// TODO: expect `[0-9]{7}` when we're using the tip cached state (#4155)
lightwalletd.expect_stdout_line_matches("Found [0-9]{6,7} blocks in cache")?;
} else if !allow_cached_state_for_full_sync {
} else if test_type.allow_lightwalletd_cached_state() {
// Timeout the test if we're somehow accidentally using a cached state in our temp dir
lightwalletd.expect_stdout_line_matches("Found 0 blocks in cache")?;
}
Expand Down Expand Up @@ -1194,7 +1195,7 @@ fn lightwalletd_integration_test(
))?;
}

if test_type == UpdateCachedState || test_type == FullSyncFromGenesis {
if matches!(test_type, UpdateCachedState | FullSyncFromGenesis { .. }) {
// Wait for Zebra to sync its cached state to the chain tip
zebrad.expect_stdout_line_matches(regex::escape("sync_percent=100"))?;

Expand Down
37 changes: 25 additions & 12 deletions zebrad/tests/common/lightwalletd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,17 @@ pub enum LightwalletdTestType {

/// Do a full sync from an empty lightwalletd state.
///
/// This test is much faster if it has a cached Zebra state.
FullSyncFromGenesis,
/// This test requires a cached Zebra state.
FullSyncFromGenesis {
/// Should the test allow a cached lightwalletd state?
///
/// If `false`, the test fails if the lightwalletd state is populated.
allow_lightwalletd_cached_state: bool,
},

/// Sync to tip from a lightwalletd cached state.
///
/// This test is much faster if it has a cached Zebra state.
/// This test requires a cached Zebra and lightwalletd state.
UpdateCachedState,
}

Expand All @@ -229,14 +234,25 @@ impl LightwalletdTestType {
pub fn needs_zebra_cached_state(&self) -> bool {
match self {
LaunchWithEmptyState => false,
FullSyncFromGenesis | UpdateCachedState => true,
FullSyncFromGenesis { .. } | UpdateCachedState => true,
}
}

/// Does this test need a lightwalletd cached state?
pub fn needs_lightwalletd_cached_state(&self) -> bool {
match self {
LaunchWithEmptyState | FullSyncFromGenesis => false,
LaunchWithEmptyState | FullSyncFromGenesis { .. } => false,
UpdateCachedState => true,
}
}

/// Does this test allow a lightwalletd cached state, even if it is not required?
pub fn allow_lightwalletd_cached_state(&self) -> bool {
match self {
LaunchWithEmptyState => false,
FullSyncFromGenesis {
allow_lightwalletd_cached_state,
} => *allow_lightwalletd_cached_state,
UpdateCachedState => true,
}
}
Expand Down Expand Up @@ -289,7 +305,7 @@ impl LightwalletdTestType {
pub fn zebrad_timeout(&self) -> Duration {
match self {
LaunchWithEmptyState => LIGHTWALLETD_DELAY,
FullSyncFromGenesis | UpdateCachedState => LIGHTWALLETD_UPDATE_TIP_DELAY,
FullSyncFromGenesis { .. } | UpdateCachedState => LIGHTWALLETD_UPDATE_TIP_DELAY,
}
}

Expand All @@ -298,7 +314,7 @@ impl LightwalletdTestType {
match self {
LaunchWithEmptyState => LIGHTWALLETD_DELAY,
UpdateCachedState => LIGHTWALLETD_UPDATE_TIP_DELAY,
FullSyncFromGenesis => LIGHTWALLETD_FULL_SYNC_TIP_DELAY,
FullSyncFromGenesis { .. } => LIGHTWALLETD_FULL_SYNC_TIP_DELAY,
}
}

Expand Down Expand Up @@ -328,10 +344,7 @@ impl LightwalletdTestType {

/// Returns `lightwalletd` log regexes that indicate the tests have failed,
/// and regexes of any failures that should be ignored.
pub fn lightwalletd_failure_messages(
&self,
allow_cached_state_for_full_sync: bool,
) -> (Vec<String>, Vec<String>) {
pub fn lightwalletd_failure_messages(&self) -> (Vec<String>, Vec<String>) {
let mut lightwalletd_failure_messages: Vec<String> = LIGHTWALLETD_FAILURE_MESSAGES
.iter()
.chain(PROCESS_FAILURE_MESSAGES)
Expand All @@ -347,7 +360,7 @@ impl LightwalletdTestType {
lightwalletd_failure_messages
.push("Got sapling height 419200 block height [0-9]{1,6} chain main".to_string());
}
if *self == FullSyncFromGenesis && !allow_cached_state_for_full_sync {
if !self.allow_lightwalletd_cached_state() {
// Fail if we need an empty lightwalletd state, but it has blocks
lightwalletd_failure_messages
.push("Got sapling height 419200 block height [1-9][0-9]* chain main".to_string());
Expand Down

0 comments on commit ee9c679

Please sign in to comment.