From 103d70ca65055bbe5fdf30781e0ebacf2e379efc Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Wed, 17 Apr 2024 16:34:19 +0000 Subject: [PATCH 1/5] added NoteInterface default methods --- zingolib/src/wallet/notes/interface.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/zingolib/src/wallet/notes/interface.rs b/zingolib/src/wallet/notes/interface.rs index c62bc23d9..1463cddc5 100644 --- a/zingolib/src/wallet/notes/interface.rs +++ b/zingolib/src/wallet/notes/interface.rs @@ -16,6 +16,12 @@ pub trait NoteInterface: Sized { fn spent_mut(&mut self) -> &mut Option<(TxId, u32)>; fn pending_spent(&self) -> &Option<(TxId, u32)>; fn pending_spent_mut(&mut self) -> &mut Option<(TxId, u32)>; + fn is_pending_spent(&self) -> bool { + Self::pending_spent(self).is_some() + } + 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 From 5c48313b779b27ab5b236fddc33e382fc31b9f93 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Wed, 17 Apr 2024 16:47:49 +0000 Subject: [PATCH 2/5] added pending_spent_note_is_pending_spent test for TransparentNote --- zingolib/src/wallet/notes/transparent.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/zingolib/src/wallet/notes/transparent.rs b/zingolib/src/wallet/notes/transparent.rs index 550d1c70c..e621bf4b8 100644 --- a/zingolib/src/wallet/notes/transparent.rs +++ b/zingolib/src/wallet/notes/transparent.rs @@ -233,3 +233,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_eq!(note.is_spent(), false); + assert_eq!(note.is_pending_spent(), true); + assert_eq!(note.is_spent_or_pending_spent(), true); + assert_eq!(note.pending_spent(), &spend); + } +} From 96bd8559bdba31d761bdd339d34b2a243fc3ebb6 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Wed, 17 Apr 2024 16:48:12 +0000 Subject: [PATCH 3/5] added pending_spent_note_is_pending_spent test for SaplingiNote --- zingolib/src/wallet/notes/sapling.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/zingolib/src/wallet/notes/sapling.rs b/zingolib/src/wallet/notes/sapling.rs index 989562371..234a211af 100644 --- a/zingolib/src/wallet/notes/sapling.rs +++ b/zingolib/src/wallet/notes/sapling.rs @@ -268,11 +268,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_eq!(note.is_spent(), false); + assert_eq!(note.is_pending_spent(), true); + assert_eq!(note.is_spent_or_pending_spent(), true); + assert_eq!(note.pending_spent(), &spend); } } From 327453dc880a0e8ca50aa60d89f6734abcf08696 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Wed, 17 Apr 2024 17:06:45 +0000 Subject: [PATCH 4/5] clippy --- zingolib/src/wallet/notes/sapling.rs | 6 +++--- zingolib/src/wallet/notes/transparent.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/zingolib/src/wallet/notes/sapling.rs b/zingolib/src/wallet/notes/sapling.rs index 234a211af..465e90ef2 100644 --- a/zingolib/src/wallet/notes/sapling.rs +++ b/zingolib/src/wallet/notes/sapling.rs @@ -280,9 +280,9 @@ pub mod tests { let note = SaplingNoteBuilder::default() .unconfirmed_spent(spend) .build(); - assert_eq!(note.is_spent(), false); - assert_eq!(note.is_pending_spent(), true); - assert_eq!(note.is_spent_or_pending_spent(), true); + 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 e621bf4b8..de94be1ba 100644 --- a/zingolib/src/wallet/notes/transparent.rs +++ b/zingolib/src/wallet/notes/transparent.rs @@ -247,9 +247,9 @@ pub mod tests { let note = TransparentNoteBuilder::default() .unconfirmed_spent(spend) .build(); - assert_eq!(note.is_spent(), false); - assert_eq!(note.is_pending_spent(), true); - assert_eq!(note.is_spent_or_pending_spent(), true); + assert!(!note.is_spent()); + assert!(note.is_pending_spent()); + assert!(note.is_spent_or_pending_spent()); assert_eq!(note.pending_spent(), &spend); } } From a0b63bb9c27e2d2a02e0328bf1135284c299e7e8 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Wed, 17 Apr 2024 17:16:18 +0000 Subject: [PATCH 5/5] added doc comments --- zingolib/src/wallet/notes/interface.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/zingolib/src/wallet/notes/interface.rs b/zingolib/src/wallet/notes/interface.rs index 0726927ce..cea71caf8 100644 --- a/zingolib/src/wallet/notes/interface.rs +++ b/zingolib/src/wallet/notes/interface.rs @@ -27,9 +27,13 @@ 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() }