revme/
cmd.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
pub mod bench;
pub mod bytecode;
pub mod eofvalidation;
pub mod evmrunner;
pub mod statetest;

use clap::Parser;

#[derive(Parser, Debug)]
#[command(infer_subcommands = true)]
#[allow(clippy::large_enum_variant)]
pub enum MainCmd {
    /// Execute Ethereum state tests.
    Statetest(statetest::Cmd),
    /// Execute eof validation tests.
    EofValidation(eofvalidation::Cmd),
    /// Run arbitrary EVM bytecode.
    Evm(evmrunner::Cmd),
    /// Print the structure of an EVM bytecode.
    Bytecode(bytecode::Cmd),
    /// Run bench from specified list.
    Bench(bench::Cmd),
}

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error(transparent)]
    Statetest(#[from] statetest::Error),
    #[error(transparent)]
    EvmRunnerErrors(#[from] evmrunner::Errors),
    #[error("Eof validation failed: {:?}/{total_tests}", total_tests-failed_test)]
    EofValidation {
        failed_test: usize,
        total_tests: usize,
    },
    #[error("Custom error: {0}")]
    Custom(&'static str),
}

impl MainCmd {
    pub fn run(&self) -> Result<(), Error> {
        match self {
            Self::Statetest(cmd) => cmd.run().map_err(Into::into),
            Self::EofValidation(cmd) => cmd.run().map_err(Into::into),
            Self::Evm(cmd) => cmd.run().map_err(Into::into),
            Self::Bytecode(cmd) => {
                cmd.run();
                Ok(())
            }
            Self::Bench(cmd) => {
                cmd.run();
                Ok(())
            }
        }
    }
}