Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zcash_client_sqlite: Ensure that all shielded change outputs are correctly flagged. #1585

Merged
merged 5 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions zcash_client_backend/src/data_api/testing/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,18 @@ where
assert_eq!(tx.received_note_count(), 0);
assert_eq!(tx.sent_note_count(), 0);
assert!(tx.is_shielding());

// Generate and scan the block including the transaction
let (h, _) = st.generate_next_block_including(*txids.first());
st.scan_cached_blocks(h, 1);

// Ensure that the transaction metadata is still correct after the update produced by scanning.
let tx = st.get_tx_from_history(*txids.first()).unwrap().unwrap();
assert_eq!(tx.spent_note_count(), 1);
assert!(tx.has_change());
assert_eq!(tx.received_note_count(), 0);
assert_eq!(tx.sent_note_count(), 0);
assert!(tx.is_shielding());
}

// FIXME: This requires fixes to the test framework.
Expand Down
18 changes: 9 additions & 9 deletions zcash_client_sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ mod tests {
#[test]
fn validate_seed() {
let st = TestBuilder::new()
.with_data_store_factory(TestDbFactory)
.with_data_store_factory(TestDbFactory::default())
.with_account_from_sapling_activation(BlockHash([0; 32]))
.build();
let account = st.test_account().unwrap();
Expand Down Expand Up @@ -1940,7 +1940,7 @@ mod tests {
#[test]
pub(crate) fn get_next_available_address() {
let mut st = TestBuilder::new()
.with_data_store_factory(TestDbFactory)
.with_data_store_factory(TestDbFactory::default())
.with_account_from_sapling_activation(BlockHash([0; 32]))
.build();
let account = st.test_account().cloned().unwrap();
Expand All @@ -1962,7 +1962,7 @@ mod tests {
#[test]
pub(crate) fn import_account_hd_0() {
let st = TestBuilder::new()
.with_data_store_factory(TestDbFactory)
.with_data_store_factory(TestDbFactory::default())
.with_account_from_sapling_activation(BlockHash([0; 32]))
.set_account_index(zip32::AccountId::ZERO)
.build();
Expand All @@ -1974,7 +1974,7 @@ mod tests {
#[test]
pub(crate) fn import_account_hd_1_then_2() {
let mut st = TestBuilder::new()
.with_data_store_factory(TestDbFactory)
.with_data_store_factory(TestDbFactory::default())
.build();

let birthday = AccountBirthday::from_parts(
Expand Down Expand Up @@ -2065,7 +2065,7 @@ mod tests {
#[test]
pub(crate) fn import_account_hd_1_then_conflicts() {
let mut st = TestBuilder::new()
.with_data_store_factory(TestDbFactory)
.with_data_store_factory(TestDbFactory::default())
.build();

let birthday = AccountBirthday::from_parts(
Expand Down Expand Up @@ -2097,7 +2097,7 @@ mod tests {
#[test]
pub(crate) fn import_account_ufvk_then_conflicts() {
let mut st = TestBuilder::new()
.with_data_store_factory(TestDbFactory)
.with_data_store_factory(TestDbFactory::default())
.build();

let birthday = AccountBirthday::from_parts(
Expand Down Expand Up @@ -2142,7 +2142,7 @@ mod tests {
#[test]
pub(crate) fn create_account_then_conflicts() {
let mut st = TestBuilder::new()
.with_data_store_factory(TestDbFactory)
.with_data_store_factory(TestDbFactory::default())
.build();

let birthday = AccountBirthday::from_parts(
Expand Down Expand Up @@ -2175,7 +2175,7 @@ mod tests {

use crate::testing::BlockCache;
let st = TestBuilder::new()
.with_data_store_factory(TestDbFactory)
.with_data_store_factory(TestDbFactory::default())
.with_block_cache(BlockCache::new())
.with_account_from_sapling_activation(BlockHash([0; 32]))
.build();
Expand Down Expand Up @@ -2208,7 +2208,7 @@ mod tests {
use crate::testing::FsBlockCache;

let mut st = TestBuilder::new()
.with_data_store_factory(TestDbFactory)
.with_data_store_factory(TestDbFactory::default())
.with_block_cache(FsBlockCache::new())
.build();

Expand Down
29 changes: 25 additions & 4 deletions zcash_client_sqlite/src/testing/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use ambassador::Delegate;
use rusqlite::Connection;
use std::collections::HashMap;
use std::num::NonZeroU32;
use uuid::Uuid;

use tempfile::NamedTempFile;

Expand Down Expand Up @@ -31,7 +32,11 @@ use zcash_primitives::{
};
use zcash_protocol::{consensus::BlockHeight, local_consensus::LocalNetwork, memo::Memo};

use crate::{error::SqliteClientError, wallet::init::init_wallet_db, AccountId, WalletDb};
use crate::{
error::SqliteClientError,
wallet::init::{init_wallet_db, init_wallet_db_internal},
AccountId, WalletDb,
};

#[cfg(feature = "transparent-inputs")]
use {
Expand Down Expand Up @@ -142,7 +147,19 @@ unsafe fn run_sqlite3<S: AsRef<OsStr>>(db_path: S, command: &str) {
eprintln!("------");
}

pub(crate) struct TestDbFactory;
#[derive(Default)]
pub(crate) struct TestDbFactory {
target_migrations: Option<Vec<Uuid>>,
}

impl TestDbFactory {
#[allow(dead_code)]
pub(crate) fn new(target_migrations: Vec<Uuid>) -> Self {
Self {
target_migrations: Some(target_migrations),
}
}
}

impl DataStoreFactory for TestDbFactory {
type Error = ();
Expand All @@ -154,7 +171,11 @@ impl DataStoreFactory for TestDbFactory {
fn new_data_store(&self, network: LocalNetwork) -> Result<Self::DataStore, Self::Error> {
let data_file = NamedTempFile::new().unwrap();
let mut db_data = WalletDb::for_path(data_file.path(), network).unwrap();
init_wallet_db(&mut db_data, None).unwrap();
if let Some(migrations) = &self.target_migrations {
init_wallet_db_internal(&mut db_data, None, migrations, true).unwrap();
} else {
init_wallet_db(&mut db_data, None).unwrap();
}
Ok(TestDb::from_parts(db_data, data_file))
}
}
Expand All @@ -166,7 +187,7 @@ impl Reset for TestDb {
let network = *st.network();
let old_db = std::mem::replace(
st.wallet_mut(),
TestDbFactory.new_data_store(network).unwrap(),
TestDbFactory::default().new_data_store(network).unwrap(),
);
old_db.take_data_file()
}
Expand Down
Loading
Loading