updates stored test config, adds a quicker test for checking that stored configs can be parsed, adds an intermediate representation of activation heights
This commit is contained in:
parent
60248e3f1f
commit
b9bdf0527c
|
@ -15,7 +15,7 @@ use tempfile::NamedTempFile;
|
|||
use tokio::{fs, io::AsyncWriteExt};
|
||||
use tracing::Span;
|
||||
|
||||
use zebra_chain::parameters::{testnet, Network, NetworkKind};
|
||||
use zebra_chain::parameters::{testnet, Network, NetworkKind, NetworkUpgrade};
|
||||
|
||||
use crate::{
|
||||
constants::{
|
||||
|
@ -625,12 +625,18 @@ impl<'de> Deserialize<'de> for Config {
|
|||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
/// Network consensus parameters for test networks such as Regtest and the default Testnet.
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
pub struct DTestnetParameters {
|
||||
pub(super) activation_heights: Vec<(u32, NetworkUpgrade)>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields, default)]
|
||||
struct DConfig {
|
||||
listen_addr: String,
|
||||
network: NetworkKind,
|
||||
testnet_parameters: Option<testnet::Parameters>,
|
||||
testnet_parameters: Option<DTestnetParameters>,
|
||||
initial_mainnet_peers: IndexSet<String>,
|
||||
initial_testnet_peers: IndexSet<String>,
|
||||
cache_dir: CacheDir,
|
||||
|
@ -669,7 +675,7 @@ impl<'de> Deserialize<'de> for Config {
|
|||
max_connections_per_ip,
|
||||
} = DConfig::deserialize(deserializer)?;
|
||||
|
||||
let network = if let Some(network_params) = testnet_parameters {
|
||||
let network = if let Some(DTestnetParameters { activation_heights }) = testnet_parameters {
|
||||
// TODO: Panic here if the initial testnet peers are the default initial testnet peers.
|
||||
assert_eq!(
|
||||
network_kind,
|
||||
|
@ -677,7 +683,17 @@ impl<'de> Deserialize<'de> for Config {
|
|||
"set network to 'Testnet' to use configured testnet parameters"
|
||||
);
|
||||
|
||||
Network::new_configured_testnet(network_params)
|
||||
let activation_heights = activation_heights
|
||||
.into_iter()
|
||||
.map(|(height, network_upgrade)| {
|
||||
(
|
||||
height.try_into().expect("activation height must be valid"),
|
||||
network_upgrade,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
Network::new_configured_testnet(testnet::Parameters { activation_heights })
|
||||
} else {
|
||||
// Convert to default `Network` for a `NetworkKind` if there are no testnet parameters.
|
||||
match network_kind {
|
||||
|
|
|
@ -922,6 +922,71 @@ fn invalid_generated_config() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Test all versions of `zebrad.toml` we have stored can be parsed by the latest `zebrad`.
|
||||
#[tracing::instrument]
|
||||
#[test]
|
||||
fn stored_configs_parsed_correctly() -> Result<()> {
|
||||
let old_configs_dir = configs_dir();
|
||||
use abscissa_core::Application;
|
||||
use zebrad::application::ZebradApp;
|
||||
|
||||
tracing::info!(?old_configs_dir, "testing older config parsing");
|
||||
|
||||
for config_file in old_configs_dir
|
||||
.read_dir()
|
||||
.expect("read_dir call failed")
|
||||
.flatten()
|
||||
{
|
||||
let config_file_path = config_file.path();
|
||||
let config_file_name = config_file_path
|
||||
.file_name()
|
||||
.expect("config files must have a file name")
|
||||
.to_str()
|
||||
.expect("config file names are valid unicode");
|
||||
|
||||
if config_file_name.starts_with('.') || config_file_name.starts_with('#') {
|
||||
// Skip editor files and other invalid config paths
|
||||
tracing::info!(
|
||||
?config_file_path,
|
||||
"skipping hidden/temporary config file path"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
// ignore files starting with getblocktemplate prefix
|
||||
// if we were not built with the getblocktemplate-rpcs feature.
|
||||
#[cfg(not(feature = "getblocktemplate-rpcs"))]
|
||||
if config_file_name.starts_with(GET_BLOCK_TEMPLATE_CONFIG_PREFIX) {
|
||||
tracing::info!(
|
||||
?config_file_path,
|
||||
"skipping getblocktemplate-rpcs config file path"
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
// ignore files starting with shieldedscan prefix
|
||||
// if we were not built with the shielded-scan feature.
|
||||
#[cfg(not(feature = "shielded-scan"))]
|
||||
if config_file_name.starts_with(SHIELDED_SCAN_CONFIG_PREFIX) {
|
||||
tracing::info!(?config_file_path, "skipping shielded-scan config file path");
|
||||
continue;
|
||||
}
|
||||
|
||||
let stored_config_path = config_file_full_path(config_file.path());
|
||||
|
||||
tracing::info!(
|
||||
?stored_config_path,
|
||||
"testing old config can be parsed by current zebrad"
|
||||
);
|
||||
|
||||
ZebradApp::default()
|
||||
.load_config(&stored_config_path)
|
||||
.expect("config should parse");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Test all versions of `zebrad.toml` we have stored can be parsed by the latest `zebrad`.
|
||||
#[tracing::instrument]
|
||||
fn stored_configs_work() -> Result<()> {
|
||||
|
|
|
@ -61,6 +61,16 @@ network = "Testnet"
|
|||
peerset_initial_target_size = 25
|
||||
|
||||
[network.testnet_parameters]
|
||||
activation_heights = [
|
||||
[0, "Genesis"],
|
||||
[1, "BeforeOverwinter"],
|
||||
[207_500, "Overwinter"],
|
||||
[280_000, "Sapling"],
|
||||
[584_000, "Blossom"],
|
||||
[903_800, "Heartwood"],
|
||||
[1_028_500, "Canopy"],
|
||||
[1_842_420, "NU5"],
|
||||
]
|
||||
|
||||
[rpc]
|
||||
debug_force_finished_sync = false
|
||||
|
|
Loading…
Reference in New Issue