zebra_scan/storage/db/
tests.rs
1use std::{collections::BTreeMap, sync::Arc};
4
5use zebra_chain::{
6 block::{Block, Height},
7 parameters::Network::{self},
8 serialization::ZcashDeserializeInto,
9 transaction,
10};
11use zebra_state::{SaplingScannedResult, TransactionIndex};
12
13use crate::{
14 storage::{Storage, INSERT_CONTROL_INTERVAL},
15 tests::{FAKE_SAPLING_VIEWING_KEY, ZECPAGES_SAPLING_VIEWING_KEY},
16 Config,
17};
18
19#[cfg(test)]
20mod snapshot;
21
22#[cfg(test)]
23mod vectors;
24
25pub fn new_test_storage(network: &Network) -> Storage {
27 Storage::new(&Config::ephemeral(), network, false)
28}
29
30pub fn add_fake_keys(storage: &mut Storage) {
32 storage.add_sapling_key(&ZECPAGES_SAPLING_VIEWING_KEY.to_string(), None);
34 storage.add_sapling_key(&FAKE_SAPLING_VIEWING_KEY.to_string(), Height(1_000_000));
36}
37
38pub fn add_fake_results(
43 storage: &mut Storage,
44 network: &Network,
45 height: Height,
46 add_progress_marker: bool,
47) {
48 let blocks = network.blockchain_map();
49
50 let block: Arc<Block> = blocks
51 .get(&height.0)
52 .expect("block height has test data")
53 .zcash_deserialize_into()
54 .expect("test data deserializes");
55
56 if add_progress_marker {
57 let next_progress_height = height.0.next_multiple_of(INSERT_CONTROL_INTERVAL);
59 storage.add_sapling_results(
60 &FAKE_SAPLING_VIEWING_KEY.to_string(),
61 Height(next_progress_height),
62 BTreeMap::new(),
63 );
64 } else {
65 storage.add_sapling_results(
67 &ZECPAGES_SAPLING_VIEWING_KEY.to_string(),
68 height,
69 block
70 .transactions
71 .iter()
72 .enumerate()
73 .map(|(index, tx)| (TransactionIndex::from_usize(index), tx.hash().into()))
74 .collect(),
75 );
76 }
77}
78
79pub fn fake_sapling_results<T: IntoIterator<Item = TransactionIndex>>(
81 transaction_indexes: T,
82) -> BTreeMap<TransactionIndex, SaplingScannedResult> {
83 let mut fake_sapling_results = BTreeMap::new();
84
85 for transaction_index in transaction_indexes {
86 fake_sapling_results.insert(
87 transaction_index,
88 SaplingScannedResult::from(transaction::Hash::from([0; 32])),
89 );
90 }
91
92 fake_sapling_results
93}