Add test methods for modifying orchard shielded data and joinsplits (#2580)

Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
This commit is contained in:
teor 2021-08-07 23:23:32 +10:00 committed by GitHub
parent a1cec27871
commit 8f4c3b09ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View File

@ -638,7 +638,7 @@ impl Transaction {
// orchard
/// Access the [`orchard::ShieldedData`] in this transaction, if there are any,
/// Access the [`orchard::ShieldedData`] in this transaction,
/// regardless of version.
pub fn orchard_shielded_data(&self) -> Option<&orchard::ShieldedData> {
match self {
@ -656,6 +656,27 @@ impl Transaction {
}
}
/// Modify the [`orchard::ShieldedData`] in this transaction,
/// regardless of version.
#[cfg(any(test, feature = "proptest-impl"))]
pub fn orchard_shielded_data_mut(&mut self) -> Option<&mut orchard::ShieldedData> {
match self {
Transaction::V5 {
orchard_shielded_data: Some(orchard_shielded_data),
..
} => Some(orchard_shielded_data),
Transaction::V1 { .. }
| Transaction::V2 { .. }
| Transaction::V3 { .. }
| Transaction::V4 { .. }
| Transaction::V5 {
orchard_shielded_data: None,
..
} => None,
}
}
/// Iterate over the [`orchard::Action`]s in this transaction, if there are any,
/// regardless of version.
pub fn orchard_actions(&self) -> impl Iterator<Item = &orchard::Action> {
@ -690,7 +711,8 @@ impl Transaction {
.map(|orchard_shielded_data| orchard_shielded_data.flags)
}
/// Return if the transaction has any Orchard shielded data.
/// Return if the transaction has any Orchard shielded data,
/// regardless of version.
pub fn has_orchard_shielded_data(&self) -> bool {
self.orchard_shielded_data().is_some()
}

View File

@ -53,6 +53,13 @@ impl<P: ZkSnarkProof> JoinSplitData<P> {
std::iter::once(&self.first).chain(self.rest.iter())
}
/// Modify the [`JoinSplit`]s in `self`,
/// in the order they appear in the transaction.
#[cfg(any(test, feature = "proptest-impl"))]
pub fn joinsplits_mut(&mut self) -> impl Iterator<Item = &mut JoinSplit<P>> {
std::iter::once(&mut self.first).chain(self.rest.iter_mut())
}
/// Iterate over the [`Nullifier`]s in `self`.
pub fn nullifiers(&self) -> impl Iterator<Item = &Nullifier> {
self.joinsplits()