json-tests vm loading

This commit is contained in:
debris 2016-03-23 18:36:05 +01:00
parent 038b67cbd4
commit 3352b0e916
7 changed files with 360 additions and 0 deletions

View File

@ -24,3 +24,4 @@ pub mod uint;
pub mod bytes;
pub mod blockchain;
pub mod spec;
pub mod vm;

53
json/src/vm/call.rs Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
//! 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
}
}

58
json/src/vm/env.rs Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
//! 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
}
}

54
json/src/vm/log.rs Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
//! 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<H256>,
}
#[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
}
}

29
json/src/vm/mod.rs Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
//! 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;

View File

@ -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/>.
//! 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();
}
}

101
json/src/vm/vm.rs Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
//! 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<Vec<Call>>,
/// Executed transaction
#[serde(rename="exec")]
pub exec: Transaction,
/// Gas.
pub gas: Uint,
/// Logs created during execution of transaction.
pub logs: Vec<Log>,
/// 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
}
}