Skip to content

Commit

Permalink
chore(revme): replace structopt with clap (#1754)
Browse files Browse the repository at this point in the history
`structopt` has long been discontinued in favor of clap:
<https://docs.rs/structopt/0.3.26/structopt/index.html#maintenance>
  • Loading branch information
DaniPopes authored Sep 12, 2024
1 parent 077c2c3 commit a914ddd
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 209 deletions.
252 changes: 103 additions & 149 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ alloy-rlp = { version = "0.3", default-features = false, features = [
] }
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
structopt = "0.3"
clap = { version = "4", features = ["derive"] }
thiserror = "1.0"
triehash = "0.8"
walkdir = "2.5"
Expand Down
16 changes: 7 additions & 9 deletions bins/revme/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ pub mod eofvalidation;
pub mod evmrunner;
pub mod statetest;

use structopt::{clap::AppSettings, StructOpt};
use clap::Parser;

#[derive(StructOpt, Debug)]
#[structopt(setting = AppSettings::InferSubcommands)]
#[derive(Parser, Debug)]
#[command(infer_subcommands = true)]
#[allow(clippy::large_enum_variant)]
pub enum MainCmd {
#[structopt(about = "Execute Ethereum state tests")]
/// Execute Ethereum state tests.
Statetest(statetest::Cmd),
#[structopt(about = "Execute eof validation tests")]
/// Execute eof validation tests.
EofValidation(eofvalidation::Cmd),
#[structopt(
about = "Evm runner command allows running arbitrary evm bytecode.\nBytecode can be provided from cli or from file with --path option."
)]
/// Run arbitrary EVM bytecode.
Evm(evmrunner::Cmd),
#[structopt(alias = "bc", about = "Prints the opcodes of an hex Bytecodes.")]
/// Print the structure of an EVM bytecode.
Bytecode(bytecode::Cmd),
}

Expand Down
12 changes: 6 additions & 6 deletions bins/revme/src/cmd/bytecode.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clap::Parser;
use revm::{
interpreter::{
analysis::{validate_eof_inner, CodeType, EofError},
Expand All @@ -6,21 +7,20 @@ use revm::{
primitives::{Bytes, Eof, MAX_INITCODE_SIZE},
};
use std::io;
use structopt::StructOpt;

/// Statetest command
#[derive(StructOpt, Debug)]
/// `bytecode` subcommand.
#[derive(Parser, Debug)]
pub struct Cmd {
/// Is EOF code in INITCODE mode.
#[structopt(long)]
#[arg(long)]
eof_initcode: bool,
/// Is EOF code in RUNTIME mode.
#[structopt(long)]
#[arg(long)]
eof_runtime: bool,
/// Bytecode in hex format. If bytes start with 0xFE it will be interpreted as a EOF.
/// Otherwise, it will be interpreted as a EOF bytecode.
/// If not provided, it will operate in interactive EOF validation mode.
#[structopt()]
#[arg()]
bytes: Option<String>,
}

Expand Down
14 changes: 7 additions & 7 deletions bins/revme/src/cmd/eofvalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ mod test_suite;
pub use test_suite::{PragueTestResult, TestResult, TestSuite, TestUnit, TestVector};

use crate::{cmd::Error, dir_utils::find_all_json_tests};
use clap::Parser;
use revm::interpreter::analysis::{validate_raw_eof_inner, CodeType, EofError};
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use structopt::StructOpt;

/// Eof validation command.
#[derive(StructOpt, Debug)]
/// `eof-validation` subcommand.
#[derive(Parser, Debug)]
pub struct Cmd {
/// Input path to eof validation test
#[structopt(required = true)]
path: Vec<PathBuf>,
/// Input paths to EOF validation tests.
#[arg(required = true, num_args = 1..)]
paths: Vec<PathBuf>,
}

impl Cmd {
/// Run statetest command.
pub fn run(&self) -> Result<(), Error> {
// check if path exists.
for path in &self.path {
for path in &self.paths {
if !path.exists() {
return Err(Error::Custom("The specified path does not exist"));
}
Expand Down
34 changes: 17 additions & 17 deletions bins/revme/src/cmd/evmrunner.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clap::Parser;
use revm::{
db::BenchmarkDB,
inspector_handle_register,
Expand All @@ -9,9 +10,6 @@ use std::io::Error as IoError;
use std::path::PathBuf;
use std::time::Duration;
use std::{borrow::Cow, fs};
use structopt::StructOpt;

extern crate alloc;

#[derive(Debug, thiserror::Error)]
pub enum Errors {
Expand All @@ -31,26 +29,26 @@ pub enum Errors {

/// Evm runner command allows running arbitrary evm bytecode.
/// Bytecode can be provided from cli or from file with --path option.
#[derive(StructOpt, Debug)]
#[derive(Parser, Debug)]
pub struct Cmd {
/// Bytecode to be executed.
#[structopt(default_value = "")]
bytecode: String,
/// Path to file containing the evm bytecode.
/// Overrides the bytecode option.
#[structopt(long)]
/// Hex-encoded EVM bytecode to be executed.
#[arg(required_unless_present = "path")]
bytecode: Option<String>,
/// Path to a file containing the hex-encoded EVM bytecode to be executed.
/// Overrides the positional `bytecode` argument.
#[arg(long)]
path: Option<PathBuf>,
/// Run in benchmarking mode.
#[structopt(long)]
#[arg(long)]
bench: bool,
/// Input bytes.
#[structopt(long, default_value = "")]
/// Hex-encoded input/calldata bytes.
#[arg(long, default_value = "")]
input: String,
/// Print the state.
#[structopt(long)]
#[arg(long)]
state: bool,
/// Print the trace.
#[structopt(long)]
#[arg(long)]
trace: bool,
}

Expand All @@ -64,9 +62,11 @@ impl Cmd {
if !path.exists() {
return Err(Errors::PathNotExists);
}
fs::read_to_string(path)?.to_owned().into()
fs::read_to_string(path)?.into()
} else if let Some(bytecode) = &self.bytecode {
bytecode.as_str().into()
} else {
self.bytecode.as_str().into()
unreachable!()
};

let bytecode = hex::decode(bytecode_str.trim()).map_err(|_| Errors::InvalidBytecode)?;
Expand Down
25 changes: 13 additions & 12 deletions bins/revme/src/cmd/statetest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,39 @@ pub mod utils;

pub use runner::TestError as Error;

use clap::Parser;
use runner::{find_all_json_tests, run, TestError};
use std::path::PathBuf;
use structopt::StructOpt;

/// Statetest command
#[derive(StructOpt, Debug)]
/// `statetest` subcommand.
#[derive(Parser, Debug)]
pub struct Cmd {
/// Path to folder or file containing the tests. If multiple paths are specified
/// they will be run in sequence.
///
/// Folders will be searched recursively for files with the extension `.json`.
#[structopt(required = true)]
path: Vec<PathBuf>,
#[clap(required = true, num_args = 1..)]
paths: Vec<PathBuf>,
/// Run tests in a single thread.
#[structopt(short = "s", long)]
#[clap(short = 's', long)]
single_thread: bool,
/// Output results in JSON format.
/// It will stop second run of evm on failure.
#[structopt(long)]
#[clap(long)]
json: bool,
/// Output outcome in JSON format. If json is true, this is implied.
/// It will stop second run of evm on failure.
#[structopt(short = "o", long)]
/// Output outcome in JSON format. If `--json` is true, this is implied.
/// It will stop second run of EVM on failure.
#[clap(short = 'o', long)]
json_outcome: bool,
#[structopt(long, alias = "no-fail-fast")]
/// Keep going after a test failure.
#[clap(long, alias = "no-fail-fast")]
keep_going: bool,
}

impl Cmd {
/// Run statetest command.
pub fn run(&self) -> Result<(), TestError> {
for path in &self.path {
for path in &self.paths {
println!("\nRunning tests in {}...", path.display());
let test_files = find_all_json_tests(path);
run(
Expand Down
11 changes: 3 additions & 8 deletions bins/revme/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use clap::Parser;
use revme::cmd::{Error, MainCmd};
use structopt::StructOpt;

pub fn main() -> Result<(), Error> {
let cmd = MainCmd::from_args();
if let Err(e) = cmd.run() {
println!("{:?}", e);
return Err(e);
}
Ok(())
fn main() -> Result<(), Error> {
MainCmd::parse().run().inspect_err(|e| eprintln!("{e:?}"))
}

0 comments on commit a914ddd

Please sign in to comment.