-
Notifications
You must be signed in to change notification settings - Fork 314
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
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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"); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 acceptrun ''
orrun ""
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All should work
There was a problem hiding this comment.
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 :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/ethereum/evmc/blob/master/test/unittests/hex_test.cpp#L71
There was a problem hiding this comment.
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 :)There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
There was a problem hiding this comment.
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?