use std::collections::HashMap;
use async_trait::async_trait;
use bytes::Bytes;
use xenith_core::Result;
#[async_trait]
pub trait ChainProvider: Send + Sync {
async fn read_storage(&self, address: [u8; 20], slot: [u8; 32]) -> Result<[u8; 32]>;
async fn call(&self, address: [u8; 20], calldata: Bytes) -> Result<Bytes>;
}
pub struct MockProvider {
slots: HashMap<[u8; 32], [u8; 32]>,
}
impl MockProvider {
pub fn new(slots: HashMap<[u8; 32], [u8; 32]>) -> Self {
Self { slots }
}
}
#[async_trait]
impl ChainProvider for MockProvider {
async fn read_storage(&self, _address: [u8; 20], slot: [u8; 32]) -> Result<[u8; 32]> {
self.slots.get(&slot).copied().ok_or_else(|| {
xenith_core::XenithError::StoreError(format!("MockProvider: slot {slot:?} not found"))
})
}
async fn call(&self, _address: [u8; 20], _calldata: Bytes) -> Result<Bytes> {
Ok(Bytes::new())
}
}