Skip to content

Commit

Permalink
cleanup some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed May 27, 2024
1 parent 5bed5b4 commit 314751e
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions zebra-scan/src/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ use std::sync::Arc;

use color_eyre::Result;

use sapling::{
zip32::{DiversifiableFullViewingKey, ExtendedSpendingKey},
Nullifier,
};
use zcash_client_backend::{
encoding::{decode_extended_full_viewing_key, encode_extended_full_viewing_key},
proto::compact_formats::ChainMetadata,
scanning::ScanningKeys,
};
use zcash_keys::keys::UnifiedFullViewingKey;
use zcash_primitives::{
constants::mainnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY, zip32::AccountId,
};

use sapling::{
zip32::{DiversifiableFullViewingKey, ExtendedSpendingKey},
Nullifier,
};

use zebra_chain::{
block::{Block, Height},
chain_tip::ChainTip,
Expand All @@ -26,7 +27,7 @@ use zebra_chain::{
use zebra_state::{SaplingScannedResult, TransactionIndex};

use crate::{
scan::{block_to_compact, scan_block},
scan::{block_to_compact, scan_block, ScanningKey},
storage::db::tests::new_test_storage,
tests::{fake_block, mock_sapling_efvk, ZECPAGES_SAPLING_VIEWING_KEY},
};
Expand All @@ -45,11 +46,7 @@ async fn scanning_from_fake_generated_blocks() -> Result<()> {

assert_eq!(block.transactions.len(), 4);

let ufvk = zcash_keys::keys::UnifiedFullViewingKey::new(Some(dfvk));
let scanning_keys = zcash_client_backend::scanning::ScanningKeys::from_account_ufvks([(
AccountId::ZERO,
ufvk.unwrap(),
)]);
let scanning_keys = scanning_key(dfvk);

let res = scan_block(&Network::Mainnet, &block, sapling_tree_size, &scanning_keys).unwrap();

Expand Down Expand Up @@ -108,8 +105,10 @@ async fn scanning_zecpages_from_populated_zebra_state() -> Result<()> {

let mut transactions_found = 0;
let mut transactions_scanned = 0;

let mut blocks_scanned = 0;

let scanning_keys = scanning_key(dfvk);

while let Some(block) = db.block(height.into()) {
// We use a dummy size of the Sapling note commitment tree. We can't set the size to zero
// because the underlying scanning function would return
Expand All @@ -125,12 +124,6 @@ async fn scanning_zecpages_from_populated_zebra_state() -> Result<()> {

let compact_block = block_to_compact(&block, chain_metadata);

let ufvk = zcash_keys::keys::UnifiedFullViewingKey::new(Some(dfvk.clone()));
let scanning_keys = zcash_client_backend::scanning::ScanningKeys::from_account_ufvks([(
AccountId::default(),
ufvk.unwrap(),
)]);

let res = scan_block(
&network,
&block,
Expand Down Expand Up @@ -195,12 +188,7 @@ fn scanning_fake_blocks_store_key_and_results() -> Result<()> {

let (block, sapling_tree_size) = fake_block(1u32.into(), nf, &dfvk, 1, true, Some(0));

// Build scanning keys
let ufvk = zcash_keys::keys::UnifiedFullViewingKey::new(Some(dfvk));
let scanning_keys = zcash_client_backend::scanning::ScanningKeys::from_account_ufvks([(
AccountId::default(),
ufvk.unwrap(),
)]);
let scanning_keys = scanning_key(dfvk);

let result = scan_block(&Network::Mainnet, &block, sapling_tree_size, &scanning_keys).unwrap();

Expand All @@ -226,3 +214,9 @@ fn scanning_fake_blocks_store_key_and_results() -> Result<()> {

Ok(())
}

/// Convert from the `DiversifiableFullViewingKey` to a `ScanningKey`.
fn scanning_key(dfvk: DiversifiableFullViewingKey) -> ScanningKey {
let ufvk = UnifiedFullViewingKey::new(Some(dfvk));
ScanningKeys::from_account_ufvks([(AccountId::ZERO, ufvk.unwrap())])
}

0 comments on commit 314751e

Please sign in to comment.