storage_interface/
mock.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8//! This module provides mock dbreader for tests.
9
10use crate::{DBReaderForPoW, DbReader, StartupInfo, TreeState};
11use anyhow::Result;
12use diem_crypto::HashValue;
13use diem_types::{
14    account_address::AccountAddress,
15    committed_block::CommittedBlock,
16    contract_event::ContractEvent,
17    epoch_change::EpochChangeProof,
18    ledger_info::LedgerInfoWithSignatures,
19    proof::AccumulatorConsistencyProof,
20    reward_distribution_event::RewardDistributionEventV2,
21    transaction::{TransactionListWithProof, TransactionWithProof, Version},
22};
23
24/// This is a mock of the dbreader in tests.
25pub struct MockDbReader;
26
27impl DbReader for MockDbReader {
28    fn get_epoch_ending_ledger_infos(
29        &self, _start_epoch: u64, _end_epoch: u64,
30    ) -> Result<EpochChangeProof> {
31        unimplemented!()
32    }
33
34    fn get_transactions(
35        &self, _start_version: Version, _batch_size: u64,
36        _ledger_version: Version, _fetch_events: bool,
37    ) -> Result<TransactionListWithProof> {
38        unimplemented!()
39    }
40
41    fn get_block_timestamp(&self, _version: u64) -> Result<u64> {
42        unimplemented!()
43    }
44
45    /// Returns the latest ledger info.
46    fn get_latest_ledger_info(&self) -> Result<LedgerInfoWithSignatures> {
47        unimplemented!()
48    }
49
50    fn get_startup_info(
51        &self, _need_pos_state: bool,
52    ) -> Result<Option<StartupInfo>> {
53        unimplemented!()
54    }
55
56    fn get_txn_by_account(
57        &self, _address: AccountAddress, _seq_num: u64,
58        _ledger_version: Version, _fetch_events: bool,
59    ) -> Result<Option<TransactionWithProof>> {
60        unimplemented!()
61    }
62
63    fn get_state_proof_with_ledger_info(
64        &self, _known_version: u64, _ledger_info: LedgerInfoWithSignatures,
65    ) -> Result<(EpochChangeProof, AccumulatorConsistencyProof)> {
66        unimplemented!()
67    }
68
69    fn get_state_proof(
70        &self, _known_version: u64,
71    ) -> Result<(
72        LedgerInfoWithSignatures,
73        EpochChangeProof,
74        AccumulatorConsistencyProof,
75    )> {
76        unimplemented!()
77    }
78
79    fn get_latest_tree_state(&self) -> Result<TreeState> { unimplemented!() }
80
81    fn get_epoch_ending_ledger_info(
82        &self, _known_version: u64,
83    ) -> Result<LedgerInfoWithSignatures> {
84        unimplemented!()
85    }
86}
87
88impl DBReaderForPoW for MockDbReader {
89    fn get_latest_ledger_info_option(
90        &self,
91    ) -> Option<LedgerInfoWithSignatures> {
92        todo!()
93    }
94
95    fn get_block_ledger_info(
96        &self, _consensus_block_id: &HashValue,
97    ) -> anyhow::Result<LedgerInfoWithSignatures> {
98        todo!()
99    }
100
101    fn get_events_by_version(
102        &self, _start_version: u64, _end_version: u64,
103    ) -> anyhow::Result<Vec<ContractEvent>> {
104        todo!()
105    }
106
107    fn get_epoch_ending_blocks(
108        &self, _start_epoch: u64, _end_epoch: u64,
109    ) -> anyhow::Result<Vec<HashValue>> {
110        todo!()
111    }
112
113    fn get_reward_event(
114        &self, _epoch: u64,
115    ) -> anyhow::Result<RewardDistributionEventV2> {
116        todo!()
117    }
118
119    fn get_committed_block_by_hash(
120        &self, _block_hash: &HashValue,
121    ) -> anyhow::Result<CommittedBlock> {
122        todo!()
123    }
124
125    fn get_committed_block_hash_by_view(
126        &self, _view: u64,
127    ) -> Result<HashValue> {
128        todo!()
129    }
130
131    fn get_ledger_info_by_voted_block(
132        &self, _block_id: &HashValue,
133    ) -> Result<LedgerInfoWithSignatures> {
134        todo!()
135    }
136
137    fn get_block_hash_by_epoch_and_round(
138        &self, _epoch: u64, _round: u64,
139    ) -> Result<HashValue> {
140        todo!()
141    }
142}