diff --git a/zebra-scan/src/tests/vectors.rs b/zebra-scan/src/tests/vectors.rs index 1869e359146..a3123759d1a 100644 --- a/zebra-scan/src/tests/vectors.rs +++ b/zebra-scan/src/tests/vectors.rs @@ -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, @@ -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}, }; @@ -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(); @@ -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 @@ -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, @@ -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(); @@ -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())]) +}