-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into open-db-for-read-only-access
- Loading branch information
Showing
32 changed files
with
427 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,58 @@ | ||
//! General scanner database tests. | ||
use std::sync::Arc; | ||
|
||
use zebra_chain::{ | ||
block::{Block, Height}, | ||
parameters::Network::{self, *}, | ||
serialization::ZcashDeserializeInto, | ||
}; | ||
use zebra_state::TransactionIndex; | ||
|
||
use crate::{ | ||
storage::Storage, | ||
tests::{FAKE_SAPLING_VIEWING_KEY, ZECPAGES_SAPLING_VIEWING_KEY}, | ||
Config, | ||
}; | ||
|
||
#[cfg(test)] | ||
mod snapshot; | ||
|
||
/// Returns an empty `Storage` suitable for testing. | ||
pub fn new_test_storage(network: Network) -> Storage { | ||
Storage::new(&Config::ephemeral(), network) | ||
Check failure on line 23 in zebra-scan/src/storage/db/tests.rs GitHub Actions / Build and Deploy Zebra Internal Docs
Check failure on line 23 in zebra-scan/src/storage/db/tests.rs GitHub Actions / Check Cargo.lock is up to date
Check failure on line 23 in zebra-scan/src/storage/db/tests.rs GitHub Actions / Test stable on ubuntu-latest
Check failure on line 23 in zebra-scan/src/storage/db/tests.rs GitHub Actions / Test beta on ubuntu-latest
Check failure on line 23 in zebra-scan/src/storage/db/tests.rs GitHub Actions / Clippy (stable) Resultsthis function takes 3 arguments but 2 arguments were supplied
|
||
} | ||
|
||
/// Add fake keys to `storage` for testing purposes. | ||
pub fn add_fake_keys(storage: &mut Storage) { | ||
// Snapshot a birthday that is automatically set to activation height | ||
storage.add_sapling_key(&ZECPAGES_SAPLING_VIEWING_KEY.to_string(), None); | ||
// Snapshot a birthday above activation height | ||
storage.add_sapling_key(&FAKE_SAPLING_VIEWING_KEY.to_string(), Height(1_000_000)); | ||
} | ||
|
||
/// Add fake results to `storage` for testing purposes. | ||
pub fn add_fake_results(storage: &mut Storage, network: Network, height: Height) { | ||
let blocks = match network { | ||
Mainnet => &*zebra_test::vectors::CONTINUOUS_MAINNET_BLOCKS, | ||
Testnet => &*zebra_test::vectors::CONTINUOUS_TESTNET_BLOCKS, | ||
}; | ||
|
||
let block: Arc<Block> = blocks | ||
.get(&height.0) | ||
.expect("block height has test data") | ||
.zcash_deserialize_into() | ||
.expect("test data deserializes"); | ||
|
||
// Fake results from the first few blocks | ||
storage.add_sapling_results( | ||
&ZECPAGES_SAPLING_VIEWING_KEY.to_string(), | ||
height, | ||
block | ||
.transactions | ||
.iter() | ||
.enumerate() | ||
.map(|(index, tx)| (TransactionIndex::from_usize(index), tx.hash().into())) | ||
.collect(), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
zebra-scan/src/storage/db/tests/snapshots/sapling_key_0_results@mainnet_0.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
source: zebra-scan/src/storage/db/tests/snapshot.rs | ||
expression: sapling_results | ||
--- | ||
{ | ||
Height(0): [ | ||
SaplingScannedResult("c4eaa58879081de3c24a7b117ed2b28300e7ec4c4c1dff1d3f1268b7857a4ddb"), | ||
], | ||
Height(419199): [], | ||
} |
13 changes: 13 additions & 0 deletions
13
zebra-scan/src/storage/db/tests/snapshots/sapling_key_0_results@mainnet_1.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
source: zebra-scan/src/storage/db/tests/snapshot.rs | ||
expression: sapling_results | ||
--- | ||
{ | ||
Height(0): [ | ||
SaplingScannedResult("c4eaa58879081de3c24a7b117ed2b28300e7ec4c4c1dff1d3f1268b7857a4ddb"), | ||
], | ||
Height(1): [ | ||
SaplingScannedResult("851bf6fbf7a976327817c738c489d7fa657752445430922d94c983c0b9ed4609"), | ||
], | ||
Height(419199): [], | ||
} |
16 changes: 16 additions & 0 deletions
16
zebra-scan/src/storage/db/tests/snapshots/sapling_key_0_results@mainnet_2.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
source: zebra-scan/src/storage/db/tests/snapshot.rs | ||
expression: sapling_results | ||
--- | ||
{ | ||
Height(0): [ | ||
SaplingScannedResult("c4eaa58879081de3c24a7b117ed2b28300e7ec4c4c1dff1d3f1268b7857a4ddb"), | ||
], | ||
Height(1): [ | ||
SaplingScannedResult("851bf6fbf7a976327817c738c489d7fa657752445430922d94c983c0b9ed4609"), | ||
], | ||
Height(2): [ | ||
SaplingScannedResult("8974d08d1c5f9c860d8b629d582a56659a4a1dcb2b5f98a25a5afcc2a784b0f4"), | ||
], | ||
Height(419199): [], | ||
} |
7 changes: 7 additions & 0 deletions
7
zebra-scan/src/storage/db/tests/snapshots/sapling_key_0_results@mainnet_keys.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
source: zebra-scan/src/storage/db/tests/snapshot.rs | ||
expression: sapling_results | ||
--- | ||
{ | ||
Height(419199): [], | ||
} |
10 changes: 10 additions & 0 deletions
10
zebra-scan/src/storage/db/tests/snapshots/sapling_key_0_results@testnet_0.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
source: zebra-scan/src/storage/db/tests/snapshot.rs | ||
expression: sapling_results | ||
--- | ||
{ | ||
Height(0): [ | ||
SaplingScannedResult("c4eaa58879081de3c24a7b117ed2b28300e7ec4c4c1dff1d3f1268b7857a4ddb"), | ||
], | ||
Height(279999): [], | ||
} |
Oops, something went wrong.