From 3352b0e916b1c903f7071f8900d3eec01858ec09 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 23 Mar 2016 18:36:05 +0100 Subject: [PATCH] json-tests vm loading --- json/src/lib.rs.in | 1 + json/src/vm/call.rs | 53 +++++++++++++++++++ json/src/vm/env.rs | 58 +++++++++++++++++++++ json/src/vm/log.rs | 54 ++++++++++++++++++++ json/src/vm/mod.rs | 29 +++++++++++ json/src/vm/transaction.rs | 64 +++++++++++++++++++++++ json/src/vm/vm.rs | 101 +++++++++++++++++++++++++++++++++++++ 7 files changed, 360 insertions(+) create mode 100644 json/src/vm/call.rs create mode 100644 json/src/vm/env.rs create mode 100644 json/src/vm/log.rs create mode 100644 json/src/vm/mod.rs create mode 100644 json/src/vm/transaction.rs create mode 100644 json/src/vm/vm.rs diff --git a/json/src/lib.rs.in b/json/src/lib.rs.in index 0d85ce569..20e7e35da 100644 --- a/json/src/lib.rs.in +++ b/json/src/lib.rs.in @@ -24,3 +24,4 @@ pub mod uint; pub mod bytes; pub mod blockchain; pub mod spec; +pub mod vm; diff --git a/json/src/vm/call.rs b/json/src/vm/call.rs new file mode 100644 index 000000000..ca955c7bd --- /dev/null +++ b/json/src/vm/call.rs @@ -0,0 +1,53 @@ +// 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 . + +//! Vm call deserialization. + +use bytes::Bytes; +use hash::Address; +use uint::Uint; + +/// Vm call deserialization. +#[derive(Debug, PartialEq, Deserialize)] +pub struct Call { + /// Call data. + pub data: Bytes, + /// Call destination. + pub destination: Address, + /// Gas limit. + #[serde(rename="gasLimit")] + pub gas_limit: Uint, + /// Call value. + pub value: Uint, +} + +#[cfg(test)] +mod tests { + use serde_json; + use vm::Call; + + #[test] + fn call_deserialization() { + let s = r#"{ + "data" : "0x1111222233334444555566667777888899990000aaaabbbbccccddddeeeeffff", + "destination" : "", + "gasLimit" : "0x1748766aa5", + "value" : "0x00" + }"#; + let _deserialized: Call = serde_json::from_str(s).unwrap(); + // TODO: validate all fields + } +} diff --git a/json/src/vm/env.rs b/json/src/vm/env.rs new file mode 100644 index 000000000..547298988 --- /dev/null +++ b/json/src/vm/env.rs @@ -0,0 +1,58 @@ +// 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 . + +//! Vm environment. +use hash::Address; +use uint::Uint; + +/// Vm environment. +#[derive(Debug, PartialEq, Deserialize)] +pub struct Env { + /// Address. + #[serde(rename="currentCoinbase")] + pub coinbase: Address, + /// Difficulty + #[serde(rename="currentDifficulty")] + pub difficulty: Uint, + /// Gas limit. + #[serde(rename="currentGasLimit")] + pub gas_limit: Uint, + /// Number. + #[serde(rename="currentNumber")] + pub number: Uint, + /// Timestamp. + #[serde(rename="currentTimestamp")] + pub timestamp: Uint, +} + +#[cfg(test)] +mod tests { + use serde_json; + use vm::Env; + + #[test] + fn env_deserialization() { + let s = r#"{ + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x0100", + "currentGasLimit" : "0x0f4240", + "currentNumber" : "0x00", + "currentTimestamp" : "0x01" + }"#; + let _deserialized: Env = serde_json::from_str(s).unwrap(); + // TODO: validate all fields + } +} diff --git a/json/src/vm/log.rs b/json/src/vm/log.rs new file mode 100644 index 000000000..b29325738 --- /dev/null +++ b/json/src/vm/log.rs @@ -0,0 +1,54 @@ +// 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 . + +//! Vm log deserialization. + +use hash::{Address, H256, Bloom}; +use bytes::Bytes; + +/// Vm log deserialization. +#[derive(Debug, PartialEq, Deserialize)] +pub struct Log { + /// Log address. + pub address: Address, + /// Log bloom. + pub bloom: Bloom, + /// Data. + pub data: Bytes, + /// Topics. + pub topics: Vec, +} + +#[cfg(test)] +mod tests { + use serde_json; + use vm::Log; + + #[test] + fn log_deserialization() { + let s = r#"{ + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008800000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000800000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000", + "data" : "0xaabbffffffffffffffffffffffffffffffffffffffffffffffffffffffffccdd", + "topics" : [ + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + ] + }"#; + let _deserialized: Log = serde_json::from_str(s).unwrap(); + // TODO: validate all fields + } +} + diff --git a/json/src/vm/mod.rs b/json/src/vm/mod.rs new file mode 100644 index 000000000..cc4a9662e --- /dev/null +++ b/json/src/vm/mod.rs @@ -0,0 +1,29 @@ +// 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 . + +//! Vm test loader. + +pub mod env; +pub mod transaction; +pub mod vm; +pub mod log; +pub mod call; + +pub use self::env::Env; +pub use self::transaction::Transaction; +pub use self::vm::Vm; +pub use self::log::Log; +pub use self::call::Call; diff --git a/json/src/vm/transaction.rs b/json/src/vm/transaction.rs new file mode 100644 index 000000000..d2ee8b89b --- /dev/null +++ b/json/src/vm/transaction.rs @@ -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 . + +//! Executed transaction. +use hash::Address; +use uint::Uint; +use bytes::Bytes; + +/// Executed transaction. +#[derive(Debug, PartialEq, Deserialize)] +pub struct Transaction { + /// Contract address. + pub address: Address, + /// Transaction sender. + #[serde(rename="caller")] + pub sender: Address, + /// Contract code. + pub code: Bytes, + /// Input data. + pub data: Bytes, + /// Gas. + pub gas: Uint, + /// Gas price. + #[serde(rename="gasPrice")] + pub gas_price: Uint, + /// Transaction origin. + pub origin: Address, + /// Sent value. + pub value: Uint, +} + +#[cfg(test)] +mod tests { + use serde_json; + use vm::Transaction; + + #[test] + fn transaction_deserialization() { + let s = r#"{ + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "caller" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055", + "data" : "0x", + "gas" : "0x0186a0", + "gasPrice" : "0x5af3107a4000", + "origin" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "value" : "0x0de0b6b3a7640000" + }"#; + let _deserialized: Transaction = serde_json::from_str(s).unwrap(); + } +} diff --git a/json/src/vm/vm.rs b/json/src/vm/vm.rs new file mode 100644 index 000000000..8e7a44986 --- /dev/null +++ b/json/src/vm/vm.rs @@ -0,0 +1,101 @@ +// 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 . + +//! Vm execution env. + +use bytes::Bytes; +use uint::Uint; +use blockchain::State; +use vm::{Transaction, Log, Call}; + +/// Reporesents vm execution environment before and after exeuction of transaction. +#[derive(Debug, PartialEq, Deserialize)] +pub struct Vm { + /// Contract calls made internaly by executed transaction. + #[serde(rename="callcreates")] + pub calls: Option>, + /// Executed transaction + #[serde(rename="exec")] + pub exec: Transaction, + /// Gas. + pub gas: Uint, + /// Logs created during execution of transaction. + pub logs: Vec, + /// Transaction output. + pub out: Bytes, + /// Post execution vm state. + #[serde(rename="post")] + pub post_state: State, + /// Pre execution vm state. + #[serde(rename="pre")] + pub pre_state: State, +} + +#[cfg(test)] +mod tests { + use serde_json; + use vm::Vm; + + #[test] + fn vm_deserialization() { + let s = r#"{ + "callcreates" : [ + ], + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "0x0100", + "currentGasLimit" : "0x0f4240", + "currentNumber" : "0x00", + "currentTimestamp" : "0x01" + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "caller" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055", + "data" : "0x", + "gas" : "0x0186a0", + "gasPrice" : "0x5af3107a4000", + "origin" : "cd1722f2947def4cf144679da39c4c32bdc35681", + "value" : "0x0de0b6b3a7640000" + }, + "gas" : "0x013874", + "logs" : [ + ], + "out" : "0x", + "post" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055", + "nonce" : "0x00", + "storage" : { + "0x00" : "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" + } + } + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "0x0de0b6b3a7640000", + "code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055", + "nonce" : "0x00", + "storage" : { + } + } + } + }"#; + let _deserialized: Vm = serde_json::from_str(s).unwrap(); + // TODO: validate all fields + } +}