Skip to content

Commit

Permalink
zcash_client_sqlite: Remove duplicative migration test.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nuttycom committed Dec 30, 2024
1 parent c278405 commit e6b45f7
Showing 1 changed file with 0 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: ShieldedPoolTester>() {
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::<SaplingPoolTester>();
}

#[test]
#[cfg(all(feature = "orchard", feature = "transparent-inputs"))]
fn orchard_shield_transparent() {
use zcash_client_backend::data_api::testing::orchard::OrchardPoolTester;

shield_transparent::<OrchardPoolTester>();
}
}

0 comments on commit e6b45f7

Please sign in to comment.