From 60db0d097a254e7825f1c806358c61149aa46044 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Mon, 4 Mar 2024 10:45:22 -0700 Subject: [PATCH] zcash_keys: Fix a few problems with no-flags compilation. --- zcash_keys/Cargo.toml | 1 + zcash_keys/src/address.rs | 12 +++++++----- zcash_keys/src/keys.rs | 9 +++++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/zcash_keys/Cargo.toml b/zcash_keys/Cargo.toml index dd32f35df2..0ba67ad086 100644 --- a/zcash_keys/Cargo.toml +++ b/zcash_keys/Cargo.toml @@ -67,6 +67,7 @@ jubjub.workspace = true proptest.workspace = true rand_core.workspace = true zcash_address = { workspace = true, features = ["test-dependencies"] } +zcash_primitives = { workspace = true, features = ["test-dependencies"] } [features] ## Enables use of transparent key parts and addresses diff --git a/zcash_keys/src/address.rs b/zcash_keys/src/address.rs index 6872e5133e..c0990c24ba 100644 --- a/zcash_keys/src/address.rs +++ b/zcash_keys/src/address.rs @@ -143,7 +143,11 @@ impl UnifiedAddress { /// Returns whether this address has a Sapling receiver. pub fn has_sapling(&self) -> bool { - self.sapling.is_some() + #[cfg(not(feature = "sapling"))] + return false; + + #[cfg(feature = "sapling")] + return self.sapling.is_some(); } /// Returns the Sapling receiver within this Unified Address, if any. @@ -213,6 +217,7 @@ impl UnifiedAddress { let result = std::iter::empty(); #[cfg(feature = "orchard")] let result = result.chain(self.orchard.map(|_| Typecode::Orchard)); + #[cfg(feature = "sapling")] let result = result.chain(self.sapling.map(|_| Typecode::Sapling)); let result = result.chain(self.transparent.map(|taddr| match taddr { TransparentAddress::PublicKeyHash(_) => Typecode::P2pkh, @@ -353,7 +358,7 @@ mod tests { use zcash_address::test_vectors; use zcash_primitives::consensus::MAIN_NETWORK; - use super::Address; + use super::{Address, UnifiedAddress}; #[cfg(feature = "sapling")] use crate::keys::sapling; @@ -361,9 +366,6 @@ mod tests { #[cfg(any(feature = "orchard", feature = "sapling"))] use zcash_primitives::zip32::AccountId; - #[cfg(any(feature = "orchard", feature = "sapling"))] - use super::UnifiedAddress; - #[test] #[cfg(any(feature = "orchard", feature = "sapling"))] fn ua_round_trip() { diff --git a/zcash_keys/src/keys.rs b/zcash_keys/src/keys.rs index 117e078124..d8ec058241 100644 --- a/zcash_keys/src/keys.rs +++ b/zcash_keys/src/keys.rs @@ -826,9 +826,14 @@ pub mod testing { #[cfg(test)] mod tests { + use super::UnifiedFullViewingKey; use proptest::prelude::proptest; - use super::UnifiedFullViewingKey; + #[cfg(any( + feature = "orchard", + feature = "sapling", + feature = "transparent-inputs" + ))] use zcash_primitives::consensus::MAIN_NETWORK; #[cfg(any(feature = "orchard", feature = "sapling"))] @@ -919,7 +924,7 @@ mod tests { ); #[cfg(not(any(feature = "orchard", feature = "sapling")))] - assert_eq!(ufvk, None); + assert!(ufvk.is_none()); #[cfg(any(feature = "orchard", feature = "sapling"))] {