use clap::{builder::RangedU64ValueParser, Parser};
use foundry_common::retry::Retry;
use std::time::Duration;
pub const RETRY_CHECK_ON_VERIFY: RetryArgs = RetryArgs { retries: 8, delay: 15 };
pub const RETRY_VERIFY_ON_CREATE: RetryArgs = RetryArgs { retries: 15, delay: 5 };
#[derive(Clone, Copy, Debug, Parser)]
#[command(about = "Allows to use retry arguments for contract verification")] pub struct RetryArgs {
#[arg(
long,
value_parser = RangedU64ValueParser::<u32>::new().range(1..),
default_value = "5",
)]
pub retries: u32,
#[arg(
long,
value_parser = RangedU64ValueParser::<u32>::new().range(0..=180),
default_value = "5",
)]
pub delay: u32,
}
impl Default for RetryArgs {
fn default() -> Self {
RETRY_VERIFY_ON_CREATE
}
}
impl RetryArgs {
pub fn into_retry(self) -> Retry {
Retry::new(self.retries, Duration::from_secs(self.delay as u64))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cli() {
let args = RetryArgs::parse_from(["foundry-cli", "--retries", "10"]);
assert_eq!(args.retries, 10);
assert_eq!(args.delay, 5);
let args = RetryArgs::parse_from(["foundry-cli", "--delay", "10"]);
assert_eq!(args.retries, 5);
assert_eq!(args.delay, 10);
let args = RetryArgs::parse_from(["foundry-cli", "--retries", "10", "--delay", "10"]);
assert_eq!(args.retries, 10);
assert_eq!(args.delay, 10);
}
}