Add sapling key derivation bech32 encoding roundtrip proptest
And fix SpendingKey Display impl bug.
This commit is contained in:
parent
9daa1ba3c8
commit
94c6d74ecb
|
@ -0,0 +1,7 @@
|
|||
# Seeds for failure cases proptest has generated in the past. It is
|
||||
# automatically read and these particular cases re-run before any
|
||||
# novel cases are generated.
|
||||
#
|
||||
# It is recommended to check this file in to source control so that
|
||||
# everyone who runs the test benefits from these saved cases.
|
||||
cc 14cc005b0333245bcb502328cfdad9a44032fe7b3fb38a8a17c2eaa10b26dd38 # shrinks to spending_key = SpendingKey { network: Mainnet, bytes: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }
|
|
@ -182,6 +182,7 @@ mod sk_hrp {
|
|||
///
|
||||
/// [ps]: https://zips.z.cash/protocol/protocol.pdf#saplingkeycomponents
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
#[cfg_attr(test, derive(Arbitrary))]
|
||||
pub struct SpendingKey {
|
||||
network: Network,
|
||||
bytes: [u8; 32],
|
||||
|
@ -223,7 +224,7 @@ impl FromStr for SpendingKey {
|
|||
|
||||
Ok(SpendingKey {
|
||||
network: match hrp.as_str() {
|
||||
ivk_hrp::MAINNET => Network::Mainnet,
|
||||
sk_hrp::MAINNET => Network::Mainnet,
|
||||
_ => Network::Testnet,
|
||||
},
|
||||
bytes: decoded_bytes,
|
||||
|
@ -713,8 +714,6 @@ impl Diversifier {
|
|||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub struct TransmissionKey(pub jubjub::AffinePoint);
|
||||
|
||||
impl Eq for TransmissionKey {}
|
||||
|
||||
impl Deref for TransmissionKey {
|
||||
type Target = jubjub::AffinePoint;
|
||||
|
||||
|
@ -732,6 +731,8 @@ impl fmt::Debug for TransmissionKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl Eq for TransmissionKey {}
|
||||
|
||||
impl TransmissionKey {
|
||||
/// This includes _KA^Sapling.DerivePublic(ivk, G_d)_, which is just a
|
||||
/// scalar mult _[ivk]G_d_.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use super::*;
|
||||
|
||||
#[cfg(test)]
|
||||
use proptest::{array, prelude::*};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[cfg(test)]
|
||||
impl Arbitrary for TransmissionKey {
|
||||
type Parameters = ();
|
||||
|
@ -95,6 +95,29 @@ mod tests {
|
|||
#[cfg(test)]
|
||||
proptest! {
|
||||
|
||||
//#[test]
|
||||
// fn test() {}
|
||||
#[test]
|
||||
fn string_roundtrips(spending_key in any::<SpendingKey>()) {
|
||||
let sk_string = spending_key.to_string();
|
||||
let spending_key_2: SpendingKey = sk_string.parse().unwrap();
|
||||
prop_assert_eq![spending_key, spending_key_2];
|
||||
|
||||
let spend_authorizing_key = SpendAuthorizingKey::from(spending_key);
|
||||
let proof_authorizing_key = ProofAuthorizingKey::from(spending_key);
|
||||
let outgoing_viewing_key = OutgoingViewingKey::from(spending_key);
|
||||
|
||||
let authorizing_key = AuthorizingKey::from(spend_authorizing_key);
|
||||
let nullifier_deriving_key = NullifierDerivingKey::from(proof_authorizing_key);
|
||||
let incoming_viewing_key =
|
||||
IncomingViewingKey::from((authorizing_key, nullifier_deriving_key));
|
||||
|
||||
// let diversifier = Diversifier::from(spending_key);
|
||||
// let transmission_key = TransmissionKey::from(incoming_viewing_key, diversifier);
|
||||
|
||||
|
||||
let string = incoming_viewing_key.to_string();
|
||||
let incoming_viewing_key_2 = string.parse::<IncomingViewingKey>().unwrap();
|
||||
|
||||
prop_assert_eq![incoming_viewing_key, incoming_viewing_key_2];
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -336,7 +336,7 @@ proptest! {
|
|||
|
||||
let mut data = Vec::new();
|
||||
|
||||
sk.zcash_serialize(&mut data).expect("sprout spending keyshould serialize");
|
||||
sk.zcash_serialize(&mut data).expect("sprout spending key should serialize");
|
||||
|
||||
let sk2 = SpendingKey::zcash_deserialize(&data[..]).expect("randomized sprout spending key should deserialize");
|
||||
|
||||
|
@ -360,7 +360,7 @@ proptest! {
|
|||
|
||||
let mut data = Vec::new();
|
||||
|
||||
ivk.zcash_serialize(&mut data).expect("t-addr should serialize");
|
||||
ivk.zcash_serialize(&mut data).expect("sprout z-addr should serialize");
|
||||
|
||||
let ivk2 = IncomingViewingKey::zcash_deserialize(&data[..]).expect("randomized ivk should deserialize");
|
||||
|
||||
|
|
Loading…
Reference in New Issue