2016-02-05 13:40:41 +01:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// 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;
|
2016-09-01 14:29:59 +02:00
|
|
|
use rlp::{UntrustedRlp, View};
|
2016-10-24 18:35:25 +02:00
|
|
|
use transaction::{Action, 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();
|
|
|
|
let old_schedule = evm::Schedule::new_frontier();
|
|
|
|
let new_schedule = evm::Schedule::new_homestead();
|
2016-03-29 13:01:26 +02:00
|
|
|
for (name, test) in tests.into_iter() {
|
2016-01-12 16:20:29 +01:00
|
|
|
let mut fail = false;
|
2016-03-29 13:01:26 +02:00
|
|
|
let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.clone()); println!("Transaction failed: {:?}", name); fail = true };
|
|
|
|
|
|
|
|
let number: Option<u64> = test.block_number.map(Into::into);
|
|
|
|
let schedule = match number {
|
|
|
|
None => &old_schedule,
|
2016-03-29 14:34:03 +02:00
|
|
|
Some(x) if x < 1_150_000 => &old_schedule,
|
2016-03-29 13:01:26 +02:00
|
|
|
Some(_) => &new_schedule
|
|
|
|
};
|
|
|
|
|
|
|
|
let rlp: Vec<u8> = test.rlp.into();
|
|
|
|
let res = UntrustedRlp::new(&rlp)
|
|
|
|
.as_val()
|
|
|
|
.map_err(From::from)
|
|
|
|
.and_then(|t: SignedTransaction| t.validate(schedule, schedule.have_delegate_call));
|
|
|
|
|
|
|
|
fail_unless(test.transaction.is_none() == res.is_err());
|
|
|
|
if let (Some(tx), Some(sender)) = (test.transaction, test.sender) {
|
2016-01-12 16:20:29 +01:00
|
|
|
let t = res.unwrap();
|
2016-03-29 13:01:26 +02:00
|
|
|
fail_unless(t.sender().unwrap() == sender.into());
|
|
|
|
let data: Vec<u8> = tx.data.into();
|
|
|
|
fail_unless(t.data == data);
|
|
|
|
fail_unless(t.gas_price == tx.gas_price.into());
|
|
|
|
fail_unless(t.nonce == tx.nonce.into());
|
|
|
|
fail_unless(t.value == tx.value.into());
|
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 {
|
|
|
|
Action::Call(dest) => fail_unless(Some(dest) == to),
|
|
|
|
Action::Create => fail_unless(None == to),
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
declare_test!{TransactionTests_ttTransactionTest, "TransactionTests/ttTransactionTest"}
|
2016-01-22 08:07:53 +01:00
|
|
|
declare_test!{heavy => TransactionTests_tt10mbDataField, "TransactionTests/tt10mbDataField"}
|
2016-01-12 16:20:29 +01:00
|
|
|
declare_test!{TransactionTests_ttWrongRLPTransaction, "TransactionTests/ttWrongRLPTransaction"}
|
|
|
|
declare_test!{TransactionTests_Homestead_ttTransactionTest, "TransactionTests/Homestead/ttTransactionTest"}
|
2016-01-21 19:32:48 +01:00
|
|
|
declare_test!{heavy => TransactionTests_Homestead_tt10mbDataField, "TransactionTests/Homestead/tt10mbDataField"}
|
2016-01-12 16:20:29 +01:00
|
|
|
declare_test!{TransactionTests_Homestead_ttWrongRLPTransaction, "TransactionTests/Homestead/ttWrongRLPTransaction"}
|
|
|
|
declare_test!{TransactionTests_RandomTests_tr201506052141PYTHON, "TransactionTests/RandomTests/tr201506052141PYTHON"}
|