ethers_core/types/
proof.rs

1use crate::types::{
2    serde_helpers::deserialize_stringified_numeric, Address, Bytes, H256, U256, U64,
3};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
7pub struct StorageProof {
8    #[serde(deserialize_with = "deserialize_stringified_numeric")]
9    pub key: U256,
10    pub proof: Vec<Bytes>,
11    pub value: U256,
12}
13
14#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
15#[serde(rename_all = "camelCase")]
16pub struct EIP1186ProofResponse {
17    pub address: Address,
18    pub balance: U256,
19    pub code_hash: H256,
20    pub nonce: U64,
21    pub storage_hash: H256,
22    pub account_proof: Vec<Bytes>,
23    pub storage_proof: Vec<StorageProof>,
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn can_deserialize_proof() {
32        serde_json::from_str::<EIP1186ProofResponse>(include_str!("../../testdata/proof.json"))
33            .unwrap();
34    }
35
36    #[test]
37    fn can_deserialize_proof_uint_key() {
38        serde_json::from_str::<EIP1186ProofResponse>(include_str!(
39            "../../testdata/proof_uint_key.json"
40        ))
41        .unwrap();
42    }
43
44    #[test]
45    fn can_deserialize_proof_empty_key() {
46        serde_json::from_str::<EIP1186ProofResponse>(include_str!(
47            "../../testdata/proof_empty_key.json"
48        ))
49        .unwrap();
50    }
51}