forge_verify/
retry.rs
1use clap::{builder::RangedU64ValueParser, Parser};
2use foundry_common::retry::Retry;
3use std::time::Duration;
4
5pub const RETRY_CHECK_ON_VERIFY: RetryArgs = RetryArgs { retries: 8, delay: 15 };
7
8pub const RETRY_VERIFY_ON_CREATE: RetryArgs = RetryArgs { retries: 15, delay: 5 };
10
11#[derive(Clone, Copy, Debug, Parser)]
13#[command(about = "Allows to use retry arguments for contract verification")] pub struct RetryArgs {
15 #[arg(
17 long,
18 value_parser = RangedU64ValueParser::<u32>::new().range(1..),
19 default_value = "5",
20 )]
21 pub retries: u32,
22
23 #[arg(
25 long,
26 value_parser = RangedU64ValueParser::<u32>::new().range(0..=180),
27 default_value = "5",
28 )]
29 pub delay: u32,
30}
31
32impl Default for RetryArgs {
33 fn default() -> Self {
34 RETRY_VERIFY_ON_CREATE
35 }
36}
37
38impl RetryArgs {
39 pub fn into_retry(self) -> Retry {
41 Retry::new(self.retries, Duration::from_secs(self.delay as u64))
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn test_cli() {
51 let args = RetryArgs::parse_from(["foundry-cli", "--retries", "10"]);
52 assert_eq!(args.retries, 10);
53 assert_eq!(args.delay, 5);
54
55 let args = RetryArgs::parse_from(["foundry-cli", "--delay", "10"]);
56 assert_eq!(args.retries, 5);
57 assert_eq!(args.delay, 10);
58
59 let args = RetryArgs::parse_from(["foundry-cli", "--retries", "10", "--delay", "10"]);
60 assert_eq!(args.retries, 10);
61 assert_eq!(args.delay, 10);
62 }
63}