This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #853 from ethcore/json_tx_refactor
refactored loading transaction json tests
- Loading branch information
Showing
9 changed files
with
267 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ pub mod spec; | |
pub mod vm; | ||
pub mod maybe; | ||
pub mod state; | ||
pub mod transaction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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/>. | ||
|
||
//! Transaction test deserialization. | ||
mod transaction; | ||
mod txtest; | ||
mod test; | ||
|
||
pub use self::transaction::Transaction; | ||
pub use self::txtest::TransactionTest; | ||
pub use self::test::Test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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/>. | ||
|
||
//! TransactionTest test deserializer. | ||
use std::collections::BTreeMap; | ||
use std::io::Read; | ||
use serde_json; | ||
use serde_json::Error; | ||
use transaction::TransactionTest; | ||
|
||
/// TransactionTest test deserializer. | ||
#[derive(Debug, PartialEq, Deserialize)] | ||
pub struct Test(BTreeMap<String, TransactionTest>); | ||
|
||
impl IntoIterator for Test { | ||
type Item = <BTreeMap<String, TransactionTest> as IntoIterator>::Item; | ||
type IntoIter = <BTreeMap<String, TransactionTest> as IntoIterator>::IntoIter; | ||
|
||
fn into_iter(self) -> Self::IntoIter { | ||
self.0.into_iter() | ||
} | ||
} | ||
|
||
impl Test { | ||
/// Loads test from json. | ||
pub fn load<R>(reader: R) -> Result<Self, Error> where R: Read { | ||
serde_json::from_reader(reader) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// 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/>. | ||
|
||
//! Transaction test transaction deserialization. | ||
use uint::Uint; | ||
use bytes::Bytes; | ||
use hash::Address; | ||
use maybe::MaybeEmpty; | ||
|
||
/// Transaction test transaction deserialization. | ||
#[derive(Debug, PartialEq, Deserialize)] | ||
pub struct Transaction { | ||
/// Transaction data. | ||
pub data: Bytes, | ||
/// Gas limit. | ||
#[serde(rename="gasLimit")] | ||
pub gas_limit: Uint, | ||
/// Gas price. | ||
#[serde(rename="gasPrice")] | ||
pub gas_price: Uint, | ||
/// Nonce. | ||
pub nonce: Uint, | ||
/// To. | ||
pub to: MaybeEmpty<Address>, | ||
/// Value. | ||
pub value: Uint, | ||
/// R. | ||
pub r: Uint, | ||
/// S. | ||
pub s: Uint, | ||
/// V. | ||
pub v: Uint, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use serde_json; | ||
use transaction::Transaction; | ||
|
||
#[test] | ||
fn transaction_deserialization() { | ||
let s = r#"{ | ||
"data" : "0x", | ||
"gasLimit" : "0xf388", | ||
"gasPrice" : "0x09184e72a000", | ||
"nonce" : "0x00", | ||
"r" : "0x2c", | ||
"s" : "0x04", | ||
"to" : "", | ||
"v" : "0x1b", | ||
"value" : "0x00" | ||
}"#; | ||
let _deserialized: Transaction = serde_json::from_str(s).unwrap(); | ||
// TODO: validate all fields | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// 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/>. | ||
|
||
//! Transaction test deserialization. | ||
use uint::Uint; | ||
use bytes::Bytes; | ||
use hash::Address; | ||
use transaction::Transaction; | ||
|
||
/// Transaction test deserialization. | ||
#[derive(Debug, PartialEq, Deserialize)] | ||
pub struct TransactionTest { | ||
/// Block number. | ||
#[serde(rename="blocknumber")] | ||
pub block_number: Option<Uint>, | ||
/// Transaction rlp. | ||
pub rlp: Bytes, | ||
/// Transaction sender. | ||
pub sender: Option<Address>, | ||
/// Transaction | ||
pub transaction: Option<Transaction>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use serde_json; | ||
use transaction::TransactionTest; | ||
|
||
#[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" | ||
} | ||
}"#; | ||
let _deserialized: TransactionTest = serde_json::from_str(s).unwrap(); | ||
// TODO: validate all fields | ||
} | ||
} |
Oops, something went wrong.