From a0ca6496870a48b3dbe72fb14f17316a23a2f282 Mon Sep 17 00:00:00 2001 From: Francisco Gindre Date: Wed, 23 Oct 2024 20:52:50 -0300 Subject: [PATCH] Fix confirmations on transparent balance and tests --- .../src/data_api/testing/transparent.rs | 16 ++++++++++++++++ zcash_client_sqlite/src/wallet/transparent.rs | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/zcash_client_backend/src/data_api/testing/transparent.rs b/zcash_client_backend/src/data_api/testing/transparent.rs index d38191053..fa0d2e902 100644 --- a/zcash_client_backend/src/data_api/testing/transparent.rs +++ b/zcash_client_backend/src/data_api/testing/transparent.rs @@ -105,6 +105,22 @@ where st.wallet().get_transparent_balances(account_id, height_2), Ok(h) if h.get(taddr) == Some(&value) ); + // TODO: Find our why this does not work. + + // let unshielded_balance = st.wallet().get_wallet_summary(0) + // .unwrap() + // .unwrap() + // .account_balances + // .get(&account_id) + // .unwrap() + // .unshielded_balance; + + // let mut expected_balance = Balance::ZERO; + + // expected_balance.add_pending_change_value(value).unwrap(); + + // assert_eq!(unshielded_balance, expected_balance); + } pub fn transparent_balance_across_shielding(dsf: DSF, cache: impl TestCache) diff --git a/zcash_client_sqlite/src/wallet/transparent.rs b/zcash_client_sqlite/src/wallet/transparent.rs index 4183aec2c..5f2c59af3 100644 --- a/zcash_client_sqlite/src/wallet/transparent.rs +++ b/zcash_client_sqlite/src/wallet/transparent.rs @@ -394,7 +394,7 @@ pub(crate) fn add_transparent_account_balances( -- the transaction that created the output is mined and with enough confirmations WHERE ( t.mined_height < :mempool_height -- tx is mined - AND :mempool_height - t.mined_height >= :min_confirmations -- has at least min_confirmations + AND t.mined_height <= (t.mined_height - :min_confirmations) -- has at least min_confirmations ) -- and the received txo is unspent AND u.id NOT IN ( @@ -433,8 +433,8 @@ pub(crate) fn add_transparent_account_balances( ON t.id_tx = u.transaction_id -- the transaction that created the output is mined with not enough confirmations or is definitely unexpired WHERE ( - (t.mined_height < :mempool_height - AND (:mempool_height - t.mined_height) < :min_confirmations) -- tx is mined but not confirmed + t.mined_height < :mempool_height + AND t.mined_height > (t.mined_height - :min_confirmations) -- tx is mined but not confirmed OR t.expiry_height = 0 -- tx will not expire OR t.expiry_height >= :mempool_height )