Get Sapling zaddr encoding roundtrip proptest working for now

TransmissionKey is just the jubjub affine point identity for now. :/
This commit is contained in:
Deirdre Connolly 2020-04-15 03:41:31 -04:00 committed by Deirdre Connolly
parent aa18937b60
commit c30a5a64b2
2 changed files with 22 additions and 17 deletions

View File

@ -95,14 +95,14 @@ impl Arbitrary for SaplingShieldedAddress {
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
(
any::<Network>(),
array::uniform11(any::<u8>()),
array::uniform32(any::<u8>()),
any::<sapling::Diversifier>(),
any::<sapling::TransmissionKey>(),
)
.prop_map(|(network, diversifier_bytes, transmission_key_bytes)| {
.prop_map(|(network, diversifier, transmission_key)| {
return Self {
network,
diversifier: sapling::Diversifier(diversifier_bytes),
transmission_key: sapling::TransmissionKey::from_bytes(transmission_key_bytes),
diversifier,
transmission_key,
};
})
.boxed()
@ -160,15 +160,14 @@ mod tests {
#[cfg(test)]
proptest! {
// TODO: uncomment when key strategies are fixed.
// #[test]
// fn sapling_address_roundtrip(zaddr in any::<SaplingShieldedAddress>()) {
#[test]
fn sapling_address_roundtrip(zaddr in any::<SaplingShieldedAddress>()) {
// let string = zaddr.to_string();
let string = zaddr.to_string();
// let zaddr2 = string.parse::<SaplingShieldedAddress>()
// .expect("randomized sapling z-addr should deserialize");
let zaddr2 = string.parse::<SaplingShieldedAddress>()
.expect("randomized sapling z-addr should deserialize");
// prop_assert_eq![zaddr, zaddr2];
// }
prop_assert_eq![zaddr, zaddr2];
}
}

View File

@ -17,7 +17,9 @@ use rand_core::{CryptoRng, RngCore};
use redjubjub::{self, SpendAuth};
#[cfg(test)]
use proptest::{arbitrary::Arbitrary, array, prelude::*};
use proptest::{array, prelude::*};
#[cfg(test)]
use proptest_derive::Arbitrary;
/// The [Randomness Beacon][1] ("URS").
///
@ -432,6 +434,7 @@ impl IncomingViewingKey {
///
/// [ps]: https://zips.z.cash/protocol/protocol.pdf#saplingkeycomponents
#[derive(Copy, Clone, Eq, PartialEq)]
#[cfg_attr(test, derive(Arbitrary))]
pub struct Diversifier(pub [u8; 11]);
impl fmt::Debug for Diversifier {
@ -521,15 +524,18 @@ impl TransmissionKey {
}
}
// TODO: fix
#[cfg(test)]
impl Arbitrary for TransmissionKey {
type Parameters = ();
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
(array::uniform32(any::<u8>()))
.prop_map(|transmission_key_bytes| {
return Self::from_bytes(transmission_key_bytes);
.prop_map(|_transmission_key_bytes| {
// TODO: actually generate something better than the identity.
//
// return Self::from_bytes(transmission_key_bytes);
return Self(jubjub::AffinePoint::identity());
})
.boxed()
}