2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2016-02-05 13:40:41 +01:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2016-02-05 13:40:41 +01:00
|
|
|
// 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.
|
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
2016-02-05 13:40:41 +01:00
|
|
|
// 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
|
2019-01-07 11:33:07 +01:00
|
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2016-02-05 13:40:41 +01:00
|
|
|
|
2018-06-25 11:21:45 +02:00
|
|
|
use std::path::Path;
|
2016-01-12 16:20:29 +01:00
|
|
|
use super::test_common::*;
|
2018-09-10 22:38:30 +02:00
|
|
|
use client::EvmTestClient;
|
2016-03-29 13:01:26 +02:00
|
|
|
use ethjson;
|
2018-04-16 15:52:12 +02:00
|
|
|
use rlp::Rlp;
|
2019-01-04 14:05:46 +01:00
|
|
|
use types::header::Header;
|
|
|
|
use types::transaction::UnverifiedTransaction;
|
|
|
|
use transaction_ext::Transaction;
|
2016-01-12 16:20:29 +01:00
|
|
|
|
2018-06-25 11:21:45 +02:00
|
|
|
/// Run transaction jsontests on a given folder.
|
|
|
|
pub fn run_test_path<H: FnMut(&str, HookType)>(p: &Path, skip: &[&'static str], h: &mut H) {
|
|
|
|
::json_tests::test_common::run_test_path(p, skip, do_json_test, h)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Run transaction jsontests on a given file.
|
|
|
|
pub fn run_test_file<H: FnMut(&str, HookType)>(p: &Path, h: &mut H) {
|
|
|
|
::json_tests::test_common::run_test_file(p, do_json_test, h)
|
|
|
|
}
|
|
|
|
|
2018-09-10 22:38:30 +02:00
|
|
|
// Block number used to run the tests.
|
|
|
|
// Make sure that all the specified features are activated.
|
|
|
|
const BLOCK_NUMBER: u64 = 0x6ffffffffffffe;
|
|
|
|
|
2018-06-25 11:21:45 +02:00
|
|
|
fn do_json_test<H: FnMut(&str, HookType)>(json_data: &[u8], start_stop_hook: &mut H) -> Vec<String> {
|
2016-03-29 13:01:26 +02:00
|
|
|
let tests = ethjson::transaction::Test::load(json_data).unwrap();
|
2016-01-12 16:20:29 +01:00
|
|
|
let mut failed = Vec::new();
|
2016-03-29 13:01:26 +02:00
|
|
|
for (name, test) in tests.into_iter() {
|
2018-06-25 11:21:45 +02:00
|
|
|
start_stop_hook(&name, HookType::OnStart);
|
|
|
|
|
2018-09-10 22:38:30 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut fail_unless = |cond: bool, title: &str| if !cond {
|
|
|
|
failed.push(format!("{}-{:?}", name, spec_name));
|
|
|
|
println!("Transaction failed: {:?}-{:?}: {:?}", name, spec_name, title);
|
2016-11-03 22:22:25 +01:00
|
|
|
};
|
2018-09-10 22:38:30 +02:00
|
|
|
|
|
|
|
let rlp: Vec<u8> = 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(BLOCK_NUMBER);
|
|
|
|
|
|
|
|
let minimal = t.gas_required(&spec.engine.schedule(header.number())).into();
|
|
|
|
if t.gas < minimal {
|
2019-01-04 14:05:46 +01:00
|
|
|
return Err(::types::transaction::Error::InsufficientGas {
|
2018-09-10 22:38:30 +02:00
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
2016-01-12 16:20:29 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-25 11:21:45 +02:00
|
|
|
|
|
|
|
start_stop_hook(&name, HookType::OnStop);
|
2016-01-12 16:20:29 +01:00
|
|
|
}
|
2016-03-29 13:01:26 +02:00
|
|
|
|
2016-01-19 13:47:30 +01:00
|
|
|
for f in &failed {
|
2016-01-12 16:20:29 +01:00
|
|
|
println!("FAILED: {:?}", f);
|
|
|
|
}
|
|
|
|
failed
|
|
|
|
}
|
|
|
|
|
2018-09-10 22:38:30 +02:00
|
|
|
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"}
|