From 2373280ba597a6865edeec50adf6924c202648da Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 23 Sep 2024 20:07:28 +0000 Subject: [PATCH 01/11] added LightWallet::get_base_ua --- zingolib/src/wallet/describe.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zingolib/src/wallet/describe.rs b/zingolib/src/wallet/describe.rs index d3bf6c0b4..7b6a1242c 100644 --- a/zingolib/src/wallet/describe.rs +++ b/zingolib/src/wallet/describe.rs @@ -302,6 +302,14 @@ impl LightWallet { .map(|(_index, sk)| *sk) .collect::>() } + + /// gets the basic receiver for the wallet. this is the only receiver implemented as 2024-09-22 + pub fn get_base_ua(&self) -> Result { + for possible_ua in self.wallet_capability().addresses().iter() { + return Ok(possible_ua.clone()); + } + Err(()) + } } #[cfg(test)] From 1915f3cbf35a47ebfb1fa59e0f23e59ab3fecb61 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 23 Sep 2024 20:34:58 +0000 Subject: [PATCH 02/11] created get_first_address by pool LightWallet method --- zingolib/src/wallet/describe.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/zingolib/src/wallet/describe.rs b/zingolib/src/wallet/describe.rs index 7b6a1242c..3da645094 100644 --- a/zingolib/src/wallet/describe.rs +++ b/zingolib/src/wallet/describe.rs @@ -1,9 +1,11 @@ //! Wallet-State reporters as LightWallet methods. +use zcash_client_backend::PoolType; use zcash_client_backend::ShieldedProtocol; use orchard::note_encryption::OrchardDomain; use sapling_crypto::note_encryption::SaplingDomain; +use zcash_primitives::consensus::NetworkConstants as _; use zcash_primitives::transaction::components::amount::NonNegativeAmount; use zcash_primitives::transaction::fees::zip317::MARGINAL_FEE; @@ -304,12 +306,40 @@ impl LightWallet { } /// gets the basic receiver for the wallet. this is the only receiver implemented as 2024-09-22 - pub fn get_base_ua(&self) -> Result { + pub fn get_first_ua(&self) -> Result { for possible_ua in self.wallet_capability().addresses().iter() { return Ok(possible_ua.clone()); } Err(()) } + + /// gets the basic receiver for the wallet. this is the only receiver implemented as 2024-09-22 + pub fn get_first_address(&self, pool: PoolType) -> Result { + let ua = self.get_first_ua()?; + match pool { + PoolType::Transparent => ua + .transparent() + .map(|taddr| { + super::keys::address_from_pubkeyhash(&self.transaction_context.config, *taddr) + }) + .ok_or(()), + PoolType::Shielded(ShieldedProtocol::Sapling) => ua + .sapling() + .map(|z_addr| { + zcash_keys::encoding::encode_payment_address( + self.transaction_context + .config + .chain + .hrp_sapling_payment_address(), + z_addr, + ) + }) + .ok_or(()), + PoolType::Shielded(ShieldedProtocol::Orchard) => { + Ok(ua.encode(&self.transaction_context.config.chain)) + } + } + } } #[cfg(test)] From f2c0ea6ab7a1b7d0740caf83d78faf312b520684 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 23 Sep 2024 20:47:43 +0000 Subject: [PATCH 03/11] use new helper in do_addresses --- zingolib/src/lightclient/describe.rs | 37 ++++++++++++++++++---------- zingolib/src/wallet/describe.rs | 17 ++++++++++--- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/zingolib/src/lightclient/describe.rs b/zingolib/src/lightclient/describe.rs index ecdfa7d6f..eafa60562 100644 --- a/zingolib/src/lightclient/describe.rs +++ b/zingolib/src/lightclient/describe.rs @@ -58,19 +58,30 @@ impl LightClient { /// TODO: Add Doc Comment Here! pub async fn do_addresses(&self) -> JsonValue { let mut objectified_addresses = Vec::new(); - for address in self.wallet.wallet_capability().addresses().iter() { - let encoded_ua = address.encode(&self.config.chain); - let transparent = address - .transparent() - .map(|taddr| address_from_pubkeyhash(&self.config, *taddr)); - objectified_addresses.push(object! { - "address" => encoded_ua, - "receivers" => object!( - "transparent" => transparent, - "sapling" => address.sapling().map(|z_addr| encode_payment_address(self.config.chain.hrp_sapling_payment_address(), z_addr)), - "orchard_exists" => address.orchard().is_some(), - ) - }) + for unified_address in self.wallet.wallet_capability().addresses().iter() { + if let Ok(encoded_ua) = self.wallet.encode_ua_as_pool( + unified_address, + PoolType::Shielded(ShieldedProtocol::Orchard), + ) { + if let Ok(transparent_address) = self + .wallet + .encode_ua_as_pool(unified_address, PoolType::Transparent) + { + if let Ok(sapling_address) = self.wallet.encode_ua_as_pool( + unified_address, + PoolType::Shielded(ShieldedProtocol::Sapling), + ) { + objectified_addresses.push(object! { + "address" => encoded_ua, + "receivers" => object!( + "transparent" => transparent_address, + "sapling" => sapling_address, + "orchard_exists" => unified_address.orchard().is_some(), + ) + }) + } + } + } } JsonValue::Array(objectified_addresses) } diff --git a/zingolib/src/wallet/describe.rs b/zingolib/src/wallet/describe.rs index 3da645094..ed50f8680 100644 --- a/zingolib/src/wallet/describe.rs +++ b/zingolib/src/wallet/describe.rs @@ -305,7 +305,7 @@ impl LightWallet { .collect::>() } - /// gets the basic receiver for the wallet. this is the only receiver implemented as 2024-09-22 + /// gets a UnifiedAddress, the first the wallet. this is the only receiver implemented as 2024-09-22 pub fn get_first_ua(&self) -> Result { for possible_ua in self.wallet_capability().addresses().iter() { return Ok(possible_ua.clone()); @@ -313,9 +313,12 @@ impl LightWallet { Err(()) } - /// gets the basic receiver for the wallet. this is the only receiver implemented as 2024-09-22 - pub fn get_first_address(&self, pool: PoolType) -> Result { - let ua = self.get_first_ua()?; + /// UnifiedAddress type is not a string. to process it into a string requires chain date. + pub fn encode_ua_as_pool( + &self, + ua: &zcash_keys::address::UnifiedAddress, + pool: PoolType, + ) -> Result { match pool { PoolType::Transparent => ua .transparent() @@ -340,6 +343,12 @@ impl LightWallet { } } } + + /// gets a string address for the wallet, based on pooltype + pub fn get_first_address(&self, pool: PoolType) -> Result { + let ua = self.get_first_ua()?; + self.encode_ua_as_pool(&ua, pool) + } } #[cfg(test)] From b6dbea0a01cf921a2c24605d4eb000c67fa646fc Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 23 Sep 2024 20:48:18 +0000 Subject: [PATCH 04/11] cargo clippy --fix --tests --all-features --- zingolib/src/lightclient/describe.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/zingolib/src/lightclient/describe.rs b/zingolib/src/lightclient/describe.rs index eafa60562..0150f8662 100644 --- a/zingolib/src/lightclient/describe.rs +++ b/zingolib/src/lightclient/describe.rs @@ -5,9 +5,9 @@ use sapling_crypto::note_encryption::SaplingDomain; use std::collections::{HashMap, HashSet}; use tokio::runtime::Runtime; -use zcash_client_backend::{encoding::encode_payment_address, PoolType, ShieldedProtocol}; +use zcash_client_backend::{PoolType, ShieldedProtocol}; use zcash_primitives::{ - consensus::{BlockHeight, NetworkConstants}, + consensus::BlockHeight, memo::Memo, }; @@ -27,7 +27,6 @@ use crate::{ }, OutgoingTxData, }, - keys::address_from_pubkeyhash, notes::{query::OutputQuery, Output, OutputInterface}, transaction_record::{SendType, TransactionKind}, LightWallet, From c2b9dece29234e5f09f8800e0cf72603d713ffed Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 23 Sep 2024 20:48:19 +0000 Subject: [PATCH 05/11] cargo fmt --- zingolib/src/lightclient/describe.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/zingolib/src/lightclient/describe.rs b/zingolib/src/lightclient/describe.rs index 0150f8662..2fcb1c8cf 100644 --- a/zingolib/src/lightclient/describe.rs +++ b/zingolib/src/lightclient/describe.rs @@ -6,10 +6,7 @@ use std::collections::{HashMap, HashSet}; use tokio::runtime::Runtime; use zcash_client_backend::{PoolType, ShieldedProtocol}; -use zcash_primitives::{ - consensus::BlockHeight, - memo::Memo, -}; +use zcash_primitives::{consensus::BlockHeight, memo::Memo}; use crate::config::margin_fee; From 7161123a2ad2c90dc7dece44e0e02ce716f199df Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 23 Sep 2024 20:56:20 +0000 Subject: [PATCH 06/11] clippy suggestions --- zingolib/src/wallet/describe.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/zingolib/src/wallet/describe.rs b/zingolib/src/wallet/describe.rs index ed50f8680..4d5ad3053 100644 --- a/zingolib/src/wallet/describe.rs +++ b/zingolib/src/wallet/describe.rs @@ -305,14 +305,17 @@ impl LightWallet { .collect::>() } + #[allow(clippy::result_unit_err)] /// gets a UnifiedAddress, the first the wallet. this is the only receiver implemented as 2024-09-22 pub fn get_first_ua(&self) -> Result { - for possible_ua in self.wallet_capability().addresses().iter() { - return Ok(possible_ua.clone()); + if let Some(possible_ua) = self.wallet_capability().addresses().iter().next() { + Ok(possible_ua.clone()) + } else { + Err(()) } - Err(()) } + #[allow(clippy::result_unit_err)] /// UnifiedAddress type is not a string. to process it into a string requires chain date. pub fn encode_ua_as_pool( &self, @@ -344,6 +347,7 @@ impl LightWallet { } } + #[allow(clippy::result_unit_err)] /// gets a string address for the wallet, based on pooltype pub fn get_first_address(&self, pool: PoolType) -> Result { let ua = self.get_first_ua()?; From 4c4a50852e4612bf06f260db33853ec045062adb Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Mon, 23 Sep 2024 21:46:27 +0000 Subject: [PATCH 07/11] undo do_addresses changes --- zingolib/src/lightclient/describe.rs | 46 ++++++++++++---------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/zingolib/src/lightclient/describe.rs b/zingolib/src/lightclient/describe.rs index 2fcb1c8cf..a7f895838 100644 --- a/zingolib/src/lightclient/describe.rs +++ b/zingolib/src/lightclient/describe.rs @@ -5,8 +5,11 @@ use sapling_crypto::note_encryption::SaplingDomain; use std::collections::{HashMap, HashSet}; use tokio::runtime::Runtime; -use zcash_client_backend::{PoolType, ShieldedProtocol}; -use zcash_primitives::{consensus::BlockHeight, memo::Memo}; +use zcash_client_backend::{encoding::encode_payment_address, PoolType, ShieldedProtocol}; +use zcash_primitives::{ + consensus::{BlockHeight, NetworkConstants}, + memo::Memo, +}; use crate::config::margin_fee; @@ -24,6 +27,7 @@ use crate::{ }, OutgoingTxData, }, + keys::address_from_pubkeyhash, notes::{query::OutputQuery, Output, OutputInterface}, transaction_record::{SendType, TransactionKind}, LightWallet, @@ -52,32 +56,22 @@ impl LightClient { } /// TODO: Add Doc Comment Here! + // todo use helpers pub async fn do_addresses(&self) -> JsonValue { let mut objectified_addresses = Vec::new(); - for unified_address in self.wallet.wallet_capability().addresses().iter() { - if let Ok(encoded_ua) = self.wallet.encode_ua_as_pool( - unified_address, - PoolType::Shielded(ShieldedProtocol::Orchard), - ) { - if let Ok(transparent_address) = self - .wallet - .encode_ua_as_pool(unified_address, PoolType::Transparent) - { - if let Ok(sapling_address) = self.wallet.encode_ua_as_pool( - unified_address, - PoolType::Shielded(ShieldedProtocol::Sapling), - ) { - objectified_addresses.push(object! { - "address" => encoded_ua, - "receivers" => object!( - "transparent" => transparent_address, - "sapling" => sapling_address, - "orchard_exists" => unified_address.orchard().is_some(), - ) - }) - } - } - } + for address in self.wallet.wallet_capability().addresses().iter() { + let encoded_ua = address.encode(&self.config.chain); + let transparent = address + .transparent() + .map(|taddr| address_from_pubkeyhash(&self.config, *taddr)); + objectified_addresses.push(object! { + "address" => encoded_ua, + "receivers" => object!( + "transparent" => transparent, + "sapling" => address.sapling().map(|z_addr| encode_payment_address(self.config.chain.hrp_sapling_payment_address(), z_addr)), + "orchard_exists" => address.orchard().is_some(), + ) + }) } JsonValue::Array(objectified_addresses) } From 51a3b0b464ff71f59551ac3ea5b36b7dba00c3d8 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Tue, 24 Sep 2024 21:12:44 +0000 Subject: [PATCH 08/11] move into test feature gate and improve feature gates --- zingolib/src/lib.rs | 2 +- zingolib/src/utils.rs | 10 +- zingolib/src/wallet/data.rs | 2 +- zingolib/src/wallet/describe.rs | 110 ++++++++++++---------- zingolib/src/wallet/notes/orchard.rs | 2 +- zingolib/src/wallet/notes/sapling.rs | 2 +- zingolib/src/wallet/notes/transparent.rs | 2 +- zingolib/src/wallet/transaction_record.rs | 2 +- 8 files changed, 71 insertions(+), 61 deletions(-) diff --git a/zingolib/src/lib.rs b/zingolib/src/lib.rs index db341720b..be9774508 100644 --- a/zingolib/src/lib.rs +++ b/zingolib/src/lib.rs @@ -17,7 +17,7 @@ pub mod lightclient; pub mod utils; pub mod wallet; -#[cfg(test)] +#[cfg(any(test, feature = "test-elevation"))] pub(crate) mod mocks; #[cfg(any(test, feature = "test-elevation"))] pub mod testutils; diff --git a/zingolib/src/utils.rs b/zingolib/src/utils.rs index cd380df65..15501f1fc 100644 --- a/zingolib/src/utils.rs +++ b/zingolib/src/utils.rs @@ -3,6 +3,7 @@ pub mod conversion; pub mod error; +#[cfg(any(test, feature = "test-elevation"))] macro_rules! build_method { ($name:ident, $localtype:ty) => { #[doc = "Set the $name field of the builder."] @@ -12,7 +13,7 @@ macro_rules! build_method { } }; } -#[cfg(test)] // temporary test gate as no production builders use this macros yet +#[cfg(any(test, feature = "test-elevation"))] macro_rules! build_method_push { ($name:ident, $localtype:ty) => { #[doc = "Push a $ty to the builder."] @@ -22,7 +23,7 @@ macro_rules! build_method_push { } }; } -#[cfg(test)] // temporary test gate as no production builders use this macros yet +#[cfg(any(test, feature = "test-elevation"))] macro_rules! build_push_list { ($name:ident, $builder:ident, $struct:ident) => { for i in &$builder.$name { @@ -31,10 +32,11 @@ macro_rules! build_push_list { }; } +#[cfg(any(test, feature = "test-elevation"))] pub(crate) use build_method; -#[cfg(test)] +#[cfg(any(test, feature = "test-elevation"))] pub(crate) use build_method_push; -#[cfg(test)] +#[cfg(any(test, feature = "test-elevation"))] pub(crate) use build_push_list; /// this mod exists to allow the use statement without cluttering the parent mod diff --git a/zingolib/src/wallet/data.rs b/zingolib/src/wallet/data.rs index 61787f407..85d60a4a5 100644 --- a/zingolib/src/wallet/data.rs +++ b/zingolib/src/wallet/data.rs @@ -1988,7 +1988,7 @@ fn read_write_empty_sapling_tree() { ) } -#[cfg(test)] +#[cfg(any(test, feature = "test-elevation"))] pub(crate) mod mocks { use zcash_primitives::memo::Memo; diff --git a/zingolib/src/wallet/describe.rs b/zingolib/src/wallet/describe.rs index 4d5ad3053..7300445d5 100644 --- a/zingolib/src/wallet/describe.rs +++ b/zingolib/src/wallet/describe.rs @@ -304,61 +304,14 @@ impl LightWallet { .map(|(_index, sk)| *sk) .collect::>() } - - #[allow(clippy::result_unit_err)] - /// gets a UnifiedAddress, the first the wallet. this is the only receiver implemented as 2024-09-22 - pub fn get_first_ua(&self) -> Result { - if let Some(possible_ua) = self.wallet_capability().addresses().iter().next() { - Ok(possible_ua.clone()) - } else { - Err(()) - } - } - - #[allow(clippy::result_unit_err)] - /// UnifiedAddress type is not a string. to process it into a string requires chain date. - pub fn encode_ua_as_pool( - &self, - ua: &zcash_keys::address::UnifiedAddress, - pool: PoolType, - ) -> Result { - match pool { - PoolType::Transparent => ua - .transparent() - .map(|taddr| { - super::keys::address_from_pubkeyhash(&self.transaction_context.config, *taddr) - }) - .ok_or(()), - PoolType::Shielded(ShieldedProtocol::Sapling) => ua - .sapling() - .map(|z_addr| { - zcash_keys::encoding::encode_payment_address( - self.transaction_context - .config - .chain - .hrp_sapling_payment_address(), - z_addr, - ) - }) - .ok_or(()), - PoolType::Shielded(ShieldedProtocol::Orchard) => { - Ok(ua.encode(&self.transaction_context.config.chain)) - } - } - } - - #[allow(clippy::result_unit_err)] - /// gets a string address for the wallet, based on pooltype - pub fn get_first_address(&self, pool: PoolType) -> Result { - let ua = self.get_first_ua()?; - self.encode_ua_as_pool(&ua, pool) - } } -#[cfg(test)] -mod tests { +#[cfg(any(test, feature = "test-elevation"))] +mod test { use orchard::note_encryption::OrchardDomain; use sapling_crypto::note_encryption::SaplingDomain; + use zcash_client_backend::{PoolType, ShieldedProtocol}; + use zcash_primitives::consensus::NetworkConstants as _; use crate::config::ZingoConfigBuilder; use zingo_status::confirmation_status::ConfirmationStatus; @@ -375,6 +328,61 @@ mod tests { }, }; + // these functions are totally good, and a better pattern for address lookup. maybe they can be gated in. + impl LightWallet { + #[allow(clippy::result_unit_err)] + /// gets a UnifiedAddress, the first the wallet. this is the only receiver implemented as 2024-09-22 + pub fn get_first_ua(&self) -> Result { + if let Some(possible_ua) = self.wallet_capability().addresses().iter().next() { + Ok(possible_ua.clone()) + } else { + Err(()) + } + } + + #[allow(clippy::result_unit_err)] + /// UnifiedAddress type is not a string. to process it into a string requires chain date. + pub fn encode_ua_as_pool( + &self, + ua: &zcash_keys::address::UnifiedAddress, + pool: PoolType, + ) -> Result { + match pool { + PoolType::Transparent => ua + .transparent() + .map(|taddr| { + crate::wallet::keys::address_from_pubkeyhash( + &self.transaction_context.config, + *taddr, + ) + }) + .ok_or(()), + PoolType::Shielded(ShieldedProtocol::Sapling) => ua + .sapling() + .map(|z_addr| { + zcash_keys::encoding::encode_payment_address( + self.transaction_context + .config + .chain + .hrp_sapling_payment_address(), + z_addr, + ) + }) + .ok_or(()), + PoolType::Shielded(ShieldedProtocol::Orchard) => { + Ok(ua.encode(&self.transaction_context.config.chain)) + } + } + } + + #[allow(clippy::result_unit_err)] + /// gets a string address for the wallet, based on pooltype + pub fn get_first_address(&self, pool: PoolType) -> Result { + let ua = self.get_first_ua()?; + self.encode_ua_as_pool(&ua, pool) + } + } + #[tokio::test] async fn confirmed_balance_excluding_dust() { let wallet = LightWallet::new( diff --git a/zingolib/src/wallet/notes/orchard.rs b/zingolib/src/wallet/notes/orchard.rs index b472882ae..21a0d7fd7 100644 --- a/zingolib/src/wallet/notes/orchard.rs +++ b/zingolib/src/wallet/notes/orchard.rs @@ -195,7 +195,7 @@ impl ShieldedNoteInterface for OrchardNote { } } -#[cfg(test)] +#[cfg(any(test, feature = "test-elevation"))] pub mod mocks { //! Mock version of the struct for testing use incrementalmerkletree::Position; diff --git a/zingolib/src/wallet/notes/sapling.rs b/zingolib/src/wallet/notes/sapling.rs index 58e2d4f46..79b8a2fa3 100644 --- a/zingolib/src/wallet/notes/sapling.rs +++ b/zingolib/src/wallet/notes/sapling.rs @@ -210,7 +210,7 @@ impl ShieldedNoteInterface for SaplingNote { } } -#[cfg(test)] +#[cfg(any(test, feature = "test-elevation"))] pub mod mocks { //! Mock version of the struct for testing use incrementalmerkletree::Position; diff --git a/zingolib/src/wallet/notes/transparent.rs b/zingolib/src/wallet/notes/transparent.rs index aa65f8f3b..b87dc3757 100644 --- a/zingolib/src/wallet/notes/transparent.rs +++ b/zingolib/src/wallet/notes/transparent.rs @@ -213,7 +213,7 @@ impl TransparentOutput { } } -#[cfg(test)] +#[cfg(any(test, feature = "test-elevation"))] pub mod mocks { //! Mock version of the struct for testing use zcash_primitives::{legacy::TransparentAddress, transaction::TxId}; diff --git a/zingolib/src/wallet/transaction_record.rs b/zingolib/src/wallet/transaction_record.rs index 735b45543..dc3986675 100644 --- a/zingolib/src/wallet/transaction_record.rs +++ b/zingolib/src/wallet/transaction_record.rs @@ -576,7 +576,7 @@ pub enum SendType { SendToSelf, } -#[cfg(test)] +#[cfg(any(test, feature = "test-elevation"))] pub mod mocks { //! Mock version of the struct for testing use zcash_primitives::transaction::TxId; From 28a03c54661136720fac2e850fa1a1c7a7f418d1 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Tue, 24 Sep 2024 21:26:21 +0000 Subject: [PATCH 09/11] fixed up feature gates --- zingolib/src/lightclient/send.rs | 4 +-- zingolib/src/mocks.rs | 3 -- zingolib/src/wallet/describe.rs | 50 +++++++++++++++++++------------- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/zingolib/src/lightclient/send.rs b/zingolib/src/lightclient/send.rs index 4b75be7c3..76db5677f 100644 --- a/zingolib/src/lightclient/send.rs +++ b/zingolib/src/lightclient/send.rs @@ -334,8 +334,8 @@ pub mod send_with_proposal { #[tokio::test] async fn complete_and_broadcast_unconnected_error() { use crate::{ - config::ZingoConfigBuilder, lightclient::LightClient, mocks::ProposalBuilder, - testvectors::seeds::ABANDON_ART_SEED, + config::ZingoConfigBuilder, lightclient::LightClient, + mocks::proposal::ProposalBuilder, testvectors::seeds::ABANDON_ART_SEED, }; let lc = LightClient::create_unconnected( &ZingoConfigBuilder::default().create(), diff --git a/zingolib/src/mocks.rs b/zingolib/src/mocks.rs index 7ef260956..8866ea6fc 100644 --- a/zingolib/src/mocks.rs +++ b/zingolib/src/mocks.rs @@ -2,9 +2,6 @@ //! Tools to facilitate mocks for structs of external crates and general mocking utilities for testing -#[cfg(feature = "test-elevation")] -pub use proposal::ProposalBuilder; - pub use sapling_crypto_note::SaplingCryptoNoteBuilder; fn zaddr_from_seed( diff --git a/zingolib/src/wallet/describe.rs b/zingolib/src/wallet/describe.rs index 7300445d5..0b0eea7ba 100644 --- a/zingolib/src/wallet/describe.rs +++ b/zingolib/src/wallet/describe.rs @@ -1,11 +1,9 @@ //! Wallet-State reporters as LightWallet methods. -use zcash_client_backend::PoolType; use zcash_client_backend::ShieldedProtocol; use orchard::note_encryption::OrchardDomain; use sapling_crypto::note_encryption::SaplingDomain; -use zcash_primitives::consensus::NetworkConstants as _; use zcash_primitives::transaction::components::amount::NonNegativeAmount; use zcash_primitives::transaction::fees::zip317::MARGINAL_FEE; @@ -308,27 +306,15 @@ impl LightWallet { #[cfg(any(test, feature = "test-elevation"))] mod test { - use orchard::note_encryption::OrchardDomain; - use sapling_crypto::note_encryption::SaplingDomain; - use zcash_client_backend::{PoolType, ShieldedProtocol}; + + use zcash_client_backend::PoolType; + use zcash_client_backend::ShieldedProtocol; use zcash_primitives::consensus::NetworkConstants as _; - use crate::config::ZingoConfigBuilder; - use zingo_status::confirmation_status::ConfirmationStatus; + use crate::wallet::LightWallet; - use crate::{ - mocks::{orchard_note::OrchardCryptoNoteBuilder, SaplingCryptoNoteBuilder}, - wallet::{ - notes::{ - orchard::mocks::OrchardNoteBuilder, sapling::mocks::SaplingNoteBuilder, - transparent::mocks::TransparentOutputBuilder, - }, - transaction_record::mocks::TransactionRecordBuilder, - LightWallet, WalletBase, - }, - }; - - // these functions are totally good, and a better pattern for address lookup. maybe they can be gated in. + // these functions are tested gold and a better pattern for address lookup. + // maybe later they can be gated in. impl LightWallet { #[allow(clippy::result_unit_err)] /// gets a UnifiedAddress, the first the wallet. this is the only receiver implemented as 2024-09-22 @@ -383,6 +369,30 @@ mod test { } } + #[cfg(test)] + use orchard::note_encryption::OrchardDomain; + #[cfg(test)] + use sapling_crypto::note_encryption::SaplingDomain; + #[cfg(test)] + use zingo_status::confirmation_status::ConfirmationStatus; + + #[cfg(test)] + use crate::config::ZingoConfigBuilder; + #[cfg(test)] + use crate::mocks::orchard_note::OrchardCryptoNoteBuilder; + #[cfg(test)] + use crate::mocks::SaplingCryptoNoteBuilder; + #[cfg(test)] + use crate::wallet::notes::orchard::mocks::OrchardNoteBuilder; + #[cfg(test)] + use crate::wallet::notes::sapling::mocks::SaplingNoteBuilder; + #[cfg(test)] + use crate::wallet::notes::transparent::mocks::TransparentOutputBuilder; + #[cfg(test)] + use crate::wallet::transaction_record::mocks::TransactionRecordBuilder; + #[cfg(test)] + use crate::wallet::WalletBase; + #[tokio::test] async fn confirmed_balance_excluding_dust() { let wallet = LightWallet::new( From dfb8785e9d081edd41316591bc619f16acf4b8f1 Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Tue, 24 Sep 2024 21:45:17 +0000 Subject: [PATCH 10/11] public mocks --- zingolib/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zingolib/src/lib.rs b/zingolib/src/lib.rs index be9774508..589ebb51c 100644 --- a/zingolib/src/lib.rs +++ b/zingolib/src/lib.rs @@ -18,7 +18,7 @@ pub mod utils; pub mod wallet; #[cfg(any(test, feature = "test-elevation"))] -pub(crate) mod mocks; +pub mod mocks; #[cfg(any(test, feature = "test-elevation"))] pub mod testutils; #[cfg(any(test, feature = "testvectors"))] From 3f002d78693dc73893f7c69eb25cda23673c160a Mon Sep 17 00:00:00 2001 From: fluidvanadium Date: Tue, 24 Sep 2024 22:06:50 +0000 Subject: [PATCH 11/11] fix doc link --- zingolib/src/mocks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zingolib/src/mocks.rs b/zingolib/src/mocks.rs index 8866ea6fc..0be2dc745 100644 --- a/zingolib/src/mocks.rs +++ b/zingolib/src/mocks.rs @@ -62,7 +62,7 @@ pub fn random_zaddr() -> ( } pub mod nullifier { - //! Module for mocking nullifiers from [`sapling_crypto::note::Nullifier`] and [`orchard::note::Nullifier`] + //! Module for mocking nullifiers from [`sapling_crypto::Nullifier`] and [`orchard::note::Nullifier`] use crate::utils::build_method;