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 ad5268c0f..e25e0711e 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 @@ -71,141 +71,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, - }, - 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, - transaction::components::{OutPoint, TxOut}, - }, - 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::(); - } }