Skip to content

Commit

Permalink
changes in MockEthProvider to add a local state root store
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez committed Jul 31, 2024
1 parent f859d5c commit 26af10a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/storage/provider/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub struct MockEthProvider {
pub accounts: Arc<Mutex<HashMap<Address, ExtendedAccount>>>,
/// Local chain spec
pub chain_spec: Arc<ChainSpec>,
/// Local state roots
pub state_roots: Arc<Mutex<Vec<B256>>>,
}

impl Default for MockEthProvider {
Expand All @@ -45,6 +47,7 @@ impl Default for MockEthProvider {
headers: Default::default(),
accounts: Default::default(),
chain_spec: Arc::new(reth_chainspec::ChainSpecBuilder::mainnet().build()),
state_roots: Default::default(),
}
}
}
Expand Down Expand Up @@ -124,6 +127,11 @@ impl MockEthProvider {
self.add_account(address, account)
}
}

/// Add state root to local state root store
pub fn add_state_root(&self, state_root: B256) {
self.state_roots.lock().push(state_root);
}
}

impl HeaderProvider for MockEthProvider {
Expand Down Expand Up @@ -540,14 +548,16 @@ impl AccountReader for MockEthProvider {

impl StateRootProvider for MockEthProvider {
fn hashed_state_root(&self, _state: HashedPostState) -> ProviderResult<B256> {
Ok(B256::default())
let state_root = self.state_roots.lock().pop().unwrap_or_default();
Ok(state_root)
}

fn hashed_state_root_with_updates(
&self,
_state: HashedPostState,
) -> ProviderResult<(B256, TrieUpdates)> {
Ok((B256::default(), Default::default()))
let state_root = self.state_roots.lock().pop().unwrap_or_default();
Ok((state_root, Default::default()))
}
}

Expand Down

0 comments on commit 26af10a

Please sign in to comment.