revm_statetest_types/test_unit.rs
1use serde::Deserialize;
2use std::collections::{BTreeMap, HashMap};
3
4use crate::{AccountInfo, Env, SpecName, Test, TransactionParts};
5use revm::primitives::{Address, Bytes};
6
7/// Single test unit struct
8#[derive(Debug, PartialEq, Eq, Deserialize)]
9//#[serde(deny_unknown_fields)]
10// field config
11pub struct TestUnit {
12 /// Test info is optional.
13 #[serde(default, rename = "_info")]
14 pub info: Option<serde_json::Value>,
15
16 /// Test environment configuration.
17 ///
18 /// Contains the environmental information for executing the test, including
19 /// block information, coinbase address, difficulty, gas limit, and other
20 /// blockchain state parameters required for proper test execution.
21 pub env: Env,
22
23 /// Pre-execution state.
24 ///
25 /// A mapping of addresses to their account information before the transaction
26 /// is executed. This represents the initial state of all accounts involved
27 /// in the test, including their balances, nonces, code, and storage.
28 pub pre: HashMap<Address, AccountInfo>,
29
30 /// Post-execution expectations per specification.
31 ///
32 /// Maps each Ethereum specification name (hardfork) to a vector of expected
33 /// test results. This allows a single test to define different expected outcomes
34 /// for different protocol versions, enabling comprehensive testing across
35 /// multiple Ethereum upgrades.
36 pub post: BTreeMap<SpecName, Vec<Test>>,
37
38 /// Transaction details to be executed.
39 ///
40 /// Contains the transaction parameters that will be executed against the
41 /// pre-state. This includes sender, recipient, value, data, gas limits,
42 /// and other transaction fields that may vary based on indices.
43 pub transaction: TransactionParts,
44
45 /// Expected output data from the transaction execution.
46 ///
47 /// Optional field containing the expected return data from the transaction.
48 /// This is typically used for testing contract calls that return specific
49 /// values or for CREATE operations that return deployed contract addresses.
50 #[serde(default)]
51 pub out: Option<Bytes>,
52 //pub config
53}