Local EIP2930 and EN/DE block tests (#237)

This commit is contained in:
rakita
2021-01-28 17:23:01 +01:00
committed by GitHub
parent 52d966ccaa
commit cfc6439f2e
29 changed files with 6724 additions and 29 deletions

View File

@@ -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 {

View File

@@ -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>,
}

View File

@@ -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.

View File

@@ -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;

View 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)
}
}

View File

@@ -25,6 +25,7 @@ use std::io::Read;
pub enum ForkSpec {
EIP150,
EIP158,
EIP2930,
Frontier,
Homestead,
Byzantium,

View File

@@ -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 {