Skip to content

Commit

Permalink
feat: extract statetest models/structs to standalone crate (#1808)
Browse files Browse the repository at this point in the history
* feat: split test models to statetest-tests

* chore: attempt documentation

* Update Cargo.toml

* Update Cargo.toml


---------
  • Loading branch information
royvardhan authored Sep 26, 2024
1 parent 411d0ef commit ca5b2fe
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 200 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"crates/state",
"crates/wiring",
"crates/specification",
"crates/statetest-types",

# examples
"examples/block_traces",
Expand All @@ -42,6 +43,7 @@ revm = { path = "crates/revm", version = "14.0.1", default-features = false }
interpreter = { path = "crates/interpreter", package = "revm-interpreter", version = "10.0.1", default-features = false }
inspector = { path = "crates/inspector", package = "revm-inspector", version = "1.0.0", default-features = false }
precompile = { path = "crates/precompile", package = "revm-precompile", version = "11.0.1", default-features = false }
statetest-types = { path = "crates/statetest-types", package = "revm-statetest-types", version = "1.0.0", default-features = false }

[workspace.package]
license = "MIT"
Expand Down
1 change: 1 addition & 0 deletions bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository.workspace = true
# revm
database.workspace = true
revm = { workspace = true, features = ["std", "hashbrown", "c-kzg", "blst"] }
statetest-types = { workspace = true }
inspector = { workspace = true, features = ["std", "serde-json"] }
# enable parse std and parse feature.
bytecode = { workspace = true, features = ["std", "parse"] }
Expand Down
1 change: 0 additions & 1 deletion bins/revme/src/cmd/statetest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod merkle_trie;
pub mod models;
mod runner;
pub mod utils;

Expand Down
198 changes: 0 additions & 198 deletions bins/revme/src/cmd/statetest/models/mod.rs

This file was deleted.

3 changes: 2 additions & 1 deletion bins/revme/src/cmd/statetest/runner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::{
merkle_trie::{log_rlp_hash, state_merkle_trie_root},
models::{SpecName, Test, TestSuite},
utils::recover_address,
};
use database::State;
Expand All @@ -20,6 +19,8 @@ use revm::{
Evm,
};
use serde_json::json;
use statetest_types::{SpecName, Test, TestSuite};

use std::{
fmt::Debug,
io::{stderr, stdout},
Expand Down
Empty file.
28 changes: 28 additions & 0 deletions crates/statetest-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "revm-statetest-types"
description = "State test types for revm"
version = "1.0.0"
authors.workspace = true
edition.workspace = true
keywords.workspace = true
license.workspace = true
repository.workspace = true
readme.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lints.rust]
unreachable_pub = "warn"
unused_must_use = "deny"
rust_2018_idioms = "deny"

[lints.rustdoc]
all = "warn"

[dependencies]
# revm
revm = { workspace = true, features = ["std", "serde"] }
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
21 changes: 21 additions & 0 deletions crates/statetest-types/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021-2024 draganrakita

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions crates/statetest-types/src/account_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use revm::primitives::{Bytes, HashMap, U256};
use serde::Deserialize;

use crate::deserializer::deserialize_str_as_u64;

/// Account information.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct AccountInfo {
pub balance: U256,
pub code: Bytes,
#[serde(deserialize_with = "deserialize_str_as_u64")]
pub nonce: u64,
pub storage: HashMap<U256, U256>,
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use revm::primitives::Address;
use serde::{de, Deserialize};

/// Deserialize a string as a u64.
pub fn deserialize_str_as_u64<'de, D>(deserializer: D) -> Result<u64, D::Error>
where
D: de::Deserializer<'de>,
Expand All @@ -15,6 +16,7 @@ where
.map_err(serde::de::Error::custom)
}

/// Deserialize a string as an optional Address.
pub fn deserialize_maybe_empty<'de, D>(deserializer: D) -> Result<Option<Address>, D::Error>
where
D: de::Deserializer<'de>,
Expand Down
24 changes: 24 additions & 0 deletions crates/statetest-types/src/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use revm::primitives::{Address, B256, U256};
use serde::Deserialize;

/// Environment variables.
#[derive(Debug, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Env {
pub current_coinbase: Address,
#[serde(default)]
pub current_difficulty: U256,
pub current_gas_limit: U256,
pub current_number: U256,
pub current_timestamp: U256,
pub current_base_fee: Option<U256>,
pub previous_hash: Option<B256>,

pub current_random: Option<B256>,
pub current_beacon_root: Option<B256>,
pub current_withdrawals_root: Option<B256>,

pub parent_blob_gas_used: Option<U256>,
pub parent_excess_blob_gas: Option<U256>,
pub current_excess_blob_gas: Option<U256>,
}
Loading

0 comments on commit ca5b2fe

Please sign in to comment.