2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-02-05 13:40:41 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// 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
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-01-12 16:20:29 +01:00
|
|
|
use super::test_common::*;
|
|
|
|
use evm;
|
2016-03-29 13:01:26 +02:00
|
|
|
use ethjson;
|
2017-03-22 14:41:46 +01:00
|
|
|
use rlp::UntrustedRlp;
|
2017-04-19 14:30:00 +02:00
|
|
|
use transaction::{Action, UnverifiedTransaction, SignedTransaction};
|
2016-01-12 16:20:29 +01:00
|
|
|
|
|
|
|
fn do_json_test(json_data: &[u8]) -> 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();
|
2017-04-19 14:30:00 +02:00
|
|
|
let frontier_schedule = evm::Schedule::new_frontier();
|
|
|
|
let homestead_schedule = evm::Schedule::new_homestead();
|
2017-09-15 21:07:54 +02:00
|
|
|
let byzantium_schedule = evm::Schedule::new_byzantium();
|
2016-03-29 13:01:26 +02:00
|
|
|
for (name, test) in tests.into_iter() {
|
2016-11-09 18:02:24 +01:00
|
|
|
let mut fail_unless = |cond: bool, title: &str| if !cond { failed.push(name.clone()); println!("Transaction failed: {:?}: {:?}", name, title); };
|
2016-03-29 13:01:26 +02:00
|
|
|
|
|
|
|
let number: Option<u64> = test.block_number.map(Into::into);
|
|
|
|
let schedule = match number {
|
2017-04-19 14:30:00 +02:00
|
|
|
None => &frontier_schedule,
|
|
|
|
Some(x) if x < 1_150_000 => &frontier_schedule,
|
|
|
|
Some(x) if x < 3_000_000 => &homestead_schedule,
|
2017-09-15 21:07:54 +02:00
|
|
|
Some(_) => &byzantium_schedule
|
2016-03-29 13:01:26 +02:00
|
|
|
};
|
2017-08-21 13:46:58 +02:00
|
|
|
let allow_chain_id_of_one = number.map_or(false, |n| n >= 2_675_000);
|
2017-04-19 14:30:00 +02:00
|
|
|
let allow_unsigned = number.map_or(false, |n| n >= 3_000_000);
|
2016-03-29 13:01:26 +02:00
|
|
|
|
|
|
|
let rlp: Vec<u8> = test.rlp.into();
|
|
|
|
let res = UntrustedRlp::new(&rlp)
|
|
|
|
.as_val()
|
2018-01-11 17:49:10 +01:00
|
|
|
.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)
|
|
|
|
});
|
2016-03-29 13:01:26 +02:00
|
|
|
|
2016-11-09 18:02:24 +01:00
|
|
|
fail_unless(test.transaction.is_none() == res.is_err(), "Validity different");
|
2016-03-29 13:01:26 +02:00
|
|
|
if let (Some(tx), Some(sender)) = (test.transaction, test.sender) {
|
2016-01-12 16:20:29 +01:00
|
|
|
let t = res.unwrap();
|
2017-04-19 14:30:00 +02:00
|
|
|
fail_unless(SignedTransaction::new(t.clone()).unwrap().sender() == sender.into(), "sender mismatch");
|
2017-08-21 13:46:58 +02:00
|
|
|
let is_acceptable_chain_id = match t.chain_id() {
|
2016-11-03 22:22:25 +01:00
|
|
|
None => true,
|
2017-08-21 13:46:58 +02:00
|
|
|
Some(1) if allow_chain_id_of_one => true,
|
2016-11-03 22:22:25 +01:00
|
|
|
_ => false,
|
|
|
|
};
|
2017-08-21 13:46:58 +02:00
|
|
|
fail_unless(is_acceptable_chain_id, "Network ID unacceptable");
|
2016-03-29 13:01:26 +02:00
|
|
|
let data: Vec<u8> = tx.data.into();
|
2016-11-09 18:02:24 +01:00
|
|
|
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");
|
2016-07-28 23:46:24 +02:00
|
|
|
let to: Option<ethjson::hash::Address> = tx.to.into();
|
2016-03-29 13:01:26 +02:00
|
|
|
let to: Option<Address> = to.map(Into::into);
|
|
|
|
match t.action {
|
2016-11-09 18:02:24 +01:00
|
|
|
Action::Call(dest) => fail_unless(Some(dest) == to, "call/destination mismatch"),
|
|
|
|
Action::Create => fail_unless(None == to, "create mismatch"),
|
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
|
|
|
|
}
|
|
|
|
|
2017-09-15 21:07:54 +02:00
|
|
|
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"}
|