2020-09-22 14:53:52 +02:00
|
|
|
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of OpenEthereum.
|
2016-07-11 09:42:41 +02:00
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
// OpenEthereum is free software: you can redistribute it and/or modify
|
2016-07-11 09:42:41 +02:00
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
// OpenEthereum is distributed in the hope that it will be useful,
|
2016-07-11 09:42:41 +02:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2020-09-22 14:53:52 +02:00
|
|
|
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
2016-07-11 09:42:41 +02:00
|
|
|
|
2020-09-22 14:53:52 +02:00
|
|
|
//! OpenEthereum EVM interpreter binary.
|
2016-07-11 09:42:41 +02:00
|
|
|
|
|
|
|
#![warn(missing_docs)]
|
2017-08-28 14:25:16 +02:00
|
|
|
|
2019-01-04 14:05:46 +01:00
|
|
|
extern crate common_types as types;
|
2016-07-11 09:42:41 +02:00
|
|
|
extern crate ethcore;
|
2017-08-28 14:25:16 +02:00
|
|
|
extern crate ethjson;
|
2017-07-06 11:36:15 +02:00
|
|
|
extern crate rustc_hex;
|
|
|
|
extern crate serde;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
2018-09-11 11:36:38 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_json;
|
2016-07-11 09:42:41 +02:00
|
|
|
extern crate docopt;
|
2020-08-05 06:08:03 +02:00
|
|
|
extern crate env_logger;
|
2018-01-10 13:35:18 +01:00
|
|
|
extern crate ethereum_types;
|
2017-07-12 13:09:17 +02:00
|
|
|
extern crate evm;
|
2017-07-03 07:31:29 +02:00
|
|
|
extern crate panic_hook;
|
2020-08-05 06:08:03 +02:00
|
|
|
extern crate parity_bytes as bytes;
|
|
|
|
extern crate vm;
|
2016-07-11 09:42:41 +02:00
|
|
|
|
2017-10-20 15:40:25 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
#[macro_use]
|
|
|
|
extern crate pretty_assertions;
|
|
|
|
|
2018-03-14 12:26:20 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
extern crate tempdir;
|
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
use bytes::Bytes;
|
2016-07-11 09:42:41 +02:00
|
|
|
use docopt::Docopt;
|
2020-08-05 06:08:03 +02:00
|
|
|
use ethcore::{json_tests, spec, TrieSpec};
|
|
|
|
use ethereum_types::{Address, U256};
|
2017-07-06 11:36:15 +02:00
|
|
|
use rustc_hex::FromHex;
|
2020-08-05 06:08:03 +02:00
|
|
|
use std::{fmt, fs, path::PathBuf, sync::Arc};
|
2017-08-10 18:47:23 +02:00
|
|
|
use vm::{ActionParams, CallType};
|
2016-07-11 09:42:41 +02:00
|
|
|
|
2017-05-26 11:06:48 +02:00
|
|
|
mod display;
|
2020-08-05 06:08:03 +02:00
|
|
|
mod info;
|
2017-05-26 11:06:48 +02:00
|
|
|
|
2017-08-01 16:41:33 +02:00
|
|
|
use info::Informant;
|
2017-05-26 11:06:48 +02:00
|
|
|
|
2016-07-11 09:42:41 +02:00
|
|
|
const USAGE: &'static str = r#"
|
|
|
|
EVM implementation for Parity.
|
2020-11-26 08:31:44 +01:00
|
|
|
Copyright 2015-2020 Parity Technologies (UK) Ltd.
|
2016-07-11 09:42:41 +02:00
|
|
|
|
|
|
|
Usage:
|
2020-11-26 08:31:44 +01:00
|
|
|
openethereum-evm state-test <file> [--json --std-json --std-dump-json --only NAME --chain CHAIN --std-out-only --std-err-only --omit-storage-output --omit-memory-output]
|
2020-09-22 14:53:52 +02:00
|
|
|
openethereum-evm stats [options]
|
|
|
|
openethereum-evm stats-jsontests-vm <file>
|
|
|
|
openethereum-evm [options]
|
|
|
|
openethereum-evm [-h | --help]
|
2016-07-11 09:42:41 +02:00
|
|
|
|
2018-06-25 11:21:45 +02:00
|
|
|
Commands:
|
|
|
|
state-test Run a state test from a json file.
|
|
|
|
stats Execute EVM runtime code and return the statistics.
|
2018-08-30 19:57:27 +02:00
|
|
|
stats-jsontests-vm Execute standard json-tests format VMTests and return
|
|
|
|
timing statistics in tsv format.
|
2018-06-25 11:21:45 +02:00
|
|
|
|
2016-07-11 09:42:41 +02:00
|
|
|
Transaction options:
|
2017-05-26 11:06:48 +02:00
|
|
|
--code CODE Contract code as hex (without 0x).
|
2017-08-10 18:47:23 +02:00
|
|
|
--to ADDRESS Recipient address (without 0x).
|
2017-05-26 11:06:48 +02:00
|
|
|
--from ADDRESS Sender address (without 0x).
|
|
|
|
--input DATA Input data as hex (without 0x).
|
|
|
|
--gas GAS Supplied gas as hex (without 0x).
|
2017-08-10 18:47:23 +02:00
|
|
|
--gas-price WEI Supplied gas price as hex (without 0x).
|
2016-07-11 09:42:41 +02:00
|
|
|
|
2017-08-28 14:25:16 +02:00
|
|
|
State test options:
|
2019-09-26 11:03:39 +02:00
|
|
|
--chain CHAIN Run only from specific chain name (i.e. one of EIP150, EIP158,
|
|
|
|
Frontier, Homestead, Byzantium, Constantinople,
|
|
|
|
ConstantinopleFix, Istanbul, EIP158ToByzantiumAt5, FrontierToHomesteadAt5,
|
2020-11-04 19:11:05 +01:00
|
|
|
HomesteadToDaoAt5, HomesteadToEIP150At5, Berlin, Yolo3).
|
2017-08-28 14:25:16 +02:00
|
|
|
--only NAME Runs only a single test matching the name.
|
|
|
|
|
2016-07-11 09:42:41 +02:00
|
|
|
General options:
|
2020-11-26 08:31:44 +01:00
|
|
|
--json Display verbose results in JSON.
|
|
|
|
--std-json Display results in standardized JSON format.
|
|
|
|
--std-err-only With --std-json redirect to err output only.
|
|
|
|
--std-out-only With --std-json redirect to out output only.
|
|
|
|
--omit-storage-output With --std-json omit storage output.
|
|
|
|
--omit-memory-output With --std-json omit memory output.
|
|
|
|
--std-dump-json Display results in standardized JSON format
|
|
|
|
with additional state dump.
|
|
|
|
|
2018-11-25 20:12:59 +01:00
|
|
|
Display result state dump in standardized JSON format.
|
2017-05-26 11:06:48 +02:00
|
|
|
--chain CHAIN Chain spec file path.
|
2016-07-11 09:42:41 +02:00
|
|
|
-h, --help Display this message and exit.
|
|
|
|
"#;
|
|
|
|
|
|
|
|
fn main() {
|
2020-08-05 06:08:03 +02:00
|
|
|
panic_hook::set_abort();
|
|
|
|
env_logger::init();
|
|
|
|
|
|
|
|
let args: Args = Docopt::new(USAGE)
|
|
|
|
.and_then(|d| d.deserialize())
|
|
|
|
.unwrap_or_else(|e| e.exit());
|
|
|
|
|
2020-11-26 08:31:44 +01:00
|
|
|
let config = args.config();
|
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
if args.cmd_state_test {
|
|
|
|
run_state_test(args)
|
|
|
|
} else if args.cmd_stats_jsontests_vm {
|
|
|
|
run_stats_jsontests_vm(args)
|
|
|
|
} else if args.flag_json {
|
2020-11-26 08:31:44 +01:00
|
|
|
run_call(args, display::json::Informant::new(config))
|
2020-08-05 06:08:03 +02:00
|
|
|
} else if args.flag_std_dump_json || args.flag_std_json {
|
|
|
|
if args.flag_std_err_only {
|
2020-11-26 08:31:44 +01:00
|
|
|
run_call(args, display::std_json::Informant::err_only(config))
|
2020-08-05 06:08:03 +02:00
|
|
|
} else if args.flag_std_out_only {
|
2020-11-26 08:31:44 +01:00
|
|
|
run_call(args, display::std_json::Informant::out_only(config))
|
2020-08-05 06:08:03 +02:00
|
|
|
} else {
|
2020-11-26 08:31:44 +01:00
|
|
|
run_call(args, display::std_json::Informant::new_default(config))
|
2020-08-05 06:08:03 +02:00
|
|
|
};
|
|
|
|
} else {
|
2020-11-26 08:31:44 +01:00
|
|
|
run_call(args, display::simple::Informant::new(config))
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
2016-07-12 09:49:16 +02:00
|
|
|
}
|
|
|
|
|
2018-06-25 11:21:45 +02:00
|
|
|
fn run_stats_jsontests_vm(args: Args) {
|
2020-08-05 06:08:03 +02:00
|
|
|
use json_tests::HookType;
|
|
|
|
use std::{
|
|
|
|
collections::HashMap,
|
|
|
|
time::{Duration, Instant},
|
|
|
|
};
|
|
|
|
|
|
|
|
let file = args.arg_file.expect("FILE (or PATH) is required");
|
|
|
|
|
|
|
|
let mut timings: HashMap<String, (Instant, Option<Duration>)> = HashMap::new();
|
|
|
|
|
|
|
|
{
|
|
|
|
let mut record_time = |name: &str, typ: HookType| match typ {
|
|
|
|
HookType::OnStart => {
|
|
|
|
timings.insert(name.to_string(), (Instant::now(), None));
|
|
|
|
}
|
|
|
|
HookType::OnStop => {
|
|
|
|
timings.entry(name.to_string()).and_modify(|v| {
|
|
|
|
v.1 = Some(v.0.elapsed());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2020-09-08 02:48:09 +02:00
|
|
|
for file_path in json_tests::find_json_files_recursive(&file) {
|
|
|
|
let json_data = std::fs::read(&file_path).unwrap();
|
|
|
|
json_tests::json_executive_test(&file_path, &json_data, &mut record_time);
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (name, v) in timings {
|
|
|
|
println!(
|
|
|
|
"{}\t{}",
|
|
|
|
name,
|
|
|
|
display::as_micros(&v.1.expect("All hooks are called with OnStop; qed"))
|
|
|
|
);
|
|
|
|
}
|
2018-06-25 11:21:45 +02:00
|
|
|
}
|
|
|
|
|
2017-08-28 14:25:16 +02:00
|
|
|
fn run_state_test(args: Args) {
|
2020-08-05 06:08:03 +02:00
|
|
|
use ethjson::state::test::Test;
|
2020-11-26 08:31:44 +01:00
|
|
|
let config = args.config();
|
2020-08-05 06:08:03 +02:00
|
|
|
let file = args.arg_file.expect("FILE is required");
|
|
|
|
let mut file = match fs::File::open(&file) {
|
|
|
|
Err(err) => die(format!("Unable to open: {:?}: {}", file, err)),
|
|
|
|
Ok(file) => file,
|
|
|
|
};
|
|
|
|
let state_test = match Test::load(&mut file) {
|
|
|
|
Err(err) => die(format!("Unable to load the test file: {}", err)),
|
|
|
|
Ok(test) => test,
|
|
|
|
};
|
|
|
|
let only_test = args.flag_only.map(|s| s.to_lowercase());
|
|
|
|
let only_chain = args.flag_chain.map(|s| s.to_lowercase());
|
|
|
|
|
|
|
|
for (name, test) in state_test {
|
|
|
|
if let Some(false) = only_test
|
|
|
|
.as_ref()
|
|
|
|
.map(|only_test| &name.to_lowercase() == only_test)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let multitransaction = test.transaction;
|
|
|
|
let env_info = test.env.into();
|
|
|
|
let pre = test.pre_state.into();
|
|
|
|
|
|
|
|
for (spec, states) in test.post_states {
|
|
|
|
if let Some(false) = only_chain
|
|
|
|
.as_ref()
|
|
|
|
.map(|only_chain| &format!("{:?}", spec).to_lowercase() == only_chain)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (idx, state) in states.into_iter().enumerate() {
|
|
|
|
let post_root = state.hash.into();
|
2021-03-03 15:57:25 +01:00
|
|
|
let transaction = multitransaction.select(&state.indexes);
|
2020-08-05 06:08:03 +02:00
|
|
|
|
|
|
|
let trie_spec = if args.flag_std_dump_json {
|
|
|
|
TrieSpec::Fat
|
|
|
|
} else {
|
|
|
|
TrieSpec::Secure
|
|
|
|
};
|
|
|
|
if args.flag_json {
|
|
|
|
info::run_transaction(
|
|
|
|
&name,
|
|
|
|
idx,
|
|
|
|
&spec,
|
|
|
|
&pre,
|
|
|
|
post_root,
|
|
|
|
&env_info,
|
|
|
|
transaction,
|
2020-11-26 08:31:44 +01:00
|
|
|
display::json::Informant::new(config),
|
2020-08-05 06:08:03 +02:00
|
|
|
trie_spec,
|
|
|
|
)
|
|
|
|
} else if args.flag_std_dump_json || args.flag_std_json {
|
|
|
|
if args.flag_std_err_only {
|
|
|
|
info::run_transaction(
|
|
|
|
&name,
|
|
|
|
idx,
|
|
|
|
&spec,
|
|
|
|
&pre,
|
|
|
|
post_root,
|
|
|
|
&env_info,
|
|
|
|
transaction,
|
2020-11-26 08:31:44 +01:00
|
|
|
display::std_json::Informant::err_only(config),
|
2020-08-05 06:08:03 +02:00
|
|
|
trie_spec,
|
|
|
|
)
|
|
|
|
} else if args.flag_std_out_only {
|
|
|
|
info::run_transaction(
|
|
|
|
&name,
|
|
|
|
idx,
|
|
|
|
&spec,
|
|
|
|
&pre,
|
|
|
|
post_root,
|
|
|
|
&env_info,
|
|
|
|
transaction,
|
2020-11-26 08:31:44 +01:00
|
|
|
display::std_json::Informant::out_only(config),
|
2020-08-05 06:08:03 +02:00
|
|
|
trie_spec,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
info::run_transaction(
|
|
|
|
&name,
|
|
|
|
idx,
|
|
|
|
&spec,
|
|
|
|
&pre,
|
|
|
|
post_root,
|
|
|
|
&env_info,
|
|
|
|
transaction,
|
2020-11-26 08:31:44 +01:00
|
|
|
display::std_json::Informant::new_default(config),
|
2020-08-05 06:08:03 +02:00
|
|
|
trie_spec,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info::run_transaction(
|
|
|
|
&name,
|
|
|
|
idx,
|
|
|
|
&spec,
|
|
|
|
&pre,
|
|
|
|
post_root,
|
|
|
|
&env_info,
|
|
|
|
transaction,
|
2020-11-26 08:31:44 +01:00
|
|
|
display::simple::Informant::new(config),
|
2020-08-05 06:08:03 +02:00
|
|
|
trie_spec,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-28 14:25:16 +02:00
|
|
|
}
|
|
|
|
|
2017-10-20 15:40:25 +02:00
|
|
|
fn run_call<T: Informant>(args: Args, informant: T) {
|
2020-08-05 06:08:03 +02:00
|
|
|
let from = arg(args.from(), "--from");
|
|
|
|
let to = arg(args.to(), "--to");
|
|
|
|
let code = arg(args.code(), "--code");
|
|
|
|
let spec = arg(args.spec(), "--chain");
|
|
|
|
let gas = arg(args.gas(), "--gas");
|
|
|
|
let gas_price = arg(args.gas_price(), "--gas-price");
|
|
|
|
let data = arg(args.data(), "--input");
|
|
|
|
|
|
|
|
if code.is_none() && to == Address::default() {
|
|
|
|
die("Either --code or --to is required.");
|
|
|
|
}
|
|
|
|
let mut params = ActionParams::default();
|
2020-11-04 19:11:05 +01:00
|
|
|
if spec.engine.params().eip2929_transition == 0 {
|
|
|
|
params.access_list.enable();
|
|
|
|
params.access_list.insert_address(from);
|
|
|
|
params.access_list.insert_address(to);
|
|
|
|
for (builtin, _) in spec.engine.builtins() {
|
|
|
|
params.access_list.insert_address(*builtin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-05 06:08:03 +02:00
|
|
|
params.call_type = if code.is_none() {
|
|
|
|
CallType::Call
|
|
|
|
} else {
|
|
|
|
CallType::None
|
|
|
|
};
|
|
|
|
params.code_address = to;
|
|
|
|
params.address = to;
|
|
|
|
params.sender = from;
|
|
|
|
params.origin = from;
|
|
|
|
params.gas = gas;
|
|
|
|
params.gas_price = gas_price;
|
|
|
|
params.code = code.map(Arc::new);
|
|
|
|
params.data = data;
|
|
|
|
|
|
|
|
let mut sink = informant.clone_sink();
|
|
|
|
let result = if args.flag_std_dump_json {
|
|
|
|
info::run_action(&spec, params, informant, TrieSpec::Fat)
|
|
|
|
} else {
|
|
|
|
info::run_action(&spec, params, informant, TrieSpec::Secure)
|
|
|
|
};
|
|
|
|
T::finish(result, &mut sink);
|
2016-07-11 09:42:41 +02:00
|
|
|
}
|
|
|
|
|
2017-07-06 11:36:15 +02:00
|
|
|
#[derive(Debug, Deserialize)]
|
2016-07-11 09:42:41 +02:00
|
|
|
struct Args {
|
2020-08-05 06:08:03 +02:00
|
|
|
cmd_stats: bool,
|
|
|
|
cmd_state_test: bool,
|
|
|
|
cmd_stats_jsontests_vm: bool,
|
|
|
|
arg_file: Option<PathBuf>,
|
|
|
|
flag_only: Option<String>,
|
|
|
|
flag_from: Option<String>,
|
|
|
|
flag_to: Option<String>,
|
|
|
|
flag_code: Option<String>,
|
|
|
|
flag_gas: Option<String>,
|
|
|
|
flag_gas_price: Option<String>,
|
|
|
|
flag_input: Option<String>,
|
|
|
|
flag_chain: Option<String>,
|
|
|
|
flag_json: bool,
|
|
|
|
flag_std_json: bool,
|
|
|
|
flag_std_dump_json: bool,
|
|
|
|
flag_std_err_only: bool,
|
|
|
|
flag_std_out_only: bool,
|
2020-11-26 08:31:44 +01:00
|
|
|
flag_omit_storage_output: bool,
|
|
|
|
flag_omit_memory_output: bool,
|
2016-07-11 09:42:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Args {
|
2020-08-05 06:08:03 +02:00
|
|
|
pub fn gas(&self) -> Result<U256, String> {
|
|
|
|
match self.flag_gas {
|
|
|
|
Some(ref gas) => gas.parse().map_err(to_string),
|
|
|
|
None => Ok(U256::from(u64::max_value())),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn gas_price(&self) -> Result<U256, String> {
|
|
|
|
match self.flag_gas_price {
|
|
|
|
Some(ref gas_price) => gas_price.parse().map_err(to_string),
|
|
|
|
None => Ok(U256::zero()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn from(&self) -> Result<Address, String> {
|
|
|
|
match self.flag_from {
|
|
|
|
Some(ref from) => from.parse().map_err(to_string),
|
|
|
|
None => Ok(Address::default()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn to(&self) -> Result<Address, String> {
|
|
|
|
match self.flag_to {
|
|
|
|
Some(ref to) => to.parse().map_err(to_string),
|
|
|
|
None => Ok(Address::default()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn code(&self) -> Result<Option<Bytes>, String> {
|
|
|
|
match self.flag_code {
|
|
|
|
Some(ref code) => code.from_hex().map(Some).map_err(to_string),
|
|
|
|
None => Ok(None),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn data(&self) -> Result<Option<Bytes>, String> {
|
|
|
|
match self.flag_input {
|
|
|
|
Some(ref input) => input.from_hex().map_err(to_string).map(Some),
|
|
|
|
None => Ok(None),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn spec(&self) -> Result<spec::Spec, String> {
|
|
|
|
Ok(match self.flag_chain {
|
2020-11-04 19:11:05 +01:00
|
|
|
Some(ref spec_name) => {
|
|
|
|
let fork_spec: Result<ethjson::spec::ForkSpec, _> =
|
|
|
|
serde_json::from_str(&format!("{:?}", spec_name));
|
|
|
|
if let Ok(fork_spec) = fork_spec {
|
|
|
|
ethcore::client::EvmTestClient::spec_from_json(&fork_spec)
|
|
|
|
.expect("this forkspec is not defined")
|
|
|
|
} else {
|
|
|
|
let file = fs::File::open(spec_name).map_err(|e| format!("{}", e))?;
|
|
|
|
spec::Spec::load(&::std::env::temp_dir(), file)?
|
|
|
|
}
|
2020-08-05 06:08:03 +02:00
|
|
|
}
|
|
|
|
None => ethcore::ethereum::new_foundation(&::std::env::temp_dir()),
|
|
|
|
})
|
|
|
|
}
|
2020-11-26 08:31:44 +01:00
|
|
|
|
|
|
|
pub fn config(&self) -> display::config::Config {
|
|
|
|
display::config::Config::new(self.flag_omit_storage_output, self.flag_omit_memory_output)
|
|
|
|
}
|
2016-07-11 09:42:41 +02:00
|
|
|
}
|
|
|
|
|
2017-05-26 11:06:48 +02:00
|
|
|
fn arg<T>(v: Result<T, String>, param: &str) -> T {
|
2020-08-05 06:08:03 +02:00
|
|
|
v.unwrap_or_else(|e| die(format!("Invalid {}: {}", param, e)))
|
2017-05-26 11:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn to_string<T: fmt::Display>(msg: T) -> String {
|
2020-08-05 06:08:03 +02:00
|
|
|
format!("{}", msg)
|
2017-05-26 11:06:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn die<T: fmt::Display>(msg: T) -> ! {
|
2020-08-05 06:08:03 +02:00
|
|
|
println!("{}", msg);
|
|
|
|
::std::process::exit(-1)
|
2016-07-11 09:42:41 +02:00
|
|
|
}
|
2017-08-18 17:44:40 +02:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-08-05 06:08:03 +02:00
|
|
|
use super::{Args, USAGE};
|
|
|
|
use docopt::Docopt;
|
2021-03-12 10:12:42 +01:00
|
|
|
use ethereum_types::Address;
|
2020-08-05 06:08:03 +02:00
|
|
|
|
|
|
|
fn run<T: AsRef<str>>(args: &[T]) -> Args {
|
|
|
|
Docopt::new(USAGE)
|
|
|
|
.and_then(|d| d.argv(args.into_iter()).deserialize())
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_parse_all_the_options() {
|
|
|
|
let args = run(&[
|
2020-09-22 14:53:52 +02:00
|
|
|
"openethereum-evm",
|
2020-08-05 06:08:03 +02:00
|
|
|
"--json",
|
|
|
|
"--std-json",
|
|
|
|
"--std-dump-json",
|
|
|
|
"--gas",
|
|
|
|
"1",
|
|
|
|
"--gas-price",
|
|
|
|
"2",
|
|
|
|
"--from",
|
|
|
|
"0000000000000000000000000000000000000003",
|
|
|
|
"--to",
|
|
|
|
"0000000000000000000000000000000000000004",
|
|
|
|
"--code",
|
|
|
|
"05",
|
|
|
|
"--input",
|
|
|
|
"06",
|
|
|
|
"--chain",
|
|
|
|
"./testfile",
|
|
|
|
"--std-err-only",
|
|
|
|
"--std-out-only",
|
|
|
|
]);
|
|
|
|
|
|
|
|
assert_eq!(args.flag_json, true);
|
|
|
|
assert_eq!(args.flag_std_json, true);
|
|
|
|
assert_eq!(args.flag_std_dump_json, true);
|
|
|
|
assert_eq!(args.flag_std_err_only, true);
|
|
|
|
assert_eq!(args.flag_std_out_only, true);
|
|
|
|
assert_eq!(args.gas(), Ok(1.into()));
|
|
|
|
assert_eq!(args.gas_price(), Ok(2.into()));
|
2021-03-12 10:12:42 +01:00
|
|
|
assert_eq!(args.from(), Ok(Address::from_low_u64_be(3)));
|
|
|
|
assert_eq!(args.to(), Ok(Address::from_low_u64_be(4)));
|
2020-08-05 06:08:03 +02:00
|
|
|
assert_eq!(args.code(), Ok(Some(vec![05])));
|
|
|
|
assert_eq!(args.data(), Ok(Some(vec![06])));
|
|
|
|
assert_eq!(args.flag_chain, Some("./testfile".to_owned()));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_parse_state_test_command() {
|
|
|
|
let args = run(&[
|
2020-09-22 14:53:52 +02:00
|
|
|
"openethereum-evm",
|
2020-08-05 06:08:03 +02:00
|
|
|
"state-test",
|
|
|
|
"./file.json",
|
|
|
|
"--chain",
|
|
|
|
"homestead",
|
|
|
|
"--only=add11",
|
|
|
|
"--json",
|
|
|
|
"--std-json",
|
|
|
|
"--std-dump-json",
|
|
|
|
]);
|
|
|
|
|
|
|
|
assert_eq!(args.cmd_state_test, true);
|
|
|
|
assert!(args.arg_file.is_some());
|
|
|
|
assert_eq!(args.flag_json, true);
|
|
|
|
assert_eq!(args.flag_std_json, true);
|
|
|
|
assert_eq!(args.flag_std_dump_json, true);
|
|
|
|
assert_eq!(args.flag_chain, Some("homestead".to_owned()));
|
|
|
|
assert_eq!(args.flag_only, Some("add11".to_owned()));
|
|
|
|
}
|
2017-08-18 17:44:40 +02:00
|
|
|
}
|