mirror of https://github.com/zcash/orchard.git
added test for arb note_type
This commit is contained in:
parent
91466fe33f
commit
7d1a606d90
|
@ -280,7 +280,7 @@ impl fmt::Debug for TransmittedNoteCiphertext {
|
|||
pub mod testing {
|
||||
use proptest::prelude::*;
|
||||
|
||||
use crate::note::NoteType;
|
||||
use crate::note::note_type::testing::arb_note_type;
|
||||
use crate::{
|
||||
address::testing::arb_address, note::nullifier::testing::arb_nullifier, value::NoteValue,
|
||||
};
|
||||
|
@ -300,11 +300,12 @@ pub mod testing {
|
|||
recipient in arb_address(),
|
||||
rho in arb_nullifier(),
|
||||
rseed in arb_rseed(),
|
||||
note_type in arb_note_type(),
|
||||
) -> Note {
|
||||
Note {
|
||||
recipient,
|
||||
value,
|
||||
note_type: NoteType::native(),
|
||||
note_type,
|
||||
rho,
|
||||
rseed,
|
||||
}
|
||||
|
|
|
@ -37,14 +37,13 @@ impl NoteType {
|
|||
pub(super) fn derive(ak: &SpendValidatingKey, assetDesc: &[u8; 64]) -> Self {
|
||||
let mut s = vec![];
|
||||
|
||||
s.extend(&ak.to_bytes());
|
||||
s.extend(ak.to_bytes());
|
||||
s.extend(assetDesc);
|
||||
|
||||
NoteType(assetID_hasher(s))
|
||||
}
|
||||
|
||||
/// Note type for the "native" currency (zec), maintains backward compatibility with Orchard untyped notes.
|
||||
#[allow(non_snake_case)]
|
||||
pub fn native() -> Self {
|
||||
NoteType(assetID_hasher(VALUE_COMMITMENT_V_BYTES.to_vec()))
|
||||
}
|
||||
|
@ -54,21 +53,22 @@ impl NoteType {
|
|||
#[cfg(any(test, feature = "test-dependencies"))]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "test-dependencies")))]
|
||||
pub mod testing {
|
||||
use group::Group;
|
||||
use pasta_curves::{arithmetic::FieldExt, pallas};
|
||||
use proptest::collection::vec;
|
||||
use proptest::prelude::*;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use super::NoteType;
|
||||
|
||||
use crate::keys::{testing::arb_spending_key, FullViewingKey};
|
||||
|
||||
prop_compose! {
|
||||
/// Generate a uniformly distributed note type
|
||||
pub fn arb_nullifier()(
|
||||
bytes in vec(any::<u8>(), 64)
|
||||
pub fn arb_note_type()(
|
||||
sk in arb_spending_key(),
|
||||
bytes32a in prop::array::uniform32(prop::num::u8::ANY),
|
||||
bytes32b in prop::array::uniform32(prop::num::u8::ANY),
|
||||
) -> NoteType {
|
||||
let point = pallas::Point::generator() * pallas::Scalar::from_bytes_wide(&<[u8; 64]>::try_from(bytes).unwrap());
|
||||
NoteType(point)
|
||||
let bytes64 = [bytes32a, bytes32b].concat();
|
||||
let fvk = FullViewingKey::from(&sk);
|
||||
NoteType::derive(&fvk.into(), &bytes64.try_into().unwrap())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -407,7 +407,7 @@ pub mod testing {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::note::NoteType;
|
||||
use crate::note::note_type::testing::arb_note_type;
|
||||
use proptest::prelude::*;
|
||||
|
||||
use super::{
|
||||
|
@ -423,7 +423,8 @@ mod tests {
|
|||
arb_note_value_bounded(MAX_NOTE_VALUE / n_values as u64).prop_flat_map(move |bound|
|
||||
prop::collection::vec((arb_value_sum_bounded(bound), arb_trapdoor()), n_values)
|
||||
)
|
||||
)
|
||||
),
|
||||
arb_note_type in arb_note_type(),
|
||||
) {
|
||||
let value_balance = values
|
||||
.iter()
|
||||
|
@ -439,9 +440,9 @@ mod tests {
|
|||
|
||||
let bvk = (values
|
||||
.into_iter()
|
||||
.map(|(value, rcv)| ValueCommitment::derive(value, rcv, NoteType::native()))
|
||||
.map(|(value, rcv)| ValueCommitment::derive(value, rcv, arb_note_type))
|
||||
.sum::<ValueCommitment>()
|
||||
- ValueCommitment::derive(value_balance, ValueCommitTrapdoor::zero(), NoteType::native()))
|
||||
- ValueCommitment::derive(value_balance, ValueCommitTrapdoor::zero(), arb_note_type))
|
||||
.into_bvk();
|
||||
|
||||
assert_eq!(redpallas::VerificationKey::from(&bsk), bvk);
|
||||
|
|
Loading…
Reference in New Issue