Skip to content

Commit f599da8

Browse files
authored
Merge pull request #914 from zancas/add_unit_test_to_transaction_record_map
Add unit test to transaction record map
2 parents 870270e + 29a3ffa commit f599da8

File tree

5 files changed

+42
-6
lines changed

5 files changed

+42
-6
lines changed

zingolib/src/test_framework.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1+
use zcash_primitives::transaction::TxId;
2+
3+
use crate::wallet::notes::TransparentNote;
14
pub(crate) mod macros;
25
mod mocks;
36

7+
#[allow(dead_code)]
8+
pub(crate) fn create_empty_txid_and_tnote() -> (zcash_primitives::transaction::TxId, TransparentNote)
9+
{
10+
// A single transparent note makes is_incoming_trsaction true.
11+
let txid = zcash_primitives::transaction::TxId::from_bytes([0u8; 32]);
12+
(
13+
txid,
14+
mocks::TransparentNoteBuilder::new()
15+
.address("t".to_string())
16+
.spent(Some((txid, 3)))
17+
.build(),
18+
)
19+
}
420
#[allow(dead_code)]
521
pub(crate) fn create_transaction_record_with_one_tnote(
22+
txid: TxId,
23+
transparent_note: TransparentNote,
624
) -> crate::wallet::transaction_record::TransactionRecord {
725
// A single transparent note makes is_incoming_trsaction true.
8-
let txid = zcash_primitives::transaction::TxId::from_bytes([0u8; 32]);
9-
let transparent_note = mocks::TransparentNoteBuilder::new()
10-
.address("t".to_string())
11-
.spent(Some((txid, 3)))
12-
.build();
1326
let mut transaction_record = crate::wallet::transaction_record::TransactionRecord::new(
1427
zingo_status::confirmation_status::ConfirmationStatus::Confirmed(
1528
zcash_primitives::consensus::BlockHeight::from_u32(5),
@@ -20,3 +33,19 @@ pub(crate) fn create_transaction_record_with_one_tnote(
2033
transaction_record.transparent_notes.push(transparent_note);
2134
transaction_record
2235
}
36+
#[allow(dead_code)]
37+
pub(crate) fn default_trecord_with_one_tnote(
38+
) -> crate::wallet::transaction_record::TransactionRecord {
39+
let (txid, transparent_note) = create_empty_txid_and_tnote();
40+
create_transaction_record_with_one_tnote(txid, transparent_note)
41+
}
42+
#[allow(dead_code)]
43+
pub(crate) fn create_note_record_id() -> crate::wallet::notes::NoteRecordIdentifier {
44+
let (txid, _tnote) = create_empty_txid_and_tnote();
45+
let index = 5u32;
46+
crate::wallet::notes::NoteRecordIdentifier {
47+
txid,
48+
pool: zcash_client_backend::PoolType::Transparent,
49+
index,
50+
}
51+
}

zingolib/src/wallet/data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ pub use crate::wallet::transaction_record::TransactionRecord;
703703
#[cfg(feature = "test-features")]
704704
fn single_transparent_note_makes_is_incoming_true() {
705705
// A single transparent note makes is_incoming_trsaction true.
706-
let transaction_record = crate::test_framework::create_transaction_record_with_one_tnote();
706+
let transaction_record = crate::test_framework::default_trecord_with_one_tnote();
707707
assert!(transaction_record.is_incoming_transaction());
708708
}
709709
#[derive(Debug)]

zingolib/src/wallet/notes/interface.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ pub trait ShieldedNoteInterface: NoteInterface + Sized {
6666
fn value_from_note(note: &Self::Note) -> u64;
6767
fn witnessed_position(&self) -> &Option<Position>;
6868
fn witnessed_position_mut(&mut self) -> &mut Option<Position>;
69+
fn to_zcb_note(&self) -> zcash_client_backend::wallet::Note;
6970
}

zingolib/src/wallet/notes/orchard.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,7 @@ impl ShieldedNoteInterface for OrchardNote {
145145
fn output_index(&self) -> &Option<u32> {
146146
&self.output_index
147147
}
148+
fn to_zcb_note(&self) -> zcash_client_backend::wallet::Note {
149+
zcash_client_backend::wallet::Note::Orchard(*self.note())
150+
}
148151
}

zingolib/src/wallet/notes/sapling.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,7 @@ impl ShieldedNoteInterface for SaplingNote {
167167
fn output_index(&self) -> &Option<u32> {
168168
&self.output_index
169169
}
170+
fn to_zcb_note(&self) -> zcash_client_backend::wallet::Note {
171+
zcash_client_backend::wallet::Note::Sapling(self.note().clone())
172+
}
170173
}

0 commit comments

Comments
 (0)