mirror of https://github.com/zcash/orchard.git
added test for `native` note type
This commit is contained in:
parent
7d1a606d90
commit
6a10f456fc
|
@ -13,7 +13,7 @@ pub struct NoteType(pub(crate) pallas::Point);
|
||||||
// the hasher used to derive the assetID
|
// the hasher used to derive the assetID
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn assetID_hasher(msg: Vec<u8>) -> pallas::Point {
|
fn assetID_hasher(msg: Vec<u8>) -> pallas::Point {
|
||||||
// TODO(zsa) replace personalization, will require circuit change.
|
// TODO(zsa) replace personalization, will require circuit change?
|
||||||
pallas::Point::hash_to_curve(VALUE_COMMITMENT_PERSONALIZATION)(&msg)
|
pallas::Point::hash_to_curve(VALUE_COMMITMENT_PERSONALIZATION)(&msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
51
src/value.rs
51
src/value.rs
|
@ -408,6 +408,7 @@ pub mod testing {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::note::note_type::testing::arb_note_type;
|
use crate::note::note_type::testing::arb_note_type;
|
||||||
|
use crate::note::NoteType;
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
@ -416,6 +417,32 @@ mod tests {
|
||||||
};
|
};
|
||||||
use crate::primitives::redpallas;
|
use crate::primitives::redpallas;
|
||||||
|
|
||||||
|
fn _bsk_consistent_with_bvk(
|
||||||
|
values: &Vec<(ValueSum, ValueCommitTrapdoor)>,
|
||||||
|
note_type: NoteType,
|
||||||
|
) {
|
||||||
|
let value_balance = values
|
||||||
|
.iter()
|
||||||
|
.map(|(value, _)| value)
|
||||||
|
.sum::<Result<ValueSum, OverflowError>>()
|
||||||
|
.expect("we generate values that won't overflow");
|
||||||
|
|
||||||
|
let bsk = values
|
||||||
|
.iter()
|
||||||
|
.map(|(_, rcv)| rcv)
|
||||||
|
.sum::<ValueCommitTrapdoor>()
|
||||||
|
.into_bsk();
|
||||||
|
|
||||||
|
let bvk = (values
|
||||||
|
.into_iter()
|
||||||
|
.map(|(value, rcv)| ValueCommitment::derive(value.clone(), rcv.clone(), note_type))
|
||||||
|
.sum::<ValueCommitment>()
|
||||||
|
- ValueCommitment::derive(value_balance, ValueCommitTrapdoor::zero(), note_type))
|
||||||
|
.into_bvk();
|
||||||
|
|
||||||
|
assert_eq!(redpallas::VerificationKey::from(&bsk), bvk);
|
||||||
|
}
|
||||||
|
|
||||||
proptest! {
|
proptest! {
|
||||||
#[test]
|
#[test]
|
||||||
fn bsk_consistent_with_bvk(
|
fn bsk_consistent_with_bvk(
|
||||||
|
@ -426,26 +453,10 @@ mod tests {
|
||||||
),
|
),
|
||||||
arb_note_type in arb_note_type(),
|
arb_note_type in arb_note_type(),
|
||||||
) {
|
) {
|
||||||
let value_balance = values
|
// Test with native note type (zec)
|
||||||
.iter()
|
_bsk_consistent_with_bvk(&values, NoteType::native());
|
||||||
.map(|(value, _)| value)
|
// Test with arbitrary note type
|
||||||
.sum::<Result<ValueSum, OverflowError>>()
|
_bsk_consistent_with_bvk(&values, arb_note_type);
|
||||||
.expect("we generate values that won't overflow");
|
|
||||||
|
|
||||||
let bsk = values
|
|
||||||
.iter()
|
|
||||||
.map(|(_, rcv)| rcv)
|
|
||||||
.sum::<ValueCommitTrapdoor>()
|
|
||||||
.into_bsk();
|
|
||||||
|
|
||||||
let bvk = (values
|
|
||||||
.into_iter()
|
|
||||||
.map(|(value, rcv)| ValueCommitment::derive(value, rcv, arb_note_type))
|
|
||||||
.sum::<ValueCommitment>()
|
|
||||||
- ValueCommitment::derive(value_balance, ValueCommitTrapdoor::zero(), arb_note_type))
|
|
||||||
.into_bvk();
|
|
||||||
|
|
||||||
assert_eq!(redpallas::VerificationKey::from(&bsk), bvk);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue