@@ -99,7 +99,7 @@ Transaction options:
99
99
--from ADDRESS Sender address (without 0x).
100
100
--input DATA Input data as hex (without 0x).
101
101
--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).
103
103
104
104
State test options:
105
105
--chain CHAIN Run only from specific chain name (i.e. one of EIP150, EIP158,
@@ -468,7 +468,6 @@ mod tests {
468
468
use docopt:: Docopt ;
469
469
use super :: { Args , USAGE , Address } ;
470
470
use ethjson:: state:: test:: { State } ;
471
- use ethjson:: spec:: ForkSpec ;
472
471
use ethcore:: { TrieSpec } ;
473
472
use ethereum_types:: { H256 } ;
474
473
use types:: transaction;
@@ -484,8 +483,9 @@ mod tests {
484
483
}
485
484
486
485
#[ derive( Debug , PartialEq , Deserialize ) ]
486
+ #[ serde( rename_all = "camelCase" ) ]
487
487
pub struct ConstantinopleStateTests {
488
- pub create2callPrecompiles : State ,
488
+ pub create2call_precompiles : State ,
489
489
}
490
490
491
491
fn run < T : AsRef < str > > ( args : & [ T ] ) -> Args {
@@ -551,50 +551,35 @@ mod tests {
551
551
}
552
552
553
553
#[ 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]
579
554
fn should_verify_state_root_using_sample_state_test_json_file ( ) {
580
555
let state_tests = include_str ! ( "../res/teststate.json" ) ;
581
556
// 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)
583
558
. expect ( "Serialization cannot fail; qed" ) ;
584
559
585
560
// 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" ;
588
562
// 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 ( ) {
594
580
for ( tx_index, tx_state) in tx_states. into_iter ( ) . enumerate ( ) {
581
+ let post_root = post_roots[ fork_index] [ tx_index] ;
595
582
let informant = display:: json:: Informant :: default ( ) ;
596
- // Hash of latest transaction index in the chain
597
- let post_root = H256 :: from_str ( "99a450d8ce5b987a71346d8a0a1203711f770745c7ef326912e46761f14cd764" ) . unwrap ( ) ;
598
583
let trie_spec = TrieSpec :: Secure ; // TrieSpec::Fat for --std_dump_json
599
584
let transaction: transaction:: SignedTransaction = multitransaction. select ( & tx_state. indexes ) . into ( ) ;
600
585
let tx_input = TxInput {
@@ -613,35 +598,37 @@ mod tests {
613
598
}
614
599
}
615
600
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]
626
602
fn should_verify_state_root_using_constantinople_state_test_json_file ( ) {
627
603
let state_tests = include_str ! ( "../res/create2callPrecompiles.json" ) ;
628
604
// 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)
630
606
. expect ( "Serialization cannot fail; qed" ) ;
631
607
632
608
// 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 ( ) {
641
628
for ( tx_index, tx_state) in tx_states. into_iter ( ) . enumerate ( ) {
642
629
let informant = display:: json:: Informant :: default ( ) ;
643
630
// 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 ] ;
645
632
let trie_spec = TrieSpec :: Secure ; // TrieSpec::Fat for --std_dump_json
646
633
let transaction: transaction:: SignedTransaction = multitransaction. select ( & tx_state. indexes ) . into ( ) ;
647
634
let tx_input = TxInput {
@@ -659,6 +646,4 @@ mod tests {
659
646
}
660
647
}
661
648
}
662
-
663
- // TODO - Add integration tests. See https://github.com/paritytech/parity-ethereum/issues/10768
664
649
}
0 commit comments