Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade note interface 2 #955

Merged
merged 9 commits into from
Apr 18, 2024
10 changes: 10 additions & 0 deletions zingolib/src/wallet/notes/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions zingolib/src/wallet/notes/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
20 changes: 20 additions & 0 deletions zingolib/src/wallet/notes/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading