feat: add reth test-vectors compact --write|--read (#11954)

This commit is contained in:
joshieDo
2024-10-25 03:34:12 +09:00
committed by GitHub
parent ba78e43938
commit 777417ad8a
51 changed files with 857 additions and 101 deletions

View File

@ -65,6 +65,13 @@ tokio-util = { workspace = true, features = ["codec"] }
tracing.workspace = true
eyre.workspace = true
# reth test-vectors
proptest = { workspace = true, optional = true }
op-alloy-consensus = { workspace = true, features = [
"arbitrary",
], optional = true }
[dev-dependencies]
tempfile.workspace = true
reth-stages = { workspace = true, features = ["test-utils"] }
@ -94,3 +101,9 @@ jemalloc = [
"reth-node-core/jemalloc",
"reth-node-metrics/jemalloc"
]
dev = [
"dep:proptest",
"reth-cli-commands/arbitrary",
"op-alloy-consensus"
]

View File

@ -16,6 +16,9 @@ pub mod import;
pub mod import_receipts;
pub mod init_state;
#[cfg(feature = "dev")]
pub mod test_vectors;
/// Commands to be executed
#[derive(Debug, Subcommand)]
pub enum Commands<Spec: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + fmt::Debug = NoArgs>
@ -55,4 +58,8 @@ pub enum Commands<Spec: ChainSpecParser = OpChainSpecParser, Ext: clap::Args + f
/// Prune according to the configuration without any limits
#[command(name = "prune")]
Prune(prune::PruneCommand<Spec>),
/// Generate Test Vectors
#[cfg(feature = "dev")]
#[command(name = "test-vectors")]
TestVectors(test_vectors::Command),
}

View File

@ -0,0 +1,72 @@
//! Command for generating test vectors.
use clap::{Parser, Subcommand};
use op_alloy_consensus::TxDeposit;
use proptest::test_runner::TestRunner;
use reth_cli_commands::{
compact_types,
test_vectors::{
compact,
compact::{
generate_vector, read_vector, GENERATE_VECTORS as ETH_GENERATE_VECTORS,
READ_VECTORS as ETH_READ_VECTORS,
},
tables,
},
};
/// Generate test-vectors for different data types.
#[derive(Debug, Parser)]
pub struct Command {
#[command(subcommand)]
command: Subcommands,
}
#[derive(Subcommand, Debug)]
/// `reth test-vectors` subcommands
pub enum Subcommands {
/// Generates test vectors for specified tables. If no table is specified, generate for all.
Tables {
/// List of table names. Case-sensitive.
names: Vec<String>,
},
/// Generates test vectors for `Compact` types with `--write`. Reads and checks generated
/// vectors with `--read`.
#[group(multiple = false, required = true)]
Compact {
/// Write test vectors to a file.
#[arg(long)]
write: bool,
/// Read test vectors from a file.
#[arg(long)]
read: bool,
},
}
impl Command {
/// Execute the command
pub async fn execute(self) -> eyre::Result<()> {
match self.command {
Subcommands::Tables { names } => {
tables::generate_vectors(names)?;
}
Subcommands::Compact { write, .. } => {
compact_types!(
regular: [
TxDeposit
], identifier: []
);
if write {
compact::generate_vectors_with(ETH_GENERATE_VECTORS)?;
compact::generate_vectors_with(GENERATE_VECTORS)?;
} else {
compact::read_vectors_with(ETH_READ_VECTORS)?;
compact::read_vectors_with(READ_VECTORS)?;
}
}
}
Ok(())
}
}

View File

@ -169,6 +169,8 @@ where
runner.run_command_until_exit(|ctx| command.execute::<OptimismNode>(ctx))
}
Commands::Prune(command) => runner.run_until_ctrl_c(command.execute::<OptimismNode>()),
#[cfg(feature = "dev")]
Commands::TestVectors(command) => runner.run_until_ctrl_c(command.execute()),
}
}