diff --git a/zcash_client_backend/src/data_api/wallet/input_selection.rs b/zcash_client_backend/src/data_api/wallet/input_selection.rs index 23c7808c7..8467407cf 100644 --- a/zcash_client_backend/src/data_api/wallet/input_selection.rs +++ b/zcash_client_backend/src/data_api/wallet/input_selection.rs @@ -273,13 +273,13 @@ impl sapling::OutputView for SaplingPayment { #[cfg(feature = "orchard")] pub(crate) struct OrchardPayment(NonNegativeAmount); -// TODO: introduce this method when it is needed for testing. -// #[cfg(test)] -// impl OrchardPayment { -// pub(crate) fn new(amount: NonNegativeAmount) -> Self { -// OrchardPayment(amount) -// } -// } +#[cfg(test)] +#[cfg(feature = "orchard")] +impl OrchardPayment { + pub(crate) fn new(amount: NonNegativeAmount) -> Self { + OrchardPayment(amount) + } +} #[cfg(feature = "orchard")] impl orchard_fees::OutputView for OrchardPayment { diff --git a/zcash_client_backend/src/fees/zip317.rs b/zcash_client_backend/src/fees/zip317.rs index ebc2aec86..6e5839f0b 100644 --- a/zcash_client_backend/src/fees/zip317.rs +++ b/zcash_client_backend/src/fees/zip317.rs @@ -237,6 +237,9 @@ mod tests { ShieldedProtocol, }; + #[cfg(feature = "orchard")] + use crate::data_api::wallet::input_selection::OrchardPayment; + #[test] fn change_without_dust() { let change_strategy = SingleOutputChangeStrategy::new( @@ -280,6 +283,50 @@ mod tests { ); } + #[test] + #[cfg(feature = "orchard")] + fn cross_pool_change_without_dust() { + let change_strategy = SingleOutputChangeStrategy::new( + Zip317FeeRule::standard(), + None, + ShieldedProtocol::Orchard, + ); + + // spend a single Sapling note that is sufficient to pay the fee + let result = change_strategy.compute_balance( + &Network::TestNetwork, + Network::TestNetwork + .activation_height(NetworkUpgrade::Nu5) + .unwrap(), + &Vec::::new(), + &Vec::::new(), + &( + sapling::builder::BundleType::DEFAULT, + &[TestSaplingInput { + note_id: 0, + value: NonNegativeAmount::const_from_u64(55000), + }][..], + &Vec::::new()[..], + ), + #[cfg(feature = "orchard")] + &( + orchard::builder::BundleType::DEFAULT, + &Vec::::new()[..], + &[OrchardPayment::new(NonNegativeAmount::const_from_u64( + 30000, + ))][..], + ), + &DustOutputPolicy::default(), + ); + + assert_matches!( + result, + Ok(balance) if + balance.proposed_change() == [ChangeValue::orchard(NonNegativeAmount::const_from_u64(5000), None)] && + balance.fee_required() == NonNegativeAmount::const_from_u64(20000) + ); + } + #[test] fn change_with_transparent_payments() { let change_strategy = SingleOutputChangeStrategy::new(