Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Fix --chain parsing in evmbin. (#6314)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw authored and arkpar committed Aug 18, 2017
1 parent 2c0a1b6 commit 5ed14c1
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions evmbin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ EVM implementation for Parity.
Copyright 2016, 2017 Parity Technologies (UK) Ltd
Usage:
evmbin stats [options]
evmbin [options]
evmbin [-h | --help]
parity-evm stats [options]
parity-evm [options]
parity-evm [-h | --help]
Transaction options:
--code CODE Contract code as hex (without 0x).
Expand Down Expand Up @@ -116,7 +116,7 @@ struct Args {
flag_gas: Option<String>,
flag_gas_price: Option<String>,
flag_input: Option<String>,
flag_spec: Option<String>,
flag_chain: Option<String>,
flag_json: bool,
}

Expand Down Expand Up @@ -164,7 +164,7 @@ impl Args {
}

pub fn spec(&self) -> Result<spec::Spec, String> {
Ok(match self.flag_spec {
Ok(match self.flag_chain {
Some(ref filename) => {
let file = fs::File::open(filename).map_err(|e| format!("{}", e))?;
spec::Spec::load(::std::env::temp_dir(), file)?
Expand All @@ -188,3 +188,37 @@ fn die<T: fmt::Display>(msg: T) -> ! {
println!("{}", msg);
::std::process::exit(-1)
}

#[cfg(test)]
mod tests {
use docopt::Docopt;
use super::{Args, USAGE};

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(&[
"parity-evm",
"--json",
"--gas", "1",
"--gas-price", "2",
"--from", "0000000000000000000000000000000000000003",
"--to", "0000000000000000000000000000000000000004",
"--code", "05",
"--input", "06",
"--chain", "./testfile",
]);

assert_eq!(args.flag_json, true);
assert_eq!(args.gas(), Ok(1.into()));
assert_eq!(args.gas_price(), Ok(2.into()));
assert_eq!(args.from(), Ok(3.into()));
assert_eq!(args.to(), Ok(4.into()));
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()));
}
}

0 comments on commit 5ed14c1

Please sign in to comment.