reth_optimism_cli/commands/
test_vectors.rs

1//! Command for generating test vectors.
2
3use clap::{Parser, Subcommand};
4use op_alloy_consensus::TxDeposit;
5use proptest::test_runner::TestRunner;
6use reth_chainspec::ChainSpec;
7use reth_cli_commands::{
8    compact_types,
9    test_vectors::{
10        compact,
11        compact::{
12            generate_vector, read_vector, GENERATE_VECTORS as ETH_GENERATE_VECTORS,
13            READ_VECTORS as ETH_READ_VECTORS,
14        },
15        tables,
16    },
17};
18use std::sync::Arc;
19
20/// Generate test-vectors for different data types.
21#[derive(Debug, Parser)]
22pub struct Command {
23    #[command(subcommand)]
24    command: Subcommands,
25}
26
27#[derive(Subcommand, Debug)]
28/// `reth test-vectors` subcommands
29pub enum Subcommands {
30    /// Generates test vectors for specified tables. If no table is specified, generate for all.
31    Tables {
32        /// List of table names. Case-sensitive.
33        names: Vec<String>,
34    },
35    /// Generates test vectors for `Compact` types with `--write`. Reads and checks generated
36    /// vectors with `--read`.
37    #[group(multiple = false, required = true)]
38    Compact {
39        /// Write test vectors to a file.
40        #[arg(long)]
41        write: bool,
42
43        /// Read test vectors from a file.
44        #[arg(long)]
45        read: bool,
46    },
47}
48
49impl Command {
50    /// Execute the command
51    pub async fn execute(self) -> eyre::Result<()> {
52        match self.command {
53            Subcommands::Tables { names } => {
54                tables::generate_vectors(names)?;
55            }
56            Subcommands::Compact { write, .. } => {
57                compact_types!(
58                    regular: [
59                        TxDeposit
60                    ], identifier: []
61                );
62
63                if write {
64                    compact::generate_vectors_with(ETH_GENERATE_VECTORS)?;
65                    compact::generate_vectors_with(GENERATE_VECTORS)?;
66                } else {
67                    compact::read_vectors_with(ETH_READ_VECTORS)?;
68                    compact::read_vectors_with(READ_VECTORS)?;
69                }
70            }
71        }
72        Ok(())
73    }
74    /// Returns the underlying chain being used to run this command
75    pub const fn chain_spec(&self) -> Option<&Arc<ChainSpec>> {
76        None
77    }
78}