cleanup json crate (#11027)
* [json]: cleanup write something here.... * nit: commit new/moved files * nit: remove needless features * nits * fix(grumbles): use explicit import `DifficultyTest` * fix(grumbles): remove needless type hints * fix(grumble): docs `from -> used by` Co-Authored-By: David <dvdplm@gmail.com> * fix(grumbles): use explicit `imports` * fix(grumble): merge `tx` and `tx_with_signing_info` * fix(grumbles): resolve introduced `TODO's`
This commit is contained in:
74
json/src/test_helpers/blockchain/block.rs
Normal file
74
json/src/test_helpers/blockchain/block.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Blockchain test block deserializer.
|
||||
|
||||
use crate::{bytes::Bytes, transaction::Transaction};
|
||||
use super::header::Header;
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Blockchain test block deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Block {
|
||||
#[serde(rename = "blockHeader")]
|
||||
header: Option<Header>,
|
||||
rlp: Bytes,
|
||||
transactions: Option<Vec<Transaction>>,
|
||||
#[serde(rename = "uncleHeaders")]
|
||||
uncles: Option<Vec<Header>>,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
/// Returns block rlp.
|
||||
pub fn rlp(&self) -> Vec<u8> {
|
||||
self.rlp.clone().into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Block;
|
||||
|
||||
#[test]
|
||||
fn block_deserialization() {
|
||||
let s = r#"{
|
||||
"blockHeader" : {
|
||||
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
|
||||
"difficulty" : "0x020000",
|
||||
"extraData" : "0x",
|
||||
"gasLimit" : "0x2fefba",
|
||||
"gasUsed" : "0x00",
|
||||
"hash" : "65ebf1b97fb89b14680267e0723d69267ec4bf9a96d4a60ffcb356ae0e81c18f",
|
||||
"mixHash" : "13735ab4156c9b36327224d92e1692fab8fc362f8e0f868c94d421848ef7cd06",
|
||||
"nonce" : "931dcc53e5edc514",
|
||||
"number" : "0x01",
|
||||
"parentHash" : "5a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5ae",
|
||||
"receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"stateRoot" : "c5c83ff43741f573a0c9b31d0e56fdd745f4e37d193c4e78544f302777aafcf3",
|
||||
"timestamp" : "0x56850b7b",
|
||||
"transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
|
||||
},
|
||||
"blocknumber" : "1",
|
||||
"rlp" : "0xf901fcf901f7a05a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5aea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0c5c83ff43741f573a0c9b31d0e56fdd745f4e37d193c4e78544f302777aafcf3a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefba808456850b7b80a013735ab4156c9b36327224d92e1692fab8fc362f8e0f868c94d421848ef7cd0688931dcc53e5edc514c0c0",
|
||||
"transaction" : [],
|
||||
"uncleHeaders" : []
|
||||
}"#;
|
||||
let _deserialized: Block = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
}
|
||||
95
json/src/test_helpers/blockchain/header.rs
Normal file
95
json/src/test_helpers/blockchain/header.rs
Normal file
@@ -0,0 +1,95 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Blockchain test header deserializer.
|
||||
|
||||
use crate::{
|
||||
bytes::Bytes,
|
||||
hash::{H64, Address, H256, Bloom},
|
||||
uint::Uint
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Blockchain test header deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Header {
|
||||
/// Blocks bloom.
|
||||
pub bloom: Bloom,
|
||||
/// Blocks author.
|
||||
#[serde(rename = "coinbase")]
|
||||
pub author: Address,
|
||||
/// Difficulty.
|
||||
pub difficulty: Uint,
|
||||
/// Extra data.
|
||||
pub extra_data: Bytes,
|
||||
/// Gas limit.
|
||||
pub gas_limit: Uint,
|
||||
/// Gas used.
|
||||
pub gas_used: Uint,
|
||||
/// Hash.
|
||||
pub hash: H256,
|
||||
/// Mix hash.
|
||||
pub mix_hash: H256,
|
||||
/// Seal nonce.
|
||||
pub nonce: H64,
|
||||
/// Block number.
|
||||
pub number: Uint,
|
||||
/// Parent hash.
|
||||
pub parent_hash: H256,
|
||||
/// Receipt root.
|
||||
#[serde(rename = "receiptTrie")]
|
||||
pub receipts_root: H256,
|
||||
/// State root.
|
||||
pub state_root: H256,
|
||||
/// Timestamp.
|
||||
pub timestamp: Uint,
|
||||
/// Transactions root.
|
||||
#[serde(rename = "transactionsTrie")]
|
||||
pub transactions_root: H256,
|
||||
/// Uncles hash.
|
||||
#[serde(rename = "uncleHash")]
|
||||
pub uncles_hash: H256,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Header;
|
||||
|
||||
#[test]
|
||||
fn header_deserialization() {
|
||||
let s = r#"{
|
||||
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
|
||||
"difficulty" : "0x020000",
|
||||
"extraData" : "0x",
|
||||
"gasLimit" : "0x2fefba",
|
||||
"gasUsed" : "0x00",
|
||||
"hash" : "65ebf1b97fb89b14680267e0723d69267ec4bf9a96d4a60ffcb356ae0e81c18f",
|
||||
"mixHash" : "13735ab4156c9b36327224d92e1692fab8fc362f8e0f868c94d421848ef7cd06",
|
||||
"nonce" : "931dcc53e5edc514",
|
||||
"number" : "0x01",
|
||||
"parentHash" : "5a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5ae",
|
||||
"receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"stateRoot" : "c5c83ff43741f573a0c9b31d0e56fdd745f4e37d193c4e78544f302777aafcf3",
|
||||
"timestamp" : "0x56850b7b",
|
||||
"transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
|
||||
}"#;
|
||||
let _deserialized: Header = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
}
|
||||
213
json/src/test_helpers/blockchain/mod.rs
Normal file
213
json/src/test_helpers/blockchain/mod.rs
Normal file
@@ -0,0 +1,213 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Blockchain test deserialization.
|
||||
|
||||
use crate::{
|
||||
bytes::Bytes,
|
||||
hash::H256,
|
||||
spec::{Ethereum, ForkSpec, Genesis, Seal, State}
|
||||
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
pub mod block;
|
||||
pub mod header;
|
||||
|
||||
pub use self::block::Block;
|
||||
pub use self::header::Header;
|
||||
|
||||
/// Type for running `Blockchain` tests
|
||||
pub type Test = super::tester::GenericTester<String, BlockChain>;
|
||||
|
||||
/// Json Block test possible engine kind.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub enum Engine {
|
||||
/// Default (old) behaviour.
|
||||
Ethash,
|
||||
/// No check of block's difficulty and nonce for tests.
|
||||
NoProof,
|
||||
}
|
||||
|
||||
impl Default for Engine {
|
||||
fn default() -> Self {
|
||||
Engine::Ethash
|
||||
}
|
||||
}
|
||||
|
||||
/// Blockchain deserialization.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct BlockChain {
|
||||
/// Genesis block header.
|
||||
#[serde(rename = "genesisBlockHeader")]
|
||||
pub genesis_block: Header,
|
||||
/// Genesis block rlp.
|
||||
#[serde(rename = "genesisRLP")]
|
||||
pub genesis_rlp: Option<Bytes>,
|
||||
/// Blocks.
|
||||
pub blocks: Vec<Block>,
|
||||
/// Post state.
|
||||
pub post_state: State,
|
||||
/// Pre state.
|
||||
#[serde(rename = "pre")]
|
||||
pub pre_state: State,
|
||||
/// Hash of best block.
|
||||
#[serde(rename = "lastblockhash")]
|
||||
pub best_block: H256,
|
||||
/// Network.
|
||||
pub network: ForkSpec,
|
||||
#[serde(default)]
|
||||
#[serde(rename="sealEngine")]
|
||||
/// Engine
|
||||
pub engine: Engine,
|
||||
}
|
||||
|
||||
impl BlockChain {
|
||||
/// Returns blocks rlp.
|
||||
pub fn blocks_rlp(&self) -> Vec<Vec<u8>> {
|
||||
self.blocks.iter().map(|block| block.rlp()).collect()
|
||||
}
|
||||
|
||||
/// Returns spec compatible genesis struct.
|
||||
pub fn genesis(&self) -> Genesis {
|
||||
Genesis {
|
||||
seal: Seal::Ethereum(Ethereum {
|
||||
nonce: self.genesis_block.nonce.clone(),
|
||||
mix_hash: self.genesis_block.mix_hash.clone(),
|
||||
}),
|
||||
difficulty: self.genesis_block.difficulty,
|
||||
author: Some(self.genesis_block.author.clone()),
|
||||
timestamp: Some(self.genesis_block.timestamp),
|
||||
parent_hash: Some(self.genesis_block.parent_hash.clone()),
|
||||
gas_limit: self.genesis_block.gas_limit,
|
||||
transactions_root: Some(self.genesis_block.transactions_root.clone()),
|
||||
receipts_root: Some(self.genesis_block.receipts_root.clone()),
|
||||
state_root: Some(self.genesis_block.state_root.clone()),
|
||||
gas_used: Some(self.genesis_block.gas_used),
|
||||
extra_data: Some(self.genesis_block.extra_data.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::BlockChain;
|
||||
|
||||
#[test]
|
||||
fn blockchain_deserialization() {
|
||||
let s = r#"{
|
||||
"blocks" : [{
|
||||
"blockHeader" : {
|
||||
"bloom" : "00000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000040000000000000000000000000000000000000000000000000000000",
|
||||
"coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
|
||||
"difficulty" : "0x020000",
|
||||
"extraData" : "0x0102030405060708091011121314151617181920212223242526272829303132",
|
||||
"gasLimit" : "0x2fefba",
|
||||
"gasUsed" : "0x560b",
|
||||
"hash" : "06b5b1742bde29468510c92641f36b719c61b3fc3e9a21c92a23978f4f7faa2a",
|
||||
"mixHash" : "5266ca43e81d25925a9ba573c3e4f9180bc076d316d90e63c6f8708b272f5ce2",
|
||||
"nonce" : "59ba4daed1898e21",
|
||||
"number" : "0x01",
|
||||
"parentHash" : "f052d217bd5275a5177a3c3b7debdfe2670f1c8394b2965ccd5c1883cc1a524d",
|
||||
"receiptTrie" : "c7778a7376099ee2e5c455791c1885b5c361b95713fddcbe32d97fd01334d296",
|
||||
"stateRoot" : "bac6177a79e910c98d86ec31a09ae37ac2de15b754fd7bed1ba52362c49416bf",
|
||||
"timestamp" : "0x56850c2c",
|
||||
"transactionsTrie" : "498785da562aa0c5dd5937cf15f22139b0b1bcf3b4fc48986e1bb1dae9292796",
|
||||
"uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
|
||||
},
|
||||
"rlp" : "0xf90285f90219a0f052d217bd5275a5177a3c3b7debdfe2670f1c8394b2965ccd5c1883cc1a524da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0bac6177a79e910c98d86ec31a09ae37ac2de15b754fd7bed1ba52362c49416bfa0498785da562aa0c5dd5937cf15f22139b0b1bcf3b4fc48986e1bb1dae9292796a0c7778a7376099ee2e5c455791c1885b5c361b95713fddcbe32d97fd01334d296b90100000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000400000000000000000000000000000000000000000000000000000008302000001832fefba82560b8456850c2ca00102030405060708091011121314151617181920212223242526272829303132a05266ca43e81d25925a9ba573c3e4f9180bc076d316d90e63c6f8708b272f5ce28859ba4daed1898e21f866f864800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d8785012a05f200801ca0ee0b9ec878fbd4258a9473199d8ecc32996a20c323c004e79e0cda20e0418ce3a04e6bc63927d1510bab54f37e46fa036faf4b2c465d271920d9afea1fadf7bd21c0",
|
||||
"transactions" : [
|
||||
{
|
||||
"data" : "0x00",
|
||||
"gasLimit" : "0xc350",
|
||||
"gasPrice" : "0x0a",
|
||||
"nonce" : "0x00",
|
||||
"r" : "0xee0b9ec878fbd4258a9473199d8ecc32996a20c323c004e79e0cda20e0418ce3",
|
||||
"s" : "0x4e6bc63927d1510bab54f37e46fa036faf4b2c465d271920d9afea1fadf7bd21",
|
||||
"to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"v" : "0x1c",
|
||||
"value" : "0x012a05f200"
|
||||
}
|
||||
],
|
||||
"uncleHeaders" : [
|
||||
]
|
||||
}],
|
||||
"network" : "Frontier",
|
||||
"genesisBlockHeader" : {
|
||||
"bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
"coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
|
||||
"difficulty" : "0x020000",
|
||||
"extraData" : "0x42",
|
||||
"gasLimit" : "0x2fefd8",
|
||||
"gasUsed" : "0x00",
|
||||
"hash" : "f052d217bd5275a5177a3c3b7debdfe2670f1c8394b2965ccd5c1883cc1a524d",
|
||||
"mixHash" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"nonce" : "0102030405060708",
|
||||
"number" : "0x00",
|
||||
"parentHash" : "0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"stateRoot" : "925002c3260b44e44c3edebad1cc442142b03020209df1ab8bb86752edbd2cd7",
|
||||
"timestamp" : "0x54c98c81",
|
||||
"transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
||||
"uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
|
||||
},
|
||||
"genesisRLP" : "0xf901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0925002c3260b44e44c3edebad1cc442142b03020209df1ab8bb86752edbd2cd7a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8808454c98c8142a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421880102030405060708c0c0",
|
||||
"lastblockhash" : "06b5b1742bde29468510c92641f36b719c61b3fc3e9a21c92a23978f4f7faa2a",
|
||||
"postState" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "0x012a05f264",
|
||||
"code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600052600060206000a1",
|
||||
"nonce" : "0x00",
|
||||
"storage" : {
|
||||
}
|
||||
},
|
||||
"8888f1f195afa192cfee860698584c030f4c9db1" : {
|
||||
"balance" : "0x4563918244f75c6e",
|
||||
"code" : "0x",
|
||||
"nonce" : "0x00",
|
||||
"storage" : {
|
||||
}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "0x012a029592",
|
||||
"code" : "0x",
|
||||
"nonce" : "0x01",
|
||||
"storage" : {
|
||||
}
|
||||
}
|
||||
},
|
||||
"pre" : {
|
||||
"095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
|
||||
"balance" : "0x64",
|
||||
"code" : "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600052600060206000a1",
|
||||
"nonce" : "0x00",
|
||||
"storage" : {
|
||||
}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
|
||||
"balance" : "0x02540be400",
|
||||
"code" : "0x",
|
||||
"nonce" : "0x00",
|
||||
"storage" : {
|
||||
}
|
||||
}
|
||||
}
|
||||
}"#;
|
||||
let _deserialized: BlockChain = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
}
|
||||
23
json/src/test_helpers/difficulty.rs
Normal file
23
json/src/test_helpers/difficulty.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use crate::{hash::H256, uint::Uint};
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Blockchain test header deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DifficultyTestCase {
|
||||
/// Parent timestamp.
|
||||
pub parent_timestamp: Uint,
|
||||
/// Parent difficulty.
|
||||
pub parent_difficulty: Uint,
|
||||
/// Parent uncle hash.
|
||||
pub parent_uncles: H256,
|
||||
/// Current timestamp.
|
||||
pub current_timestamp: Uint,
|
||||
/// Current difficulty.
|
||||
pub current_difficulty: Uint,
|
||||
/// Current block number.
|
||||
pub current_block_number: Uint,
|
||||
}
|
||||
|
||||
/// Type for running `Difficulty` tests
|
||||
pub type DifficultyTest = super::tester::GenericTester<String, DifficultyTestCase>;
|
||||
37
json/src/test_helpers/mod.rs
Normal file
37
json/src/test_helpers/mod.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Test structures for JSON deserialization.
|
||||
|
||||
/// Blockchain test helpers
|
||||
pub mod blockchain;
|
||||
/// Difficulty test helpers
|
||||
pub mod difficulty;
|
||||
/// Tests to skip helpers
|
||||
pub mod skip;
|
||||
/// State test helpers
|
||||
pub mod state;
|
||||
/// Test primitives
|
||||
pub mod tester;
|
||||
/// Transaction test helpers
|
||||
pub mod transaction;
|
||||
/// Trie test helpers
|
||||
pub mod trie;
|
||||
/// Vm test helpers
|
||||
pub mod vm {
|
||||
/// Type for running `vm` tests
|
||||
pub type Test = super::tester::GenericTester<String, crate::vm::Vm>;
|
||||
}
|
||||
58
json/src/test_helpers/skip.rs
Normal file
58
json/src/test_helpers/skip.rs
Normal file
@@ -0,0 +1,58 @@
|
||||
use std::collections::BTreeMap;
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Test to skip (only if issue ongoing)
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct SkipStates {
|
||||
/// Block tests
|
||||
pub block: Vec<BlockSkipStates>,
|
||||
/// State tests
|
||||
pub state: Vec<StateSkipStates>,
|
||||
|
||||
}
|
||||
|
||||
/// Block test to skip.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct BlockSkipStates {
|
||||
/// Issue reference.
|
||||
pub reference: String,
|
||||
/// Test failing name.
|
||||
pub failing: String,
|
||||
/// Items failing for the test.
|
||||
pub subtests: Vec<String>,
|
||||
}
|
||||
|
||||
/// State test to skip.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct StateSkipStates {
|
||||
/// Issue reference.
|
||||
pub reference: String,
|
||||
/// Test failing name.
|
||||
pub failing: String,
|
||||
/// Items failing for the test.
|
||||
pub subtests: BTreeMap<String, StateSkipSubStates>
|
||||
}
|
||||
|
||||
/// State subtest to skip.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct StateSkipSubStates {
|
||||
/// State test number of this item. Or '*' for all state.
|
||||
pub subnumbers: Vec<String>,
|
||||
/// Chain for this items.
|
||||
pub chain: String,
|
||||
}
|
||||
|
||||
impl SkipStates {
|
||||
/// Empty skip states.
|
||||
pub fn empty() -> Self {
|
||||
SkipStates {
|
||||
block: Vec::new(),
|
||||
state: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Loads test from json.
|
||||
pub fn load<R>(reader: R) -> Result<Self, serde_json::Error> where R: std::io::Read {
|
||||
serde_json::from_reader(reader)
|
||||
}
|
||||
}
|
||||
203
json/src/test_helpers/state.rs
Normal file
203
json/src/test_helpers/state.rs
Normal file
@@ -0,0 +1,203 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! State test deserialization.
|
||||
|
||||
/// Type for running `State` tests
|
||||
pub type Test = super::tester::GenericTester<String, State>;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use serde::Deserialize;
|
||||
use crate::{
|
||||
bytes::Bytes,
|
||||
hash::{Address, H256},
|
||||
maybe::MaybeEmpty,
|
||||
uint::Uint,
|
||||
spec::{ForkSpec, State as AccountState},
|
||||
transaction::Transaction,
|
||||
vm::Env
|
||||
};
|
||||
|
||||
/// 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,
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
}
|
||||
|
||||
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],
|
||||
gas_price: self.gas_price,
|
||||
nonce: self.nonce,
|
||||
to: self.to.clone(),
|
||||
value: self.value[indexes.value as usize],
|
||||
r: Default::default(),
|
||||
s: Default::default(),
|
||||
v: Default::default(),
|
||||
secret: self.secret.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,
|
||||
}
|
||||
|
||||
/// State test indexed state result deserialization.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct PostStateResult {
|
||||
/// Post state hash
|
||||
pub hash: H256,
|
||||
/// Indexes
|
||||
pub indexes: PostStateIndexes,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json;
|
||||
use super::{MultiTransaction, State};
|
||||
|
||||
#[test]
|
||||
fn multi_transaction_deserialization() {
|
||||
let s = r#"{
|
||||
"data": [ "" ],
|
||||
"gasLimit": [ "0x2dc6c0", "0x222222" ],
|
||||
"gasPrice": "0x01",
|
||||
"nonce": "0x00",
|
||||
"secretKey": "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"to": "1000000000000000000000000000000000000000",
|
||||
"value": [ "0x00", "0x01", "0x02" ]
|
||||
}"#;
|
||||
let _deserialized: MultiTransaction = serde_json::from_str(s).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_deserialization() {
|
||||
let s = r#"{
|
||||
"env": {
|
||||
"currentCoinbase": "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
|
||||
"currentDifficulty": "0x0100",
|
||||
"currentGasLimit": "0x01c9c380",
|
||||
"currentNumber": "0x00",
|
||||
"currentTimestamp": "0x01",
|
||||
"previousHash": "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"
|
||||
},
|
||||
"post": {
|
||||
"EIP150": [
|
||||
{
|
||||
"hash": "3e6dacc1575c6a8c76422255eca03529bbf4c0dda75dfc110b22d6dc4152396f",
|
||||
"indexes": { "data": 0, "gas": 0, "value": 0 }
|
||||
},
|
||||
{
|
||||
"hash": "99a450d8ce5b987a71346d8a0a1203711f770745c7ef326912e46761f14cd764",
|
||||
"indexes": { "data": 0, "gas": 0, "value": 1 }
|
||||
}
|
||||
],
|
||||
"EIP158": [
|
||||
{
|
||||
"hash": "3e6dacc1575c6a8c76422255eca03529bbf4c0dda75dfc110b22d6dc4152396f",
|
||||
"indexes": { "data": 0, "gas": 0, "value": 0 }
|
||||
},
|
||||
{
|
||||
"hash": "99a450d8ce5b987a71346d8a0a1203711f770745c7ef326912e46761f14cd764",
|
||||
"indexes": { "data": 0, "gas": 0, "value": 1 }
|
||||
}
|
||||
]
|
||||
},
|
||||
"pre": {
|
||||
"1000000000000000000000000000000000000000": {
|
||||
"balance": "0x0de0b6b3a7640000",
|
||||
"code": "0x6040600060406000600173100000000000000000000000000000000000000162055730f1600055",
|
||||
"nonce": "0x00",
|
||||
"storage": {
|
||||
}
|
||||
},
|
||||
"1000000000000000000000000000000000000001": {
|
||||
"balance": "0x0de0b6b3a7640000",
|
||||
"code": "0x604060006040600060027310000000000000000000000000000000000000026203d090f1600155",
|
||||
"nonce": "0x00",
|
||||
"storage": {
|
||||
}
|
||||
},
|
||||
"1000000000000000000000000000000000000002": {
|
||||
"balance": "0x00",
|
||||
"code": "0x600160025533600455346007553060e6553260e8553660ec553860ee553a60f055",
|
||||
"nonce": "0x00",
|
||||
"storage": {
|
||||
}
|
||||
},
|
||||
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
|
||||
"balance": "0x0de0b6b3a7640000",
|
||||
"code": "0x",
|
||||
"nonce": "0x00",
|
||||
"storage": {
|
||||
}
|
||||
}
|
||||
},
|
||||
"transaction": {
|
||||
"data": [ "" ],
|
||||
"gasLimit": [ "285000", "100000", "6000" ],
|
||||
"gasPrice": "0x01",
|
||||
"nonce": "0x00",
|
||||
"secretKey": "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8",
|
||||
"to": "095e7baea6a6c7c4c2dfeb977efac326af552d87",
|
||||
"value": [ "10", "0" ]
|
||||
}
|
||||
}"#;
|
||||
let _deserialized: State = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
}
|
||||
27
json/src/test_helpers/tester.rs
Normal file
27
json/src/test_helpers/tester.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use std::collections::BTreeMap;
|
||||
use serde::Deserialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
/// A genric wrapper over a `BTreeMap` for tests
|
||||
#[derive(Deserialize)]
|
||||
pub struct GenericTester<T: Ord, U>(BTreeMap<T, U>);
|
||||
|
||||
impl<T: Ord, U> IntoIterator for GenericTester<T, U> {
|
||||
type Item = <BTreeMap<T, U> as IntoIterator>::Item;
|
||||
type IntoIter = <BTreeMap<T, U> as IntoIterator>::IntoIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U> GenericTester<T, U>
|
||||
where
|
||||
T: DeserializeOwned + Ord,
|
||||
U: DeserializeOwned
|
||||
{
|
||||
/// Loads test from json.
|
||||
pub fn load<R>(reader: R) -> Result<Self, serde_json::Error> where R: std::io::Read {
|
||||
serde_json::from_reader(reader)
|
||||
}
|
||||
}
|
||||
83
json/src/test_helpers/transaction.rs
Normal file
83
json/src/test_helpers/transaction.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Transaction test deserialization.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use crate::{bytes::Bytes, hash::{Address, H256}, spec::ForkSpec};
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Type for running `Transaction` tests
|
||||
pub type Test = super::tester::GenericTester<String, TransactionTest>;
|
||||
|
||||
/// Transaction test deserialization.
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct TransactionTest {
|
||||
pub rlp: Bytes,
|
||||
pub _info: serde::de::IgnoredAny,
|
||||
#[serde(flatten)]
|
||||
pub post_state: BTreeMap<ForkSpec, PostState>,
|
||||
}
|
||||
|
||||
/// TransactionTest post state.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct PostState {
|
||||
/// Transaction sender.
|
||||
pub sender: Option<Address>,
|
||||
/// Transaction hash.
|
||||
pub hash: Option<H256>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::TransactionTest;
|
||||
|
||||
#[test]
|
||||
fn transaction_deserialization() {
|
||||
let s = r#"{
|
||||
"Byzantium" : {
|
||||
"hash" : "4782cb5edcaeda1f0aef204b161214f124cefade9e146245183abbb9ca01bca5",
|
||||
"sender" : "2ea991808ba979ba103147edfd72304ebd95c028"
|
||||
},
|
||||
"Constantinople" : {
|
||||
"hash" : "4782cb5edcaeda1f0aef204b161214f124cefade9e146245183abbb9ca01bca5",
|
||||
"sender" : "2ea991808ba979ba103147edfd72304ebd95c028"
|
||||
},
|
||||
"EIP150" : {
|
||||
},
|
||||
"EIP158" : {
|
||||
"hash" : "4782cb5edcaeda1f0aef204b161214f124cefade9e146245183abbb9ca01bca5",
|
||||
"sender" : "2ea991808ba979ba103147edfd72304ebd95c028"
|
||||
},
|
||||
"Frontier" : {
|
||||
},
|
||||
"Homestead" : {
|
||||
},
|
||||
"_info" : {
|
||||
"comment" : "",
|
||||
"filledwith" : "cpp-1.3.0+commit.1829957d.Linux.g++",
|
||||
"lllcversion" : "Version: 0.4.18-develop.2017.10.11+commit.81f9f86c.Linux.g++",
|
||||
"source" : "src/TransactionTestsFiller/ttVValue/V_equals37Filler.json",
|
||||
"sourceHash" : "89ef69312d4c0b4e3742da501263d23d2a64f180258ac93940997ac6a17b9b19"
|
||||
},
|
||||
"rlp" : "0xf865808698852840a46f82d6d894095e7baea6a6c7c4c2dfeb977efac326af552d87808025a098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa01887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3"
|
||||
}"#;
|
||||
|
||||
let _deserialized: TransactionTest = serde_json::from_str(s).unwrap();
|
||||
// TODO: validate all fields
|
||||
}
|
||||
}
|
||||
153
json/src/test_helpers/trie/input.rs
Normal file
153
json/src/test_helpers/trie/input.rs
Normal file
@@ -0,0 +1,153 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Trie test input deserialization.
|
||||
|
||||
use std::fmt;
|
||||
use std::collections::BTreeMap;
|
||||
use std::str::FromStr;
|
||||
use crate::bytes::Bytes;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use serde::de::{Error as ErrorTrait, Visitor, MapAccess, SeqAccess};
|
||||
|
||||
/// Trie test input.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Input {
|
||||
/// Input params.
|
||||
pub data: BTreeMap<Bytes, Option<Bytes>>,
|
||||
}
|
||||
|
||||
impl<'a> Deserialize<'a> for Input {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: Deserializer<'a>
|
||||
{
|
||||
deserializer.deserialize_any(InputVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct InputVisitor;
|
||||
|
||||
impl<'a> Visitor<'a> for InputVisitor {
|
||||
type Value = Input;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(formatter, "a map of bytes into bytes")
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> where V: MapAccess<'a> {
|
||||
let mut result = BTreeMap::new();
|
||||
|
||||
loop {
|
||||
let key_str: Option<String> = visitor.next_key()?;
|
||||
let key = match key_str {
|
||||
Some(ref k) if k.starts_with("0x") => Bytes::from_str(k).map_err(V::Error::custom)?,
|
||||
Some(k) => Bytes::new(k.into_bytes()),
|
||||
None => { break; }
|
||||
};
|
||||
|
||||
let val_str: Option<String> = visitor.next_value()?;
|
||||
let val = match val_str {
|
||||
Some(ref v) if v.starts_with("0x") => Some(Bytes::from_str(v).map_err(V::Error::custom)?),
|
||||
Some(v) => Some(Bytes::new(v.into_bytes())),
|
||||
None => None,
|
||||
};
|
||||
|
||||
result.insert(key, val);
|
||||
}
|
||||
|
||||
let input = Input {
|
||||
data: result
|
||||
};
|
||||
|
||||
Ok(input)
|
||||
}
|
||||
|
||||
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> where V: SeqAccess<'a> {
|
||||
let mut result = BTreeMap::new();
|
||||
|
||||
loop {
|
||||
let keyval: Option<Vec<Option<String>>> = visitor.next_element()?;
|
||||
let keyval = match keyval {
|
||||
Some(k) => k,
|
||||
_ => { break; },
|
||||
};
|
||||
|
||||
if keyval.len() != 2 {
|
||||
return Err(V::Error::custom("Invalid key value pair."));
|
||||
}
|
||||
|
||||
let key_str = &keyval[0];
|
||||
let val_str = &keyval[1];
|
||||
|
||||
let key = match *key_str {
|
||||
Some(ref k) if k.starts_with("0x") => Bytes::from_str(k).map_err(V::Error::custom)?,
|
||||
Some(ref k) => Bytes::new(k.clone().into_bytes()),
|
||||
None => { break; }
|
||||
};
|
||||
|
||||
let val = match *val_str {
|
||||
Some(ref v) if v.starts_with("0x") => Some(Bytes::from_str(v).map_err(V::Error::custom)?),
|
||||
Some(ref v) => Some(Bytes::new(v.clone().into_bytes())),
|
||||
None => None,
|
||||
};
|
||||
|
||||
result.insert(key, val);
|
||||
}
|
||||
|
||||
let input = Input {
|
||||
data: result
|
||||
};
|
||||
|
||||
Ok(input)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{BTreeMap, Bytes, Input};
|
||||
|
||||
#[test]
|
||||
fn input_deserialization_from_map() {
|
||||
let s = r#"{
|
||||
"0x0045" : "0x0123456789",
|
||||
"be" : "e",
|
||||
"0x0a" : null
|
||||
}"#;
|
||||
|
||||
let input: Input = serde_json::from_str(s).unwrap();
|
||||
let mut map = BTreeMap::new();
|
||||
map.insert(Bytes::new(vec![0, 0x45]), Some(Bytes::new(vec![0x01, 0x23, 0x45, 0x67, 0x89])));
|
||||
map.insert(Bytes::new(vec![0x62, 0x65]), Some(Bytes::new(vec![0x65])));
|
||||
map.insert(Bytes::new(vec![0x0a]), None);
|
||||
assert_eq!(input.data, map);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn input_deserialization_from_array() {
|
||||
let s = r#"[
|
||||
["0x0045", "0x0123456789"],
|
||||
["be", "e"],
|
||||
["0x0a", null]
|
||||
]"#;
|
||||
|
||||
let input: Input = serde_json::from_str(s).unwrap();
|
||||
let mut map = BTreeMap::new();
|
||||
map.insert(Bytes::new(vec![0, 0x45]), Some(Bytes::new(vec![0x01, 0x23, 0x45, 0x67, 0x89])));
|
||||
map.insert(Bytes::new(vec![0x62, 0x65]), Some(Bytes::new(vec![0x65])));
|
||||
map.insert(Bytes::new(vec![0x0a]), None);
|
||||
assert_eq!(input.data, map);
|
||||
}
|
||||
}
|
||||
37
json/src/test_helpers/trie/mod.rs
Normal file
37
json/src/test_helpers/trie/mod.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Ethereum.
|
||||
|
||||
// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Trie test deserialization.
|
||||
|
||||
mod input;
|
||||
|
||||
pub use self::input::Input;
|
||||
|
||||
/// Type used by `trie` tests
|
||||
pub type Test = super::tester::GenericTester<String, Trie>;
|
||||
|
||||
use serde::Deserialize;
|
||||
use crate::hash::H256;
|
||||
|
||||
/// Trie test deserialization.
|
||||
#[derive(Debug, Deserialize, PartialEq)]
|
||||
pub struct Trie {
|
||||
/// Trie test input.
|
||||
#[serde(rename = "in")]
|
||||
pub input: Input,
|
||||
/// Trie root hash.
|
||||
pub root: H256,
|
||||
}
|
||||
Reference in New Issue
Block a user