reth_cli_commands/test_vectors/
mod.rs

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