Skip to content

EVM Tools Package

Defines EVM tools for use in the Ethereum specification.

create_parser()

Create a command-line argument parser for the evm tool.

Source code in packages/testing/src/execution_testing/evm_tools/__init__.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def create_parser() -> argparse.ArgumentParser:
    """
    Create a command-line argument parser for the evm tool.
    """
    new_parser = argparse.ArgumentParser(
        description=DESCRIPTION,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )

    commit_hash = get_git_commit_hash()

    # Add -v option to parser to show the version of the tool
    new_parser.add_argument(
        "-v",
        "--version",
        action="version",
        version=f"%(prog)s {__version__} (Git commit: {commit_hash})",
        help="Show the version of the tool.",
    )

    # Add options to the t8n tool
    subparsers = new_parser.add_subparsers(dest="evm_tool")

    daemon_arguments(subparsers)
    t8n_arguments(subparsers)
    b11r_arguments(subparsers)
    state_test_arguments(subparsers)

    return new_parser

get_git_commit_hash() cached

Run the 'git rev-parse HEAD' command to get the commit hash.

Source code in packages/testing/src/execution_testing/evm_tools/__init__.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@cache
def get_git_commit_hash() -> str:
    """
    Run the 'git rev-parse HEAD' command to get the commit hash.
    """
    try:
        result = subprocess.run(
            ["git", "rev-parse", "HEAD"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            text=True,
            check=True,
        )

        # Extract and return the commit hash
        commit_hash = result.stdout.strip()
        return commit_hash
    # Handle errors (e.g., Git not found, not in a Git repository)
    except FileNotFoundError as e:
        return str(e)
    except subprocess.CalledProcessError as e:
        return "Error: " + str(e)

main(args=None, out_file=None, in_file=None, fork_cache=None)

Run the tools based on the given options.

Source code in packages/testing/src/execution_testing/evm_tools/__init__.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def main(
    args: Optional[Sequence[Text]] = None,
    out_file: Optional[TextIO] = None,
    in_file: Optional[TextIO] = None,
    fork_cache: Optional[ForkCache] = None,
) -> int:
    """Run the tools based on the given options."""
    parser = create_parser()

    options, _ = parser.parse_known_args(args)

    if out_file is None:
        out_file = sys.stdout

    if in_file is None:
        in_file = sys.stdin

    with ExitStack() as exit_stack:
        if fork_cache is None:
            fork_cache = ForkCache()
            exit_stack.push(fork_cache)

        if options.evm_tool == "t8n":
            return run_t8n_cli(options, out_file, in_file, fork_cache)
        elif options.evm_tool == "b11r":
            b11r_tool = B11R(options, out_file, in_file)
            return b11r_tool.run()
        elif options.evm_tool == "daemon":
            daemon = Daemon(options)
            return daemon.run()
        elif options.evm_tool == "statetest":
            state_test = StateTest(options, out_file, in_file)
            return state_test.run()
        else:
            parser.print_help(file=out_file)
            return 0