From 1b20809aa5dab2481790bd31a9ef62db4920c42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 30 Aug 2018 15:03:42 +0200 Subject: [PATCH 01/11] Update & fix JSON state tests. --- ethcore/res/ethereum/tests | 2 +- ethcore/src/client/evm_test_client.rs | 12 +++++++++++- ethcore/src/json_tests/mod.rs | 6 +++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ethcore/res/ethereum/tests b/ethcore/res/ethereum/tests index b6011c3fb56..726b161ba8a 160000 --- a/ethcore/res/ethereum/tests +++ b/ethcore/res/ethereum/tests @@ -1 +1 @@ -Subproject commit b6011c3fb567d7178915574de0a8d4b5331fe725 +Subproject commit 726b161ba8a739691006cc1ba080672bb50a9d49 diff --git a/ethcore/src/client/evm_test_client.rs b/ethcore/src/client/evm_test_client.rs index c54dc2a98e5..436a0b90a52 100644 --- a/ethcore/src/client/evm_test_client.rs +++ b/ethcore/src/client/evm_test_client.rs @@ -217,9 +217,19 @@ impl<'a> EvmTestClient<'a> { let result = self.state.apply_with_tracing(&env_info, self.spec.engine.machine(), &transaction, tracer, vm_tracer); let scheme = self.spec.engine.machine().create_address_scheme(env_info.number); + // Touch the coinbase at the end of the test to simulate + // miner reward. + // Details: https://github.com/paritytech/parity-ethereum/issues/9431 + let schedule = self.spec.engine.machine().schedule(env_info.number); + self.state.add_balance(&env_info.author, &0.into(), if schedule.no_empty { + state::CleanupMode::NoEmpty + } else { + state::CleanupMode::ForceCreate + }).ok(); + self.state.commit().ok(); + match result { Ok(result) => { - self.state.commit().ok(); TransactResult::Ok { state_root: *self.state.root(), gas_left: initial_gas - result.receipt.gas_used, diff --git a/ethcore/src/json_tests/mod.rs b/ethcore/src/json_tests/mod.rs index fa1c822ce2a..4cad723ea84 100644 --- a/ethcore/src/json_tests/mod.rs +++ b/ethcore/src/json_tests/mod.rs @@ -19,7 +19,7 @@ #[macro_use] mod test_common; -mod transaction; +// mod transaction; mod executive; mod state; mod chain; @@ -30,8 +30,8 @@ mod difficulty; pub use self::test_common::HookType; -pub use self::transaction::run_test_path as run_transaction_test_path; -pub use self::transaction::run_test_file as run_transaction_test_file; +// pub use self::transaction::run_test_path as run_transaction_test_path; +// pub use self::transaction::run_test_file as run_transaction_test_file; pub use self::executive::run_test_path as run_executive_test_path; pub use self::executive::run_test_file as run_executive_test_file; pub use self::state::run_test_path as run_state_test_path; From bfb380e81b5e1326d93d5b274b1585b2132fdf21 Mon Sep 17 00:00:00 2001 From: cheme Date: Thu, 30 Aug 2018 16:47:24 +0200 Subject: [PATCH 02/11] Update tests to be able to run ethtest at 021fe3d410773024cd5f0387e62db6e6ec800f32. - Touch user in state - Adjust transaction tests to new json format --- ethcore/res/ethereum/tests | 2 +- ethcore/src/client/evm_test_client.rs | 54 +++++++----- ethcore/src/json_tests/transaction.rs | 107 ++++++++++++------------ ethcore/src/state/mod.rs | 6 ++ json/src/transaction/txtest.rs | 114 +++++++++++++++++++++----- 5 files changed, 186 insertions(+), 97 deletions(-) diff --git a/ethcore/res/ethereum/tests b/ethcore/res/ethereum/tests index b6011c3fb56..021fe3d4107 160000 --- a/ethcore/res/ethereum/tests +++ b/ethcore/res/ethereum/tests @@ -1 +1 @@ -Subproject commit b6011c3fb567d7178915574de0a8d4b5331fe725 +Subproject commit 021fe3d410773024cd5f0387e62db6e6ec800f32 diff --git a/ethcore/src/client/evm_test_client.rs b/ethcore/src/client/evm_test_client.rs index c54dc2a98e5..3d95586da36 100644 --- a/ethcore/src/client/evm_test_client.rs +++ b/ethcore/src/client/evm_test_client.rs @@ -69,12 +69,12 @@ pub struct EvmTestClient<'a> { } impl<'a> fmt::Debug for EvmTestClient<'a> { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_struct("EvmTestClient") - .field("state", &self.state) - .field("spec", &self.spec.name) - .finish() - } + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.debug_struct("EvmTestClient") + .field("state", &self.state) + .field("spec", &self.spec.name) + .finish() + } } impl<'a> EvmTestClient<'a> { @@ -212,27 +212,39 @@ impl<'a> EvmTestClient<'a> { error: error.into(), }; } + let remove_empty_account = env_info.number >= self.spec.params().eip161d_transition; // Apply transaction let result = self.state.apply_with_tracing(&env_info, self.spec.engine.machine(), &transaction, tracer, vm_tracer); let scheme = self.spec.engine.machine().create_address_scheme(env_info.number); + // post actions + if result.is_ok() { + self.state.commit().ok(); + } + // From ethtest comments. In case : + // - the coinbase suicided, or + // - there are only 'bad' transactions, which aren't executed. In those cases, + // the coinbase gets no txfee, so isn't created, and thus needs to be touched + // touch the coinbase + if !remove_empty_account { + self.state.test_touch(&env_info.author).expect("Touch account"); + self.state.commit().ok(); // TODO a commit that keep empty account... + } + match result { - Ok(result) => { - self.state.commit().ok(); - TransactResult::Ok { - state_root: *self.state.root(), - gas_left: initial_gas - result.receipt.gas_used, - outcome: result.receipt.outcome, - output: result.output, - trace: result.trace, - vm_trace: result.vm_trace, - logs: result.receipt.logs, - contract_address: if let transaction::Action::Create = transaction.action { - Some(executive::contract_address(scheme, &transaction.sender(), &transaction.nonce, &transaction.data).0) - } else { - None - } + Ok(result) => TransactResult::Ok { + state_root: *self.state.root(), + gas_left: initial_gas - result.receipt.gas_used, + outcome: result.receipt.outcome, + output: result.output, + trace: result.trace, + vm_trace: result.vm_trace, + logs: result.receipt.logs, + contract_address: if let transaction::Action::Create = transaction.action { + Some(executive::contract_address(scheme, &transaction.sender(), &transaction.nonce, &transaction.data).0) + } else { + None } }, Err(error) => TransactResult::Err { diff --git a/ethcore/src/json_tests/transaction.rs b/ethcore/src/json_tests/transaction.rs index af16481f41f..c91b7bc0145 100644 --- a/ethcore/src/json_tests/transaction.rs +++ b/ethcore/src/json_tests/transaction.rs @@ -16,10 +16,10 @@ use std::path::Path; use super::test_common::*; -use evm; use ethjson; use rlp::Rlp; -use transaction::{Action, UnverifiedTransaction, SignedTransaction}; +use transaction::{UnverifiedTransaction, SignedTransaction}; +use client::{EvmTestClient}; /// Run transaction jsontests on a given folder. pub fn run_test_path(p: &Path, skip: &[&'static str], h: &mut H) { @@ -34,55 +34,54 @@ pub fn run_test_file(p: &Path, h: &mut H) { fn do_json_test(json_data: &[u8], start_stop_hook: &mut H) -> Vec { let tests = ethjson::transaction::Test::load(json_data).unwrap(); let mut failed = Vec::new(); - let frontier_schedule = evm::Schedule::new_frontier(); - let homestead_schedule = evm::Schedule::new_homestead(); - let byzantium_schedule = evm::Schedule::new_byzantium(); for (name, test) in tests.into_iter() { start_stop_hook(&name, HookType::OnStart); - let mut fail_unless = |cond: bool, title: &str| if !cond { failed.push(name.clone()); println!("Transaction failed: {:?}: {:?}", name, title); }; - - let number: Option = test.block_number.map(Into::into); - let schedule = match number { - None => &frontier_schedule, - Some(x) if x < 1_150_000 => &frontier_schedule, - Some(x) if x < 3_000_000 => &homestead_schedule, - Some(_) => &byzantium_schedule - }; - let allow_chain_id_of_one = number.map_or(false, |n| n >= 2_675_000); - let allow_unsigned = number.map_or(false, |n| n >= 3_000_000); - - let rlp: Vec = test.rlp.into(); - let res = Rlp::new(&rlp) - .as_val() - .map_err(::error::Error::from) - .and_then(|t: UnverifiedTransaction| { - t.validate(schedule, schedule.have_delegate_call, allow_chain_id_of_one, allow_unsigned).map_err(Into::into) - }); + let rlp: Vec = test.rlp.clone().into(); - fail_unless(test.transaction.is_none() == res.is_err(), "Validity different"); - if let (Some(tx), Some(sender)) = (test.transaction, test.sender) { - let t = res.unwrap(); - fail_unless(SignedTransaction::new(t.clone()).unwrap().sender() == sender.into(), "sender mismatch"); - let is_acceptable_chain_id = match t.chain_id() { - None => true, - Some(1) if allow_chain_id_of_one => true, - _ => false, + for (spec_name, infos) in test.infos { + let spec = match EvmTestClient::spec_from_json(&spec_name) { + Some(spec) => spec, + None => { + println!(" - {} | {:?} Ignoring tests because of missing spec", name, spec_name); + continue; + } }; - fail_unless(is_acceptable_chain_id, "Network ID unacceptable"); - let data: Vec = tx.data.into(); - fail_unless(t.data == data, "data mismatch"); - fail_unless(t.gas_price == tx.gas_price.into(), "gas_price mismatch"); - fail_unless(t.nonce == tx.nonce.into(), "nonce mismatch"); - fail_unless(t.value == tx.value.into(), "value mismatch"); - let to: Option = tx.to.into(); - let to: Option
= to.map(Into::into); - match t.action { - Action::Call(dest) => fail_unless(Some(dest) == to, "call/destination mismatch"), - Action::Create => fail_unless(None == to, "create mismatch"), + + // using block 0 is safe with test conf (by convention enable feature are 0 and disable are Max) + let block_number = 0; + + // using block 0 is safe with test conf (by convention enable feature are 0 and disable are Max + let schedule = spec.params().schedule(block_number); + + let info = format!("{} | {:?} ...", name, spec_name); + + let mut fail_unless = |cond: bool, title: &str| if !cond { failed.push(name.clone()); println!("Transaction failed: {:?}: {:?}", info, title); }; + + let allow_chain_id_of_one = block_number >= spec.params().eip160_transition; + let allow_unsigned = block_number >= spec.params().eip160_transition; + + let res = Rlp::new(&rlp) + .as_val() + .map_err(::error::Error::from) + .and_then(|t: UnverifiedTransaction| { + t.validate(&schedule, schedule.have_delegate_call, allow_chain_id_of_one, allow_unsigned).map_err(Into::into) + }); + + fail_unless(infos.hash.is_none() == res.is_err(), "Validity different"); + if let (Some(hash), Some(sender)) = (infos.hash, infos.sender) { + let t = res.unwrap(); + fail_unless(t.hash() == hash, "Transaction hash mismatch"); + fail_unless(SignedTransaction::new(t.clone()).unwrap().sender() == sender.into(), "sender mismatch"); + let is_acceptable_chain_id = match t.chain_id() { + None => true, + Some(1) if allow_chain_id_of_one => true, + _ => false, + }; + fail_unless(is_acceptable_chain_id, "Network ID unacceptable"); } - } + } start_stop_hook(&name, HookType::OnStop); } @@ -92,13 +91,13 @@ fn do_json_test(json_data: &[u8], start_stop_hook: &mu failed } -declare_test!{TransactionTests_ttEip155VitaliksHomesead, "TransactionTests/ttEip155VitaliksHomesead"} -declare_test!{TransactionTests_ttEip155VitaliksEip158, "TransactionTests/ttEip155VitaliksEip158"} -declare_test!{TransactionTests_ttEip158, "TransactionTests/ttEip158"} -declare_test!{TransactionTests_ttFrontier, "TransactionTests/ttFrontier"} -declare_test!{TransactionTests_ttHomestead, "TransactionTests/ttHomestead"} -declare_test!{TransactionTests_ttVRuleEip158, "TransactionTests/ttVRuleEip158"} -declare_test!{TransactionTests_ttWrongRLPFrontier, "TransactionTests/ttWrongRLPFrontier"} -declare_test!{TransactionTests_ttWrongRLPHomestead, "TransactionTests/ttWrongRLPHomestead"} -declare_test!{TransactionTests_ttConstantinople, "TransactionTests/ttConstantinople"} -declare_test!{TransactionTests_ttSpecConstantinople, "TransactionTests/ttSpecConstantinople"} +declare_test!{TransactionTests_ttAddress, "TransactionTests/ttAddress"} +declare_test!{TransactionTests_ttData, "TransactionTests/ttData"} +declare_test!{TransactionTests_ttGasLimit, "TransactionTests/ttGasLimit"} +declare_test!{TransactionTests_ttGasPrice, "TransactionTests/ttGasPrice"} +declare_test!{TransactionTests_ttNonce, "TransactionTests/ttNonce"} +declare_test!{TransactionTests_ttRSValue, "TransactionTests/ttRSValue"} +declare_test!{TransactionTests_ttSignature, "TransactionTests/ttSignature"} +declare_test!{TransactionTests_ttValue, "TransactionTests/ttValue"} +declare_test!{TransactionTests_ttVValue, "TransactionTests/ttVValue"} +declare_test!{TransactionTests_ttWrongRLP, "TransactionTests/ttWrongRLP"} diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs index 323e11ccb2b..3fcbbc2f6da 100644 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -759,6 +759,12 @@ impl State { Ok(()) } + /// Expose touch function for test case only. + #[cfg(any(test, feature = "test-helpers"))] + pub fn test_touch(&mut self, a: &Address) -> TrieResult<()> { + self.touch(a) + } + /// Commits our cached account changes into the trie. pub fn commit(&mut self) -> Result<(), Error> { // first, commit the sub trees. diff --git a/json/src/transaction/txtest.rs b/json/src/transaction/txtest.rs index 60d65e70d66..e773e86fcbb 100644 --- a/json/src/transaction/txtest.rs +++ b/json/src/transaction/txtest.rs @@ -19,22 +19,76 @@ use uint::Uint; use bytes::Bytes; use hash::Address; -use transaction::Transaction; +use std::collections::BTreeMap; +use ethereum_types::H256; +use state::test::ForkSpec; +use serde::de::{Deserialize, Deserializer, MapAccess, Visitor, IgnoredAny}; +use std::fmt; +use serde_json; /// Transaction test deserialization. -#[derive(Debug, PartialEq, Deserialize)] +#[derive(Debug, PartialEq)] pub struct TransactionTest { - /// Block number. - #[serde(rename="blocknumber")] - pub block_number: Option, /// Transaction rlp. pub rlp: Bytes, + pub infos: BTreeMap, +} + +/// Transaction test info for each chain spec. +#[derive(Debug, PartialEq, Deserialize)] +pub struct TransactionTestInfos { /// Transaction sender. pub sender: Option
, - /// Transaction - pub transaction: Option, + /// Transaction hash + pub hash: Option, } +impl<'de> Deserialize<'de> for TransactionTest { + fn deserialize(deserializer: D) -> Result + where D: Deserializer<'de> { + let (rlp, infos) = deserializer.deserialize_map(VisitorTransaction)?; + Ok(TransactionTest { rlp, infos }) + } +} + +struct VisitorTransaction; + +impl<'de> Visitor<'de> for VisitorTransaction +{ + type Value = (Bytes, BTreeMap); + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("Transaction test visitor expect map") + } + + fn visit_map(self, mut access: M) -> Result + where M: MapAccess<'de> { + let mut map = BTreeMap::new(); + let mut rlp = None; + + loop { + match access.next_key::()? { + Some(ref k) if k == "rlp" => { + rlp = Some(access.next_value()?); + }, + Some(ref k) => { + if let Ok(fork_spec) = serde_json::from_str::(k) { + let v = access.next_value()?; + map.insert(fork_spec, v); + } else { + // skip unknown + access.next_value::()?; + } + }, + None => break, + }; + } + + Ok((rlp.expect("No rlp"), map)) + } +} + + #[cfg(test)] mod tests { use serde_json; @@ -43,20 +97,38 @@ mod tests { #[test] fn transaction_deserialization() { let s = r#"{ - "blocknumber" : "0", - "rlp" : "0xf83f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870b801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a3664935301", - "sender" : "e115cf6bb5656786569dd273705242ca72d84bc0", - "transaction" : { - "data" : "", - "gasLimit" : "0x5208", - "gasPrice" : "0x01", - "nonce" : "0x00", - "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", - "s" : "0x01", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "v" : "0x1b", - "value" : "0x0b" - } + "Byzantium" : { + "hash" : "2781a1444a7a4a646bf551f90913054dc47b2f3493d4a82a057445eb9e1c98cf", + "sender" : "2fbffb0b9f709fd1fa4db9ff7342f2e6b3b2b7a6" + }, + "Constantinople" : { + "hash" : "2781a1444a7a4a646bf551f90913054dc47b2f3493d4a82a057445eb9e1c98cf", + "sender" : "2fbffb0b9f709fd1fa4db9ff7342f2e6b3b2b7a6" + }, + "EIP150" : { + "hash" : "2781a1444a7a4a646bf551f90913054dc47b2f3493d4a82a057445eb9e1c98cf", + "sender" : "2fbffb0b9f709fd1fa4db9ff7342f2e6b3b2b7a6" + }, + "EIP158" : { + "hash" : "2781a1444a7a4a646bf551f90913054dc47b2f3493d4a82a057445eb9e1c98cf", + "sender" : "2fbffb0b9f709fd1fa4db9ff7342f2e6b3b2b7a6" + }, + "Frontier" : { + "hash" : "2781a1444a7a4a646bf551f90913054dc47b2f3493d4a82a057445eb9e1c98cf", + "sender" : "2fbffb0b9f709fd1fa4db9ff7342f2e6b3b2b7a6" + }, + "Homestead" : { + "hash" : "2781a1444a7a4a646bf551f90913054dc47b2f3493d4a82a057445eb9e1c98cf", + "sender" : "2fbffb0b9f709fd1fa4db9ff7342f2e6b3b2b7a6" + }, + "_info" : { + "comment" : "", + "filledwith" : "cpp-1.3.0+commit.1829957d.Linux.g++", + "lllcversion" : "Version: 0.4.18-develop.2017.10.11+commit.81f9f86c.Linux.g++", + "source" : "src/TransactionTestsFiller/ttAddress/AddressLessThan20Prefixed0Filler.json", + "sourceHash" : "c10a162dc48a3bc2a5f245c6c0aaede958ba6d76352907d777693e49cd621abe" + }, + "rlp" : "0xf85f800182520894000000000000000000000000000b9331677e6ebf0a801ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa01887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3" }"#; let _deserialized: TransactionTest = serde_json::from_str(s).unwrap(); // TODO: validate all fields From b8188c57d7d6c26236986356c49ba92a0beb1821 Mon Sep 17 00:00:00 2001 From: cheme Date: Thu, 30 Aug 2018 17:58:45 +0200 Subject: [PATCH 03/11] Switch to same commit for submodule ethereum/test as geth (next includes constantinople changes). Added test `json_tests::trie::generic::TrieTests_trieanyorder` and a few difficulty tests. --- ethcore/res/ethereum/tests | 2 +- ethcore/src/json_tests/difficulty.rs | 49 ++++++++++++++++++++++++---- ethcore/src/json_tests/trie.rs | 1 + json/src/transaction/txtest.rs | 1 - 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/ethcore/res/ethereum/tests b/ethcore/res/ethereum/tests index 021fe3d4107..b8a21c19369 160000 --- a/ethcore/res/ethereum/tests +++ b/ethcore/res/ethereum/tests @@ -1 +1 @@ -Subproject commit 021fe3d410773024cd5f0387e62db6e6ec800f32 +Subproject commit b8a21c193696976ca3b33b6d82107601063a5d26 diff --git a/ethcore/src/json_tests/difficulty.rs b/ethcore/src/json_tests/difficulty.rs index 2647e16595f..0de1f1777b7 100644 --- a/ethcore/src/json_tests/difficulty.rs +++ b/ethcore/src/json_tests/difficulty.rs @@ -52,26 +52,61 @@ pub fn json_difficulty_test(json_data: &[u8], spec: Sp vec![] } -mod difficulty_test_byzantium { +macro_rules! difficulty_json_test { + ( $spec:ident ) => { + use super::json_difficulty_test; + use tempdir::TempDir; use json_tests::HookType; fn do_json_test(json_data: &[u8], h: &mut H) -> Vec { - json_difficulty_test(json_data, ::ethereum::new_byzantium_test(), h) + let tempdir = TempDir::new("").unwrap(); + json_difficulty_test(json_data, ::ethereum::$spec(&tempdir.path()), h) } - declare_test!{DifficultyTests_difficultyByzantium, "BasicTests/difficultyByzantium.json"} + } } -mod difficulty_test_foundation { +macro_rules! difficulty_json_test_nopath { + ( $spec:ident ) => { + use super::json_difficulty_test; - use tempdir::TempDir; use json_tests::HookType; fn do_json_test(json_data: &[u8], h: &mut H) -> Vec { - let tempdir = TempDir::new("").unwrap(); - json_difficulty_test(json_data, ::ethereum::new_foundation(&tempdir.path()), h) + json_difficulty_test(json_data, ::ethereum::$spec(), h) } + } +} + +mod difficulty_test { + difficulty_json_test!(new_foundation); + declare_test!{DifficultyTests_difficulty, "BasicTests/difficulty.json"} +} + +mod difficulty_test_byzantium { + difficulty_json_test_nopath!(new_byzantium_test); + declare_test!{DifficultyTests_difficultyByzantium, "BasicTests/difficultyByzantium.json"} +} + +mod difficulty_test_foundation { + difficulty_json_test!(new_foundation); declare_test!{DifficultyTests_difficultyMainNetwork, "BasicTests/difficultyMainNetwork.json"} } + +mod difficulty_test_ropsten { + difficulty_json_test_nopath!(new_ropsten_test); + declare_test!{DifficultyTests_difficultyRopsten, "BasicTests/difficultyRopsten.json"} +} + +mod difficulty_test_frontier { + difficulty_json_test_nopath!(new_frontier_test); + declare_test!{DifficultyTests_difficultyFrontier, "BasicTests/difficultyFrontier.json"} +} + +mod difficulty_test_homestead { + difficulty_json_test_nopath!(new_homestead_test); + declare_test!{DifficultyTests_difficultyHomestead, "BasicTests/difficultyHomestead.json"} +} + diff --git a/ethcore/src/json_tests/trie.rs b/ethcore/src/json_tests/trie.rs index 0466c4de1f1..e3d50cea9ec 100644 --- a/ethcore/src/json_tests/trie.rs +++ b/ethcore/src/json_tests/trie.rs @@ -83,6 +83,7 @@ mod generic { declare_test!{TrieTests_trietest, "TrieTests/trietest"} declare_test!{TrieTests_trieanyorder, "TrieTests/trieanyorder"} + declare_test!{TrieTests_trietestnextprev, "TrieTests/trietestnextprev"} } mod secure { diff --git a/json/src/transaction/txtest.rs b/json/src/transaction/txtest.rs index e773e86fcbb..7b4892ec40d 100644 --- a/json/src/transaction/txtest.rs +++ b/json/src/transaction/txtest.rs @@ -16,7 +16,6 @@ //! Transaction test deserialization. -use uint::Uint; use bytes::Bytes; use hash::Address; use std::collections::BTreeMap; From 83f48e63aba9b0456e67075222e6dbfdd29c59e3 Mon Sep 17 00:00:00 2001 From: cheme Date: Thu, 30 Aug 2018 18:27:59 +0200 Subject: [PATCH 04/11] Remove trietestnextprev as it would require to parse differently and implement it. --- ethcore/src/json_tests/trie.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/ethcore/src/json_tests/trie.rs b/ethcore/src/json_tests/trie.rs index e3d50cea9ec..0466c4de1f1 100644 --- a/ethcore/src/json_tests/trie.rs +++ b/ethcore/src/json_tests/trie.rs @@ -83,7 +83,6 @@ mod generic { declare_test!{TrieTests_trietest, "TrieTests/trietest"} declare_test!{TrieTests_trieanyorder, "TrieTests/trieanyorder"} - declare_test!{TrieTests_trietestnextprev, "TrieTests/trietestnextprev"} } mod secure { From 5dbae4fb5d859855a519ecd681bd32368e8985d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 30 Aug 2018 16:09:11 +0200 Subject: [PATCH 05/11] Support new (shitty) format of transaction tests. --- ethcore/res/ethereum/eip161_test.json | 2 +- ethcore/src/client/evm_test_client.rs | 2 +- ethcore/src/json_tests/mod.rs | 6 +- ethcore/src/json_tests/state.rs | 8 ++ ethcore/src/json_tests/test_common.rs | 7 +- ethcore/src/json_tests/transaction.rs | 112 +++++++++++++------------ ethcore/transaction/src/transaction.rs | 17 ---- json/src/blockchain/blockchain.rs | 3 +- json/src/spec/mod.rs | 2 +- json/src/spec/spec.rs | 15 ++++ json/src/state/test.rs | 16 +--- json/src/transaction/test.rs | 2 +- json/src/transaction/txtest.rs | 65 +++++++++----- 13 files changed, 138 insertions(+), 119 deletions(-) diff --git a/ethcore/res/ethereum/eip161_test.json b/ethcore/res/ethereum/eip161_test.json index 079ce7d55a2..b22a23ef3f7 100644 --- a/ethcore/res/ethereum/eip161_test.json +++ b/ethcore/res/ethereum/eip161_test.json @@ -24,7 +24,7 @@ "eip161dTransition": "0x0", "eip98Transition": "0x7fffffffffffffff", "eip86Transition": "0x7fffffffffffffff", - "eip155Transition": "0x7fffffffffffffff", + "eip155Transition": "0x0", "maxCodeSize": 24576, "maxCodeSizeTransition": "0x0" }, diff --git a/ethcore/src/client/evm_test_client.rs b/ethcore/src/client/evm_test_client.rs index 436a0b90a52..7ecde562468 100644 --- a/ethcore/src/client/evm_test_client.rs +++ b/ethcore/src/client/evm_test_client.rs @@ -60,7 +60,7 @@ impl fmt::Display for EvmTestError { } use ethereum; -use ethjson::state::test::ForkSpec; +use ethjson::spec::ForkSpec; /// Simplified, single-block EVM test client. pub struct EvmTestClient<'a> { diff --git a/ethcore/src/json_tests/mod.rs b/ethcore/src/json_tests/mod.rs index 4cad723ea84..fa1c822ce2a 100644 --- a/ethcore/src/json_tests/mod.rs +++ b/ethcore/src/json_tests/mod.rs @@ -19,7 +19,7 @@ #[macro_use] mod test_common; -// mod transaction; +mod transaction; mod executive; mod state; mod chain; @@ -30,8 +30,8 @@ mod difficulty; pub use self::test_common::HookType; -// pub use self::transaction::run_test_path as run_transaction_test_path; -// pub use self::transaction::run_test_file as run_transaction_test_file; +pub use self::transaction::run_test_path as run_transaction_test_path; +pub use self::transaction::run_test_file as run_transaction_test_file; pub use self::executive::run_test_path as run_executive_test_path; pub use self::executive::run_test_file as run_executive_test_file; pub use self::state::run_test_path as run_state_test_path; diff --git a/ethcore/src/json_tests/state.rs b/ethcore/src/json_tests/state.rs index da171697216..a6bbaed100d 100644 --- a/ethcore/src/json_tests/state.rs +++ b/ethcore/src/json_tests/state.rs @@ -114,12 +114,16 @@ mod state_tests { json_chain_test(json_data, h) } + declare_test!{GeneralStateTest_stArgsZeroOneBalance, "GeneralStateTests/stArgsZeroOneBalance/"} declare_test!{GeneralStateTest_stAttackTest, "GeneralStateTests/stAttackTest/"} declare_test!{GeneralStateTest_stBadOpcodeTest, "GeneralStateTests/stBadOpcode/"} + declare_test!{GeneralStateTest_stBugs, "GeneralStateTests/stBugs/"} declare_test!{GeneralStateTest_stCallCodes, "GeneralStateTests/stCallCodes/"} + declare_test!{GeneralStateTest_stCallCreateCallCodeTest, "GeneralStateTests/stCallCreateCallCodeTest/"} declare_test!{GeneralStateTest_stCallDelegateCodesCallCodeHomestead, "GeneralStateTests/stCallDelegateCodesCallCodeHomestead/"} declare_test!{GeneralStateTest_stCallDelegateCodesHomestead, "GeneralStateTests/stCallDelegateCodesHomestead/"} declare_test!{GeneralStateTest_stChangedEIP150, "GeneralStateTests/stChangedEIP150/"} + declare_test!{GeneralStateTest_stCodeCopyTest, "GeneralStateTests/stCodeCopyTest/"} declare_test!{GeneralStateTest_stCodeSizeLimit, "GeneralStateTests/stCodeSizeLimit/"} declare_test!{GeneralStateTest_stCreateTest, "GeneralStateTests/stCreateTest/"} declare_test!{GeneralStateTest_stDelegatecallTestHomestead, "GeneralStateTests/stDelegatecallTestHomestead/"} @@ -135,12 +139,15 @@ mod state_tests { declare_test!{GeneralStateTest_stMemoryTest, "GeneralStateTests/stMemoryTest/"} declare_test!{GeneralStateTest_stNonZeroCallsTest, "GeneralStateTests/stNonZeroCallsTest/"} declare_test!{GeneralStateTest_stPreCompiledContracts, "GeneralStateTests/stPreCompiledContracts/"} + declare_test!{GeneralStateTest_stPreCompiledContracts2, "GeneralStateTests/stPreCompiledContracts2/"} declare_test!{heavy => GeneralStateTest_stQuadraticComplexityTest, "GeneralStateTests/stQuadraticComplexityTest/"} declare_test!{GeneralStateTest_stRandom, "GeneralStateTests/stRandom/"} + declare_test!{GeneralStateTest_stRandom2, "GeneralStateTests/stRandom2/"} declare_test!{GeneralStateTest_stRecursiveCreate, "GeneralStateTests/stRecursiveCreate/"} declare_test!{GeneralStateTest_stRefundTest, "GeneralStateTests/stRefundTest/"} declare_test!{GeneralStateTest_stReturnDataTest, "GeneralStateTests/stReturnDataTest/"} declare_test!{GeneralStateTest_stRevertTest, "GeneralStateTests/stRevertTest/"} + declare_test!{GeneralStateTest_stShift, "GeneralStateTests/stShift/"} declare_test!{GeneralStateTest_stSolidityTest, "GeneralStateTests/stSolidityTest/"} declare_test!{GeneralStateTest_stSpecialTest, "GeneralStateTests/stSpecialTest/"} declare_test!{GeneralStateTest_stStackTests, "GeneralStateTests/stStackTests/"} @@ -152,4 +159,5 @@ mod state_tests { declare_test!{GeneralStateTest_stZeroCallsRevert, "GeneralStateTests/stZeroCallsRevert/"} declare_test!{GeneralStateTest_stZeroCallsTest, "GeneralStateTests/stZeroCallsTest/"} declare_test!{GeneralStateTest_stZeroKnowledge, "GeneralStateTests/stZeroKnowledge/"} + declare_test!{GeneralStateTest_stZeroKnowledge2, "GeneralStateTests/stZeroKnowledge2/"} } diff --git a/ethcore/src/json_tests/test_common.rs b/ethcore/src/json_tests/test_common.rs index 39b7447c7e8..3e0b9cf8e65 100644 --- a/ethcore/src/json_tests/test_common.rs +++ b/ethcore/src/json_tests/test_common.rs @@ -51,6 +51,8 @@ pub fn run_test_path( }}) { run_test_path(&p, skip, runner, start_stop_hook) } + } else if path.extension().and_then(|s| s.to_str()) == Some("swp") { + // Ignore junk } else { let mut path = p.to_path_buf(); path.set_extension("json"); @@ -64,7 +66,10 @@ pub fn run_test_file( start_stop_hook: &mut H ) { let mut data = Vec::new(); - let mut file = File::open(&path).expect("Error opening test file"); + let mut file = match File::open(&path) { + Ok(file) => file, + Err(_) => panic!("Error opening test file at: {:?}", path), + }; file.read_to_end(&mut data).expect("Error reading test file"); let results = runner(&data, start_stop_hook); let empty: [String; 0] = []; diff --git a/ethcore/src/json_tests/transaction.rs b/ethcore/src/json_tests/transaction.rs index af16481f41f..e3a9fc17339 100644 --- a/ethcore/src/json_tests/transaction.rs +++ b/ethcore/src/json_tests/transaction.rs @@ -16,10 +16,11 @@ use std::path::Path; use super::test_common::*; -use evm; +use client::EvmTestClient; +use header::Header; use ethjson; use rlp::Rlp; -use transaction::{Action, UnverifiedTransaction, SignedTransaction}; +use transaction::UnverifiedTransaction; /// Run transaction jsontests on a given folder. pub fn run_test_path(p: &Path, skip: &[&'static str], h: &mut H) { @@ -34,52 +35,54 @@ pub fn run_test_file(p: &Path, h: &mut H) { fn do_json_test(json_data: &[u8], start_stop_hook: &mut H) -> Vec { let tests = ethjson::transaction::Test::load(json_data).unwrap(); let mut failed = Vec::new(); - let frontier_schedule = evm::Schedule::new_frontier(); - let homestead_schedule = evm::Schedule::new_homestead(); - let byzantium_schedule = evm::Schedule::new_byzantium(); for (name, test) in tests.into_iter() { start_stop_hook(&name, HookType::OnStart); - let mut fail_unless = |cond: bool, title: &str| if !cond { failed.push(name.clone()); println!("Transaction failed: {:?}: {:?}", name, title); }; - - let number: Option = test.block_number.map(Into::into); - let schedule = match number { - None => &frontier_schedule, - Some(x) if x < 1_150_000 => &frontier_schedule, - Some(x) if x < 3_000_000 => &homestead_schedule, - Some(_) => &byzantium_schedule - }; - let allow_chain_id_of_one = number.map_or(false, |n| n >= 2_675_000); - let allow_unsigned = number.map_or(false, |n| n >= 3_000_000); - - let rlp: Vec = test.rlp.into(); - let res = Rlp::new(&rlp) - .as_val() - .map_err(::error::Error::from) - .and_then(|t: UnverifiedTransaction| { - t.validate(schedule, schedule.have_delegate_call, allow_chain_id_of_one, allow_unsigned).map_err(Into::into) - }); - - fail_unless(test.transaction.is_none() == res.is_err(), "Validity different"); - if let (Some(tx), Some(sender)) = (test.transaction, test.sender) { - let t = res.unwrap(); - fail_unless(SignedTransaction::new(t.clone()).unwrap().sender() == sender.into(), "sender mismatch"); - let is_acceptable_chain_id = match t.chain_id() { - None => true, - Some(1) if allow_chain_id_of_one => true, - _ => false, + for (spec_name, result) in test.post_state { + let spec = match EvmTestClient::spec_from_json(&spec_name) { + Some(spec) => spec, + None => { + println!(" - {} | {:?} Ignoring tests because of missing spec", name, spec_name); + continue; + } }; - fail_unless(is_acceptable_chain_id, "Network ID unacceptable"); - let data: Vec = tx.data.into(); - fail_unless(t.data == data, "data mismatch"); - fail_unless(t.gas_price == tx.gas_price.into(), "gas_price mismatch"); - fail_unless(t.nonce == tx.nonce.into(), "nonce mismatch"); - fail_unless(t.value == tx.value.into(), "value mismatch"); - let to: Option = tx.to.into(); - let to: Option
= to.map(Into::into); - match t.action { - Action::Call(dest) => fail_unless(Some(dest) == to, "call/destination mismatch"), - Action::Create => fail_unless(None == to, "create mismatch"), + + let mut fail_unless = |cond: bool, title: &str| if !cond { + failed.push(format!("{}-{:?}", name, spec_name)); + println!("Transaction failed: {:?}-{:?}: {:?}", name, spec_name, title); + }; + + let rlp: Vec = test.rlp.clone().into(); + let res = Rlp::new(&rlp) + .as_val() + .map_err(::error::Error::from) + .and_then(|t: UnverifiedTransaction| { + let mut header: Header = Default::default(); + // Use high enough number to activate all required features. + header.set_number(0x6ffffffffffffe); + + let minimal = t.gas_required(&spec.engine.schedule(header.number())).into(); + if t.gas < minimal { + return Err(::transaction::Error::InsufficientGas { + minimal, got: t.gas, + }.into()); + } + spec.engine.verify_transaction_basic(&t, &header)?; + Ok(spec.engine.verify_transaction_unordered(t, &header)?) + }); + + match (res, result.hash, result.sender) { + (Ok(t), Some(hash), Some(sender)) => { + fail_unless(t.sender() == sender.into(), "sender mismatch"); + fail_unless(t.hash() == hash.into(), "hash mismatch"); + }, + (Err(_), None, None) => {}, + data => { + fail_unless( + false, + &format!("Validity different: {:?}", data) + ); + } } } @@ -92,13 +95,14 @@ fn do_json_test(json_data: &[u8], start_stop_hook: &mu failed } -declare_test!{TransactionTests_ttEip155VitaliksHomesead, "TransactionTests/ttEip155VitaliksHomesead"} -declare_test!{TransactionTests_ttEip155VitaliksEip158, "TransactionTests/ttEip155VitaliksEip158"} -declare_test!{TransactionTests_ttEip158, "TransactionTests/ttEip158"} -declare_test!{TransactionTests_ttFrontier, "TransactionTests/ttFrontier"} -declare_test!{TransactionTests_ttHomestead, "TransactionTests/ttHomestead"} -declare_test!{TransactionTests_ttVRuleEip158, "TransactionTests/ttVRuleEip158"} -declare_test!{TransactionTests_ttWrongRLPFrontier, "TransactionTests/ttWrongRLPFrontier"} -declare_test!{TransactionTests_ttWrongRLPHomestead, "TransactionTests/ttWrongRLPHomestead"} -declare_test!{TransactionTests_ttConstantinople, "TransactionTests/ttConstantinople"} -declare_test!{TransactionTests_ttSpecConstantinople, "TransactionTests/ttSpecConstantinople"} +declare_test!{TransactionTests_ttAddress, "TransactionTests/ttAddress"} +declare_test!{TransactionTests_ttData, "TransactionTests/ttData"} +declare_test!{TransactionTests_ttGasLimit, "TransactionTests/ttGasLimit"} +declare_test!{TransactionTests_ttGasPrice, "TransactionTests/ttGasPrice"} +declare_test!{TransactionTests_ttNonce, "TransactionTests/ttNonce"} +declare_test!{TransactionTests_ttRSValue, "TransactionTests/ttRSValue"} +declare_test!{TransactionTests_ttSignature, "TransactionTests/ttSignature"} +declare_test!{TransactionTests_ttValue, "TransactionTests/ttValue"} +declare_test!{TransactionTests_ttVValue, "TransactionTests/ttVValue"} +declare_test!{TransactionTests_ttWrongRLP, "TransactionTests/ttWrongRLP"} + diff --git a/ethcore/transaction/src/transaction.rs b/ethcore/transaction/src/transaction.rs index 49804f1870f..f5034c4b2ae 100644 --- a/ethcore/transaction/src/transaction.rs +++ b/ethcore/transaction/src/transaction.rs @@ -393,23 +393,6 @@ impl UnverifiedTransaction { Ok(recover(&self.signature(), &self.unsigned.hash(self.chain_id()))?) } - /// Do basic validation, checking for valid signature and minimum gas, - // TODO: consider use in block validation. - #[cfg(feature = "json-tests")] - pub fn validate(self, schedule: &Schedule, require_low: bool, allow_chain_id_of_one: bool, allow_empty_signature: bool) - -> Result - { - let chain_id = if allow_chain_id_of_one { Some(1) } else { None }; - self.verify_basic(require_low, chain_id, allow_empty_signature)?; - if !allow_empty_signature || !self.is_unsigned() { - self.recover_public()?; - } - if self.gas < U256::from(self.gas_required(&schedule)) { - return Err(error::Error::InvalidGasLimit(::unexpected::OutOfBounds{min: Some(U256::from(self.gas_required(&schedule))), max: None, found: self.gas}).into()) - } - Ok(self) - } - /// Verify basic signature params. Does not attempt sender recovery. pub fn verify_basic(&self, check_low_s: bool, chain_id: Option, allow_empty_signature: bool) -> Result<(), error::Error> { if check_low_s && !(allow_empty_signature && self.is_unsigned()) { diff --git a/json/src/blockchain/blockchain.rs b/json/src/blockchain/blockchain.rs index 9e4d650b85a..ff0bc556f9b 100644 --- a/json/src/blockchain/blockchain.rs +++ b/json/src/blockchain/blockchain.rs @@ -21,8 +21,7 @@ use hash::H256; use blockchain::state::State; use blockchain::header::Header; use blockchain::block::Block; -use state::test::ForkSpec; -use spec::{Genesis, Seal, Ethereum}; +use spec::{ForkSpec, Genesis, Seal, Ethereum}; /// Blockchain deserialization. #[derive(Debug, PartialEq, Deserialize)] diff --git a/json/src/spec/mod.rs b/json/src/spec/mod.rs index 26965c887d0..fdede4a47fc 100644 --- a/json/src/spec/mod.rs +++ b/json/src/spec/mod.rs @@ -36,7 +36,7 @@ pub use self::account::Account; pub use self::builtin::{Builtin, Pricing, Linear}; pub use self::genesis::Genesis; pub use self::params::Params; -pub use self::spec::Spec; +pub use self::spec::{Spec, ForkSpec}; pub use self::seal::{Seal, Ethereum, AuthorityRoundSeal, TendermintSeal}; pub use self::engine::Engine; pub use self::state::State; diff --git a/json/src/spec/spec.rs b/json/src/spec/spec.rs index 2be695689e4..a15d1faf6e6 100644 --- a/json/src/spec/spec.rs +++ b/json/src/spec/spec.rs @@ -21,6 +21,21 @@ use serde_json; use serde_json::Error; use spec::{Params, Genesis, Engine, State, HardcodedSync}; +/// Fork spec definition +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deserialize)] +pub enum ForkSpec { + EIP150, + EIP158, + Frontier, + Homestead, + Byzantium, + Constantinople, + EIP158ToByzantiumAt5, + FrontierToHomesteadAt5, + HomesteadToDaoAt5, + HomesteadToEIP150At5, +} + /// Spec deserialization. #[derive(Debug, PartialEq, Deserialize)] pub struct Spec { diff --git a/json/src/state/test.rs b/json/src/state/test.rs index 528a49b5a66..85eac0c935f 100644 --- a/json/src/state/test.rs +++ b/json/src/state/test.rs @@ -21,6 +21,7 @@ use std::collections::BTreeMap; use uint::Uint; use bytes::Bytes; use hash::{Address, H256}; +use spec::ForkSpec; use state::{Env, AccountState, Transaction}; use maybe::MaybeEmpty; use serde_json::{self, Error}; @@ -97,21 +98,6 @@ impl MultiTransaction { } } -/// State test transaction deserialization. -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Deserialize)] -pub enum ForkSpec { - EIP150, - EIP158, - Frontier, - Homestead, - Byzantium, - Constantinople, - EIP158ToByzantiumAt5, - FrontierToHomesteadAt5, - HomesteadToDaoAt5, - HomesteadToEIP150At5, -} - /// State test indexes deserialization. #[derive(Debug, PartialEq, Deserialize)] pub struct PostStateIndexes { diff --git a/json/src/transaction/test.rs b/json/src/transaction/test.rs index e1bd588de35..2c5f39f13cf 100644 --- a/json/src/transaction/test.rs +++ b/json/src/transaction/test.rs @@ -23,7 +23,7 @@ use serde_json::Error; use transaction::TransactionTest; /// TransactionTest test deserializer. -#[derive(Debug, PartialEq, Deserialize)] +#[derive(Debug, Deserialize)] pub struct Test(BTreeMap); impl IntoIterator for Test { diff --git a/json/src/transaction/txtest.rs b/json/src/transaction/txtest.rs index 60d65e70d66..2be035b4fe9 100644 --- a/json/src/transaction/txtest.rs +++ b/json/src/transaction/txtest.rs @@ -16,23 +16,29 @@ //! Transaction test deserialization. -use uint::Uint; +use std::collections::BTreeMap; use bytes::Bytes; use hash::Address; -use transaction::Transaction; +use hash::H256; +use spec::ForkSpec; /// Transaction test deserialization. -#[derive(Debug, PartialEq, Deserialize)] +#[derive(Debug, Deserialize)] pub struct TransactionTest { - /// Block number. - #[serde(rename="blocknumber")] - pub block_number: Option, - /// Transaction rlp. pub rlp: Bytes, + pub _info: ::serde::de::IgnoredAny, + #[serde(flatten)] + pub post_state: BTreeMap, +} + +/// TransactionTest post state. +#[derive(Debug, PartialEq, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct PostState { /// Transaction sender. pub sender: Option
, - /// Transaction - pub transaction: Option, + /// Transaction hash. + pub hash: Option, } #[cfg(test)] @@ -43,21 +49,34 @@ mod tests { #[test] fn transaction_deserialization() { let s = r#"{ - "blocknumber" : "0", - "rlp" : "0xf83f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870b801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a3664935301", - "sender" : "e115cf6bb5656786569dd273705242ca72d84bc0", - "transaction" : { - "data" : "", - "gasLimit" : "0x5208", - "gasPrice" : "0x01", - "nonce" : "0x00", - "r" : "0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353", - "s" : "0x01", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "v" : "0x1b", - "value" : "0x0b" - } + "Byzantium" : { + "hash" : "4782cb5edcaeda1f0aef204b161214f124cefade9e146245183abbb9ca01bca5", + "sender" : "2ea991808ba979ba103147edfd72304ebd95c028" + }, + "Constantinople" : { + "hash" : "4782cb5edcaeda1f0aef204b161214f124cefade9e146245183abbb9ca01bca5", + "sender" : "2ea991808ba979ba103147edfd72304ebd95c028" + }, + "EIP150" : { + }, + "EIP158" : { + "hash" : "4782cb5edcaeda1f0aef204b161214f124cefade9e146245183abbb9ca01bca5", + "sender" : "2ea991808ba979ba103147edfd72304ebd95c028" + }, + "Frontier" : { + }, + "Homestead" : { + }, + "_info" : { + "comment" : "", + "filledwith" : "cpp-1.3.0+commit.1829957d.Linux.g++", + "lllcversion" : "Version: 0.4.18-develop.2017.10.11+commit.81f9f86c.Linux.g++", + "source" : "src/TransactionTestsFiller/ttVValue/V_equals37Filler.json", + "sourceHash" : "89ef69312d4c0b4e3742da501263d23d2a64f180258ac93940997ac6a17b9b19" + }, + "rlp" : "0xf865808698852840a46f82d6d894095e7baea6a6c7c4c2dfeb977efac326af552d87808025a098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa01887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3" }"#; + let _deserialized: TransactionTest = serde_json::from_str(s).unwrap(); // TODO: validate all fields } From f6aa44373ebb8c4885ef1b2c389385de918de2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 30 Aug 2018 18:46:09 +0200 Subject: [PATCH 06/11] Ignore junk in ethereum/tests repo. --- ethcore/src/json_tests/test_common.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ethcore/src/json_tests/test_common.rs b/ethcore/src/json_tests/test_common.rs index 3e0b9cf8e65..ce5c68a73a0 100644 --- a/ethcore/src/json_tests/test_common.rs +++ b/ethcore/src/json_tests/test_common.rs @@ -41,6 +41,7 @@ pub fn run_test_path( os.push(".json"); os }).collect(); + let extension = path.extension().and_then(|s| s.to_str()); if path.is_dir() { for p in read_dir(path).unwrap().filter_map(|e| { let e = e.unwrap(); @@ -51,7 +52,7 @@ pub fn run_test_path( }}) { run_test_path(&p, skip, runner, start_stop_hook) } - } else if path.extension().and_then(|s| s.to_str()) == Some("swp") { + } else if extension == Some("swp") || extension == None { // Ignore junk } else { let mut path = p.to_path_buf(); From 1d0aecc6ed75ccc809dea610217b193a8818feaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 30 Aug 2018 18:59:54 +0200 Subject: [PATCH 07/11] Ignore incorrect test. --- ethcore/src/json_tests/state.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ethcore/src/json_tests/state.rs b/ethcore/src/json_tests/state.rs index a6bbaed100d..a4fcd96c9d1 100644 --- a/ethcore/src/json_tests/state.rs +++ b/ethcore/src/json_tests/state.rs @@ -159,5 +159,11 @@ mod state_tests { declare_test!{GeneralStateTest_stZeroCallsRevert, "GeneralStateTests/stZeroCallsRevert/"} declare_test!{GeneralStateTest_stZeroCallsTest, "GeneralStateTests/stZeroCallsTest/"} declare_test!{GeneralStateTest_stZeroKnowledge, "GeneralStateTests/stZeroKnowledge/"} - declare_test!{GeneralStateTest_stZeroKnowledge2, "GeneralStateTests/stZeroKnowledge2/"} + + // Attempts to send a transaction that requires more than current balance: + // Tx: + // https://github.com/ethereum/tests/blob/726b161ba8a739691006cc1ba080672bb50a9d49/GeneralStateTests/stZeroKnowledge2/ecmul_0-3_5616_28000_96.json#L170 + // Balance: + // https://github.com/ethereum/tests/blob/726b161ba8a739691006cc1ba080672bb50a9d49/GeneralStateTests/stZeroKnowledge2/ecmul_0-3_5616_28000_96.json#L126 + declare_test!{ignore => GeneralStateTest_stZeroKnowledge2, "GeneralStateTests/stZeroKnowledge2/"} } From 832195225c4f2d96ef1cdd166146835cb2bcd1dc Mon Sep 17 00:00:00 2001 From: cheme Date: Thu, 30 Aug 2018 19:57:06 +0200 Subject: [PATCH 08/11] Update to a later commit --- ethcore/res/ethereum/tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/res/ethereum/tests b/ethcore/res/ethereum/tests index 726b161ba8a..b8a21c19369 160000 --- a/ethcore/res/ethereum/tests +++ b/ethcore/res/ethereum/tests @@ -1 +1 @@ -Subproject commit 726b161ba8a739691006cc1ba080672bb50a9d49 +Subproject commit b8a21c193696976ca3b33b6d82107601063a5d26 From 25c6a42fa64635f835ded348546e4a568dc38816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 31 Aug 2018 10:00:57 +0200 Subject: [PATCH 09/11] Move block number to a constant. --- ethcore/src/json_tests/transaction.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ethcore/src/json_tests/transaction.rs b/ethcore/src/json_tests/transaction.rs index e3a9fc17339..70021c9e985 100644 --- a/ethcore/src/json_tests/transaction.rs +++ b/ethcore/src/json_tests/transaction.rs @@ -32,6 +32,10 @@ pub fn run_test_file(p: &Path, h: &mut H) { ::json_tests::test_common::run_test_file(p, do_json_test, h) } +// Block number used to run the tests. +// Make sure that all the specified features are activated. +const BLOCK_NUMBER: u64 = 0x6ffffffffffffe; + fn do_json_test(json_data: &[u8], start_stop_hook: &mut H) -> Vec { let tests = ethjson::transaction::Test::load(json_data).unwrap(); let mut failed = Vec::new(); @@ -59,7 +63,7 @@ fn do_json_test(json_data: &[u8], start_stop_hook: &mu .and_then(|t: UnverifiedTransaction| { let mut header: Header = Default::default(); // Use high enough number to activate all required features. - header.set_number(0x6ffffffffffffe); + header.set_number(BLOCK_NUMBER); let minimal = t.gas_required(&spec.engine.schedule(header.number())).into(); if t.gas < minimal { From 60dceb2e41a49b1ebe0b1d158a5ad5b851896145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 31 Aug 2018 11:17:45 +0200 Subject: [PATCH 10/11] Fix ZK2 test - touched account should also be cleared. --- ethcore/src/client/evm_test_client.rs | 8 ++++++++ ethcore/src/json_tests/state.rs | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ethcore/src/client/evm_test_client.rs b/ethcore/src/client/evm_test_client.rs index 176e99dbad8..69b7935263f 100644 --- a/ethcore/src/client/evm_test_client.rs +++ b/ethcore/src/client/evm_test_client.rs @@ -226,6 +226,14 @@ impl<'a> EvmTestClient<'a> { } else { state::CleanupMode::ForceCreate }).ok(); + // Touching also means that we should remove the account if it's within eip161 + // conditions. + self.state.kill_garbage( + &vec![env_info.author].into_iter().collect(), + schedule.kill_empty, + &None, + false + ).ok(); self.state.commit().ok(); match result { diff --git a/ethcore/src/json_tests/state.rs b/ethcore/src/json_tests/state.rs index a4fcd96c9d1..5837f191c7d 100644 --- a/ethcore/src/json_tests/state.rs +++ b/ethcore/src/json_tests/state.rs @@ -165,5 +165,5 @@ mod state_tests { // https://github.com/ethereum/tests/blob/726b161ba8a739691006cc1ba080672bb50a9d49/GeneralStateTests/stZeroKnowledge2/ecmul_0-3_5616_28000_96.json#L170 // Balance: // https://github.com/ethereum/tests/blob/726b161ba8a739691006cc1ba080672bb50a9d49/GeneralStateTests/stZeroKnowledge2/ecmul_0-3_5616_28000_96.json#L126 - declare_test!{ignore => GeneralStateTest_stZeroKnowledge2, "GeneralStateTests/stZeroKnowledge2/"} + declare_test!{GeneralStateTest_stZeroKnowledge2, "GeneralStateTests/stZeroKnowledge2/"} } From e355c6d131ad62378e1b05ef660fbe8f1e13d8a4 Mon Sep 17 00:00:00 2001 From: cheme Date: Mon, 10 Sep 2018 22:04:57 +0200 Subject: [PATCH 11/11] Fix conflict resolution --- ethcore/res/ethereum/eip161_test.json | 1 - 1 file changed, 1 deletion(-) diff --git a/ethcore/res/ethereum/eip161_test.json b/ethcore/res/ethereum/eip161_test.json index b22a23ef3f7..b64b6b0470e 100644 --- a/ethcore/res/ethereum/eip161_test.json +++ b/ethcore/res/ethereum/eip161_test.json @@ -23,7 +23,6 @@ "eip161abcTransition": "0x0", "eip161dTransition": "0x0", "eip98Transition": "0x7fffffffffffffff", - "eip86Transition": "0x7fffffffffffffff", "eip155Transition": "0x0", "maxCodeSize": 24576, "maxCodeSizeTransition": "0x0"