Reformat the source code

This commit is contained in:
Artem Vorotnikov
2020-08-05 07:08:03 +03:00
parent 253ff3f37b
commit 610d9baba4
742 changed files with 175791 additions and 141379 deletions

View File

@@ -15,30 +15,30 @@
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! State test log deserialization.
use hash::{Address, H256, Bloom};
use bytes::Bytes;
use hash::{Address, Bloom, H256};
/// State test log deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub struct Log {
/// Address.
pub address: Address,
/// Topics.
pub topics: Vec<H256>,
/// Data.
pub data: Bytes,
/// Bloom.
pub bloom: Bloom,
/// Address.
pub address: Address,
/// Topics.
pub topics: Vec<H256>,
/// Data.
pub data: Bytes,
/// Bloom.
pub bloom: Bloom,
}
#[cfg(test)]
mod tests {
use serde_json;
use state::Log;
use serde_json;
use state::Log;
#[test]
fn log_deserialization() {
let s = r#"{
#[test]
fn log_deserialization() {
let s = r#"{
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008800000000000000000020000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000",
"data" : "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
@@ -46,7 +46,7 @@ mod tests {
"0000000000000000000000000000000000000000000000000000000000000000"
]
}"#;
let _deserialized: Log = serde_json::from_str(s).unwrap();
// TODO: validate all fields
}
let _deserialized: Log = serde_json::from_str(s).unwrap();
// TODO: validate all fields
}
}

View File

@@ -16,14 +16,11 @@
//! State test deserialization.
pub mod state;
pub mod transaction;
pub mod test;
pub mod log;
pub mod state;
pub mod test;
pub mod transaction;
pub use self::state::State;
pub use self::transaction::Transaction;
pub use self::test::Test;
pub use self::log::Log;
pub use vm::Env as Env;
pub use self::{log::Log, state::State, test::Test, transaction::Transaction};
pub use blockchain::State as AccountState;
pub use vm::Env;

View File

@@ -18,39 +18,39 @@
use bytes::Bytes;
use hash::H256;
use state::{Env, AccountState, Transaction, Log};
use state::{AccountState, Env, Log, Transaction};
/// State test deserialization.
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct State {
/// Environment.
pub env: Env,
/// Output.
#[serde(rename = "out")]
pub output: Bytes,
/// Pre state.
#[serde(rename = "pre")]
pub pre_state: AccountState,
/// Post state.
#[serde(rename = "post")]
pub post_state: AccountState,
/// Post state root.
pub post_state_root: H256,
/// Transaction.
pub transaction: Transaction,
/// Logs.
pub logs: Vec<Log>
/// Environment.
pub env: Env,
/// Output.
#[serde(rename = "out")]
pub output: Bytes,
/// Pre state.
#[serde(rename = "pre")]
pub pre_state: AccountState,
/// Post state.
#[serde(rename = "post")]
pub post_state: AccountState,
/// Post state root.
pub post_state_root: H256,
/// Transaction.
pub transaction: Transaction,
/// Logs.
pub logs: Vec<Log>,
}
#[cfg(test)]
mod tests {
use serde_json;
use state::State;
use serde_json;
use state::State;
#[test]
fn state_deserialization() {
let s = r#"{
#[test]
fn state_deserialization() {
let s = r#"{
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "0x0100",
@@ -150,7 +150,7 @@ mod tests {
"value" : "0x00"
}
}"#;
let _deserialized: State = serde_json::from_str(s).unwrap();
// TODO: validate all fields
}
let _deserialized: State = serde_json::from_str(s).unwrap();
// TODO: validate all fields
}
}

View File

@@ -16,115 +16,117 @@
//! General test deserialization.
use std::io::Read;
use std::collections::BTreeMap;
use uint::Uint;
use bytes::Bytes;
use hash::{Address, H256};
use spec::ForkSpec;
use state::{Env, AccountState, Transaction};
use maybe::MaybeEmpty;
use serde_json::{self, Error};
use spec::ForkSpec;
use state::{AccountState, Env, Transaction};
use std::{collections::BTreeMap, io::Read};
use uint::Uint;
/// State test deserializer.
#[derive(Debug, PartialEq, Deserialize)]
pub struct Test(BTreeMap<String, State>);
impl IntoIterator for Test {
type Item = <BTreeMap<String, State> as IntoIterator>::Item;
type IntoIter = <BTreeMap<String, State> as IntoIterator>::IntoIter;
type Item = <BTreeMap<String, State> as IntoIterator>::Item;
type IntoIter = <BTreeMap<String, State> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
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)
}
/// Loads test from json.
pub fn load<R>(reader: R) -> Result<Self, Error>
where
R: Read,
{
serde_json::from_reader(reader)
}
}
/// State test deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub struct State {
/// Environment.
pub env: Env,
/// Pre state.
#[serde(rename = "pre")]
pub pre_state: AccountState,
/// Post state.
#[serde(rename = "post")]
pub post_states: BTreeMap<ForkSpec, Vec<PostStateResult>>,
/// Transaction.
pub transaction: MultiTransaction,
/// Environment.
pub env: Env,
/// Pre state.
#[serde(rename = "pre")]
pub pre_state: AccountState,
/// Post state.
#[serde(rename = "post")]
pub post_states: BTreeMap<ForkSpec, Vec<PostStateResult>>,
/// Transaction.
pub transaction: MultiTransaction,
}
/// State test transaction deserialization.
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MultiTransaction {
/// Transaction data set.
pub data: Vec<Bytes>,
/// Gas limit set.
pub gas_limit: Vec<Uint>,
/// Gas price.
pub gas_price: Uint,
/// Nonce.
pub nonce: Uint,
/// Secret key.
#[serde(rename = "secretKey")]
pub secret: Option<H256>,
/// To.
pub to: MaybeEmpty<Address>,
/// Value set.
pub value: Vec<Uint>,
/// Transaction data set.
pub data: Vec<Bytes>,
/// Gas limit set.
pub gas_limit: Vec<Uint>,
/// Gas price.
pub gas_price: Uint,
/// Nonce.
pub nonce: Uint,
/// Secret key.
#[serde(rename = "secretKey")]
pub secret: Option<H256>,
/// To.
pub to: MaybeEmpty<Address>,
/// Value set.
pub value: Vec<Uint>,
}
impl MultiTransaction {
/// Build transaction with given indexes.
pub fn select(&self, indexes: &PostStateIndexes) -> Transaction {
Transaction {
data: self.data[indexes.data as usize].clone(),
gas_limit: self.gas_limit[indexes.gas as usize].clone(),
gas_price: self.gas_price.clone(),
nonce: self.nonce.clone(),
secret: self.secret.clone(),
to: self.to.clone(),
value: self.value[indexes.value as usize].clone(),
}
}
/// Build transaction with given indexes.
pub fn select(&self, indexes: &PostStateIndexes) -> Transaction {
Transaction {
data: self.data[indexes.data as usize].clone(),
gas_limit: self.gas_limit[indexes.gas as usize].clone(),
gas_price: self.gas_price.clone(),
nonce: self.nonce.clone(),
secret: self.secret.clone(),
to: self.to.clone(),
value: self.value[indexes.value as usize].clone(),
}
}
}
/// State test indexes deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub struct PostStateIndexes {
/// Index into transaction data set.
pub data: u64,
/// Index into transaction gas limit set.
pub gas: u64,
/// Index into transaction value set.
pub value: u64,
/// Index into transaction data set.
pub data: u64,
/// Index into transaction gas limit set.
pub gas: u64,
/// Index into transaction value set.
pub value: u64,
}
/// State test indexed state result deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub struct PostStateResult {
/// Post state hash
pub hash: H256,
/// Indexes
pub indexes: PostStateIndexes,
/// Post state hash
pub hash: H256,
/// Indexes
pub indexes: PostStateIndexes,
}
#[cfg(test)]
mod tests {
use serde_json;
use super::{MultiTransaction, State};
use super::{MultiTransaction, State};
use serde_json;
#[test]
fn multi_transaction_deserialization() {
let s = r#"{
#[test]
fn multi_transaction_deserialization() {
let s = r#"{
"data" : [ "" ],
"gasLimit" : [ "0x2dc6c0", "0x222222" ],
"gasPrice" : "0x01",
@@ -133,12 +135,12 @@ mod tests {
"to" : "1000000000000000000000000000000000000000",
"value" : [ "0x00", "0x01", "0x02" ]
}"#;
let _deserialized: MultiTransaction = serde_json::from_str(s).unwrap();
}
let _deserialized: MultiTransaction = serde_json::from_str(s).unwrap();
}
#[test]
fn state_deserialization() {
let s = r#"{
#[test]
fn state_deserialization() {
let s = r#"{
"env" : {
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
"currentDifficulty" : "0x0100",
@@ -209,7 +211,7 @@ mod tests {
"value" : [ "10", "0" ]
}
}"#;
let _deserialized: State = serde_json::from_str(s).unwrap();
// TODO: validate all fields
}
let _deserialized: State = serde_json::from_str(s).unwrap();
// TODO: validate all fields
}
}

View File

@@ -16,40 +16,40 @@
//! State test transaction deserialization.
use uint::Uint;
use bytes::Bytes;
use hash::{Address, H256};
use maybe::MaybeEmpty;
use uint::Uint;
/// State test transaction deserialization.
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Transaction {
/// Transaction data.
pub data: Bytes,
/// Gas limit.
pub gas_limit: Uint,
/// Gas price.
pub gas_price: Uint,
/// Nonce.
pub nonce: Uint,
/// Secret key.
#[serde(rename = "secretKey")]
pub secret: Option<H256>,
/// To.
pub to: MaybeEmpty<Address>,
/// Value.
pub value: Uint,
/// Transaction data.
pub data: Bytes,
/// Gas limit.
pub gas_limit: Uint,
/// Gas price.
pub gas_price: Uint,
/// Nonce.
pub nonce: Uint,
/// Secret key.
#[serde(rename = "secretKey")]
pub secret: Option<H256>,
/// To.
pub to: MaybeEmpty<Address>,
/// Value.
pub value: Uint,
}
#[cfg(test)]
mod tests {
use serde_json;
use state::Transaction;
use serde_json;
use state::Transaction;
#[test]
fn transaction_deserialization() {
let s = r#"{
#[test]
fn transaction_deserialization() {
let s = r#"{
"data" : "",
"gasLimit" : "0x2dc6c0",
"gasPrice" : "0x01",
@@ -58,7 +58,7 @@ mod tests {
"to" : "1000000000000000000000000000000000000000",
"value" : "0x00"
}"#;
let _deserialized: Transaction = serde_json::from_str(s).unwrap();
// TODO: validate all fields
}
let _deserialized: Transaction = serde_json::from_str(s).unwrap();
// TODO: validate all fields
}
}