Skip to main content

miden_client/test_utils/
mock.rs

1use alloc::boxed::Box;
2use alloc::collections::{BTreeMap, BTreeSet};
3use alloc::sync::Arc;
4use alloc::vec::Vec;
5
6use miden_protocol::Word;
7use miden_protocol::account::delta::AccountUpdateDetails;
8use miden_protocol::account::{AccountCode, AccountId, StorageSlot, StorageSlotContent};
9use miden_protocol::address::NetworkId;
10use miden_protocol::block::{BlockHeader, BlockNumber, ProvenBlock};
11use miden_protocol::crypto::merkle::mmr::{Forest, Mmr, MmrProof};
12use miden_protocol::crypto::merkle::smt::SmtProof;
13use miden_protocol::note::{NoteHeader, NoteId, NoteScript, NoteTag, Nullifier};
14use miden_protocol::transaction::{ProvenTransaction, TransactionInputs};
15use miden_testing::{MockChain, MockChainNote};
16use miden_tx::utils::sync::RwLock;
17
18use crate::Client;
19use crate::rpc::domain::account::{
20    AccountDetails,
21    AccountProof,
22    AccountStorageDetails,
23    AccountStorageMapDetails,
24    AccountStorageRequirements,
25    AccountUpdateSummary,
26    AccountVaultDetails,
27    FetchedAccount,
28    StorageMapEntries,
29    StorageMapEntry,
30};
31use crate::rpc::domain::account_vault::{AccountVaultInfo, AccountVaultUpdate};
32use crate::rpc::domain::note::{
33    CommittedNote,
34    CommittedNoteMetadata,
35    FetchedNote,
36    NoteSyncBlock,
37    NoteSyncInfo,
38};
39use crate::rpc::domain::nullifier::NullifierUpdate;
40use crate::rpc::domain::storage_map::{StorageMapInfo, StorageMapUpdate};
41use crate::rpc::domain::sync::ChainMmrInfo;
42use crate::rpc::domain::transaction::{TransactionRecord, TransactionsInfo};
43use crate::rpc::{AccountStateAt, NodeRpcClient, RpcError, RpcStatusInfo};
44
45pub type MockClient<AUTH> = Client<AUTH>;
46
47/// Mock RPC API
48///
49/// This struct implements the RPC API used by the client to communicate with the node. It simulates
50/// most of the functionality of the actual node, with some small differences:
51/// - It uses a [`MockChain`] to simulate the blockchain state.
52/// - Blocks are not automatically created after time passes, but rather new blocks are created when
53///   calling the `prove_block` method.
54/// - Network account and transactions aren't supported in the current version.
55/// - Account update block numbers aren't tracked, so any endpoint that returns when certain account
56///   updates were made will return the chain tip block number instead.
57#[derive(Clone)]
58pub struct MockRpcApi {
59    account_commitment_updates: Arc<RwLock<BTreeMap<BlockNumber, BTreeMap<AccountId, Word>>>>,
60    pub mock_chain: Arc<RwLock<MockChain>>,
61    oversize_threshold: usize,
62}
63
64impl Default for MockRpcApi {
65    fn default() -> Self {
66        Self::new(MockChain::new())
67    }
68}
69
70impl MockRpcApi {
71    // Constant to use in mocked pagination.
72    const PAGINATION_BLOCK_LIMIT: u32 = 5;
73
74    /// Creates a new [`MockRpcApi`] instance with the state of the provided [`MockChain`].
75    pub fn new(mock_chain: MockChain) -> Self {
76        Self {
77            account_commitment_updates: Arc::new(RwLock::new(build_account_updates(&mock_chain))),
78            mock_chain: Arc::new(RwLock::new(mock_chain)),
79            oversize_threshold: 1000,
80        }
81    }
82
83    /// Sets the oversize threshold for `get_account_proof`. Any storage map with more
84    /// entries than this threshold, or a vault with more assets, will have the
85    /// `too_many_entries` / `too_many_assets` flags set in the response.
86    #[must_use]
87    pub fn with_oversize_threshold(mut self, threshold: usize) -> Self {
88        self.oversize_threshold = threshold;
89        self
90    }
91
92    /// Returns the current MMR of the blockchain.
93    pub fn get_mmr(&self) -> Mmr {
94        self.mock_chain.read().blockchain().as_mmr().clone()
95    }
96
97    /// Returns the chain tip block number.
98    pub fn get_chain_tip_block_num(&self) -> BlockNumber {
99        self.mock_chain.read().latest_block_header().block_num()
100    }
101
102    /// Advances the mock chain by proving the next block, committing all pending objects to the
103    /// chain in the process.
104    pub fn prove_block(&self) {
105        let proven_block = self.mock_chain.write().prove_next_block().unwrap();
106        let mut account_commitment_updates = self.account_commitment_updates.write();
107        let block_num = proven_block.header().block_num();
108        let updates: BTreeMap<AccountId, Word> = proven_block
109            .body()
110            .updated_accounts()
111            .iter()
112            .map(|update| (update.account_id(), update.final_state_commitment()))
113            .collect();
114
115        if !updates.is_empty() {
116            account_commitment_updates.insert(block_num, updates);
117        }
118    }
119
120    /// Retrieves a block by its block number.
121    fn get_block_by_num(&self, block_num: BlockNumber) -> BlockHeader {
122        self.mock_chain.read().block_header(block_num.as_usize())
123    }
124
125    /// Retrieves account vault updates in a given block range.
126    /// This method tries to simulate pagination by limiting the number of blocks processed per
127    /// request.
128    fn get_sync_account_vault_request(
129        &self,
130        block_from: BlockNumber,
131        block_to: Option<BlockNumber>,
132        account_id: AccountId,
133    ) -> AccountVaultInfo {
134        let chain_tip = self.get_chain_tip_block_num();
135        let target_block = block_to.unwrap_or(chain_tip).min(chain_tip);
136
137        let page_end_block: BlockNumber = (block_from.as_u32() + Self::PAGINATION_BLOCK_LIMIT)
138            .min(target_block.as_u32())
139            .into();
140
141        let mut updates = vec![];
142        for block in self.mock_chain.read().proven_blocks() {
143            let block_number = block.header().block_num();
144            // Only include blocks in range (block_from, page_end_block]
145            if block_number <= block_from || block_number > page_end_block {
146                continue;
147            }
148
149            for update in block
150                .body()
151                .updated_accounts()
152                .iter()
153                .filter(|block_acc_update| block_acc_update.account_id() == account_id)
154            {
155                let AccountUpdateDetails::Delta(account_delta) = update.details().clone() else {
156                    continue;
157                };
158
159                let vault_delta = account_delta.vault();
160
161                for asset in vault_delta.added_assets() {
162                    let account_vault_update = AccountVaultUpdate {
163                        block_num: block_number,
164                        asset: Some(asset),
165                        vault_key: asset.vault_key(),
166                    };
167                    updates.push(account_vault_update);
168                }
169            }
170        }
171
172        AccountVaultInfo {
173            chain_tip,
174            block_number: page_end_block,
175            updates,
176        }
177    }
178
179    /// Retrieves transactions in a given block range that match the provided account IDs
180    fn get_sync_transactions_request(
181        &self,
182        block_from: BlockNumber,
183        block_to: Option<BlockNumber>,
184        account_ids: &[AccountId],
185    ) -> TransactionsInfo {
186        let chain_tip = self.get_chain_tip_block_num();
187        let block_to = match block_to {
188            Some(block_to) => block_to,
189            None => chain_tip,
190        };
191
192        let mut transaction_records = vec![];
193        for block in self.mock_chain.read().proven_blocks() {
194            let block_number = block.header().block_num();
195            if block_number <= block_from || block_number > block_to {
196                continue;
197            }
198
199            for transaction_header in block.body().transactions().as_slice() {
200                if !account_ids.contains(&transaction_header.account_id()) {
201                    continue;
202                }
203
204                transaction_records.push(TransactionRecord {
205                    block_num: block_number,
206                    transaction_header: transaction_header.clone(),
207                    output_notes: vec![],
208                });
209            }
210        }
211
212        TransactionsInfo {
213            chain_tip,
214            block_num: block_to,
215            transaction_records,
216        }
217    }
218
219    /// Retrieves storage map updates in a given block range.
220    ///
221    /// This method tries to simulate pagination of the real node.
222    fn get_sync_storage_maps_request(
223        &self,
224        block_from: BlockNumber,
225        block_to: Option<BlockNumber>,
226        account_id: AccountId,
227    ) -> StorageMapInfo {
228        let chain_tip = self.get_chain_tip_block_num();
229        let target_block = block_to.unwrap_or(chain_tip).min(chain_tip);
230
231        let page_end_block: BlockNumber = (block_from.as_u32() + Self::PAGINATION_BLOCK_LIMIT)
232            .min(target_block.as_u32())
233            .into();
234
235        let mut updates = vec![];
236        for block in self.mock_chain.read().proven_blocks() {
237            let block_number = block.header().block_num();
238            if block_number <= block_from || block_number > page_end_block {
239                continue;
240            }
241
242            for update in block
243                .body()
244                .updated_accounts()
245                .iter()
246                .filter(|block_acc_update| block_acc_update.account_id() == account_id)
247            {
248                let AccountUpdateDetails::Delta(account_delta) = update.details().clone() else {
249                    continue;
250                };
251
252                let storage_delta = account_delta.storage();
253
254                for (slot_name, map_delta) in storage_delta.maps() {
255                    for (key, value) in map_delta.entries() {
256                        let storage_map_info = StorageMapUpdate {
257                            block_num: block_number,
258                            slot_name: slot_name.clone(),
259                            key: *key,
260                            value: *value,
261                        };
262                        updates.push(storage_map_info);
263                    }
264                }
265            }
266        }
267
268        StorageMapInfo {
269            chain_tip,
270            block_number: page_end_block,
271            updates,
272        }
273    }
274
275    pub fn get_available_notes(&self) -> Vec<MockChainNote> {
276        self.mock_chain.read().committed_notes().values().cloned().collect()
277    }
278
279    pub fn get_public_available_notes(&self) -> Vec<MockChainNote> {
280        self.mock_chain
281            .read()
282            .committed_notes()
283            .values()
284            .filter(|n| matches!(n, MockChainNote::Public(_, _)))
285            .cloned()
286            .collect()
287    }
288
289    pub fn get_private_available_notes(&self) -> Vec<MockChainNote> {
290        self.mock_chain
291            .read()
292            .committed_notes()
293            .values()
294            .filter(|n| matches!(n, MockChainNote::Private(_, _, _)))
295            .cloned()
296            .collect()
297    }
298
299    pub fn advance_blocks(&self, num_blocks: u32) {
300        let current_height = self.get_chain_tip_block_num();
301        let mut mock_chain = self.mock_chain.write();
302        mock_chain.prove_until_block(current_height + num_blocks).unwrap();
303    }
304}
305#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
306#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
307impl NodeRpcClient for MockRpcApi {
308    fn has_genesis_commitment(&self) -> Option<Word> {
309        None
310    }
311
312    async fn set_genesis_commitment(&self, _commitment: Word) -> Result<(), RpcError> {
313        // The mock client doesn't use accept headers, so we don't need to do anything here.
314        Ok(())
315    }
316
317    /// Returns note updates after the specified block number. Only notes that match the
318    /// provided tags will be returned, grouped by block.
319    async fn sync_notes(
320        &self,
321        block_num: BlockNumber,
322        block_to: Option<BlockNumber>,
323        note_tags: &BTreeSet<NoteTag>,
324    ) -> Result<NoteSyncInfo, RpcError> {
325        let chain_tip = self.get_chain_tip_block_num();
326        let upper_bound = block_to.unwrap_or(chain_tip);
327
328        // Collect all blocks with matching notes in the range (block_num, upper_bound]
329        let mut blocks_with_notes: BTreeMap<BlockNumber, BTreeMap<NoteId, CommittedNote>> =
330            BTreeMap::new();
331        for note in self.mock_chain.read().committed_notes().values() {
332            let note_block = note.inclusion_proof().location().block_num();
333            if note_tags.contains(&note.metadata().tag())
334                && note_block > block_num
335                && note_block <= upper_bound
336            {
337                let committed = CommittedNote::new(
338                    note.id(),
339                    CommittedNoteMetadata::Full(note.metadata().clone()),
340                    note.inclusion_proof().clone(),
341                );
342                blocks_with_notes.entry(note_block).or_default().insert(note.id(), committed);
343            }
344        }
345
346        // Always include the upper_bound block (with empty notes if needed), matching the
347        // node behavior where the range-end block is always present when the scan completes.
348        blocks_with_notes.entry(upper_bound).or_default();
349
350        let blocks: Vec<NoteSyncBlock> = blocks_with_notes
351            .into_iter()
352            .map(|(bn, notes)| {
353                let block_header = self.get_block_by_num(bn);
354                let mmr_path = self.get_mmr().open(bn.as_usize()).unwrap().merkle_path().clone();
355                NoteSyncBlock { block_header, mmr_path, notes }
356            })
357            .collect();
358
359        Ok(NoteSyncInfo { chain_tip, block_to: upper_bound, blocks })
360    }
361
362    async fn sync_chain_mmr(
363        &self,
364        block_from: BlockNumber,
365        block_to: Option<BlockNumber>,
366    ) -> Result<ChainMmrInfo, RpcError> {
367        let chain_tip = self.get_chain_tip_block_num();
368        let target_block = block_to.unwrap_or(chain_tip).min(chain_tip);
369
370        let from_forest = if block_from == chain_tip {
371            target_block.as_usize()
372        } else {
373            block_from.as_u32() as usize + 1
374        };
375
376        let mmr_delta = self
377            .get_mmr()
378            .get_delta(Forest::new(from_forest), Forest::new(target_block.as_usize()))
379            .unwrap();
380
381        let block_header = self.get_block_by_num(target_block);
382
383        Ok(ChainMmrInfo {
384            block_from,
385            block_to: target_block,
386            mmr_delta,
387            block_header,
388        })
389    }
390
391    /// Retrieves the block header for the specified block number. If the block number is not
392    /// provided, the chain tip block header will be returned.
393    async fn get_block_header_by_number(
394        &self,
395        block_num: Option<BlockNumber>,
396        include_mmr_proof: bool,
397    ) -> Result<(BlockHeader, Option<MmrProof>), RpcError> {
398        let block = if let Some(block_num) = block_num {
399            self.mock_chain.read().block_header(block_num.as_usize())
400        } else {
401            self.mock_chain.read().latest_block_header()
402        };
403
404        let mmr_proof = if include_mmr_proof {
405            Some(self.get_mmr().open(block_num.unwrap().as_usize()).unwrap())
406        } else {
407            None
408        };
409
410        Ok((block, mmr_proof))
411    }
412
413    /// Returns the node's tracked notes that match the provided note IDs.
414    async fn get_notes_by_id(&self, note_ids: &[NoteId]) -> Result<Vec<FetchedNote>, RpcError> {
415        // assume all public notes for now
416        let notes = self.mock_chain.read().committed_notes().clone();
417
418        let hit_notes = note_ids.iter().filter_map(|id| notes.get(id));
419        let mut return_notes = vec![];
420        for note in hit_notes {
421            let fetched_note = match note {
422                MockChainNote::Private(note_id, note_metadata, note_inclusion_proof) => {
423                    let note_header = NoteHeader::new(*note_id, note_metadata.clone());
424                    FetchedNote::Private(note_header, note_inclusion_proof.clone())
425                },
426                MockChainNote::Public(note, note_inclusion_proof) => {
427                    FetchedNote::Public(note.clone(), note_inclusion_proof.clone())
428                },
429            };
430            return_notes.push(fetched_note);
431        }
432        Ok(return_notes)
433    }
434
435    /// Simulates the submission of a proven transaction to the node. This will create a new block
436    /// just for the new transaction and return the block number of the newly created block.
437    async fn submit_proven_transaction(
438        &self,
439        proven_transaction: ProvenTransaction,
440        _tx_inputs: TransactionInputs, // Unnecessary for testing client itself.
441    ) -> Result<BlockNumber, RpcError> {
442        // TODO: add some basic validations to test error cases
443
444        {
445            let mut mock_chain = self.mock_chain.write();
446            mock_chain.add_pending_proven_transaction(proven_transaction.clone());
447        };
448
449        let block_num = self.get_chain_tip_block_num();
450
451        Ok(block_num)
452    }
453
454    /// Returns the node's tracked account details for the specified account ID.
455    /// Always returns the full account for public accounts.
456    async fn get_account_details(&self, account_id: AccountId) -> Result<FetchedAccount, RpcError> {
457        let summary =
458            self.account_commitment_updates
459                .read()
460                .iter()
461                .rev()
462                .find_map(|(block_num, updates)| {
463                    updates.get(&account_id).map(|commitment| AccountUpdateSummary {
464                        commitment: *commitment,
465                        last_block_num: *block_num,
466                    })
467                });
468
469        if let Ok(account) = self.mock_chain.read().committed_account(account_id) {
470            let summary = summary.unwrap_or_else(|| AccountUpdateSummary {
471                commitment: account.to_commitment(),
472                last_block_num: BlockNumber::GENESIS,
473            });
474            Ok(FetchedAccount::new_public(account.clone(), summary))
475        } else if let Some(summary) = summary {
476            Ok(FetchedAccount::new_private(account_id, summary))
477        } else {
478            Err(RpcError::ExpectedDataMissing(format!(
479                "account {account_id} not found in mock commitment updates or mock chain"
480            )))
481        }
482    }
483
484    /// Returns the account proof for the specified account. The `known_account_code` parameter
485    /// is ignored in the mock implementation and the latest account code is always returned.
486    async fn get_account_proof(
487        &self,
488        account_id: AccountId,
489        account_storage_requirements: AccountStorageRequirements,
490        account_state: AccountStateAt,
491        _known_account_code: Option<AccountCode>,
492        _known_vault_commitment: Option<Word>,
493    ) -> Result<(BlockNumber, AccountProof), RpcError> {
494        let mock_chain = self.mock_chain.read();
495
496        let block_number = match account_state {
497            AccountStateAt::Block(number) => number,
498            AccountStateAt::ChainTip => mock_chain.latest_block_header().block_num(),
499        };
500
501        let headers = if account_id.has_public_state() {
502            let account = mock_chain.committed_account(account_id).unwrap();
503
504            let mut map_details = vec![];
505            for slot_name in account_storage_requirements.inner().keys() {
506                if let Some(StorageSlotContent::Map(storage_map)) =
507                    account.storage().get(slot_name).map(StorageSlot::content)
508                {
509                    let entries: Vec<StorageMapEntry> = storage_map
510                        .entries()
511                        .map(|(key, value)| StorageMapEntry { key: *key, value: *value })
512                        .collect();
513
514                    // NOTE: The mock returns all entries even when too_many_entries is set.
515                    // In production, the node would return partial data for oversized maps.
516                    let too_many_entries = entries.len() > self.oversize_threshold;
517                    let account_storage_map_detail = AccountStorageMapDetails {
518                        slot_name: slot_name.clone(),
519                        too_many_entries,
520                        entries: StorageMapEntries::AllEntries(entries),
521                    };
522
523                    map_details.push(account_storage_map_detail);
524                } else {
525                    panic!("Storage slot {slot_name} is not a map");
526                }
527            }
528
529            let storage_details = AccountStorageDetails {
530                header: account.storage().to_header(),
531                map_details,
532            };
533
534            let mut assets = vec![];
535            for asset in account.vault().assets() {
536                assets.push(asset);
537            }
538            let vault_details = AccountVaultDetails {
539                too_many_assets: assets.len() > self.oversize_threshold,
540                assets,
541            };
542
543            Some(AccountDetails {
544                header: account.into(),
545                storage_details,
546                code: account.code().clone(),
547                vault_details,
548            })
549        } else {
550            None
551        };
552
553        let witness = mock_chain.account_tree().open(account_id);
554
555        let proof = AccountProof::new(witness, headers).unwrap();
556
557        Ok((block_number, proof))
558    }
559
560    /// Returns the nullifiers created after the specified block number that match the provided
561    /// prefixes.
562    async fn sync_nullifiers(
563        &self,
564        prefixes: &[u16],
565        from_block_num: BlockNumber,
566        block_to: Option<BlockNumber>,
567    ) -> Result<Vec<NullifierUpdate>, RpcError> {
568        let nullifiers = self
569            .mock_chain
570            .read()
571            .nullifier_tree()
572            .entries()
573            .filter_map(|(nullifier, block_num)| {
574                let within_range = if let Some(to_block) = block_to {
575                    block_num >= from_block_num && block_num <= to_block
576                } else {
577                    block_num >= from_block_num
578                };
579
580                if prefixes.contains(&nullifier.prefix()) && within_range {
581                    Some(NullifierUpdate { nullifier, block_num })
582                } else {
583                    None
584                }
585            })
586            .collect::<Vec<_>>();
587
588        Ok(nullifiers)
589    }
590
591    /// Returns proofs for all the provided nullifiers.
592    async fn check_nullifiers(&self, nullifiers: &[Nullifier]) -> Result<Vec<SmtProof>, RpcError> {
593        Ok(nullifiers
594            .iter()
595            .map(|nullifier| self.mock_chain.read().nullifier_tree().open(nullifier).into_proof())
596            .collect())
597    }
598
599    async fn get_block_by_number(&self, block_num: BlockNumber) -> Result<ProvenBlock, RpcError> {
600        let block = self
601            .mock_chain
602            .read()
603            .proven_blocks()
604            .iter()
605            .find(|b| b.header().block_num() == block_num)
606            .unwrap()
607            .clone();
608
609        Ok(block)
610    }
611
612    async fn get_note_script_by_root(&self, root: Word) -> Result<NoteScript, RpcError> {
613        let note = self
614            .get_available_notes()
615            .iter()
616            .find(|note| note.note().is_some_and(|n| n.script().root() == root))
617            .unwrap()
618            .clone();
619
620        Ok(note.note().unwrap().script().clone())
621    }
622
623    async fn sync_storage_maps(
624        &self,
625        block_from: BlockNumber,
626        block_to: Option<BlockNumber>,
627        account_id: AccountId,
628    ) -> Result<StorageMapInfo, RpcError> {
629        let mut all_updates = Vec::new();
630        let mut current_block_from = block_from;
631        let chain_tip = self.get_chain_tip_block_num();
632        let target_block = block_to.unwrap_or(chain_tip).min(chain_tip);
633
634        loop {
635            let response =
636                self.get_sync_storage_maps_request(current_block_from, block_to, account_id);
637            all_updates.extend(response.updates);
638
639            if response.block_number >= target_block {
640                return Ok(StorageMapInfo {
641                    chain_tip: response.chain_tip,
642                    block_number: response.block_number,
643                    updates: all_updates,
644                });
645            }
646
647            current_block_from = (response.block_number.as_u32() + 1).into();
648        }
649    }
650
651    async fn sync_account_vault(
652        &self,
653        block_from: BlockNumber,
654        block_to: Option<BlockNumber>,
655        account_id: AccountId,
656    ) -> Result<AccountVaultInfo, RpcError> {
657        let mut all_updates = Vec::new();
658        let mut current_block_from = block_from;
659        let chain_tip = self.get_chain_tip_block_num();
660        let target_block = block_to.unwrap_or(chain_tip).min(chain_tip);
661
662        loop {
663            let response =
664                self.get_sync_account_vault_request(current_block_from, block_to, account_id);
665            all_updates.extend(response.updates);
666
667            if response.block_number >= target_block {
668                return Ok(AccountVaultInfo {
669                    chain_tip: response.chain_tip,
670                    block_number: response.block_number,
671                    updates: all_updates,
672                });
673            }
674
675            current_block_from = (response.block_number.as_u32() + 1).into();
676        }
677    }
678
679    async fn sync_transactions(
680        &self,
681        block_from: BlockNumber,
682        block_to: Option<BlockNumber>,
683        account_ids: Vec<AccountId>,
684    ) -> Result<TransactionsInfo, RpcError> {
685        let response = self.get_sync_transactions_request(block_from, block_to, &account_ids);
686        Ok(response)
687    }
688
689    async fn get_network_id(&self) -> Result<NetworkId, RpcError> {
690        Ok(NetworkId::Testnet)
691    }
692
693    async fn get_rpc_limits(&self) -> Result<crate::rpc::RpcLimits, RpcError> {
694        Ok(crate::rpc::RpcLimits::default())
695    }
696
697    fn has_rpc_limits(&self) -> Option<crate::rpc::RpcLimits> {
698        None
699    }
700
701    async fn set_rpc_limits(&self, _limits: crate::rpc::RpcLimits) {
702        // No-op for mock client
703    }
704
705    async fn get_status_unversioned(&self) -> Result<RpcStatusInfo, RpcError> {
706        Ok(RpcStatusInfo {
707            version: env!("CARGO_PKG_VERSION").into(),
708            genesis_commitment: None,
709            store: None,
710            block_producer: None,
711        })
712    }
713}
714
715// CONVERSIONS
716// ================================================================================================
717
718impl From<MockChain> for MockRpcApi {
719    fn from(mock_chain: MockChain) -> Self {
720        MockRpcApi::new(mock_chain)
721    }
722}
723
724// HELPERS
725// ================================================================================================
726
727fn build_account_updates(
728    mock_chain: &MockChain,
729) -> BTreeMap<BlockNumber, BTreeMap<AccountId, Word>> {
730    let mut account_commitment_updates = BTreeMap::new();
731    for block in mock_chain.proven_blocks() {
732        let block_num = block.header().block_num();
733        let mut updates = BTreeMap::new();
734
735        for update in block.body().updated_accounts() {
736            updates.insert(update.account_id(), update.final_state_commitment());
737        }
738
739        if updates.is_empty() {
740            continue;
741        }
742
743        account_commitment_updates.insert(block_num, updates);
744    }
745    account_commitment_updates
746}