From 56ee6770b5045f3a8a8d8387235713a1186d90d5 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 12 Jan 2016 15:45:40 +0100 Subject: [PATCH] All transaction tests pass. Nicer testing framework. --- | 0 Cargo.toml | 2 +- src/lib.rs | 2 ++ src/transaction.rs | 48 ++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 45 insertions(+), 7 deletions(-) delete mode 100644 diff --git a/ b/ deleted file mode 100644 index e69de29bb..000000000 diff --git a/Cargo.toml b/Cargo.toml index 1c7085b03..bffab3ac3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ rocksdb = "0.2" heapsize = "0.2.0" rust-crypto = "0.2.34" time = "0.1" - +#interpolate_idents = { git = "https://github.com/SkylerLipthay/interpolate_idents" } evmjit = { path = "rust-evmjit", optional = true } [features] diff --git a/src/lib.rs b/src/lib.rs index 1e7da98dc..3ead3966d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ #![feature(cell_extras)] #![feature(augmented_assignments)] +//#![feature(plugin)] +//#![plugin(interpolate_idents)] //! Ethcore's ethereum implementation //! //! ### Rust version diff --git a/src/transaction.rs b/src/transaction.rs index 64f5b5806..9a326211e 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -209,13 +209,17 @@ mod tests { fn do_json_test(json_data: &[u8]) -> Vec { let json = Json::from_str(::std::str::from_utf8(json_data).unwrap()).expect("Json is invalid"); let mut failed = Vec::new(); - let schedule = Schedule::new_frontier(); + let old_schedule = Schedule::new_frontier(); + let new_schedule = Schedule::new_homestead(); for (name, test) in json.as_object().unwrap() { let mut fail = false; let mut fail_unless = |cond: bool| if !cond && fail { failed.push(name.to_string()); fail = true }; - let _ = BlockNumber::from_str(test["blocknumber"].as_string().unwrap()).unwrap(); + let schedule = match test.find("blocknumber") + .and_then(|j| j.as_string()) + .and_then(|s| BlockNumber::from_str(s).ok()) + .unwrap_or(0) { x if x < 900000 => &old_schedule, _ => &new_schedule }; let rlp = bytes_from_json(&test["rlp"]); - let res = UntrustedRlp::new(&rlp).as_val().map_err(|e| From::from(e)).and_then(|t: Transaction| t.validate(&schedule)); + let res = UntrustedRlp::new(&rlp).as_val().map_err(|e| From::from(e)).and_then(|t: Transaction| t.validate(schedule)); fail_unless(test.find("transaction").is_none() == res.is_err()); if let (Some(&Json::Object(ref tx)), Some(&Json::String(ref expect_sender))) = (test.find("transaction"), test.find("sender")) { let t = res.unwrap(); @@ -238,17 +242,49 @@ mod tests { failed } - macro_rules! declare_test { - ($test_set_name: ident/$name: ident) => { + // Once we have interpolate idents. + /*macro_rules! declare_test { + ($test_set_name: ident / $name: ident) => { #[test] #[allow(non_snake_case)] fn $name() { assert!(do_json_test(include_bytes!(concat!("../res/ethereum/tests/", stringify!($test_set_name), "/", stringify!($name), ".json"))).len() == 0); } - } + }; + ($test_set_name: ident / $prename: ident / $name: ident) => { + #[test] + #[allow(non_snake_case)] + interpolate_idents! { fn [$prename _ $name]() + { + let json = include_bytes!(concat!("../res/ethereum/tests/", stringify!($test_set_name), "/", stringify!($prename), "/", stringify!($name), ".json")); + assert!(do_json_test(json).len() == 0); + } + } + }; } declare_test!{TransactionTests/ttTransactionTest} declare_test!{TransactionTests/tt10mbDataField} declare_test!{TransactionTests/ttWrongRLPTransaction} + declare_test!{TransactionTests/Homestead/ttTransactionTest} + declare_test!{TransactionTests/Homestead/tt10mbDataField} + declare_test!{TransactionTests/Homestead/ttWrongRLPTransaction} + declare_test!{TransactionTests/RandomTests/tr201506052141PYTHON}*/ + + macro_rules! declare_test { + ($id: ident, $name: expr) => { + #[test] + #[allow(non_snake_case)] + fn $id() { + assert!(do_json_test(include_bytes!(concat!("../res/ethereum/tests/", $name, ".json"))).len() == 0); + } + }; + } + declare_test!{TransactionTests_ttTransactionTest, "TransactionTests/ttTransactionTest"} + declare_test!{TransactionTests_tt10mbDataField, "TransactionTests/tt10mbDataField"} + declare_test!{TransactionTests_ttWrongRLPTransaction, "TransactionTests/ttWrongRLPTransaction"} + declare_test!{TransactionTests_Homestead_ttTransactionTest, "TransactionTests/Homestead/ttTransactionTest"} + declare_test!{TransactionTests_Homestead_tt10mbDataField, "TransactionTests/Homestead/tt10mbDataField"} + declare_test!{TransactionTests_Homestead_ttWrongRLPTransaction, "TransactionTests/Homestead/ttWrongRLPTransaction"} + declare_test!{TransactionTests_RandomTests_tr201506052141PYTHON, "TransactionTests/RandomTests/tr201506052141PYTHON"} } \ No newline at end of file