diff --git a/crates/storage/provider/src/test_utils/mock.rs b/crates/storage/provider/src/test_utils/mock.rs index d484d1e65784..bf8d9affbd3e 100644 --- a/crates/storage/provider/src/test_utils/mock.rs +++ b/crates/storage/provider/src/test_utils/mock.rs @@ -42,9 +42,9 @@ use std::{ /// A mock implementation for Provider interfaces. #[derive(Debug, Clone)] -pub struct MockEthProvider { +pub struct MockEthProvider { /// Local block store - pub blocks: Arc>>, + pub blocks: Arc>>>, /// Local header store pub headers: Arc>>, /// Local account store @@ -55,7 +55,52 @@ pub struct MockEthProvider { pub state_roots: Arc>>, } -impl Default for MockEthProvider { +impl MockEthProvider { + /// Add block to local block store + pub fn add_block(&self, hash: B256, block: Block) { + self.add_header(hash, block.header.clone()); + self.blocks.lock().insert(hash, block); + } + + /// Add multiple blocks to local block store + pub fn extend_blocks(&self, iter: impl IntoIterator)>) { + for (hash, block) in iter { + self.add_header(hash, block.header.clone()); + self.add_block(hash, block) + } + } + + /// Add header to local header store + pub fn add_header(&self, hash: B256, header: Header) { + self.headers.lock().insert(hash, header); + } + + /// Add multiple headers to local header store + pub fn extend_headers(&self, iter: impl IntoIterator) { + for (hash, header) in iter { + self.add_header(hash, header) + } + } + + /// Add account to local account store + pub fn add_account(&self, address: Address, account: ExtendedAccount) { + self.accounts.lock().insert(address, account); + } + + /// Add account to local account store + pub fn extend_accounts(&self, iter: impl IntoIterator) { + for (address, account) in iter { + 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 Default for MockEthProvider { fn default() -> Self { Self { blocks: Default::default(), @@ -104,51 +149,6 @@ impl ExtendedAccount { } } -impl MockEthProvider { - /// Add block to local block store - pub fn add_block(&self, hash: B256, block: Block) { - self.add_header(hash, block.header.clone()); - self.blocks.lock().insert(hash, block); - } - - /// Add multiple blocks to local block store - pub fn extend_blocks(&self, iter: impl IntoIterator) { - for (hash, block) in iter { - self.add_header(hash, block.header.clone()); - self.add_block(hash, block) - } - } - - /// Add header to local header store - pub fn add_header(&self, hash: B256, header: Header) { - self.headers.lock().insert(hash, header); - } - - /// Add multiple headers to local header store - pub fn extend_headers(&self, iter: impl IntoIterator) { - for (hash, header) in iter { - self.add_header(hash, header) - } - } - - /// Add account to local account store - pub fn add_account(&self, address: Address, account: ExtendedAccount) { - self.accounts.lock().insert(address, account); - } - - /// Add account to local account store - pub fn extend_accounts(&self, iter: impl IntoIterator) { - for (address, account) in iter { - 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); - } -} - /// Mock node. #[derive(Debug)] pub struct MockNode;