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

upgraded sapling note builder to build later and allow value changes #990

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions zingolib/src/test_framework/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ mod sapling_crypto_note {

/// A struct to build a mock sapling_crypto::Note from scratch.
/// Distinguish [`sapling_crypto::Note`] from [`crate::wallet::notes::SaplingNote`]. The latter wraps the former with some other attributes.
#[derive(Clone, Copy)]
pub struct SaplingCryptoNoteBuilder {
recipient: Option<PaymentAddress>,
value: Option<NoteValue>,
Expand Down
18 changes: 13 additions & 5 deletions zingolib/src/wallet/notes/sapling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ impl ShieldedNoteInterface for SaplingNote {
pub mod mocks {
//! Mock version of the struct for testing
use incrementalmerkletree::Position;
use sapling_crypto::value::NoteValue;
use zcash_primitives::{memo::Memo, transaction::TxId};

use crate::{
test_framework::mocks::build_method,
test_framework::mocks::{build_method, SaplingCryptoNoteBuilder},
wallet::{notes::ShieldedNoteInterface, traits::FromBytes},
};

Expand All @@ -211,7 +212,7 @@ pub mod mocks {
/// to create a mock SaplingNote
pub(crate) struct SaplingNoteBuilder {
diversifier: Option<sapling_crypto::Diversifier>,
note: Option<sapling_crypto::Note>,
note: Option<SaplingCryptoNoteBuilder>,
witnessed_position: Option<Option<Position>>,
output_index: Option<Option<u32>>,
nullifier: Option<Option<sapling_crypto::Nullifier>>,
Expand Down Expand Up @@ -242,7 +243,7 @@ pub mod mocks {

// Methods to set each field
build_method!(diversifier, sapling_crypto::Diversifier);
build_method!(note, sapling_crypto::Note);
build_method!(note, SaplingCryptoNoteBuilder);
build_method!(witnessed_position, Option<Position>);
build_method!(output_index, Option<u32>);
build_method!(nullifier, Option<sapling_crypto::Nullifier>);
Expand All @@ -255,12 +256,19 @@ pub mod mocks {
self
}
build_method!(have_spending_key, bool);
pub fn value(mut self, value: u64) -> Self {
self.note
.as_mut()
.unwrap()
.value(NoteValue::from_raw(value));
self
}

/// builds a mock SaplingNote after all pieces are supplied
pub fn build(self) -> SaplingNote {
SaplingNote::from_parts(
self.diversifier.unwrap(),
self.note.unwrap(),
self.note.unwrap().build(),
self.witnessed_position.unwrap(),
self.nullifier.unwrap(),
self.spent.unwrap(),
Expand All @@ -277,7 +285,7 @@ pub mod mocks {
fn default() -> Self {
SaplingNoteBuilder::new()
.diversifier(sapling_crypto::Diversifier([0; 11]))
.note(crate::test_framework::mocks::SaplingCryptoNoteBuilder::default().build())
.note(crate::test_framework::mocks::SaplingCryptoNoteBuilder::default())
.witnessed_position(Some(Position::from(0)))
.output_index(Some(0))
.nullifier(Some(sapling_crypto::Nullifier::from_bytes([0; 32])))
Expand Down
Loading