vvmbin 0.1.0

Tetsy VVM Implementation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
// Copyright 2015-2020 Parity Technologies (UK) Ltd.
// This file is part of Tetsy Vapory.

// Tetsy Vapory is free software: you can redistribute it and/or modify
// 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.

// Tetsy Vapory is distributed in the hope that it will be useful,
// 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
// along with Tetsy Vapory.  If not, see <http://www.gnu.org/licenses/>.

//! Tetsy VVM Interpreter Binary.
//!
//! ## Overview
//!
//! The Tetsy VVM interpreter binary is a tool in the Tetsy
//! Vapory toolchain. It is an VVM implementation for Tetsy Vapory that
//! is used to run a standalone version of the VVM interpreter.
//!
//! ## Usage
//!
//! The vvmbin tool is not distributed with regular Tetsy Vapory releases
//! so you need to build it from source and run it like so:
//!
//! ```bash
//! cargo build -p vvmbin --release
//! ./target/release/tetsy-vvm --help
//! ```

#![warn(missing_docs)]

use std::sync::Arc;
use std::{fmt, fs};
use std::path::PathBuf;

use tetsy_bytes::Bytes;
use docopt::Docopt;
use rustc_hex::FromHex;
use vapory_types::{U256, Address};
use vapcore::{json_tests, test_helpers::TrieSpec};
use vapcore_spec;
use serde::Deserialize;
use tetsy_vm::{ActionParams, ActionType};

mod info;
mod display;

use crate::info::{Informant, TxInput};

const USAGE: &'static str = r#"
VVM implementation for Tetsy.
  Copyright 2015-2020 Parity Technologies (UK) Ltd.

Usage:
    tetsy-vvm state-test <file> [--chain CHAIN --only NAME --json --std-json --std-dump-json --std-out-only --std-err-only]
    tetsy-vvm stats [options]
    tetsy-vvm stats-jsontests-vm <file>
    tetsy-vvm [options]
    tetsy-vvm [-h | --help]

Commands:
    state-test         Run a state test on a provided state test JSON file.
    stats              Execute VVM runtime code and return the statistics.
    stats-jsontests-vm Execute standard json-tests on a provided state test JSON
                       file path, format VMTests, and return timing statistics
                       in tsv format.

Transaction options:
    --code CODE        Contract code as hex (without 0x).
    --to ADDRESS       Recipient address (without 0x).
    --from ADDRESS     Sender address (without 0x).
    --input DATA       Input data as hex (without 0x).
    --gas GAS          Supplied gas as hex (without 0x).
    --gas-price WEI    Supplied gas price as hex (without 0x).

State test options:
    --chain CHAIN      Run only from specific chain name (i.e. one of EIP150, EIP158,
                       Frontier, Homestead, Byzantium, Constantinople,
                       ConstantinopleFix, Istanbul, EIP158ToByzantiumAt5, FrontierToHomesteadAt5,
                       HomesteadToDaoAt5, HomesteadToEIP150At5).
    --only NAME        Runs only a single test matching the name.

General options:
    --chain PATH       Path to chain spec file.
    --json             Display verbose results in JSON.
    --std-json         Display results in standardized JSON format.
    --std-dump-json    Display results in standardized JSON format
                       with additional state dump.
    --std-err-only     With --std-json redirect to err output only.
    --std-out-only     With --std-json redirect to out output only.
    -h, --help         Display this message and exit.
"#;

fn main() {
	panic_hook::set_abort();
	env_logger::init();

	let args: Args = Docopt::new(USAGE).and_then(|d| d.deserialize()).unwrap_or_else(|e| e.exit());

	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 {
		run_call(args, display::json::Informant::default())
	} else if args.flag_std_dump_json || args.flag_std_json {
		if args.flag_std_err_only {
			run_call(args, display::std_json::Informant::err_only())
		} else if args.flag_std_out_only {
			run_call(args, display::std_json::Informant::out_only())
		} else {
			run_call(args, display::std_json::Informant::default())
		};
	} else {
		run_call(args, display::simple::Informant::default())
	}
}

fn run_state_test(args: Args) {
	use vapjson::test_helpers::state::Test;

	// Parse the specified state test JSON file provided to the command `state-test <file>`.
	let file = args.arg_file.expect("PATH to a state test JSON file is required");
	let mut file = match fs::File::open(&file) {
		Err(err) => die(format!("Unable to open path: {:?}: {}", 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,
	};
	// Parse the name CLI option `--only NAME`.
	let only_test = args.flag_only.map(|s| s.to_lowercase());
	// Parse the chain `--chain CHAIN`
	let only_chain = args.flag_chain.map(|s| s.to_lowercase());

	// Iterate over 1st level (outer) key-value pair of the state test JSON file.
	// Skip to next iteration if CLI option `--only NAME` was parsed into `only_test` and does not match
	// the current key `state_test_name` (i.e. add11, create2callPrecompiles).
	for (state_test_name, test) in state_test {
		if let Some(false) = only_test.as_ref().map(|only_test| {
			&state_test_name.to_lowercase() == only_test
		}) {
			continue;
		}

		// Assign from 2nd level key-value pairs of the state test JSON file (i.e. env, post, pre, transaction).
		let multitransaction = test.transaction;
		let env_info = test.env.into();
		let pre = test.pre_state.into();

		// Iterate over remaining "post" key of the 2nd level key-value pairs in the state test JSON file.
		// Skip to next iteration if CLI option `--chain CHAIN` was parsed into `only_chain` and does not match
		// the current key `fork_spec_name` (i.e. Constantinople, EIP150, EIP158).
		for (fork_spec_name, states) in test.post_states {
			if let Some(false) = only_chain.as_ref().map(|only_chain| {
				&format!("{:?}", fork_spec_name).to_lowercase() == only_chain
			}) {
				continue;
			}

			// Iterate over the 3rd level key-value pairs of the state test JSON file
			// (i.e. list of transactions and associated state roots hashes corresponding each chain).
			for (tx_index, state) in states.into_iter().enumerate() {
				let post_root = state.hash.into();
				let transaction = multitransaction.select(&state.indexes).into();

				// Determine the type of trie with state root to create in the database.
				// The database is a key-value datastore implemented as a database-backend
				// modified Merkle tree.
				// Use a secure trie database specification when CLI option `--std-dump-json`
				// is specified, otherwise use secure trie with fat trie database.
				let trie_spec = if args.flag_std_dump_json {
					TrieSpec::Fat
				} else {
					TrieSpec::Secure
				};

				// Execute the given transaction and verify resulting state root
				// for CLI option `--std-dump-json` or `--std-json`.
				if args.flag_std_dump_json || args.flag_std_json {
					if args.flag_std_err_only {
						let tx_input = TxInput {
							state_test_name: &state_test_name,
							tx_index,
							fork_spec_name: &fork_spec_name,
							pre_state: &pre,
							post_root,
							env_info: &env_info,
							transaction,
							informant: display::std_json::Informant::err_only(),
							trie_spec,
						};
						// Use Standard JSON informant with err only
						info::run_transaction(tx_input);
					} else if args.flag_std_out_only {
						let tx_input = TxInput {
							state_test_name: &state_test_name,
							tx_index,
							fork_spec_name: &fork_spec_name,
							pre_state: &pre,
							post_root,
							env_info: &env_info,
							transaction,
							informant: display::std_json::Informant::out_only(),
							trie_spec,
						};
						// Use Standard JSON informant with out only
						info::run_transaction(tx_input);
					} else {
						let tx_input = TxInput {
							state_test_name: &state_test_name,
							tx_index,
							fork_spec_name: &fork_spec_name,
							pre_state: &pre,
							post_root,
							env_info: &env_info,
							transaction,
							informant: display::std_json::Informant::default(),
							trie_spec,
						};
						// Use Standard JSON informant default
						info::run_transaction(tx_input);
					}
				} else {
					// Execute the given transaction and verify resulting state root
					// for CLI option `--json`.
					if args.flag_json {
						let tx_input = TxInput {
							state_test_name: &state_test_name,
							tx_index,
							fork_spec_name: &fork_spec_name,
							pre_state: &pre,
							post_root,
							env_info: &env_info,
							transaction,
							informant: display::json::Informant::default(),
							trie_spec,
						};
						// Use JSON informant
						info::run_transaction(tx_input);
					} else {
						let tx_input = TxInput {
							state_test_name: &state_test_name,
							tx_index,
							fork_spec_name: &fork_spec_name,
							pre_state: &pre,
							post_root,
							env_info: &env_info,
							transaction,
							informant: display::simple::Informant::default(),
							trie_spec,
						};
						// Use Simple informant
						info::run_transaction(tx_input);
					}
				}
			}
		}
	}
}

fn run_stats_jsontests_vm(args: Args) {
	use crate::json_tests::HookType;
	use std::collections::HashMap;
	use std::time::{Instant, Duration};

	let file = args.arg_file.expect("PATH to a state test JSON file 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());
					});
				},
			}
		};
		if !file.is_file() {
			json_tests::run_executive_test_path(&file, &[], &mut record_time);
		} else {
			json_tests::run_executive_test_file(&file, &mut record_time);
		}
	}

	for (name, v) in timings {
		println!("{}\t{}", name, display::as_micros(&v.1.expect("All hooks are called with OnStop; qed")));
	}
}

// CLI command `stats`
fn run_call<T: Informant>(args: Args, informant: T) {
	let code = arg(args.code(), "--code");
	let to = arg(args.to(), "--to");
	let from = arg(args.from(), "--from");
	let data = arg(args.data(), "--input");
	let gas = arg(args.gas(), "--gas");
	let gas_price = arg(args.gas_price(), "--gas-price");
	let spec = arg(args.spec(), "--chain");

	if code.is_none() && to == Address::zero() {
		die("Either --code or --to is required.");
	}

	let mut params = ActionParams::default();
	params.action_type = if code.is_none() { ActionType::Call } else { ActionType::Create };
	params.code = code.map(Arc::new);
	params.code_address = to;
	params.address = to;
	params.sender = from;
	params.origin = from;
	params.data = data;
	params.gas = gas;
	params.gas_price = gas_price;

	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);
}

#[derive(Debug, Deserialize)]
struct Args {
	cmd_stats: bool,
	cmd_state_test: bool,
	cmd_stats_jsontests_vm: bool,
	arg_file: Option<PathBuf>,
	flag_code: Option<String>,
	flag_to: Option<String>,
	flag_from: Option<String>,
	flag_input: Option<String>,
	flag_gas: Option<String>,
	flag_gas_price: Option<String>,
	flag_only: 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,
}

impl Args {
	// CLI option `--code CODE`
	/// Set the contract code in hex. Only send to either a contract code or a recipient address.
	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),
		}
	}

	// CLI option `--to ADDRESS`
	/// Set the recipient address in hex. Only send to either a contract code or a recipient address.
	pub fn to(&self) -> Result<Address, String> {
		match self.flag_to {
			Some(ref to) => to.parse().map_err(to_string),
			None => Ok(Address::zero()),
		}
	}

	// CLI option `--from ADDRESS`
	/// Set the sender address.
	pub fn from(&self) -> Result<Address, String> {
		match self.flag_from {
			Some(ref from) => from.parse().map_err(to_string),
			None => Ok(Address::zero()),
		}
	}

	// CLI option `--input DATA`
	/// Set the input data in hex.
	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),
		}
	}

	// CLI option `--gas GAS`
	/// Set the gas limit in units of gas. Defaults to max value to allow code to run for whatever time is required.
	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())),
		}
	}

	// CLI option `--gas-price WEI`
	/// Set the gas price. Defaults to zero to allow the code to run even if an account with no balance
	/// is used, otherwise such accounts would not have sufficient funds to pay the transaction fee.
	/// Defaulting to zero also makes testing easier since it is not necessary to specify a special configuration file.
	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()),
		}
	}

	// CLI option `--chain PATH`
	/// Set the path of the chain specification JSON file.
	pub fn spec(&self) -> Result<vapcore_spec::Spec, String> {
		Ok(match self.flag_chain {
			Some(ref filename) => {
				let file = fs::File::open(filename).map_err(|e| e.to_string())?;
				vapcore_spec::Spec::load(&::std::env::temp_dir(), file).map_err(|e| e.to_string())?
			},
			None => {
				vapcore_spec::new_foundation(&::std::env::temp_dir())
			},
		})
	}
}

fn arg<T>(v: Result<T, String>, param: &str) -> T {
	v.unwrap_or_else(|e| die(format!("Invalid {}: {}", param, e)))
}

fn to_string<T: fmt::Display>(msg: T) -> String {
	format!("{}", msg)
}

fn die<T: fmt::Display>(msg: T) -> ! {
	println!("{}", msg);
	::std::process::exit(-1)
}

#[cfg(test)]
mod tests {
	use common_types::transaction;
	use docopt::Docopt;
	use vapcore::test_helpers::TrieSpec;
	use vapjson::test_helpers::state::State;
	use serde::Deserialize;

	use super::{Args, USAGE, Address, run_call};
	use crate::{
		display::std_json::tests::informant,
		info::{self, TxInput}
	};

	#[derive(Debug, PartialEq, Deserialize)]
	pub struct SampleStateTests {
		pub add11: State,
		pub add12: State,
	}

	#[derive(Debug, PartialEq, Deserialize)]
	#[serde(rename_all = "camelCase")]
	pub struct ConstantinopleStateTests {
		pub create2call_precompiles: State,
	}

	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(&[
			"tetsy-vvm",
			"--code", "05",
			"--to", "0000000000000000000000000000000000000004",
			"--from", "0000000000000000000000000000000000000003",
			"--input", "06",
			"--gas", "1",
			"--gas-price", "2",
			"--chain", "./testfile.json",
			"--json",
			"--std-json",
			"--std-dump-json",
			"--std-err-only",
			"--std-out-only",
		]);

		assert_eq!(args.code(), Ok(Some(vec![05])));
		assert_eq!(args.to(), Ok(Address::from_low_u64_be(4)));
		assert_eq!(args.from(), Ok(Address::from_low_u64_be(3)));
		assert_eq!(args.data(), Ok(Some(vec![06]))); // input data
		assert_eq!(args.gas(), Ok(1.into()));
		assert_eq!(args.gas_price(), Ok(2.into()));
		assert_eq!(args.flag_chain, Some("./testfile.json".to_owned()));
		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);
	}

	#[test]
	fn should_parse_state_test_command() {
		let args = run(&[
			"tetsy-vvm",
			"state-test",
			"./file.json",
			"--chain", "homestead",
			"--only=add11",
			"--json",
			"--std-json",
			"--std-dump-json",
			"--std-out-only",
			"--std-err-only",
		]);

		assert_eq!(args.cmd_state_test, true);
		assert!(args.arg_file.is_some());
		assert_eq!(args.flag_chain, Some("homestead".to_owned()));
		assert_eq!(args.flag_only, Some("add11".to_owned()));
		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_out_only, true);
		assert_eq!(args.flag_std_err_only, true);
	}

	#[test]
	#[should_panic]
	fn should_not_parse_only_flag_without_state_test() {
		let _ = run(&[
			"tetsy-vvm",
			"./file.json",
			"--chain", "homestead",
			"--only=add11",
			"--json",
		]);
	}

	#[test]
	#[should_panic]
	fn should_not_parse_only_flag_with_stats() {
		let _ = run(&[
			"tetsy-vvm",
			"stats",
			"./file.json",
			"--chain", "homestead",
			"--only=add11",
			"--json",
		]);
	}

	#[test]
	fn should_not_verify_state_root_using_sample_state_test_json_file() {
		let state_tests = include_str!("../res/teststate.json");
		// Parse the specified state test JSON file to simulate the CLI command `state-test <file>`.
		let deserialized_state_tests: SampleStateTests = serde_json::from_str(state_tests)
			.expect("Serialization cannot fail; qed");

		// Simulate the name CLI option `--only NAME`
		let state_test_name = "add11";
		let pre = deserialized_state_tests.add11.pre_state.into();
		let env_info = deserialized_state_tests.add11.env.into();
		let multitransaction = deserialized_state_tests.add11.transaction;

		for (fork_spec_name, tx_states) in deserialized_state_tests.add11.post_states.iter() {
			for (tx_index, tx_state) in tx_states.into_iter().enumerate() {
				let (informant, _, res) = informant();
				let trie_spec = TrieSpec::Secure;
				let transaction: transaction::SignedTransaction = multitransaction.select(&tx_state.indexes).into();
				let tx_input = TxInput {
					state_test_name: &state_test_name,
					tx_index,
					fork_spec_name: &fork_spec_name,
					pre_state: &pre,
					post_root: tx_states[tx_index].hash.0,
					env_info: &env_info,
					transaction,
					informant,
					trie_spec,
				};
				assert!(!info::run_transaction(tx_input));
				assert!(
					&String::from_utf8_lossy(&**res.0.lock().unwrap()).contains("State root mismatch")
				);
			}
		}
	}

	#[test]
	fn should_verify_state_root_using_constantinople_state_test_json_file() {
		let state_tests = include_str!("../res/create2callPrecompiles.json");
		// Parse the specified state test JSON file to simulate the CLI command `state-test <file>`.
		let deserialized_state_tests: ConstantinopleStateTests = serde_json::from_str(state_tests)
			.expect("Serialization cannot fail; qed");

		// Simulate the name CLI option `--only NAME`
		let state_test_name = "create2callPrecompiles";
		let pre = deserialized_state_tests.create2call_precompiles.pre_state.into();
		let env_info = deserialized_state_tests.create2call_precompiles.env.into();
		let multitransaction = deserialized_state_tests.create2call_precompiles.transaction;
		for (fork_spec_name, tx_states) in deserialized_state_tests.create2call_precompiles.post_states.iter() {
			for (tx_index, tx_state) in tx_states.into_iter().enumerate() {
				let (informant, _, _) = informant();
				let trie_spec = TrieSpec::Secure; // TrieSpec::Fat for --std_dump_json
				let transaction: transaction::SignedTransaction = multitransaction.select(&tx_state.indexes).into();
				let tx_input = TxInput {
					state_test_name: &state_test_name,
					tx_index,
					fork_spec_name: &fork_spec_name,
					pre_state: &pre,
					post_root: tx_states[tx_index].hash.0,
					env_info: &env_info,
					transaction,
					informant,
					trie_spec,
				};
				assert!(info::run_transaction(tx_input));
			}
		}
	}

	#[test]
	fn should_error_out_of_gas() {
		let args = run(&[
			"tetsy-vvm",
			"stats",
			"--to", "0000000000000000000000000000000000000004",
			"--from", "0000000000000000000000000000000000000003",
			"--code", "05",
			"--input", "06",
			"--gas", "1",
			"--gas-price", "2",
			"--only=add11",
			"--std-json",
			"--std-out-only",
		]);

		let (inf, _, res) = informant();
		run_call(args, inf);

		assert!(
			&String::from_utf8_lossy(&**res.0.lock().unwrap())
				.starts_with(r#"{"error":"VVM: Out of gas","gasUsed":"0x1","#),
		);
	}

	#[test]
	fn should_not_error_out_of_gas() {
		let args = run(&[
			"tetsy-vvm",
			"stats",
			"--to", "0000000000000000000000000000000000000004",
			"--from", "0000000000000000000000000000000000000003",
			"--code", "05",
			"--input", "06",
			"--gas", "21",
			"--gas-price", "2",
			"--only=add11",
			"--std-json",
			"--std-out-only",
		]);

		let (inf, _, res) = informant();
		run_call(args, inf);

		assert!(
			&String::from_utf8_lossy(&**res.0.lock().unwrap())
				.starts_with(r#"{"output":"0x06","gasUsed":"0x12","#),
		);
	}
}