Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evmc tool CLI improvements #574

Merged
merged 3 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion test/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ add_evmc_tool_test(

add_evmc_tool_test(
copy_input
"--vm $<TARGET_FILE:evmc::example-vm> run 600035600052596000f3 --input aabbccdd"
"--vm $<TARGET_FILE:evmc::example-vm> run 600035600052596000f3 --input 0xaabbccdd"
"Result: +success[\r\n]+Gas used: +7[\r\n]+Output: +aabbccdd00000000000000000000000000000000000000000000000000000000[\r\n]"
)

Expand All @@ -39,5 +39,17 @@ add_evmc_tool_test(
"Result: +success[\r\n]+Gas used: +6[\r\n]+Output: +02[\r\n]"
)

add_evmc_tool_test(
invalid_hex_code
"--vm $<TARGET_FILE:evmc::example-vm> run 0x600"
"code: incomplete hex byte pair"
)

add_evmc_tool_test(
invalid_hex_input
"--vm $<TARGET_FILE:evmc::example-vm> run 0x --input aa0y"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we accept this weird Ethereum concept of 0x for empty input? Does it accept run '' or run "" ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All should work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add one more test with that? I hope we can remove the run 0x case at some point in the future :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant adding a test for run "".

And yes, I know it currently accepts 0x as empty and not asking to remove it right now :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried 30 mins, but I don't know how to do this in CMake.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I thought "--vm $<TARGET_FILE:evmc::example-vm> run '' --input aa0y" would have been enough?

"--input: invalid hex digit"
)

get_property(TOOLS_TESTS DIRECTORY PROPERTY TESTS)
set_tests_properties(${TOOLS_TESTS} PROPERTIES ENVIRONMENT LLVM_PROFILE_FILE=${CMAKE_BINARY_DIR}/tools-%p.profraw)
24 changes: 22 additions & 2 deletions tools/evmc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,32 @@

#include "tools/commands/commands.hpp"
#include <CLI/CLI.hpp>
#include <evmc/hex.hpp>
#include <evmc/loader.h>

namespace
{
struct HexValidator : public CLI::Validator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

{
HexValidator() : CLI::Validator{"HEX"}
{
name_ = "HEX";
func_ = [](const std::string& str) -> std::string {
const auto error_code = evmc::validate_hex(str);
if (error_code)
return error_code.message();
return {};
};
}
};
} // namespace

int main(int argc, const char** argv)
{
using namespace evmc;

static HexValidator Hex;

std::string vm_config;
std::string code_hex;
int64_t gas = 1000000;
Expand All @@ -23,10 +43,10 @@ int main(int argc, const char** argv)
*app.add_option("--vm", vm_config, "EVMC VM module")->envname("EVMC_VM");

auto& run_cmd = *app.add_subcommand("run", "Execute EVM bytecode");
run_cmd.add_option("code", code_hex, "Hex-encoded bytecode")->required();
run_cmd.add_option("code", code_hex, "Bytecode")->required()->check(Hex);
axic marked this conversation as resolved.
Show resolved Hide resolved
run_cmd.add_option("--gas", gas, "Execution gas limit", true)->check(CLI::Range(0, 1000000000));
run_cmd.add_option("--rev", rev, "EVM revision", true);
run_cmd.add_option("--input", input_hex, "Hex-encoded input bytes");
run_cmd.add_option("--input", input_hex, "Input bytes")->check(Hex);
run_cmd.add_flag(
"--create", create,
"Create new contract out of the code and then execute this contract with the input");
Expand Down