diff --git a/zingolib/src/wallet/notes/interface.rs b/zingolib/src/wallet/notes/interface.rs index 6d83581e9..cea71caf8 100644 --- a/zingolib/src/wallet/notes/interface.rs +++ b/zingolib/src/wallet/notes/interface.rs @@ -27,6 +27,16 @@ pub trait NoteInterface: Sized { /// TODO: Add Doc Comment Here! fn pending_spent_mut(&mut self) -> &mut Option<(TxId, u32)>; + + /// Returns true if the note has been presumptively spent but the spent has not been validated. + fn is_pending_spent(&self) -> bool { + Self::pending_spent(self).is_some() + } + + /// Returns false if the note is spendable. + fn is_spent_or_pending_spent(&self) -> bool { + self.is_spent() || self.is_pending_spent() + } } /// ShieldedNotes are either part of a Sapling or Orchard Pool diff --git a/zingolib/src/wallet/notes/sapling.rs b/zingolib/src/wallet/notes/sapling.rs index 30e75ba1e..fa485c6eb 100644 --- a/zingolib/src/wallet/notes/sapling.rs +++ b/zingolib/src/wallet/notes/sapling.rs @@ -282,11 +282,21 @@ pub mod mocks { } #[cfg(test)] -mod tests { - use super::mocks::SaplingNoteBuilder; +pub mod tests { + use crate::{ + test_framework::mocks::default_txid, + wallet::notes::{sapling::mocks::SaplingNoteBuilder, NoteInterface}, + }; #[test] - pub fn build_sapling_note() { - let _sapling_note = SaplingNoteBuilder::default().build(); + fn pending_spent_note_is_pending_spent() { + let spend = Some((default_txid(), 641312)); + let note = SaplingNoteBuilder::default() + .unconfirmed_spent(spend) + .build(); + assert!(!note.is_spent()); + assert!(note.is_pending_spent()); + assert!(note.is_spent_or_pending_spent()); + assert_eq!(note.pending_spent(), &spend); } } diff --git a/zingolib/src/wallet/notes/transparent.rs b/zingolib/src/wallet/notes/transparent.rs index f9ce42c4e..297267f9d 100644 --- a/zingolib/src/wallet/notes/transparent.rs +++ b/zingolib/src/wallet/notes/transparent.rs @@ -249,3 +249,23 @@ pub mod mocks { } } } + +#[cfg(test)] +pub mod tests { + use crate::{ + test_framework::mocks::default_txid, + wallet::notes::{transparent::mocks::TransparentNoteBuilder, NoteInterface}, + }; + + #[test] + fn pending_spent_note_is_pending_spent() { + let spend = Some((default_txid(), 112358)); + let note = TransparentNoteBuilder::default() + .unconfirmed_spent(spend) + .build(); + assert!(!note.is_spent()); + assert!(note.is_pending_spent()); + assert!(note.is_spent_or_pending_spent()); + assert_eq!(note.pending_spent(), &spend); + } +}