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

Commit b9a3d63

Browse files
author
Andronik Ordian
committed
[evmbin] more cleanup
1 parent cc07f59 commit b9a3d63

File tree

1 file changed

+45
-60
lines changed

1 file changed

+45
-60
lines changed

evmbin/src/main.rs

Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Transaction options:
9999
--from ADDRESS Sender address (without 0x).
100100
--input DATA Input data as hex (without 0x).
101101
--gas GAS Supplied gas as hex (without 0x).
102-
--gas-price WEI Supplied gas price as hex (without 0x).
102+
--gas-price WEI Supplied gas price as hex (without 0x).
103103
104104
State test options:
105105
--chain CHAIN Run only from specific chain name (i.e. one of EIP150, EIP158,
@@ -468,7 +468,6 @@ mod tests {
468468
use docopt::Docopt;
469469
use super::{Args, USAGE, Address};
470470
use ethjson::state::test::{State};
471-
use ethjson::spec::ForkSpec;
472471
use ethcore::{TrieSpec};
473472
use ethereum_types::{H256};
474473
use types::transaction;
@@ -484,8 +483,9 @@ mod tests {
484483
}
485484

486485
#[derive(Debug, PartialEq, Deserialize)]
486+
#[serde(rename_all = "camelCase")]
487487
pub struct ConstantinopleStateTests {
488-
pub create2callPrecompiles: State,
488+
pub create2call_precompiles: State,
489489
}
490490

491491
fn run<T: AsRef<str>>(args: &[T]) -> Args {
@@ -551,50 +551,35 @@ mod tests {
551551
}
552552

553553
#[test]
554-
fn should_parse_specific_state_tests_from_test_state_test_json_file() {
555-
let state_tests = include_str!("../res/teststate.json");
556-
let _deserialized_state_tests: SampleStateTests = serde_json::from_str(state_tests)
557-
.expect("Serialization cannot fail; qed");
558-
let state_test_add11: State = _deserialized_state_tests.add11;
559-
let state_test_add12: State = _deserialized_state_tests.add12;
560-
}
561-
562-
#[test]
563-
fn should_parse_specific_state_test_from_constantinople_state_test_json_file() {
564-
let state_tests = include_str!("../res/create2callPrecompiles.json");
565-
let _deserialized_state_tests: ConstantinopleStateTests = serde_json::from_str(state_tests)
566-
.expect("Serialization cannot fail; qed");
567-
let state_test_create2callPrecompiles: State = _deserialized_state_tests.create2callPrecompiles;
568-
}
569-
570-
// Simulate using CLI command `state-test` and option `--json` (JSON informant)
571-
// to execute a given transaction and verify its resulting state root
572-
// using teststate.json
573-
//
574-
// ```
575-
// cargo build -p evmbin;
576-
// ./target/debug/parity-evm state-test ./evmbin/res/teststate.json --only add11 --chain EIP150 --json
577-
// ```
578-
#[test]
579554
fn should_verify_state_root_using_sample_state_test_json_file() {
580555
let state_tests = include_str!("../res/teststate.json");
581556
// Parse the specified state test JSON file to simulate the CLI command `state-test <file>`.
582-
let _deserialized_state_tests: SampleStateTests = serde_json::from_str(state_tests)
557+
let deserialized_state_tests: SampleStateTests = serde_json::from_str(state_tests)
583558
.expect("Serialization cannot fail; qed");
584559

585560
// Simulate the name CLI option `--only NAME`
586-
let state_test_name = "add11".to_string();
587-
let tx_index = 1;
561+
let state_test_name = "add11";
588562
// Simulate the chain `--chain CHAIN`
589-
let fork_spec_name = ForkSpec::EIP150;
590-
let pre = _deserialized_state_tests.add11.pre_state.into();
591-
let env_info = _deserialized_state_tests.add11.env.into();
592-
let multitransaction = _deserialized_state_tests.add11.transaction;
593-
for (fork_spec_name, tx_states) in _deserialized_state_tests.add11.post_states {
563+
let pre = deserialized_state_tests.add11.pre_state.into();
564+
let env_info = deserialized_state_tests.add11.env.into();
565+
let multitransaction = deserialized_state_tests.add11.transaction;
566+
567+
let post_roots = [
568+
// EIP-150
569+
[
570+
H256::from_str("f4455d9332a9e171fc41b48350457147c21fc0a92364d9925913f7421e15aa95").unwrap(),
571+
H256::from_str("a0bc824c4186c4c1543851894fbf707b5b1cf771d15e74f3517daf0a3415fe5b").unwrap(),
572+
],
573+
// EIP-158
574+
[
575+
H256::from_str("f4455d9332a9e171fc41b48350457147c21fc0a92364d9925913f7421e15aa95").unwrap(),
576+
H256::from_str("27682055e1899031c92d253ee1d22c40f70a6943724168c0b694a1a503664e0a").unwrap(),
577+
],
578+
];
579+
for (fork_index, (fork_spec_name, tx_states)) in deserialized_state_tests.add11.post_states.iter().enumerate() {
594580
for (tx_index, tx_state) in tx_states.into_iter().enumerate() {
581+
let post_root = post_roots[fork_index][tx_index];
595582
let informant = display::json::Informant::default();
596-
// Hash of latest transaction index in the chain
597-
let post_root = H256::from_str("99a450d8ce5b987a71346d8a0a1203711f770745c7ef326912e46761f14cd764").unwrap();
598583
let trie_spec = TrieSpec::Secure; // TrieSpec::Fat for --std_dump_json
599584
let transaction: transaction::SignedTransaction = multitransaction.select(&tx_state.indexes).into();
600585
let tx_input = TxInput {
@@ -613,35 +598,37 @@ mod tests {
613598
}
614599
}
615600

616-
// Simulate using CLI command `state-test` and option `--json` (JSON informant)
617-
// to execute a given transaction and verify its resulting state root
618-
// using create2callPrecompiles.json
619-
//
620-
// ```
621-
// cargo build -p evmbin;
622-
// ./target/debug/parity-evm state-test \
623-
// ./evmbin/res/create2callPrecompiles.json --only create2callPrecompiles --chain Constantinople --json
624-
// ```
625-
#[test]
601+
#[test]
626602
fn should_verify_state_root_using_constantinople_state_test_json_file() {
627603
let state_tests = include_str!("../res/create2callPrecompiles.json");
628604
// Parse the specified state test JSON file to simulate the CLI command `state-test <file>`.
629-
let _deserialized_state_tests: ConstantinopleStateTests = serde_json::from_str(state_tests)
605+
let deserialized_state_tests: ConstantinopleStateTests = serde_json::from_str(state_tests)
630606
.expect("Serialization cannot fail; qed");
631607

632608
// Simulate the name CLI option `--only NAME`
633-
let state_test_name = "create2callPrecompiles".to_string();
634-
let tx_index = 7;
635-
// Simulate the chain `--chain CHAIN`
636-
let fork_spec_name = ForkSpec::Constantinople;
637-
let pre = _deserialized_state_tests.create2callPrecompiles.pre_state.into();
638-
let env_info = _deserialized_state_tests.create2callPrecompiles.env.into();
639-
let multitransaction = _deserialized_state_tests.create2callPrecompiles.transaction;
640-
for (fork_spec_name, tx_states) in _deserialized_state_tests.create2callPrecompiles.post_states {
609+
let state_test_name = "create2callPrecompiles";
610+
let post_roots = [
611+
// Constantinople
612+
[
613+
H256::from_str("3dfdcd1d19badbbba8b0c953504e8b4685270ee5b86e155350b6ef1042c9ce43").unwrap(),
614+
H256::from_str("88803085d3420aec76078e215f67fc5f7b6f297fbe19d85c2236ad685d0fc7fc").unwrap(),
615+
H256::from_str("57181dda5c067cb31f084c4118791b40d5028c39071e83e60e7f7403d683527e").unwrap(),
616+
H256::from_str("f04c1039893eb6959354c3c16e9fe025d4b9dc3981362f79c56cc427dca0d544").unwrap(),
617+
H256::from_str("5d5db3d6c4377b34b74ecf8638f684acb220cc7ce286ae5f000ffa74faf38bae").unwrap(),
618+
H256::from_str("f8343b2e05ae120bf25947de840cedf1ca2c1bcda1cdb89d218427d8a84d4798").unwrap(),
619+
H256::from_str("305a8a8a7d9da97d14ed2259503d9373d803ea4b7fbf8c360f50b1b30a3d04ed").unwrap(),
620+
H256::from_str("de1d3953b508913c6e3e9bd412cd50daf60bb177517e5d1e8ccb0dab193aed03").unwrap(),
621+
],
622+
];
623+
let pre = deserialized_state_tests.create2call_precompiles.pre_state.into();
624+
let env_info = deserialized_state_tests.create2call_precompiles.env.into();
625+
let multitransaction = deserialized_state_tests.create2call_precompiles.transaction;
626+
for (fork_index, (fork_spec_name, tx_states)) in
627+
deserialized_state_tests.create2call_precompiles.post_states.iter().enumerate() {
641628
for (tx_index, tx_state) in tx_states.into_iter().enumerate() {
642629
let informant = display::json::Informant::default();
643630
// Hash of latest transaction index in the chain
644-
let post_root = H256::from_str("0xde1d3953b508913c6e3e9bd412cd50daf60bb177517e5d1e8ccb0dab193aed03").unwrap();
631+
let post_root = post_roots[fork_index][tx_index];
645632
let trie_spec = TrieSpec::Secure; // TrieSpec::Fat for --std_dump_json
646633
let transaction: transaction::SignedTransaction = multitransaction.select(&tx_state.indexes).into();
647634
let tx_input = TxInput {
@@ -659,6 +646,4 @@ mod tests {
659646
}
660647
}
661648
}
662-
663-
// TODO - Add integration tests. See https://github.com/paritytech/parity-ethereum/issues/10768
664649
}

0 commit comments

Comments
 (0)