1use std::collections::HashMap;
2
3use async_trait::async_trait;
4use bytes::Bytes;
5use xenith_core::Result;
6
7#[async_trait]
15pub trait ChainProvider: Send + Sync {
16 async fn read_storage(&self, address: [u8; 20], slot: [u8; 32]) -> Result<[u8; 32]>;
18
19 async fn call(&self, address: [u8; 20], calldata: Bytes) -> Result<Bytes>;
21}
22
23pub struct MockProvider {
27 slots: HashMap<[u8; 32], [u8; 32]>,
28}
29
30impl MockProvider {
31 pub fn new(slots: HashMap<[u8; 32], [u8; 32]>) -> Self {
33 Self { slots }
34 }
35}
36
37#[async_trait]
38impl ChainProvider for MockProvider {
39 async fn read_storage(&self, _address: [u8; 20], slot: [u8; 32]) -> Result<[u8; 32]> {
40 self.slots.get(&slot).copied().ok_or_else(|| {
41 xenith_core::XenithError::StoreError(format!("MockProvider: slot {slot:?} not found"))
42 })
43 }
44
45 async fn call(&self, _address: [u8; 20], _calldata: Bytes) -> Result<Bytes> {
46 Ok(Bytes::new())
47 }
48}