From e29622e972374e98852753f2cfc2763f80b20adf Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 23 Jul 2024 16:45:12 +0000 Subject: [PATCH 1/3] zcash_client_sqlite: Check that ZIP 320 spend creates expected history --- zcash_client_sqlite/src/testing/pool.rs | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/zcash_client_sqlite/src/testing/pool.rs b/zcash_client_sqlite/src/testing/pool.rs index 5e64a06eb..76d172749 100644 --- a/zcash_client_sqlite/src/testing/pool.rs +++ b/zcash_client_sqlite/src/testing/pool.rs @@ -313,6 +313,7 @@ pub(crate) fn send_multi_step_proposed_transfer() { legacy::keys::{NonHardenedChildIndex, TransparentKeyScope}, transaction::builder::{BuildConfig, Builder}, }; + use zcash_protocol::value::ZatBalance; use crate::wallet::{sapling::tests::test_prover, GAP_LIMIT}; @@ -452,6 +453,34 @@ pub(crate) fn send_multi_step_proposed_transfer() { (sent_v, sent_to_addr, None, None) if sent_v == u64::try_from(transfer_amount).unwrap() && sent_to_addr == Some(tex_addr.encode(&st.wallet().params))); + // Check that the transaction history matches what we expect. + let tx_history = st.get_tx_history().unwrap(); + + let tx_0 = tx_history + .iter() + .find(|tx| tx.txid() == *txids.first()) + .unwrap(); + let tx_1 = tx_history + .iter() + .find(|tx| tx.txid() == *txids.last()) + .unwrap(); + + assert_eq!(tx_0.account_id(), &account_id); + assert!(!tx_0.expired_unmined()); + assert_eq!(tx_0.has_change(), expected_step0_change.is_positive()); + assert_eq!( + tx_0.account_value_delta(), + -ZatBalance::from(expected_step0_fee), + ); + + assert_eq!(tx_1.account_id(), &account_id); + assert!(!tx_1.expired_unmined()); + assert!(!tx_1.has_change()); + assert_eq!( + tx_1.account_value_delta(), + -ZatBalance::from(expected_ephemeral), + ); + (ephemeral_addr.unwrap(), txids) }; From 1a562fb2088f66b741f5ebddba5803cfa618a927 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 23 Jul 2024 16:45:46 +0000 Subject: [PATCH 2/3] zcash_client_sqlite: Fix bug in `utxos_to_txos` migration zcash/librustzcash@72d8df8e68c2180f06a0efe7a6ebf737b511e44d altered the `v_received_notes` view to include transparent coins (renaming it to `v_received_outputs`), and updated `v_transactions` to not separately query transparent coins. The latter queried `v_received_notes` twice, once to fetch notes received in a transaction, and again to fetch notes spent in a transaction. The spent notes were obtained by joining on the junction table `v_received_note_spends` to get the spent-in transaction's ID. The commit retained the junction table join, but didn't use it due to a typo, leading to notes being "spent-in" the transaction they were received in. This bug had several effects: - `account_balance_delta` showed `+change` for transactions in which a change note was received that had not yet been spent. - `account_balance_delta` showed `0` for transactions in which all received notes had been subsequently spent. - Transactions that spent funds with no change were omitted. --- zcash_client_sqlite/src/wallet/db.rs | 2 +- zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/zcash_client_sqlite/src/wallet/db.rs b/zcash_client_sqlite/src/wallet/db.rs index 65ce3b148..b57079041 100644 --- a/zcash_client_sqlite/src/wallet/db.rs +++ b/zcash_client_sqlite/src/wallet/db.rs @@ -700,7 +700,7 @@ notes AS ( ON ros.pool = ro.pool AND ros.received_output_id = ro.id_within_pool_table JOIN transactions - ON transactions.id_tx = ro.transaction_id + ON transactions.id_tx = ros.transaction_id ), -- Obtain a count of the notes that the wallet created in each transaction, -- not counting change notes. diff --git a/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs b/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs index b1ccbbd7f..33ffbd1b8 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/utxos_to_txos.rs @@ -229,7 +229,7 @@ impl RusqliteMigration for Migration { ON ros.pool = ro.pool AND ros.received_output_id = ro.id_within_pool_table JOIN transactions - ON transactions.id_tx = ro.transaction_id + ON transactions.id_tx = ros.transaction_id ), -- Obtain a count of the notes that the wallet created in each transaction, -- not counting change notes. From bbb73b04952d815beed4c8fd0b42c44ace6a23af Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 23 Jul 2024 17:03:22 +0000 Subject: [PATCH 3/3] Fix clippy lint --- zcash_client_sqlite/src/testing.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zcash_client_sqlite/src/testing.rs b/zcash_client_sqlite/src/testing.rs index d5dbd72e0..2019723b0 100644 --- a/zcash_client_sqlite/src/testing.rs +++ b/zcash_client_sqlite/src/testing.rs @@ -1,10 +1,9 @@ -use std::ffi::OsStr; use std::fmt; use std::num::NonZeroU32; use std::{collections::BTreeMap, convert::Infallible}; #[cfg(feature = "unstable")] -use std::fs::File; +use std::{ffi::OsStr, fs::File}; use group::ff::Field; use incrementalmerkletree::{Marking, Position, Retention};