Local EIP2930 and EN/DE block tests (#237)
This commit is contained in:
@@ -23,11 +23,11 @@ use bytes::Bytes;
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct Block {
|
||||
#[serde(rename = "blockHeader")]
|
||||
header: Option<Header>,
|
||||
rlp: Bytes,
|
||||
transactions: Option<Vec<Transaction>>,
|
||||
pub header: Option<Header>,
|
||||
pub rlp: Bytes,
|
||||
pub transactions: Option<Vec<Transaction>>,
|
||||
#[serde(rename = "uncleHeaders")]
|
||||
uncles: Option<Vec<Header>>,
|
||||
pub uncles: Option<Vec<Header>>,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
|
||||
@@ -17,18 +17,31 @@
|
||||
//! Blockchain test transaction deserialization.
|
||||
|
||||
use bytes::Bytes;
|
||||
use ethereum_types::{H160, H256};
|
||||
use uint::Uint;
|
||||
|
||||
/// Blockchain test transaction deserialization.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Transaction {
|
||||
data: Bytes,
|
||||
gas_limit: Uint,
|
||||
gas_price: Uint,
|
||||
nonce: Uint,
|
||||
r: Uint,
|
||||
s: Uint,
|
||||
v: Uint,
|
||||
value: Uint,
|
||||
#[serde(rename = "type")]
|
||||
pub transaction_type: Option<Uint>,
|
||||
pub data: Bytes,
|
||||
pub gas_limit: Uint,
|
||||
pub gas_price: Uint,
|
||||
pub nonce: Uint,
|
||||
pub r: Uint,
|
||||
pub s: Uint,
|
||||
pub v: Uint,
|
||||
pub value: Uint,
|
||||
pub chain_id: Option<Uint>,
|
||||
pub access_list: Option<Vec<AccessList>>,
|
||||
pub hash: Option<H256>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AccessList {
|
||||
pub address: H160,
|
||||
pub storage_keys: Vec<H256>,
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ use std::{fmt, ops::Deref, str::FromStr};
|
||||
|
||||
/// Lenient bytes json deserialization for test json files.
|
||||
#[derive(Default, Debug, PartialEq, Eq, Clone, PartialOrd, Ord)]
|
||||
pub struct Bytes(Vec<u8>);
|
||||
pub struct Bytes(pub Vec<u8>);
|
||||
|
||||
impl Bytes {
|
||||
/// Creates bytes struct.
|
||||
|
||||
@@ -31,6 +31,7 @@ extern crate maplit;
|
||||
pub mod blockchain;
|
||||
pub mod bytes;
|
||||
pub mod hash;
|
||||
pub mod local_tests;
|
||||
pub mod maybe;
|
||||
pub mod spec;
|
||||
pub mod state;
|
||||
|
||||
26
crates/ethjson/src/local_tests/mod.rs
Normal file
26
crates/ethjson/src/local_tests/mod.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use blockchain::block::Block;
|
||||
use serde_json::{self, Error};
|
||||
use std::{collections::BTreeMap, io::Read};
|
||||
|
||||
/// Blockchain test deserializer.
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct BlockEnDeTest(BTreeMap<String, Block>);
|
||||
|
||||
impl IntoIterator for BlockEnDeTest {
|
||||
type Item = <BTreeMap<String, Block> as IntoIterator>::Item;
|
||||
type IntoIter = <BTreeMap<String, Block> as IntoIterator>::IntoIter;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl BlockEnDeTest {
|
||||
/// Loads test from json.
|
||||
pub fn load<R>(reader: R) -> Result<Self, Error>
|
||||
where
|
||||
R: Read,
|
||||
{
|
||||
serde_json::from_reader(reader)
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ use std::io::Read;
|
||||
pub enum ForkSpec {
|
||||
EIP150,
|
||||
EIP158,
|
||||
EIP2930,
|
||||
Frontier,
|
||||
Homestead,
|
||||
Byzantium,
|
||||
|
||||
@@ -123,6 +123,8 @@ impl SkipStates {
|
||||
/// Describes a github.com/ethereum/tests suite
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct EthereumTestSuite {
|
||||
/// local tests
|
||||
pub local: Vec<LocalTests>,
|
||||
/// Blockchain tests
|
||||
pub chain: Vec<ChainTests>,
|
||||
/// State tests
|
||||
@@ -159,6 +161,15 @@ pub enum TestTrieSpec {
|
||||
Secure,
|
||||
}
|
||||
|
||||
/// A set of local tests
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct LocalTests {
|
||||
/// Path of the json tests
|
||||
pub path: PathBuf,
|
||||
/// Test type
|
||||
pub test_type: String,
|
||||
}
|
||||
|
||||
/// A set of blockchain tests
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
pub struct ChainTests {
|
||||
|
||||
Reference in New Issue
Block a user