Skip to content

Commit 5be4740

Browse files
committed
finished unit test
1 parent f681918 commit 5be4740

File tree

3 files changed

+61
-38
lines changed

3 files changed

+61
-38
lines changed

zingolib/src/mocks.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ pub mod orchard_note {
279279
build_method!(rho, Rho);
280280
build_method!(random_seed, RandomSeed);
281281

282+
/// selects a default recipient address for the orchard note
283+
pub fn default_recipient(&mut self) -> &mut Self {
284+
let bytes = [0; 32];
285+
let sk = SpendingKey::from_bytes(bytes).unwrap();
286+
let fvk: FullViewingKey = (&sk).into();
287+
let recipient = fvk.address_at(0u32, Scope::External);
288+
289+
self.recipient(recipient)
290+
}
291+
282292
/// selects a random recipient address for the orchard note
283293
pub fn randomize_recipient(&mut self) -> &mut Self {
284294
let mut rng = OsRng;
@@ -343,7 +353,7 @@ pub mod orchard_note {
343353
impl Default for OrchardCryptoNoteBuilder {
344354
fn default() -> Self {
345355
Self::new()
346-
.randomize_recipient()
356+
.default_recipient()
347357
.randomize_rho_and_rseed()
348358
.value(NoteValue::from_raw(800_000))
349359
.clone()

zingolib/src/wallet/describe.rs

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,9 @@ impl LightWallet {
174174
<D as Domain>::Recipient: Recipient,
175175
<D as Domain>::Note: PartialEq + Clone,
176176
{
177-
let wallet_tip = self
178-
.blocks
179-
.read()
180-
.await
181-
.first()
182-
.map(|block| block.height as u32)
183-
.unwrap_or(0);
184177
#[allow(clippy::type_complexity)]
185178
let filters: &[Box<dyn Fn(&&D::WalletNote, &TransactionRecord) -> bool>] = &[
186-
Box::new(|_, transaction| {
187-
transaction
188-
.status
189-
.is_confirmed_before_or_at(&BlockHeight::from_u32(wallet_tip))
190-
}),
179+
Box::new(|_, transaction| transaction.status.is_confirmed()),
191180
Box::new(|note, _| !note.pending_receipt()),
192181
Box::new(|note, _| note.value() >= MARGINAL_FEE.into_u64()),
193182
];
@@ -329,17 +318,21 @@ impl LightWallet {
329318
#[cfg(test)]
330319
mod tests {
331320
use orchard::note_encryption::OrchardDomain;
321+
use sapling_crypto::note_encryption::SaplingDomain;
322+
332323
use zingo_status::confirmation_status::ConfirmationStatus;
333324
use zingoconfig::ZingoConfigBuilder;
334325

335-
use crate::wallet::{
336-
data::BlockData,
337-
notes::{
338-
orchard::mocks::OrchardNoteBuilder, sapling::mocks::SaplingNoteBuilder,
339-
transparent::mocks::TransparentOutputBuilder,
326+
use crate::{
327+
mocks::{orchard_note::OrchardCryptoNoteBuilder, SaplingCryptoNoteBuilder},
328+
wallet::{
329+
notes::{
330+
orchard::mocks::OrchardNoteBuilder, sapling::mocks::SaplingNoteBuilder,
331+
transparent::mocks::TransparentOutputBuilder,
332+
},
333+
transaction_record::mocks::TransactionRecordBuilder,
334+
LightWallet, WalletBase,
340335
},
341-
transaction_record::mocks::TransactionRecordBuilder,
342-
LightWallet, WalletBase,
343336
};
344337

345338
#[tokio::test]
@@ -350,30 +343,47 @@ mod tests {
350343
1,
351344
)
352345
.unwrap();
353-
wallet
354-
.set_blocks(vec![BlockData {
355-
ecb: [0u8; 32].to_vec(),
356-
height: 100,
357-
}])
358-
.await;
359346
let confirmed_tx_record = TransactionRecordBuilder::default()
360347
.status(ConfirmationStatus::Confirmed(80.into()))
361348
.transparent_outputs(TransparentOutputBuilder::default())
362349
.sapling_notes(SaplingNoteBuilder::default())
350+
.sapling_notes(SaplingNoteBuilder::default())
351+
.sapling_notes(
352+
SaplingNoteBuilder::default()
353+
.note(
354+
SaplingCryptoNoteBuilder::default()
355+
.value(sapling_crypto::value::NoteValue::from_raw(3_000))
356+
.clone(),
357+
)
358+
.clone(),
359+
)
360+
.orchard_notes(OrchardNoteBuilder::default())
363361
.orchard_notes(OrchardNoteBuilder::default())
362+
.orchard_notes(
363+
OrchardNoteBuilder::default()
364+
.note(
365+
OrchardCryptoNoteBuilder::default()
366+
.value(orchard::value::NoteValue::from_raw(5_000))
367+
.clone(),
368+
)
369+
.clone(),
370+
)
371+
.orchard_notes(
372+
OrchardNoteBuilder::default()
373+
.note(
374+
OrchardCryptoNoteBuilder::default()
375+
.value(orchard::value::NoteValue::from_raw(2_000))
376+
.clone(),
377+
)
378+
.clone(),
379+
)
364380
.build();
365381
let pending_tx_record = TransactionRecordBuilder::default()
366382
.status(ConfirmationStatus::Pending(95.into()))
367383
.transparent_outputs(TransparentOutputBuilder::default())
368384
.sapling_notes(SaplingNoteBuilder::default())
369385
.orchard_notes(OrchardNoteBuilder::default())
370386
.build();
371-
let confirmed_above_wallet_tip_tx_record = TransactionRecordBuilder::default()
372-
.status(ConfirmationStatus::Confirmed(110.into()))
373-
.transparent_outputs(TransparentOutputBuilder::default())
374-
.sapling_notes(SaplingNoteBuilder::default())
375-
.orchard_notes(OrchardNoteBuilder::default())
376-
.build();
377387
{
378388
let mut tx_map = wallet
379389
.transaction_context
@@ -386,16 +396,19 @@ mod tests {
386396
tx_map
387397
.transaction_records_by_id
388398
.insert_transaction_record(pending_tx_record);
389-
tx_map
390-
.transaction_records_by_id
391-
.insert_transaction_record(confirmed_above_wallet_tip_tx_record);
392399
}
393400

401+
assert_eq!(
402+
wallet
403+
.confirmed_balance_excluding_dust::<SaplingDomain>(None)
404+
.await,
405+
Some(400_000)
406+
);
394407
assert_eq!(
395408
wallet
396409
.confirmed_balance_excluding_dust::<OrchardDomain>(None)
397410
.await,
398-
None
399-
)
411+
Some(1_605_000)
412+
);
400413
}
401414
}

zingolib/src/wallet/transaction_record.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ pub mod mocks {
655655
),
656656
),
657657
datetime: Some(1705077003),
658-
txid: Some(crate::mocks::default_txid()),
658+
txid: Some(crate::mocks::random_txid()),
659659
spent_sapling_nullifiers: vec![],
660660
spent_orchard_nullifiers: vec![],
661661
transparent_outputs: vec![],

0 commit comments

Comments
 (0)