1mod env;
2mod transaction;
3
4pub use env::*;
5pub use transaction::*;
6
7use serde::Deserialize;
8use std::collections::{BTreeMap, HashMap};
9
10use crate::{AccountInfo, Config, SpecName};
11use cfx_rpc_primitives::Bytes;
12use cfx_types::{Address, H256};
13
14#[derive(Debug, PartialEq, Eq, Deserialize)]
16#[serde(rename_all = "camelCase", deny_unknown_fields)]
17pub struct StateTest {
18 pub expect_exception: Option<String>,
19
20 pub indexes: TxPartIndices,
22 pub hash: H256,
24 pub logs: H256,
29
30 #[serde(default)]
34 pub state: HashMap<Address, AccountInfo>,
35
36 pub txbytes: Option<Bytes>,
38}
39
40#[derive(Debug, PartialEq, Eq, Deserialize)]
42pub struct StateTestUnit {
45 #[serde(default, rename = "_info")]
47 pub info: Option<serde_json::Value>,
48
49 pub env: Env,
50 pub pre: HashMap<Address, AccountInfo>,
51 pub post: BTreeMap<SpecName, Vec<StateTest>>,
52 pub transaction: TransactionParts,
53 #[serde(default)]
54 pub out: Option<Bytes>,
55 pub config: Config,
56}
57
58#[derive(Debug, PartialEq, Eq, Deserialize)]
60pub struct StateTestSuite(pub BTreeMap<String, StateTestUnit>);
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn deserialize_test_unit() {
68 let json = r#"
69 {
70 "env": {
71 "currentCoinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
72 "currentGasLimit": "0x016345785d8a0000",
73 "currentNumber": "0x01",
74 "currentTimestamp": "0x03e8",
75 "currentRandom": "0x0000000000000000000000000000000000000000000000000000000000000000",
76 "currentDifficulty": "0x00",
77 "currentBaseFee": "0x07",
78 "currentExcessBlobGas": "0x0e0000"
79 },
80 "pre": {
81 "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
82 "nonce": "0x00",
83 "balance": "0x04b2e7dc",
84 "code": "0x",
85 "storage": {}
86 }
87 },
88 "transaction": {
89 "nonce": "0x00",
90 "maxPriorityFeePerGas": "0x00",
91 "maxFeePerGas": "0x07",
92 "gasLimit": [
93 "0x6a44"
94 ],
95 "to": "0x8a0a19589531694250d570040a0c4b74576919b8",
96 "value": [
97 "0x00"
98 ],
99 "data": [
100 "0x00"
101 ],
102 "accessLists": [
103 [
104 {
105 "address": "0x0000000000000000000000000000000000000064",
106 "storageKeys": [
107 "0x0000000000000000000000000000000000000000000000000000000000000064",
108 "0x00000000000000000000000000000000000000000000000000000000000000c8"
109 ]
110 }
111 ]
112 ],
113 "maxFeePerBlobGas": "0x64",
114 "blobVersionedHashes": [
115 "0x0100000000000000000000000000000000000000000000000000000000000000",
116 "0x0100000000000000000000000000000000000000000000000000000000000001",
117 "0x0100000000000000000000000000000000000000000000000000000000000002",
118 "0x0100000000000000000000000000000000000000000000000000000000000003",
119 "0x0100000000000000000000000000000000000000000000000000000000000004",
120 "0x0100000000000000000000000000000000000000000000000000000000000005"
121 ],
122 "sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
123 "secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
124 },
125 "post": {
126 "Cancun": [
127 {
128 "hash": "0x70151ef6e11989505a79932f38c191bdbb22a2ff455460ddc53ef3b056d378ff",
129 "logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
130 "txbytes": "0x03f9018701808007826a44948a0a19589531694250d570040a0c4b74576919b88000f85bf859940000000000000000000000000000000000000064f842a00000000000000000000000000000000000000000000000000000000000000064a000000000000000000000000000000000000000000000000000000000000000c864f8c6a00100000000000000000000000000000000000000000000000000000000000000a00100000000000000000000000000000000000000000000000000000000000001a00100000000000000000000000000000000000000000000000000000000000002a00100000000000000000000000000000000000000000000000000000000000003a00100000000000000000000000000000000000000000000000000000000000004a0010000000000000000000000000000000000000000000000000000000000000501a01fd714a1b7065e945bffbe064dfe72b1f0a9f482cd3d03ffa78884bd9331b19ea04066aba133e51239e007914fc7ee21bd2591c39d1d201b3b813f03d2f4ca9088",
131 "indexes": {
132 "data": 0,
133 "gas": 0,
134 "value": 0
135 },
136 "state": {
137 "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
138 "nonce": "0x01",
139 "balance": "0x04a40000",
140 "code": "0x",
141 "storage": {}
142 }
143 }
144 }
145 ]
146 },
147 "config": {
148 "blobSchedule": {
149 "Cancun": {
150 "target": "0x03",
151 "max": "0x06",
152 "baseFeeUpdateFraction": "0x32f0ed"
153 }
154 },
155 "chainid": "0x01"
156 },
157 "_info": {
158 "hash": "0xd992bae1a97e5e6134325c6b02b86087700fef37fa53a6f5a72c50829d8fca77",
159 "comment": "`execution-spec-tests` generated test",
160 "filling-transition-tool": "ethereum-spec-evm-resolver 0.0.5",
161 "description": "Test function documentation:\n\n Check that transaction is accepted when user can exactly afford the blob gas specified (and\n max_fee_per_gas would be enough for current block).\n\n - Transactions with max fee equal or higher than current block base fee\n - Transactions with and without priority fee\n - Transactions with and without value\n - Transactions with and without calldata\n - Transactions with max fee per blob gas lower or higher than the priority fee",
162 "url": "https://github.com/ethereum/execution-spec-tests/tree/v4.1.0/tests/cancun/eip4844_blobs/test_blob_txs.py#L633",
163 "fixture-format": "state_test",
164 "reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4844.md",
165 "reference-spec-version": "de2e4a46ad93fc04e6fe3174dc6e90a3307bdb5f",
166 "eels-resolution": {
167 "git-url": "https://github.com/ethereum/execution-specs.git",
168 "branch": "master",
169 "commit": "78fb726158c69d8fa164e28f195fabf6ab59b915"
170 }
171 }
172 }
173 "#;
174 let test_unit: StateTestUnit = serde_json::from_str(json).unwrap();
175 println!("{:?}", test_unit);
176 }
177}