Skip to content

Commit

Permalink
zcash_client_backend: Add a test for ZIP 317 cross-pool payments.
Browse files Browse the repository at this point in the history
  • Loading branch information
nuttycom committed Mar 13, 2024
1 parent b3d06ba commit b2597aa
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
14 changes: 7 additions & 7 deletions zcash_client_backend/src/data_api/wallet/input_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
47 changes: 47 additions & 0 deletions zcash_client_backend/src/fees/zip317.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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::<TestTransparentInput>::new(),
&Vec::<TxOut>::new(),
&(
sapling::builder::BundleType::DEFAULT,
&[TestSaplingInput {
note_id: 0,
value: NonNegativeAmount::const_from_u64(55000),
}][..],
&Vec::<Infallible>::new()[..],
),
#[cfg(feature = "orchard")]
&(
orchard::builder::BundleType::DEFAULT,
&Vec::<Infallible>::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(
Expand Down

0 comments on commit b2597aa

Please sign in to comment.