use std::{
collections::{HashMap, HashSet},
num::NonZeroU32,
path::PathBuf,
time::Duration,
};
use smart_config::{
ByteSize, DescribeConfig, DeserializeConfig, EtherAmount, ExampleConfig, de, fallback,
metadata::{SizeUnit, TimeUnit},
pat::{LazyRegex, lazy_regex},
value::SecretString,
};
static APP_NAME_REGEX: LazyRegex = lazy_regex!(r"^[a-z][-a-z0-9]*$");
#[derive(Debug, DescribeConfig, DeserializeConfig, ExampleConfig)]
pub(crate) struct TestConfig {
#[config(default_t = "app".into(), validate(APP_NAME_REGEX))]
pub app_name: String,
#[config(example = 8080, deprecated = "bind_to")]
pub port: u16,
#[config(default, validate(0.0..=10.0), example = Some(0.5))]
pub scaling_factor: Option<f32>,
#[config(default_t = "/tmp".into(), fallback = &fallback::Env("TMPDIR"))]
pub temp_dir: PathBuf,
#[config(default, alias = "dirs", with = de::Delimited::new(":"))]
#[config(example = HashSet::from_iter(["./local".into()]))]
pub dir_paths: HashSet<PathBuf>,
#[config(default_t = 16 * SizeUnit::MiB, deprecated = ".experimental.cache_size")]
pub cache_size: ByteSize,
#[config(default_t = 1 * TimeUnit::Minutes, with = TimeUnit::Seconds)]
pub timeout_sec: Duration,
#[config(nest)]
pub experimental: ExperimentalConfig,
}
#[derive(Debug, DescribeConfig, DeserializeConfig, ExampleConfig)]
#[config(derive(Default))]
pub(crate) struct ExperimentalConfig {
#[config(example = Some("correct horse battery staple".into()))]
pub api_key: Option<SecretString>,
#[config(default, with = de::Entries::WELL_KNOWN.named("method", "rps"))]
#[config(example = HashMap::from_iter([
("eth_call".into(), NonZeroU32::new(100).unwrap()),
("eth_blockNumber".into(), NonZeroU32::new(1).unwrap()),
]))]
pub method_limits: HashMap<String, NonZeroU32>,
#[config(
default,
with = de::Entries::WELL_KNOWN.delimited(
lazy_regex!(ref r"\s*[,\n]\s*"),
lazy_regex!(ref r"\s*=\s*"),
)
)]
pub balances: HashMap<u64, EtherAmount>,
}