From e6b45f76f8d2a71149cc0646c8f906e8e78dd6b0 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 27 Dec 2024 08:26:21 -0700 Subject: [PATCH] zcash_client_sqlite: Remove duplicative migration test. This removes a `fix_bad_change_flagging` migration test duplicated from `zcash_client_backend::data_api::testing::pool::shiled_transparent`. It is impractical to maintain backwards compatibility to earlier database states for the entire test harness, which is more or less what retaining this test would require, and the desired outcome is already demonstrated by the `shield_transparent` test; demonstrating the fix directly is unnecessary. --- .../migrations/fix_bad_change_flagging.rs | 131 ------------------ 1 file changed, 131 deletions(-) diff --git a/zcash_client_sqlite/src/wallet/init/migrations/fix_bad_change_flagging.rs b/zcash_client_sqlite/src/wallet/init/migrations/fix_bad_change_flagging.rs index 056070fe0..38b1d49ae 100644 --- a/zcash_client_sqlite/src/wallet/init/migrations/fix_bad_change_flagging.rs +++ b/zcash_client_sqlite/src/wallet/init/migrations/fix_bad_change_flagging.rs @@ -72,139 +72,8 @@ impl RusqliteMigration for Migration { mod tests { use crate::wallet::init::migrations::tests::test_migrate; - #[cfg(feature = "transparent-inputs")] - use { - crate::{ - testing::{db::TestDbFactory, BlockCache}, - wallet::init::init_wallet_db, - }, - ::transparent::bundle::{OutPoint, TxOut}, - zcash_client_backend::{ - data_api::{ - testing::{ - pool::ShieldedPoolTester, sapling::SaplingPoolTester, AddressType, TestBuilder, - }, - wallet::input_selection::GreedyInputSelector, - Account as _, WalletRead as _, WalletWrite as _, - }, - fees::{standard, DustOutputPolicy, StandardFeeRule}, - wallet::WalletTransparentOutput, - }, - zcash_primitives::block::BlockHash, - zcash_protocol::value::Zatoshis, - }; - #[test] fn migrate() { test_migrate(&[super::MIGRATION_ID]); } - - #[cfg(feature = "transparent-inputs")] - fn shield_transparent() { - let ds_factory = TestDbFactory::new( - super::DEPENDENCIES - .iter() - .copied() - // Pull in the account UUID migration so `TestBuilder::build` works. - .chain(Some(super::super::add_account_uuids::MIGRATION_ID)) - .collect(), - ); - let cache = BlockCache::new(); - let mut st = TestBuilder::new() - .with_data_store_factory(ds_factory) - .with_block_cache(cache) - .with_account_from_sapling_activation(BlockHash([0; 32])) - .build(); - - let account = st.test_account().cloned().unwrap(); - let dfvk = T::test_account_fvk(&st); - - let uaddr = st - .wallet() - .get_current_address(account.id()) - .unwrap() - .unwrap(); - let taddr = uaddr.transparent().unwrap(); - - // Ensure that the wallet has at least one block - let (h, _, _) = st.generate_next_block( - &dfvk, - AddressType::Internal, - Zatoshis::const_from_u64(50000), - ); - st.scan_cached_blocks(h, 1); - - let utxo = WalletTransparentOutput::from_parts( - OutPoint::fake(), - TxOut { - value: Zatoshis::const_from_u64(100000), - script_pubkey: taddr.script(), - }, - Some(h), - ) - .unwrap(); - - let res0 = st.wallet_mut().put_received_transparent_utxo(&utxo); - assert_matches!(res0, Ok(_)); - - let fee_rule = StandardFeeRule::Zip317; - - let input_selector = GreedyInputSelector::new(); - let change_strategy = standard::SingleOutputChangeStrategy::new( - fee_rule, - None, - T::SHIELDED_PROTOCOL, - DustOutputPolicy::default(), - ); - - let txids = st - .shield_transparent_funds( - &input_selector, - &change_strategy, - Zatoshis::from_u64(10000).unwrap(), - account.usk(), - &[*taddr], - account.id(), - 1, - ) - .unwrap(); - assert_eq!(txids.len(), 1); - - 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()); - - // Prior to the fix that removes the source of the error this migration is addressing, - // this scanning will result in a state where `tx.is_shielding() == false`. However, - // we can't validate that here, because after that fix, this test would fail. - let (h, _) = st.generate_next_block_including(*txids.first()); - st.scan_cached_blocks(h, 1); - - // Complete the migration to resolve the incorrect change flag value. - init_wallet_db(st.wallet_mut().db_mut(), None).unwrap(); - - 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()); - } - - #[test] - #[cfg(feature = "transparent-inputs")] - fn sapling_shield_transparent() { - shield_transparent::(); - } - - #[test] - #[cfg(all(feature = "orchard", feature = "transparent-inputs"))] - fn orchard_shield_transparent() { - use zcash_client_backend::data_api::testing::orchard::OrchardPoolTester; - - shield_transparent::(); - } }