reth_cli_commands/test_vectors/
mod.rs

1//! Command for generating test vectors.
2
3use clap::{Parser, Subcommand};
4
5pub mod compact;
6pub mod tables;
7
8/// Generate test-vectors for different data types.
9#[derive(Debug, Parser)]
10pub struct Command {
11    #[command(subcommand)]
12    command: Subcommands,
13}
14
15#[derive(Subcommand, Debug)]
16/// `reth test-vectors` subcommands
17pub enum Subcommands {
18    /// Generates test vectors for specified tables. If no table is specified, generate for all.
19    Tables {
20        /// List of table names. Case-sensitive.
21        names: Vec<String>,
22    },
23    /// Randomly generate test vectors for each `Compact` type using the `--write` flag.
24    ///
25    /// The generated vectors are serialized in both `json` and `Compact` formats and saved to a
26    /// file.
27    ///
28    /// Use the `--read` flag to read and validate the previously generated vectors from a file.
29    #[group(multiple = false, required = true)]
30    Compact {
31        /// Write test vectors to a file.
32        #[arg(long)]
33        write: bool,
34
35        /// Read test vectors from a file.
36        #[arg(long)]
37        read: bool,
38    },
39}
40
41impl Command {
42    /// Execute the command
43    pub async fn execute(self) -> eyre::Result<()> {
44        match self.command {
45            Subcommands::Tables { names } => {
46                tables::generate_vectors(names)?;
47            }
48            Subcommands::Compact { write, .. } => {
49                if write {
50                    compact::generate_vectors()?;
51                } else {
52                    compact::read_vectors()?;
53                }
54            }
55        }
56        Ok(())
57    }
58}