Skip to content

Commit

Permalink
Merge pull request #914 from zancas/add_unit_test_to_transaction_reco…
Browse files Browse the repository at this point in the history
…rd_map

Add unit test to transaction record map
  • Loading branch information
zancas authored Apr 11, 2024
2 parents 870270e + 29a3ffa commit f599da8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
39 changes: 34 additions & 5 deletions zingolib/src/test_framework.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
use zcash_primitives::transaction::TxId;

use crate::wallet::notes::TransparentNote;
pub(crate) mod macros;
mod mocks;

#[allow(dead_code)]
pub(crate) fn create_empty_txid_and_tnote() -> (zcash_primitives::transaction::TxId, TransparentNote)
{
// A single transparent note makes is_incoming_trsaction true.
let txid = zcash_primitives::transaction::TxId::from_bytes([0u8; 32]);
(
txid,
mocks::TransparentNoteBuilder::new()
.address("t".to_string())
.spent(Some((txid, 3)))
.build(),
)
}
#[allow(dead_code)]
pub(crate) fn create_transaction_record_with_one_tnote(
txid: TxId,
transparent_note: TransparentNote,
) -> crate::wallet::transaction_record::TransactionRecord {
// A single transparent note makes is_incoming_trsaction true.
let txid = zcash_primitives::transaction::TxId::from_bytes([0u8; 32]);
let transparent_note = mocks::TransparentNoteBuilder::new()
.address("t".to_string())
.spent(Some((txid, 3)))
.build();
let mut transaction_record = crate::wallet::transaction_record::TransactionRecord::new(
zingo_status::confirmation_status::ConfirmationStatus::Confirmed(
zcash_primitives::consensus::BlockHeight::from_u32(5),
Expand All @@ -20,3 +33,19 @@ pub(crate) fn create_transaction_record_with_one_tnote(
transaction_record.transparent_notes.push(transparent_note);
transaction_record
}
#[allow(dead_code)]
pub(crate) fn default_trecord_with_one_tnote(
) -> crate::wallet::transaction_record::TransactionRecord {
let (txid, transparent_note) = create_empty_txid_and_tnote();
create_transaction_record_with_one_tnote(txid, transparent_note)
}
#[allow(dead_code)]
pub(crate) fn create_note_record_id() -> crate::wallet::notes::NoteRecordIdentifier {
let (txid, _tnote) = create_empty_txid_and_tnote();
let index = 5u32;
crate::wallet::notes::NoteRecordIdentifier {
txid,
pool: zcash_client_backend::PoolType::Transparent,
index,
}
}
2 changes: 1 addition & 1 deletion zingolib/src/wallet/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ pub use crate::wallet::transaction_record::TransactionRecord;
#[cfg(feature = "test-features")]
fn single_transparent_note_makes_is_incoming_true() {
// A single transparent note makes is_incoming_trsaction true.
let transaction_record = crate::test_framework::create_transaction_record_with_one_tnote();
let transaction_record = crate::test_framework::default_trecord_with_one_tnote();
assert!(transaction_record.is_incoming_transaction());
}
#[derive(Debug)]
Expand Down
1 change: 1 addition & 0 deletions zingolib/src/wallet/notes/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ pub trait ShieldedNoteInterface: NoteInterface + Sized {
fn value_from_note(note: &Self::Note) -> u64;
fn witnessed_position(&self) -> &Option<Position>;
fn witnessed_position_mut(&mut self) -> &mut Option<Position>;
fn to_zcb_note(&self) -> zcash_client_backend::wallet::Note;
}
3 changes: 3 additions & 0 deletions zingolib/src/wallet/notes/orchard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,7 @@ impl ShieldedNoteInterface for OrchardNote {
fn output_index(&self) -> &Option<u32> {
&self.output_index
}
fn to_zcb_note(&self) -> zcash_client_backend::wallet::Note {
zcash_client_backend::wallet::Note::Orchard(*self.note())
}
}
3 changes: 3 additions & 0 deletions zingolib/src/wallet/notes/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,7 @@ impl ShieldedNoteInterface for SaplingNote {
fn output_index(&self) -> &Option<u32> {
&self.output_index
}
fn to_zcb_note(&self) -> zcash_client_backend::wallet::Note {
zcash_client_backend::wallet::Note::Sapling(self.note().clone())
}
}

0 comments on commit f599da8

Please sign in to comment.